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 01:58:21 2014 +0000
Revision:
6:11b35048d384
Parent:
4:3cb4e78e0846
Parent:
5:28bbda0fe9b5
Child:
7:032ae28fae2e
version 3 : Operation by BusOut

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 6:11b35048d384 4 // version 3 : Operation by BusOut
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 4:3cb4e78e0846 12 int main()
okano 4:3cb4e78e0846 13 {
okano 0:6e775c640f78 14 while(1) {
okano 4:3cb4e78e0846 15
okano 4:3cb4e78e0846 16 // pulse orser : "p26 -> p25 -> p24 -> p23" for 4*90(=360) steps
okano 4:3cb4e78e0846 17
okano 4:3cb4e78e0846 18 for ( int i = 0; i < 90; i++ ) {
okano 6:11b35048d384 19 motor_out = 1;
okano 4:3cb4e78e0846 20 wait( INTERVAL );
okano 4:3cb4e78e0846 21
okano 6:11b35048d384 22 motor_out = 2;
okano 4:3cb4e78e0846 23 wait( INTERVAL );
okano 4:3cb4e78e0846 24
okano 6:11b35048d384 25 motor_out = 4;
okano 4:3cb4e78e0846 26 wait( INTERVAL );
okano 4:3cb4e78e0846 27
okano 6:11b35048d384 28 motor_out = 8;
okano 4:3cb4e78e0846 29 wait( INTERVAL );
okano 4:3cb4e78e0846 30 }
okano 4:3cb4e78e0846 31
okano 4:3cb4e78e0846 32 // pulse orser : "p23 -> p24 -> p25 -> p26" for 4*90(=360) steps
okano 4:3cb4e78e0846 33
okano 4:3cb4e78e0846 34 for ( int i = 0; i < 90; i++ ) {
okano 6:11b35048d384 35 motor_out = 8;
okano 4:3cb4e78e0846 36 wait( INTERVAL );
okano 4:3cb4e78e0846 37
okano 6:11b35048d384 38 motor_out = 4;
okano 4:3cb4e78e0846 39 wait( INTERVAL );
okano 4:3cb4e78e0846 40
okano 6:11b35048d384 41 motor_out = 2;
okano 4:3cb4e78e0846 42 wait( INTERVAL );
okano 4:3cb4e78e0846 43
okano 6:11b35048d384 44 motor_out = 1;
okano 4:3cb4e78e0846 45 wait( INTERVAL );
okano 4:3cb4e78e0846 46 }
okano 0:6e775c640f78 47 }
okano 0:6e775c640f78 48 }