Very simple operation samples of unipolar stepper motor. This code has been made to help beginners to learn the stepper motor. The history of the code shows the how to generate pulses from very basic level.
Diff: main.cpp
- Revision:
- 7:032ae28fae2e
- Parent:
- 6:11b35048d384
- Child:
- 8:6f3f8e5da87b
diff -r 11b35048d384 -r 032ae28fae2e main.cpp --- a/main.cpp Sat Jan 11 01:58:21 2014 +0000 +++ b/main.cpp Sat Jan 11 02:05:17 2014 +0000 @@ -1,7 +1,7 @@ // stepper motor operation sample (learn it step by step). // showing how to control a unipolar stepper motor by mbed digital output ports. // -// version 3 : Operation by BusOut +// version 4 : Output pulse pattern in array #include "mbed.h" @@ -9,6 +9,8 @@ #define INTERVAL 0.01 +char pattern[] = { 1, 2, 4, 8 }; + int main() { while(1) { @@ -16,32 +18,32 @@ // pulse orser : "p26 -> p25 -> p24 -> p23" for 4*90(=360) steps for ( int i = 0; i < 90; i++ ) { - motor_out = 1; + motor_out = pattern[ 0 ]; wait( INTERVAL ); - motor_out = 2; + motor_out = pattern[ 1 ]; wait( INTERVAL ); - motor_out = 4; + motor_out = pattern[ 2 ]; wait( INTERVAL ); - motor_out = 8; + motor_out = pattern[ 3 ]; wait( INTERVAL ); } // pulse orser : "p23 -> p24 -> p25 -> p26" for 4*90(=360) steps for ( int i = 0; i < 90; i++ ) { - motor_out = 8; + motor_out = pattern[ 3 ]; wait( INTERVAL ); - motor_out = 4; + motor_out = pattern[ 2 ]; wait( INTERVAL ); - motor_out = 2; + motor_out = pattern[ 1 ]; wait( INTERVAL ); - motor_out = 1; + motor_out = pattern[ 0 ]; wait( INTERVAL ); } }