Welcome! Log In Create A New Profile

Advanced

Steppers not stepping correctly - Mega and Pololu

Posted by Thorp 
Steppers not stepping correctly - Mega and Pololu
June 22, 2010 01:25PM
Hi All,

I'm having some issues getting my steppers to step correctly.

I am using the arduino mega and pololu drivers.

Video should help with the details:
[www.youtube.com]

Thanks for the help!

Thorp
Re: Steppers not stepping correctly - Mega and Pololu
June 22, 2010 02:51PM
When you make a connection with a wire like that you get severe switch bounce. I.e. instead of one clean pulse you get dozens very close together. The chip can keep up and moves many phases very quickly but the motor is just left behind. If you get say 9 pulses very close together the motor will go 7 micro-steps backwards rather than 9 forwards.

To single step manually like that you need a switch de-bounce circuit which is normally a two pole switch and a set / reset flip flop.

Much easier to test it with a simple loop of code on the Arduino. I think there is an example in the wiki instructions for making the RepRap stepper boards.


[www.hydraraptor.blogspot.com]
Re: Steppers not stepping correctly - Mega and Pololu
June 22, 2010 04:58PM
I was going to suggest that you make sure you don't have your PWM (current limiting) turned down too far, and that your axes are not too tight for your available torque...

But I think nophead's likely got it in one.

I wrote a simple program to push pulses out of the Mega (motors on the bench)... strikes me as a more real-world test than trying for single steps.

It's really basic, but gave me confidence pretty quickly:

/*
PololuTestMega

Runs 3 Pololu stepper boards by controlling the Direction, Enable and Step pins
Arduino Mega RepStrap Electronics
Created 16 June 2010
By Al Adrian

*/

const int Enablex = 29; // Enable pin x as per Hydra Firmware
const int Directionx = 31; // Direction pin x
const int Stepx = 33; // Step pin x

const int Enabley = 23; // Enable pin y
const int Directiony = 25; // Direction pin y
const int Stepy = 27; // Step pin y

const int Enablez = 22; // Enable pin z
const int Directionz = 24; // Direction pin z
const int Stepz = 26; // Step pin z

int Delay;
int Cnt;
int Circle;
// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pins as output:
pinMode(Enablex, OUTPUT);
pinMode(Directionx, OUTPUT);
pinMode(Stepx, OUTPUT);
pinMode(Enabley, OUTPUT);
pinMode(Directiony, OUTPUT);
pinMode(Stepy, OUTPUT);
pinMode(Enablez, OUTPUT);
pinMode(Directionz, OUTPUT);
pinMode(Stepz, OUTPUT);

digitalWrite (Directionx, LOW); //LOW Clockwise, HIGH Counter Clockwise
digitalWrite (Directiony, LOW); //LOW Clockwise, HIGH Counter Clockwise
digitalWrite (Directionz, LOW); //LOW Clockwise, HIGH Counter Clockwise
digitalWrite (Enablex, LOW); //LOW is Pololu enabled
digitalWrite (Enabley, LOW); //LOW is Pololu enabled
digitalWrite (Enablez, LOW); //LOW is Pololu enabled

Delay = 100; //microseconds
Circle = 9999; //400 steps around on the little motor, *16 for the 1/16 mode minus1
}

// the loop() method runs over and over again,
// as long as the Arduino has power


void loop()
{
for (Cnt=0;Cnt <= Circle; Cnt++){

digitalWrite(Stepx, HIGH); // set the Step on
digitalWrite(Stepy, HIGH); // set the Step on
digitalWrite(Stepz, HIGH); // set the Step on
delayMicroseconds(Delay); // wait for a tenth second
digitalWrite(Stepx, LOW); // set the Step off
digitalWrite(Stepy, LOW); // set the Step off
digitalWrite(Stepz, LOW); // set the Step on
}
digitalWrite (Directionx, HIGH);
digitalWrite (Directiony, HIGH);
digitalWrite (Directionz, HIGH);

delay (500);
for (Cnt=0;Cnt <= Circle; Cnt++){

digitalWrite(Stepx, HIGH); // set the Step on
digitalWrite(Stepy, HIGH); // set the Step on
digitalWrite(Stepz, HIGH); // set the Step on
delayMicroseconds(Delay); // wait for a tenth second
digitalWrite(Stepx, LOW); // set the Step off
digitalWrite(Stepy, LOW); // set the Step off
digitalWrite(Stepz, LOW); // set the Step on
}
digitalWrite (Directionx, LOW);
digitalWrite (Directiony, LOW);
digitalWrite (Directionz, LOW);
delay (500) ;
}

