
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.
main.cpp@2:e9fbf2c17789, 2014-01-11 (annotated)
- Committer:
- okano
- Date:
- Sat Jan 11 01:31:36 2014 +0000
- Revision:
- 2:e9fbf2c17789
- Parent:
- 1:e49f906a4dbd
- Child:
- 3:db008e5009d0
version 1 : Output pulses to p23, p24, p25 and p26 ports
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:6e775c640f78 | 1 | // stepper motor operation sample (learn it step by step). |
okano | 0:6e775c640f78 | 2 | // showing how to control a unipolar stepper motor by mbed digital output ports. |
okano | 0:6e775c640f78 | 3 | // |
okano | 2:e9fbf2c17789 | 4 | // version 1 : Output pulses to p23, p24, p25 and p26 ports |
okano | 0:6e775c640f78 | 5 | |
okano | 0:6e775c640f78 | 6 | #include "mbed.h" |
okano | 0:6e775c640f78 | 7 | |
okano | 2:e9fbf2c17789 | 8 | DigitalOut motor_out0( p26 ); |
okano | 2:e9fbf2c17789 | 9 | DigitalOut motor_out1( p25 ); |
okano | 2:e9fbf2c17789 | 10 | DigitalOut motor_out2( p24 ); |
okano | 2:e9fbf2c17789 | 11 | DigitalOut motor_out3( p23 ); |
okano | 0:6e775c640f78 | 12 | |
okano | 1:e49f906a4dbd | 13 | #define INTERVAL 0.01 |
okano | 1:e49f906a4dbd | 14 | |
okano | 0:6e775c640f78 | 15 | int main() { |
okano | 1:e49f906a4dbd | 16 | |
okano | 0:6e775c640f78 | 17 | while(1) { |
okano | 0:6e775c640f78 | 18 | |
okano | 0:6e775c640f78 | 19 | motor_out0 = 1; |
okano | 0:6e775c640f78 | 20 | motor_out1 = 0; |
okano | 0:6e775c640f78 | 21 | motor_out2 = 0; |
okano | 0:6e775c640f78 | 22 | motor_out3 = 0; |
okano | 1:e49f906a4dbd | 23 | wait( INTERVAL ); |
okano | 0:6e775c640f78 | 24 | |
okano | 0:6e775c640f78 | 25 | motor_out0 = 0; |
okano | 0:6e775c640f78 | 26 | motor_out1 = 1; |
okano | 0:6e775c640f78 | 27 | motor_out2 = 0; |
okano | 0:6e775c640f78 | 28 | motor_out3 = 0; |
okano | 1:e49f906a4dbd | 29 | wait( INTERVAL ); |
okano | 0:6e775c640f78 | 30 | |
okano | 0:6e775c640f78 | 31 | motor_out0 = 0; |
okano | 0:6e775c640f78 | 32 | motor_out1 = 0; |
okano | 0:6e775c640f78 | 33 | motor_out2 = 1; |
okano | 0:6e775c640f78 | 34 | motor_out3 = 0; |
okano | 1:e49f906a4dbd | 35 | wait( INTERVAL ); |
okano | 0:6e775c640f78 | 36 | |
okano | 0:6e775c640f78 | 37 | motor_out0 = 0; |
okano | 0:6e775c640f78 | 38 | motor_out1 = 0; |
okano | 0:6e775c640f78 | 39 | motor_out2 = 0; |
okano | 0:6e775c640f78 | 40 | motor_out3 = 1; |
okano | 1:e49f906a4dbd | 41 | wait( INTERVAL ); |
okano | 0:6e775c640f78 | 42 | } |
okano | 0:6e775c640f78 | 43 | } |