Sub topic 10
Converting RPM to Step Timing
This chapter assumes you know basic Arduino programming, motor step angle, microstepping, and how a STEP/DIR driver is wired. The driver receives one step for each rising edge on its STEP input. The time between those edges determines the motor speed.
From RPM to steps per second
A motor's mechanical steps per revolution depend on both its step angle and the driver's microstepping setting.
For a motor with step angle \(a\):
\[ \text{full steps per revolution} = \frac{360}{a} \]
Then include microstepping:
\[ \text{steps per revolution} = \text{full steps per revolution} \times \text{microstep factor} \]
The required step rate is:
\[ \text{steps per second} = \frac{\text{RPM} \times \text{steps per revolution}}{60} \]
The interval between step pulses is:
\[ \text{interval in microseconds} = \frac{1,000,000}{\text{steps per second}} \]
For example, a 1.8-degree motor has 200 full steps per revolution. At 16× microstepping, it needs 3,200 pulses per revolution. At 60 RPM:
| Value | Calculation | Result |
|---|---|---|
| Steps per revolution | 200 × 16 | 3,200 |
| Steps per second | 60 × 3,200 ÷ 60 | 3,200 |
| Pulse interval | 1,000,000 ÷ 3,200 | 312.5 microseconds |
The motor shaft makes one revolution per second, although the driver receives 3,200 step pulses per second.
Generating pulses on Arduino
This example uses a 200-step motor in full-step mode. It produces 250 steps per second, which equals 75 RPM.
const int STEP_PIN = 3;
const int DIR_PIN = 4;
const unsigned long STEP_INTERVAL_US = 4000;
const unsigned long HIGH_TIME_US = 10;
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(STEP_PIN, LOW);
digitalWrite(DIR_PIN, HIGH);
}
void loop() {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(HIGH_TIME_US);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(STEP_INTERVAL_US - HIGH_TIME_US);
}The complete pulse period is 4,000 microseconds, or 250 pulses per second. With 200 steps per revolution:
\[ 250 \times \frac{60}{200} = 75\text{ RPM} \]
The driver usually requires a minimum STEP high and low time. Check its datasheet. A 10-microsecond high period is suitable for many drivers, but it is not universal.
Calculating an interval in code
unsigned long stepIntervalMicros(float rpm, int stepsPerRev) {
if (rpm <= 0.0f || stepsPerRev <= 0) {
return 0;
}
return (unsigned long)(60000000.0f / (rpm * stepsPerRev));
}At high step rates, delayMicroseconds() and ordinary loop code become less precise. Interrupt-based timers or a motion library can produce more consistent timing.
Exercise
A 1.8-degree motor uses 8× microstepping and must run at 30 RPM. What step rate is required?
Show answer
It has 200 × 8 = 1,600 steps per revolution. The step rate is 30 × 1,600 ÷ 60 = 800 steps per second.