
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@9:e568dea69ab5, 2014-01-11 (annotated)
- Committer:
- okano
- Date:
- Sat Jan 11 02:11:56 2014 +0000
- Revision:
- 9:e568dea69ab5
- Parent:
- 8:6f3f8e5da87b
- Child:
- 10:f00d0b8775d4
version 6 : 2-phase drive
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 | 9:e568dea69ab5 | 4 | // version 6 : 2-phase drive |
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 | 9:e568dea69ab5 | 12 | // 1-phase drive pattern |
okano | 9:e568dea69ab5 | 13 | // char pattern[] = { 1, 2, 4, 8 }; |
okano | 9:e568dea69ab5 | 14 | |
okano | 9:e568dea69ab5 | 15 | // 2-phase drive pattern |
okano | 9:e568dea69ab5 | 16 | char pattern[] = { 0x3, 0x6, 0xC, 0x9 }; |
okano | 7:032ae28fae2e | 17 | |
okano | 4:3cb4e78e0846 | 18 | int main() |
okano | 4:3cb4e78e0846 | 19 | { |
okano | 0:6e775c640f78 | 20 | while(1) { |
okano | 4:3cb4e78e0846 | 21 | |
okano | 4:3cb4e78e0846 | 22 | // pulse orser : "p26 -> p25 -> p24 -> p23" for 4*90(=360) steps |
okano | 4:3cb4e78e0846 | 23 | |
okano | 8:6f3f8e5da87b | 24 | for ( int i = 0; i < 360; i++ ) { |
okano | 8:6f3f8e5da87b | 25 | motor_out = pattern[ i % 4 ]; |
okano | 4:3cb4e78e0846 | 26 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 27 | } |
okano | 4:3cb4e78e0846 | 28 | |
okano | 4:3cb4e78e0846 | 29 | // pulse orser : "p23 -> p24 -> p25 -> p26" for 4*90(=360) steps |
okano | 4:3cb4e78e0846 | 30 | |
okano | 8:6f3f8e5da87b | 31 | for ( int i = 0; i < 360; i++ ) { |
okano | 8:6f3f8e5da87b | 32 | motor_out = pattern[ 3 - (i % 4) ]; |
okano | 4:3cb4e78e0846 | 33 | wait( INTERVAL ); |
okano | 4:3cb4e78e0846 | 34 | } |
okano | 0:6e775c640f78 | 35 | } |
okano | 0:6e775c640f78 | 36 | } |