Hello, I have a little problem in programming a stepper motor with PIC16f877A.
I'm not so familiar with programming, but I have an stepper motor wich I want to program to do a specific number of steps when an input signal is applied
to PORTB where I have 5 inputs buttons. In Proteus this code worked well, but when I made the circuit on breadboard, motor is only spinning clockwise.. and it not spinning only 50 steps as I specified in program, it just keep spinning as long as I keep the button for clockwise pushed, when the button for cclockwise is pressed, I got nothing.
I'm using ULN2003AN as steper motor driver and 28byj-48 motor.
The surce code is shown below:
Can you please help me?
Moderators note: used code tags
I'm not so familiar with programming, but I have an stepper motor wich I want to program to do a specific number of steps when an input signal is applied
to PORTB where I have 5 inputs buttons. In Proteus this code worked well, but when I made the circuit on breadboard, motor is only spinning clockwise.. and it not spinning only 50 steps as I specified in program, it just keep spinning as long as I keep the button for clockwise pushed, when the button for cclockwise is pressed, I got nothing.
I'm using ULN2003AN as steper motor driver and 28byj-48 motor.
The surce code is shown below:
C:
int clockwise[]={0b00001100,0b00000110,0b00000011,0b00001001};
int cclockwise[]={0b00001001,0b00000011,0b00000110,0b00001100};
int i;
int y;
int a;
int count;
int k;
void main() {
TRISD = 0b00000000; // PORT D as output port
TRISB = 0b11111111; // PORT B as input port
PORTD = 0b00000000;
PORTB = 0b00110000;
k=0; //condition
do
{
if((PORTB.RB3==1||PORTB.RB1==1) && k==0 ) //buttons input
{
k=1;
a=50; // number of steps
for(y=0;y<a;y++)
{
i=y%4;
PORTD=clockwise[I];
delay_ms(70); // speed
}
}
else if((PORTB.RB5==0) && k==0) //buttons input
{
k=1;
a=50;
for(y=0;y<a;y++)
{
i=y%4;
PORTD=clockwise[I];
delay_ms(40);
}
}
else
if((PORTB.RB4==1||PORTB.RB2==1) && k==1 )// buttons input
{
k=0;
a=50;
for(y=0;y<a;y++)
{
i=y%4;
PORTD=cclockwise[I];
delay_ms(70);
}
}
}
while(1);
}
Can you please help me?
Moderators note: used code tags