I am using arduino to drive a bipolar stepper motor. The circuit goes like this: Adruino --> L298 Hbridge -->Stepper motor.
I am using this sequence (x1 x2 y1 y2)= 1010-->0110-->0101-->1001 (and the opposite way for anticlockwise) to step the motor.
The problem is whenever I ask the stepper to run clockwise for say 10 steps, it first steps 1 step in anti clockwise direction then continues in the clockwise direction for the rest of the steps so I eventually get only 8 steps stepped in the direction that i want ( 1 step stepped in wrong direction and 1 step to come back to the initial position are lost). The vice versa happens if I want to step in the anti clockwise direction as well. I looked up the stepper library of arduino and found that the step sequence that i am using is indeed correct. I don't know where I am going wrong. Please help me.
@Robin2 The sequence that i had posted is the recommended sequence that is widely used.Even the stepper library of arduino uses the same ( can be found here: bit.ly/NUt2Pw )I am sure the physical connections are proper. Also if there were some problems with the connection like a swap or a dry solder it will affect the entire experiment and not just the first step.
@MarkT I am using a 6V 1.2 A motor. As of now it is run open load except for a timing belt connected to a potentiometer for feedback. I am giving a 12V supply to the driver derived from a Switched Mode Power Supply.And the problem happens across all speeds of interest to me from 1 step per 2 seconds to 10rpm.
@ dave-in-nj I cant post the full code as it has several other components. I will give you the stubs that are related:
sendSequence is a method that sends a particular sequence to the motor. This will basically give the 4step sequences for rotating the motor. This is called by the method rotate.
void sendSequence(int index)
{
DDRD|= B11110000;
switch (index)
{
case 0:
digitalWrite(13,LOW);
PORTD= B10100000;
break;
case 1:
digitalWrite(13,HIGH);
PORTD= B01100000;
break;
case 2:
digitalWrite(13,LOW);
PORTD= B01010000;
break;
case 3:
digitalWrite(13,HIGH);
PORTD= B10010000;
break;
}
void rotate()
{
if(motorEngaged) engageMotor(); // basically sets motor to the first sequence which in this case is 1010
int i=0,j=0;
for(i=0;i<operationCycles;i++) //iterate till number of cycles
{
// Serial.print("#");Serial.println(i);
for(j=1;j<=operationSteps;j++) //iterate till no of steps
{
if(operationClockwise) { sendSequence(j%4); globalSteps++; } // starts from second sequence and continues rotating
else { sendSequence(4-j%4); globalSteps--; } // for opposite direction
delay(operationStepDelay); // delay set by rpm
}
operationClockwise = !operationClockwise; //change direction after every cycle
}
Serial.println(serialTerminator);
}
@Grumpy_Mike The potentiometer is just mechanically fixed. The system is still open loop. It is fixed via a 1:9 Gear Enhanced timing belt so that a step(1.8 degrees) would give a rotation of about 16 degrees on the pot which would give me a considerable change in resistance. But the feedback is still not taken in to get a closed loop system
The timing belt is accurate because it has been previously used. And also i think hysteresis again should not just affect only the first step alone. please correct me if i am wrong.
vivekvk: @Robin2 The sequence that i had posted is the recommended sequence that is widely used.Even the stepper library of arduino uses the same ( can be found here: bit.ly/NUt2Pw )I am sure the physical connections are proper. Also if there were some problems with the connection like a swap or a dry solder it will affect the entire experiment and not just the first step.
I can't remember the exact quote but it's something like this - "trying the same thing over and over and expecting the outcome to be different"
vivekvk: @Robin2 The sequence that i had posted is the recommended sequence that is widely used.Even the stepper library of arduino uses the same ( can be found here: bit.ly/NUt2Pw )I am sure the physical connections are proper. Also if there were some problems with the connection like a swap or a dry solder it will affect the entire experiment and not just the first step.
I can't remember the exact quote but it's something like this - "trying the same thing over and over and expecting the outcome to be different"
...R
I don't get your point. What i am trying to say is even though i am using the same sequence the outcome is different.
vivekvk:
I don't get your point. What i am trying to say is even though i am using the same sequence the outcome is different.
Unless I have completely misunderstood you, you are saying that it gives the same response every time even if it is not the response you want. Repeating the same thing over and over is not going to make it give the correct response. Doing something different might (even if it seems unorthodox).
And you still haven't say how fast you are trying to step it (ie what's the value
of operationStepDelay?)
BTW an L298 running at >1A isn't going to last long, unless you've got
substantial heatsinking/cooling.
[ actually that error isn't the only problem, you aren't maintaining state at all
inbetween calls to rotate() and you must:
byte phase = 0 ;
int step_delay = ?? ;
void do_steps (int numsteps, boolean direction)
{
for (int i = 0 ; i < numsteps ; i++)
{
phase += direction ? +1 : -1 ;
sendSequence (phase & 3) ;
delay (step_delay) ;
}
}
would be more like it - global state kept in variable phase, lower two bits are
used to generate motor signals, direction means increment or decrement phase.