# Understanding the relationship of Pulse and Stepper RPM

This may be a better question for the Physics StackExchange so tell me if I should move the question.

I have a pretty simple script that I'm using to control the RPM of my stepper motor:

``````void loop(){
digitalWrite(PIN, HIGH);
delayMicroseconds(wait);
digitalWrite(PIN, LOW);
}
``````

as you can see it's just producing a pretty standard pulse, I have my Arduino connected to a driver that manages the motor. The `wait` variable comes from a second order equation I derived from measuring the RPM with a Tachometer and tweaking the value.

``````// From data RPM = 31729/x + 17.327 thus x = 31729/(RPM-17.527)
wait = M/(RPM-C);
``````

It works pretty well, I get readings consistently within only 1 - 2 rotations off. But the slope and intercept seem completely arbitrary to me. Is there a chance it has to do with the clock speed of the Arduino? I'm using an Uno and from playing around with the numbers I can't seem to find a relationship. From what I can tell, the driver looks hardwired so I don't think it has much to do with the equation.

Any idea what these values, the slope/intercept mean?

Equation: `RPM=31729/wait + 17.327` M:`31729` and C:`17.327`

• I wonder if this generates a proper pulse. It needs a delay after `digitalWrite(PIN, LOW);`
– rmi
Commented Apr 30, 2014 at 4:25
• There's definitely a clock dependent granularity and additional delay among other potential problems. For steady rotation, consider using a hardware timer to drive a pin, or failing that trigger an interrupt so that at least the overall rate remains constant. There should be a fixed factor of step rate as long as the system is operating properly, but there will be both a rate and am acceleration at which it starts skipping steps, especially under load or resonance. Commented May 2, 2014 at 9:42