Program Stepper motor to do a specific number of steps

Thread Starter

voldeparso

Joined Apr 10, 2016
6
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:

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
 

Thread Starter

voldeparso

Joined Apr 10, 2016
6
Thank you for your reply, yes they do have pull-up resistors. I checked with multimeter and when I press cclockwise button, the voltage of the output pins of ULN2003 is 5V, all of them. I start to think is something wrong with the way I wired stepper motor to the driver
 

AlbertHall

Joined Jun 4, 2014
12,347
Lines 20 and 43 enable action when the buttons are NOT pressed. If the intended action is that nothing should happen until a button is pressed then change the conditions for RB1, RB2, RB3, and RB4 to '= 0'. Then let us know what happens.
 
Top