Thursday, February 25, 2010

Embedded System Design 1 - Stepper Motor Driver Program

Components

  • 4 x PUSH BUTTON (SW1 – SW4)
  • 4 x RESISTOR 10K (R1 – R4)
  • 4 x RESISTOR 3.3K (R6 – R9)
  • 4 x MOTOR DRIVE TRANSISTOR (TR2 – TR5)
  • 4 x FORWARD BIAS DIODE (D1 - D4)
  • 1 x STEPPER MOTOR (42SPM – 24DCZA)
  • 1 x POWER SUPPLY (9V)
  • BREADBOARD
  • 1 x PIC16F887


Description

This is the stepper motor driver program to drive the 2 phase unipolar stepper motor either to turn 90 degrees to the left or 90 degrees to the right from its current direction depends on the input from the user using the PUSH BUTTON LEFT, RIGHT AND STOP.

Circuit Diagram
C Source Code

#include<16f887.h>

#device ICD=TRUE

#fuses HS, NOLVP, NOWDT

#use delay(clock = 20000000)

#byte PORTA = 8


#define STOP PIN_B1

#define LEFT PIN_B0

#define RIGHT PIN_B2


void main(){


SET_TRIS_A(0x00); //PORTA all is output

SET_TRIS_B(0x27); //RB0,1,2,5 = INPUT , RB7 = OUTPUT

PORTA = 0x05; //Initialize the PORTA to 0000 0101 '0' degree of angle

while(TRUE){

if(!input(PIN_B1)) //PUSH BUTTON TO STOP THE STEPPER MOTOR

PORTA = 0x05;

//PUSH BUTTON TO TURN THE STEPPER MOTOR TO THE LEFT

if(!input(PIN_B0)){

//if at 0 degree, turn the motor to left to new direction

//90 degree to the left

if(PORTA == 0x05){

PORTA = 0x06;

delay_ms(5000);

goto esc;

}

//if at 90 degree and to the left, turn the motor to the new direction

//180 degree to the left

else if(PORTA == 0x06){

PORTA = 0x0A;

delay_ms(5000);

goto esc;

}

//if at 180 degree and to the left, turn the motor to the new direction

//270 degree to the left

else if(PORTA == 0x0A){

PORTA = 0x09;

delay_ms(5000);

goto esc;

}


//if at 270 degree and to the left, turn the motor to the new direction

//0 degree

else if(PORTA == 0x09){

PORTA = 0x05;

delay_ms(5000);

goto esc;

}

}

//PUSH BUTTON TO TURN THE MOTOR TO THE RIGHT

if(!input(PIN_B2)){

//if at 0 degree, turn the motor to right to new direction

//90 degree to the right

if(PORTA == 0x05){

PORTA = 0x09;

delay_ms(5000);

goto esc;

}

//if at 90 degree and to the right, turn the motor to the new direction

//180 degree to the right

else if(PORTA == 0x09){

PORTA = 0x0A;

delay_ms(5000);

goto esc;

}

//if at 180 degree and to the right, turn the motor to the new direction

//270 degree to the right

else if(PORTA == 0x0A){

PORTA = 0x06;

delay_ms(5000);

goto esc;

}

//if at 270 degree and to the right, turn the motor to the new direction

//0 degree

else if(PORTA == 0x06){

PORTA = 0x05;

delay_ms(5000);

goto esc;

}

}

esc: continue;

}

}


References

http://www.massmind.org/images/www/hobby_elec/e_step.htm

http://www.imagesco.com/articles/picstepper/03.html



Written By
-OWJ@2010-

0 comments: