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.

Dependencies:   mbed

Committer:
okano
Date:
Sat Jan 11 02:08:45 2014 +0000
Revision:
8:6f3f8e5da87b
Parent:
7:032ae28fae2e
Child:
9:e568dea69ab5
version 5 : Smaller loop using array index

Who changed what in which revision?

UserRevisionLine numberNew 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 8:6f3f8e5da87b 4 // version 5 : Smaller loop using array index
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 8:6f3f8e5da87b 20 for ( int i = 0; i < 360; i++ ) {
okano 8:6f3f8e5da87b 21 motor_out = pattern[ i % 4 ];
okano 4:3cb4e78e0846 22 wait( INTERVAL );
okano 4:3cb4e78e0846 23 }
okano 4:3cb4e78e0846 24
okano 4:3cb4e78e0846 25 // pulse orser : "p23 -> p24 -> p25 -> p26" for 4*90(=360) steps
okano 4:3cb4e78e0846 26
okano 8:6f3f8e5da87b 27 for ( int i = 0; i < 360; i++ ) {
okano 8:6f3f8e5da87b 28 motor_out = pattern[ 3 - (i % 4) ];
okano 4:3cb4e78e0846 29 wait( INTERVAL );
okano 4:3cb4e78e0846 30 }
okano 0:6e775c640f78 31 }
okano 0:6e775c640f78 32 }