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:
3:db008e5009d0
Parent:
2:e9fbf2c17789
Child:
4:3cb4e78e0846

File content as of revision 3:db008e5009d0:

//  stepper motor operation sample (learn it step by step). 
//  showing how to control a unipolar stepper motor by mbed digital output ports.
//  
//  version 1-1 : Rotate motor in reverse direction

#include "mbed.h"

DigitalOut  motor_out0( p26 );
DigitalOut  motor_out1( p25 );
DigitalOut  motor_out2( p24 );
DigitalOut  motor_out3( p23 );

#define     INTERVAL    0.01

int main() {
    
    while(1) {
        
        motor_out0  = 0;
        motor_out1  = 0;
        motor_out2  = 0;
        motor_out3  = 1;
        wait( INTERVAL );
        
        motor_out0  = 0;
        motor_out1  = 0;
        motor_out2  = 1;
        motor_out3  = 0;
        wait( INTERVAL );
        
        motor_out0  = 0;
        motor_out1  = 1;
        motor_out2  = 0;
        motor_out3  = 0;
        wait( INTERVAL );
        
        motor_out0  = 1;
        motor_out1  = 0;
        motor_out2  = 0;
        motor_out3  = 0;
        wait( INTERVAL );
    }
}