Go Down

Topic: Stepper positioning errors on stop (Read 744 times) previous topic - next topic


Sep 19, 2011, 11:27 pm Last Edit: Sep 19, 2011, 11:42 pm by father_gorry Reason: 1
Basically, I'm making stepper play notes by turning its direction. Here is the base code:
Code: [Select]
void flip(){ //step+ OR step-
 dir_state = !dir_state;
 digitalWrite(DIR_PIN, dir_state);
 for(int i=0 ; i<8 ; i++){
   digitalWrite(STEP_PIN, HIGH);
   digitalWrite(STEP_PIN, LOW);
   //if(dir_state){shifted += 1;}else {shifted -=1;}

First, I've tested all my bipolar steppers with this code, and they worked fine. I removed delays inside rotate(), and they were still fine with Sparkfun's EasyDriver.

Than I tried my flip() function and have found that tone intervals are not exact the same, probably because Atmega takes some processing time before comparing current and previous microseconds. Also, there were accidental positioning errors on stop, with shifted == +-1. Predictable, I thought.

To get good tone, I connected a tone(4) pin to attachInterrupt(1,flip,CHANGE), made all vars volatile, but got horror. The tone itself became clear, but after noTone(4) come unpredictable positioning errors, about 2-24 microsteps clockwise only. Strangely, "shifted" equals 0 every time this way.
When I set interrupt to RISING along with doubling frequency, positioning error turns to +-8.

What is the nature of that errors and how to avoid them? Thanks.

Go Up