
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@7:032ae28fae2e, 2014-01-11 (annotated)
- Committer:
- okano
- Date:
- Sat Jan 11 02:05:17 2014 +0000
- Revision:
- 7:032ae28fae2e
- Parent:
- 6:11b35048d384
- Child:
- 8:6f3f8e5da87b
version 4 : Output pulse pattern in array
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 4:3cb4e78e0846 | 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 | 4:3cb4e78e0846 | 3 | // |
okano | 7:032ae28fae2e | 4 | // version 4 : Output pulse pattern in array |
okano | 0:6e775c640f78 | 5 | |
okano | 0:6e775c640f78 | 6 | #include "mbed.h" |
okano | 0:6e775c640f78 | 7 | |
okano | 6:11b35048d384 | 8 | BusOut motor_out( p26, p25, p24, p23 ); |
okano | 0:6e775c640f78 | 9 | |
okano | 1:e49f906a4dbd | 10 | #define INTERVAL 0.01 |
okano | 1:e49f906a4dbd | 11 | |
okano | 7:032ae28fae2e | 12 | char pattern[] = { 1, 2, 4, 8 }; |
okano | 7:032ae28fae2e | 13 | |
okano | 4:3cb4e78e0846 | 14 | int main() |
okano | 4:3cb4e78e0846 | 15 | { |
okano | 0:6e775c640f78 | 16 | while(1) { |
okano | 4:3cb4e78e0846 | 17 | |
okano | 4:3cb4e78e0846 | 18 | // pulse orser : "p26 -> p25 -> p24 -> p23" for 4*90(=360) steps |
okano | 4:3cb4e78e0846 | 19 | |
okano | 4:3cb4e78e0846 | 20 | for ( int i = 0; i < 90; i++ ) { |
okano | 7:032ae28fae2e | 21 | motor_out = pattern[ 0 ]; |
okano | 4:3cb4e78e0846 | 22 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 23 | |
okano | 7:032ae28fae2e | 24 | motor_out = pattern[ 1 ]; |
okano | 4:3cb4e78e0846 | 25 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 26 | |
okano | 7:032ae28fae2e | 27 | motor_out = pattern[ 2 ]; |
okano | 4:3cb4e78e0846 | 28 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 29 | |
okano | 7:032ae28fae2e | 30 | motor_out = pattern[ 3 ]; |
okano | 4:3cb4e78e0846 | 31 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 32 | } |
okano | 4:3cb4e78e0846 | 33 | |
okano | 4:3cb4e78e0846 | 34 | // pulse orser : "p23 -> p24 -> p25 -> p26" for 4*90(=360) steps |
okano | 4:3cb4e78e0846 | 35 | |
okano | 4:3cb4e78e0846 | 36 | for ( int i = 0; i < 90; i++ ) { |
okano | 7:032ae28fae2e | 37 | motor_out = pattern[ 3 ]; |
okano | 4:3cb4e78e0846 | 38 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 39 | |
okano | 7:032ae28fae2e | 40 | motor_out = pattern[ 2 ]; |
okano | 4:3cb4e78e0846 | 41 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 42 | |
okano | 7:032ae28fae2e | 43 | motor_out = pattern[ 1 ]; |
okano | 4:3cb4e78e0846 | 44 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 45 | |
okano | 7:032ae28fae2e | 46 | motor_out = pattern[ 0 ]; |
okano | 4:3cb4e78e0846 | 47 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 48 | } |
okano | 0:6e775c640f78 | 49 | } |
okano | 0:6e775c640f78 | 50 | } |