Im basically writing a c code to control a rs 440-420 stepper motor using a PIC16F648A. The task is to have two switch which will control the direction of the motor (clockwise/anticlockwise).
i have written all of the code, the genernal idea is when the clockwise switch is 1(active high) the motor will turn clockwise and when the anticlockwise is high it will go anticlockwise and when both are zero the motor will not turn.
the code works up to when i want the motor to turn anticlockwise it goes clockwise but when i want it to go clockwise it turns clockwise. theys no problems with the circuit.
This is my c code.
i have attached the datasheets for the motor and the PIC device.
If u can help in any way i really appreciate it.
Thank you
i have written all of the code, the genernal idea is when the clockwise switch is 1(active high) the motor will turn clockwise and when the anticlockwise is high it will go anticlockwise and when both are zero the motor will not turn.
the code works up to when i want the motor to turn anticlockwise it goes clockwise but when i want it to go clockwise it turns clockwise. theys no problems with the circuit.
This is my c code.
Rich (BB code):
#include <16F648A.h>
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO,NOPUT, NOPROTECT, NOLVP, NOMCLR
struct Motor_pin{
boolean forward:1;
boolean backward:1;
int unused:6;
int motor_pin_output:4;
int unused2:4;
};
int const LUTB[4]={0x03, 0x06, 0x0c, 0x09};
int const LUTF[4]={0x09, 0x0c, 0x06, 0x03};
static struct Motor_pin motor1;
static struct Motor_pin direction;
void forward_stepper(int steps)
{
int i;
for(i=0;i<=steps;i++)
{ motor1.motor_pin_output=LUTF[i%4];
delay_ms(20);
}
}
void backward_stepper(int steps)
{
int i;
for(i=steps;i>0;i--)
{ motor1.motor_pin_output=LUTB[i%4];
delay_ms(20);
}
}
void variables()
{
direction.forward = 1;
direction.backward = 1;
direction.motor_pin_output = 0x00;
}
void main ()
{
int forever=1;
#byte motor1 = 0x05
#byte direction = 0x85
variables();
while(forever)
{
if(motor1.forward == 1)
forward_stepper(100);
else
if (motor1.backward == 1)
backward_stepper(100);
}
}
If u can help in any way i really appreciate it.
Thank you
Attachments
-
194.5 KB Views: 42
-
2.7 MB Views: 40