SLOA312 December   2021 DRV8412 , DRV8424 , DRV8426 , DRV8428 , DRV8434 , DRV8436 , DRV8803 , DRV8804 , DRV8805 , DRV8806 , DRV8844 , DRV8847 , DRV8932 , DRV8935 , DRV8955

PRODUCTION DATA  

  1.   Trademarks
  2. 1Introduction
  3. 2Principle of Operation
    1. 2.1 Unipolar Stepper Motors
    2. 2.2 Bipolar Stepper Motors
  4. 3How to Drive Unipolar Stepper Motors with DRV8xxx Drivers
    1. 3.1 Driving Unipolar Motor with Four-channel Low-side Driver
    2. 3.2 Driving a Unipolar Motor with a Bipolar Driver
    3. 3.3 Driving Unipolar Motor with Four-channel Half-Bridge Driver
      1. 3.3.1 Driving in Full-step Mode
        1. 3.3.1.1 Full-step Mode with One Phase ON
        2. 3.3.1.2 Two Phases ON
      2. 3.3.2 Driving in Half-step Mode
      3. 3.3.3 Example Pseudocode
        1. 3.3.3.1 Code for Full-step with One Phase ON
        2. 3.3.3.2 Code for Full-step with Two Phase ON
        3. 3.3.3.3 Code for Half-step
  5. 4References

Code for Half-step

1. /// 0111 0011 1011 1001 1101 1100 1110 0110 // input format
2.	
3. int in1 = 8;
4. int in2 = 9;
5. int in3 = 10;
6. int in4 = 11;
7.	
8. int i = 0;
9. int freq = 200;
10.       unsigned long t_half =0.5*(1000000/freq);
11.	
12.	
13.       void setup()
14.       {
15.         pinMode(in1, OUTPUT);
16.         pinMode(in2, OUTPUT);
17.         pinMode(in3, OUTPUT);
18.         pinMode(in4, OUTPUT);
19.       }
20.	
21.       void loop() {
22.         delayMicroseconds(t_half);
23.         i=i+1;
24.         if (i >=8)  {i=0;}
25.        switch(i)
26.        {
27.         case 0:
28.           digitalWrite(in1,LOW);
29.           digitalWrite(in3,HIGH);
30.           digitalWrite(in2,HIGH);
31.           digitalWrite(in4,HIGH);
32.         break;
33.         case 1:
34.           digitalWrite(in1,LOW);
35.           digitalWrite(in3,LOW);
36.           digitalWrite(in2,HIGH);
37.           digitalWrite(in4,HIGH);
38.         break;
39.         case 2:
40.           digitalWrite(in1,HIGH);
41.           digitalWrite(in3,LOW);
42.           digitalWrite(in2,HIGH);
43.           digitalWrite(in4,HIGH);
44.         break;
45.         case 3:
46.           digitalWrite(in1,HIGH);
47.           digitalWrite(in3,LOW);
48.           digitalWrite(in2,LOW);
49.           digitalWrite(in4,HIGH);
50.         break;
51.         case 4:
52.           digitalWrite(in1,HIGH);
53.           digitalWrite(in3,HIGH);
54.           digitalWrite(in2,LOW);
55.           digitalWrite(in4,HIGH);
56.         break;
57.         case 5:
58.           digitalWrite(in1,HIGH);
59.           digitalWrite(in3,HIGH);
60.           digitalWrite(in2,LOW);
61.           digitalWrite(in4,LOW);
62.         break;
63.         case 6:
64.           digitalWrite(in1,HIGH);
65.           digitalWrite(in3,HIGH);
66.           digitalWrite(in2,HIGH);
67.           digitalWrite(in4,LOW);
68.         break;
69.         case 7:
70.           digitalWrite(in1,LOW);
71.           digitalWrite(in3,HIGH);
72.           digitalWrite(in2,HIGH);
73.           digitalWrite(in4,LOW);
74.         break;
75.         }
76.       }