Hope this helps.

Al...


[araspitfire.blogspot.com]
Re: Steppers not stepping correctly - Mega and Pololu
June 22, 2010 06:28PM
Got them spinning!!!
Yehhha.

araspitfire, I tried using your code but found the pulse width to be too small. pulsing the pin longer, for 1 ms seemed to do the trick.

Thanks guys!

I modified your code and ended up with this:
/* 
PololuTestMega 

Runs 3 Pololu stepper boards by controlling the Direction, Enable and Step pins 
Arduino Mega RepStrap Electronics 
Created 16 June 2010 
By Al Adrian 

*/ 

const int Enablex = 24; // Enable pin x as per Hydra Firmware 
const int Directionx = 28; // Direction pin x 
const int Stepx = 26; // Step pin x 

const int Enabley = 30; // Enable pin y 
const int Directiony = 34; // Direction pin y 
const int Stepy = 32; // Step pin y 

const int Enablez = 36; // Enable pin z 
const int Directionz = 40; // Direction pin z 
const int Stepz = 38; // Step pin z 

int Delay; 
int Cnt; 
int Circle; 
// The setup() method runs once, when the sketch starts 

void setup() { 
// initialize the digital pins as output: 
pinMode(Enablex, OUTPUT); 
pinMode(Directionx, OUTPUT); 
pinMode(Stepx, OUTPUT); 
pinMode(Enabley, OUTPUT); 
pinMode(Directiony, OUTPUT); 
pinMode(Stepy, OUTPUT); 
pinMode(Enablez, OUTPUT); 
pinMode(Directionz, OUTPUT); 
pinMode(Stepz, OUTPUT); 

digitalWrite (Directionx, LOW); //LOW Clockwise, HIGH Counter Clockwise 
digitalWrite (Directiony, LOW); //LOW Clockwise, HIGH Counter Clockwise 
digitalWrite (Directionz, LOW); //LOW Clockwise, HIGH Counter Clockwise 
digitalWrite (Enablex, LOW); //LOW is Pololu enabled 
digitalWrite (Enabley, LOW); //LOW is Pololu enabled 
digitalWrite (Enablez, LOW); //LOW is Pololu enabled 

Delay = 1000; //microseconds 
Circle = 9999; //400 steps around on the little motor, *16 for the 1/16 mode minus1 
} 

// the loop() method runs over and over again, 
// as long as the Arduino has power 


void loop() 
{

digitalWrite(Stepx, HIGH); // set the Step on 
digitalWrite(Stepy, HIGH); // set the Step on 
digitalWrite(Stepz, HIGH); // set the Step on 
delayMicroseconds(Delay); // wait for a tenth second 
digitalWrite(Stepx, LOW); // set the Step off 
digitalWrite(Stepy, LOW); // set the Step off 
digitalWrite(Stepz, LOW); // set the Step on 
delayMicroseconds(Delay); // wait for a tenth second 

} 
Re: Steppers not stepping correctly - Mega and Pololu
June 26, 2010 09:48PM
And now I'm on to the next hurdle.

I'm having trouble with the 5D firmware. I can use my own code to step no problem but I run into problems when I switch over to the 5d firmware. I have changed the pin assignments on the pins tab under 'mega' and I have 'mega' set as the board in the compiler. Not sure what is wrong...

