Debian Codegraph @

docs/stepper.md

raw symbols SCIP
1 # Built-in stepper motor sequence generator
2
3 Stepper motors move by taking precise steps. This means that the controller can move to a defined
4 position, and back to the starting position without errors. Motors can have large step sizes (20 steps per revolution), or very small (600/rev)
5
6
7 The kuttypy GUI can generate a full step sequence for controlling 4 wire stepper motors via PB0-PB3 pins.
8 Since the current driving capability of the ATMEGA32 is somewhat limited, it is
9 advisable to use a push-pull driver IC such as the L293D with larger motors.
10
11 ![Screenshot](images/stepper.png)
12
13 ## Procedure
14
15 - Launch the window from the menu on the bottom right side of the screen
16 - Connect 4 wire, 2 phase stepper motor's A+,B+,A-,B- to PB0, PB1, PB2, PB3
17 - use the left and right arrow buttons to take single steps
18 - home button to return to original position
19 - the numeric entry field to move to a different position
20
21 ## Video of the stepping sequence
22 LEDs are connected to PB0-PB3 to show the stepping signal outputs
23
24 <video controls width="600">
25 <source src="../images/stepper.webm"
26 type="video/webm">
27 Sorry, your browser doesn't support embedded videos.
28 </video>
29
30 ## Applications
31
32 - Move a light sensor (TSL2561) along a diffraction pattern, and record the intensity profile
33 - Rotate the analyzer in a [Malus's law experiment](../malus), and record the intensity variation which corresponds to IoCos^2(Theta)$
34
35
36 # C Code for controlling
37
38 We'll be using the 28BYJ-48 stepper motor and its controller. It is unipolar.
39 B0 to B3 pins will be set as output, and the stepping sequence will be applied to
40 these pins.
41
42 ![](images/stepper-photo.jpeg)
43
44 The motor driver
45
46 ![](images/stepper-driver-photo.jpeg)
47
48
49 ```python
50 #include<avr/kp.h>
51
52 #define DELAY 5
53 #define STEPS 200
54 int main (void)
55 {
56 DDRB = 15; //For controlling the stepper motor
57 uint8_t steps[]={0b1100,0b0110,0b0011,0b1001}; // 12,6,3,9
58 uint16_t pos = 0;
59 for(;;)
60 {
61 for(pos=0;pos<STEPS;pos++){
62 PORTB=steps[2];
63 delay_ms(DELAY);
64 PORTB=steps[1];
65 delay_ms(DELAY);
66 PORTB=steps[0];
67 delay_ms(DELAY);
68 PORTB=steps[3];
69 delay_ms(DELAY);
70 }
71 for(pos=0;pos<STEPS;pos++){
72 PORTB=steps[0];
73 delay_ms(DELAY);
74 PORTB=steps[1];
75 delay_ms(DELAY);
76 PORTB=steps[2];
77 delay_ms(DELAY);
78 PORTB=steps[3];
79 delay_ms(DELAY);
80 }
81 }
82 return 0;
83 }
84 ```
85
86
87 ## Stepping Sequence
88
89 ```commandline
90 // Connect pins B0 to B3 for the motor driver input.
91
92 wave drive sequence
93 Step B0 B1 B2 B3 Decimal
94 1 1 0 0 0 1
95 2 0 1 0 0 2
96 3 0 0 1 0 4
97 4 0 0 0 1 8
98 5 1 0 0 0 1 (Repeat)
99
100
101 Full Step
102
103 Step B0 B1 B2 B3 Decimal
104 1 1 1 0 0 3
105 2 0 1 1 0 6
106 3 0 0 1 1 12
107 4 1 0 0 1 9
108 5 1 1 0 0 3 (Repeat)
109
110
111 Half Step ( used in the C code below )
112
113 Step B0 B1 B2 B3 Decimal
114 1 1 0 0 0 1
115 2 1 1 0 0 3
116 3 0 1 0 0 2
117 4 0 1 1 0 6
118 5 0 0 1 0 4
119 6 0 0 1 1 12
120 7 0 0 0 1 8
121 8 1 0 0 1 9
122 9 1 0 0 0 1 (Repeat)
123
124 ```