Welcome! Log In Create A New Profile

Advanced

Stepper Motor jerking ( video )

Posted by RogertT 
Stepper Motor jerking ( video )
September 01, 2013 07:19AM
Hi guys,
Here's my vidoe of a biporal stepper motor jerking: [youtu.be]

And my arduino code that's supposed to make the motor work smoothing one half-step at a time and then pause for a second.

int pin1 = 2;
int pin2 = 3;
int pin3 = 5;
int pin4 = 6;

int delayMin = 10;
int delayTime = 1000;

void setup() {
  
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  pinMode(pin4, OUTPUT);
  pinMode(pin3, OUTPUT);

  Serial.begin(9600);
  pwm();
  
}

void loop() {}


void pwm()
{

///////////////////////////////////////////////

Serial.println("COIL ONE->TWO STARTING!");

for ( int i = 0; i<=250; i=i+25 )
{ 
    Serial.print("COIL ONE->TWO : ");
    Serial.println(i);
  
    analogWrite(pin1, 0);
    analogWrite(pin2, 250);
    analogWrite(pin3, 250);
    analogWrite(pin4, i);
  
    delay(delayMin);
} 
  
  Serial.println("COIL ONE->TWO FINISHED!");
  delay(delayTime);
  Serial.println(" - - - ");

///////////////////////////////////////////////

///////////////////////////////////////////////

Serial.println("COIL TWO->THREE STARTING!");

for ( int i = 0; i<=250; i=i+25 )
{ 
    Serial.print("COIL TWO->THREE : ");
    Serial.println(i);
  
    analogWrite(pin1, 0);
    analogWrite(pin2, 250);
    analogWrite(pin3, 250-i);
    analogWrite(pin4, 250);
  
    delay(delayMin);
} 
  
  Serial.println("COIL TWO->THREE FINISHED!");
  delay(delayTime);
  Serial.println(" - - - ");

///////////////////////////////////////////////

///////////////////////////////////////////////

Serial.println("COIL THREE->FOUR STARTING!");

for ( int i = 0; i<=250; i=i+25 )
{ 
    Serial.print("COIL THREE->FOUR : ");
    Serial.println(i);
  
    analogWrite(pin1, i);
    analogWrite(pin2, 250);
    analogWrite(pin3, 0);
    analogWrite(pin4, 250);
  
    delay(delayMin);
} 
  
  Serial.println("COIL THREE->FOUR FINISHED!");
  delay(delayTime);
  Serial.println(" - - - ");
  
///////////////////////////////////////////////

///////////////////////////////////////////////

Serial.println("COIL FOUR->FIVE STARTING!");

for ( int i = 0; i<=250; i=i+25 )
{ 
    Serial.print("COIL FOUR->FIVE : ");
    Serial.println(i);
  
    analogWrite(pin1, 250);
    analogWrite(pin2, 250-i);
    analogWrite(pin3, 0);
    analogWrite(pin4, 250);
  
    delay(delayMin);
} 
  
  Serial.println("COIL FOUR->FIVE FINISHED!");
  delay(delayTime);
  Serial.println(" - - - ");

///////////////////////////////////////////////

///////////////////////////////////////////////

Serial.println("COIL FIVE->SIX STARTING!");

for ( int i = 0; i<=250; i=i+25 )
{ 
    Serial.print("COIL FIVE->SIX : ");
    Serial.println(i);
  
    analogWrite(pin1, 250);
    analogWrite(pin2, 0);
    analogWrite(pin3, i);
    analogWrite(pin4, 250);
  
    delay(delayMin);
} 
  
  Serial.println("COIL FIVE->SIX FINISHED!");
  delay(delayTime);
  Serial.println(" - - - ");

///////////////////////////////////////////////

///////////////////////////////////////////////

Serial.println("COIL SIX->SEVEN STARTING!");

for ( int i = 0; i<=250; i=i+25 )
{ 
    Serial.print("COIL SIX->SEVEN : ");
    Serial.println(i);
  
    analogWrite(pin1, 250);
    analogWrite(pin2, 0);
    analogWrite(pin3, 250);
    analogWrite(pin4, 250-i);
  
    delay(delayMin);
} 
  
  Serial.println("COIL SIX->SEVEN FINISHED!");
  delay(delayTime);
  Serial.println(" - - - ");

///////////////////////////////////////////////

///////////////////////////////////////////////

Serial.println("COIL SEVEN->EIGHT STARTING!");

for ( int i = 0; i<=250; i=i+25 )
{ 
    Serial.print("COIL SEVEN->EIGHT : ");
    Serial.println(i);
  
    analogWrite(pin1, 250);
    analogWrite(pin2, i);
    analogWrite(pin3, 250);
    analogWrite(pin4, 0);
  
    delay(delayMin);
} 
  
  Serial.println("COIL SEVEN->EIGHT FINISHED!");
  delay(delayTime);
  Serial.println(" - - - ");

///////////////////////////////////////////////

///////////////////////////////////////////////

Serial.println("COIL EIGHT->ONE STARTING!");

for ( int i = 0; i<=250; i=i+25 )
{ 
    Serial.print("COIL EIGHT->ONE : ");
    Serial.println(i);
  
    analogWrite(pin1, 250-i);
    analogWrite(pin2, 250);
    analogWrite(pin3, 250);
    analogWrite(pin4, 0);
  
    delay(delayMin);
} 
  
  Serial.println("COIL EIGHT->ONE FINISHED!");
  delay(delayTime);
  Serial.println(" - - - ");

///////////////////////////////////////////////

    pwm();

}