Video to illustrate:
[www.youtube.com]
Re: Steppers not stepping correctly - Mega and Pololu
June 27, 2010 06:47PM
Test code:
/* 
PololuTestMega 

Runs 3 Pololu stepper boards by controlling the Direction, Enable and Step pins 
Arduino Mega RepStrap Electronics 
Created 16 June 2010 
By Al Adrian 

*/ 

const int Enablex = 24; // Enable pin x as per Hydra Firmware 
const int Directionx = 28; // Direction pin x 
const int Stepx = 26; // Step pin x 

const int Enabley = 30; // Enable pin y 
const int Directiony = 34; // Direction pin y 
const int Stepy = 32; // Step pin y 

const int Enablez = 36; // Enable pin z 
const int Directionz = 40; // Direction pin z 
const int Stepz = 38; // Step pin z 

int i;
int Delay; 
int Cnt; 
int Circle; 
// The setup() method runs once, when the sketch starts 

void setup() { 
// initialize the digital pins as output: 
pinMode(Enablex, OUTPUT); 
pinMode(Directionx, OUTPUT); 
pinMode(Stepx, OUTPUT); 
pinMode(Enabley, OUTPUT); 
pinMode(Directiony, OUTPUT); 
pinMode(Stepy, OUTPUT); 
pinMode(Enablez, OUTPUT); 
pinMode(Directionz, OUTPUT); 
pinMode(Stepz, OUTPUT); 

digitalWrite (Directionx, LOW); //LOW Clockwise, HIGH Counter Clockwise 
digitalWrite (Directiony, LOW); //LOW Clockwise, HIGH Counter Clockwise 
digitalWrite (Directionz, LOW); //LOW Clockwise, HIGH Counter Clockwise 
digitalWrite (Enablex, LOW); //LOW is Pololu enabled 
digitalWrite (Enabley, LOW); //LOW is Pololu enabled 
digitalWrite (Enablez, LOW); //LOW is Pololu enabled 

Delay = 60; //microseconds 
Circle = 9999; //400 steps around on the little motor, *16 for the 1/16 mode minus1 
} 

// the loop() method runs over and over again, 
// as long as the Arduino has power 


void loop() 
{
digitalWrite(Directionx, LOW); // set the Direction low
digitalWrite(Directiony, LOW); // set the Direction HIGH
digitalWrite(Directionz, LOW); // set the Direction HIGH

for (int i = 0; i < 100; i++){
  digitalWrite(Stepx, HIGH); // set the Step on 
  digitalWrite(Stepy, HIGH); // set the Step on 
  digitalWrite(Stepz, HIGH); // set the Step on 
  delayMicroseconds(Delay); // wait for a tenth second 
  digitalWrite(Stepx, LOW); // set the Step off 
  digitalWrite(Stepy, LOW); // set the Step off 
  digitalWrite(Stepz, LOW); // set the Step on 
  delayMicroseconds(Delay); // wait for a tenth second
  delay(20);
}

digitalWrite(Directionx, HIGH); // set the Direction HIGH
digitalWrite(Directiony, HIGH); // set the Direction HIGH
digitalWrite(Directionz, HIGH); // set the Direction HIGH

for (int i = 0; i < 100; i++){
  digitalWrite(Stepx, HIGH); // set the Step on 
  digitalWrite(Stepy, HIGH); // set the Step on 
  digitalWrite(Stepz, HIGH); // set the Step on 
  delayMicroseconds(Delay); // wait for a tenth second 
  digitalWrite(Stepx, LOW); // set the Step off 
  digitalWrite(Stepy, LOW); // set the Step off 
  digitalWrite(Stepz, LOW); // set the Step on 
  delayMicroseconds(Delay); // wait for a tenth second 
  delay(20);
}

} 
Hi Thorp,

I have used your last code to test my steppermotor. It seems to work, however, when I power up the arduino board, the motor starts stepping right away in one direction. Only after 10 seconds, the motor does the alterniating directions after every 100 steps. Do you know how i prevent it from starting right away?

cheers, tim
Sorry, only registered users may post in this forum.

Click here to login