Go Down

Topic: Stepper control CNC shield without GRBL. Microstepping maximum steps problem (Read 168 times) previous topic - next topic

MrGls

Dear Forum,

I have run into a problem with my setup concerning micro stepping.
My goal is to use a spindle for a vertical movement an so far I have everything working.
The problem is the amount of microsteps I want my motor to execute.
I am working with an arduino UNO and CNC shield v3 with the DRV8825 driver and I am using 1/32 micro step function.
My motor is a NEMA 17. 0.9 degrees per whole step(so 400 steps per revolution). With the 1/32 micro steps it becomes 12800 microsteps per revolution.
So far I am using simple code like this:

Code: [Select]

#define EN          8 
#define X_DIR     5
#define X_STP     2

int delayTime=10; //Delay between each pause (uS)
int stps=12800;      // Steps to move

void step(boolean dir, byte dirPin, byte stepperPin, int steps)

{

  digitalWrite(dirPin, dir);

  delay(100);

  for (int i = 0; i < steps; i++) {

    digitalWrite(stepperPin, HIGH);

    delayMicroseconds(delayTime);

    digitalWrite(stepperPin, LOW);

    delayMicroseconds(delayTime);

  }

}

void setup() {
 
pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
pinMode(EN, OUTPUT);

 step(false, X_DIR, X_STP, 12800); //X
delay(100);

}


void loop() {

}


So far so good. Everything does what I want.
But when I try to let my motor make more revolutions(by increasing the pulses for steps), I run into a problem.
For example when I increase the required steps to:
Code: [Select]
step(false, X_DIR, X_STP, 4 * 12800); //X
My motor does not respond anymore. 3 * 12800 still works, but higher does not. I was able to let the motor execute my command twice by adding another copy of the code below, but it will still have a slight delay in between.
Therefore my question to you is, what is the reason my stepper does not want to execute more then 35000 micro steps in one command?

I hope I have explained my problem with sufficient clarity and that one of you has a solution for me.

With kind regards,

MrGls
With kind regards,

MrGls

wildbill

I am surprised that it works with three times. The issue looks like overflow. You're passing the number of steps as a signed two byte int which takes a maximum value of 32767. 4*12800 is too large and it overflows to give you a negative number, so your loop in the step function does nothing.

MrGls

Dear WildBill,

Thank you for you quick response. I think you are right.
Is it possible to define the pulses differently then? So to define stps as something else than an integer?
I am quite a beginner in programming.

With kind regards,

MrGls

ps: you were right about the 32767 value. 3* did not work. I made it work on 30000 and not 3 * 12800.
With kind regards,

MrGls

wildbill

Try changing the function parameter to long instead of int. You may want to do the same to your stps variable too.

MrGls

WildBill, You are the man! Thank you for helping. I will be back soon for new questions(I expect)

With kind regards,

MrGls
With kind regards,

MrGls

Go Up