And the smooth transit work for most of the times, except for transits 3-4 and 8-1 , at this moments you can see it jerking.

Any idea what I might be doing wrong? Also is this hi-pitch sound normal?

Thanks. )
Re: Stepper Motor jerking ( video )
September 01, 2013 09:39AM
I'm not familiar with Arduino as I usually use PIC but I think I can make some comments that are generic enough to be applicable regardless of what processor is used and hopefully still of some use.

My guess is that you have something wrong either with the PWM output on pin 1 or the driver electronics it is controlling. Steps 8>1 and 3>4 are the only ones that put an 'analog' value rather than full on or full off onto pin 1. It is likley that instead of PWM the driver is only switching between full on and full off.

If you have an oscilloscope then perhaps first thing to check is what actually comes out on pins 1 with various PWM values. For instance stop it at the point is at "analogWrite(pin1, 0);" where I expect there would be zero output, at analogWrite(pin1, 125); where I would expect a 50% duty cycle and 250, which should give 100% duty cycle or perhaps permanently on.

Try the same on the other pins, just to make sure you know what to expect on pin 1.


You mention the high pitch sound - that is quite normal for stepper motor controls especially when using microstepping. Sometimes the chopping frequency is high enough to be inaudible.

I would expect to here the sound most when any of the ouptuts is not full on or full off and probably not at all when the outputs are all either 0 or 250.

Try make the program stop for a relatively long time half way through each microstepping sequence by inserting a pause when i=125. You should hear the high pitched sound at each pause. My guess is that you won't hear it in the middle of 3>4 and 8>1. If so this confirms something is wrong either with the driver on pin 1 or perhaps just its PWM settings.


Something else I noted (not related to the problem you report) , which may or may not be intentional is that you have an extra step at the end of each sequence. The last step of each sequence is the same as the first step of the next. If you try to make continuous motion in this way you will have small jerks at the end of each microstepping sequence.

This can be corrected (unless it is intentionally like that) by changing the "for ( int i = 0; i<=250; i=i+25 )" into "for ( int i = 0; i<250; i=i+25 )", that is putting a 'less than' rather than a 'less than or equal'.
Re: Stepper Motor jerking ( video )
September 01, 2013 09:55AM
I've just watched the video (it wasn't working for me earlier), and it somewhat confirms what I was thinking and perhaps also something else.

I note the absence of the high pitch sound during the 'jerk' movement, which somewhat confirms that there was DC on the motor coil instead of a PWM signal.

Also in steps 4>5 and 7>8 the pitch is distinctly lower, suggesting a PWM frequency which may be too low. The sound should be quite similar for all eight microstepping sequences as in each case there are three outputs fixed at full on or full off and one varying output. Each varying output should make more or less the same sound.

What I can tell from the sounds is:
Pin 1: No PWM, just DC on or off (but could possibly be very high frequency PWM that cannot be heard)
Pin 2: Lower than normal PWM frequency
Pin 3: Sounds like normal PWM
Pin 4: Sounds like normal PWM
Re: Stepper Motor jerking ( video )
September 01, 2013 10:13AM
Thanks lister6520, appears that pin 2 of arduino nando doesn't provide PWM.
Switched to pin 11 instead and now everything works perfect! smileys with beer

Edited 1 time(s). Last edit at 09/01/2013 10:15AM by RogertT.
Sorry, only registered users may post in this forum.

Click here to login