Pages: [1]   Go Down
Author Topic: Stepper positioning errors on stop  (Read 472 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
Basically, I'm making stepper play notes by turning its direction. Here is the base code:
Code:
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.
« Last Edit: September 19, 2011, 04:42:49 pm by father_gorry » Logged

Pages: [1]   Go Up
Jump to: