Hardware Reference
In-Depth Information
55 enable(int enable) {
56 gpio_write(g_enable, enable);
57 }
58
59 /*
60 * Drive the appropriate GPIO outputs :
61 */
62 static void
63 drive(int L1L2) {
64 gpio_write(g_in1, L1L2&0x08);
65 gpio_write(g_in2, L1L2&0x04);
66 gpio_write(g_in3, L1L2&0x02);
67 gpio_write(g_in4, L1L2&0x01);
68 }
69
70 /*
71 * Take one step in a direction :
72 */
73 static void
74 step(int direction) {
75 static const int modes[3][8] = {
76 { 0b1000, 0b0010, 0b0100, 0b0001 }, /* Mode 1 */
77 { 0b1010, 0b0110, 0b0101, 0b1001 }, /* Mode 2 */
78 { 0b1000, 0b1010, 0b0010, 0b0110, 0b0100, 0b0101,
0b0001, 0b1001 }
79 } ;
80 static int stepno = 0; /* Last step no.*/
81 int m = stepper_mode < 2 ? 4 : 8; /* Max steps for mode */
82
83 if ( direction < 0 )
84 direction = m − 1;
85
86 enable(0); /* Disable motor */
87 drive(modes[stepper_mode][stepno]); /* Change fields */
88 enable(1); /* Drive motor */
89
90 stepno = (stepno+direction) % m; /* Next step */
91 }
92
93 /*
94 * Set the stepper mode of operation :
95 */
96 static inline void
Search WWH ::




Custom Search