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

main.cpp

Committer:
okano
Date:
2014-01-11
Revision:
6:11b35048d384
Parent:
4:3cb4e78e0846
Parent:
5:28bbda0fe9b5
Child:
7:032ae28fae2e

File content as of revision 6:11b35048d384:

//  stepper motor operation sample (learn it step by step).
//  showing how to control a unipolar stepper motor by mbed digital output ports.
//
//  version 3 : Operation by BusOut

#include "mbed.h"

BusOut      motor_out( p26, p25, p24, p23 );

#define     INTERVAL    0.01

int main()
{
    while(1) {

        //  pulse orser : "p26 -> p25 -> p24 -> p23" for 4*90(=360) steps

        for ( int i = 0; i < 90; i++ ) {
            motor_out   = 1;
            wait( INTERVAL );

            motor_out   = 2;
            wait( INTERVAL );

            motor_out   = 4;
            wait( INTERVAL );

            motor_out   = 8;
            wait( INTERVAL );
        }

        //  pulse orser : "p23 -> p24 -> p25 -> p26" for 4*90(=360) steps

        for ( int i = 0; i < 90; i++ ) {
            motor_out   = 8;
            wait( INTERVAL );

            motor_out   = 4;
            wait( INTERVAL );

            motor_out   = 2;
            wait( INTERVAL );

            motor_out   = 1;
            wait( INTERVAL );
        }
    }
}