Step interval for a speed
Compute the time between step pulses for a target speed in RPM. A medium embedded C problem (Motors), run and graded in the browser.
medium · Motors · motors · stepper · timing
To spin a stepper at rpm revolutions per minute, pulses must arrive at a steady interval.
Write step_interval_us(rpm, steps_per_rev, microstep): the time between two step pulses in microseconds, rounded to the nearest microsecond.
Return 0 if rpm is 0 (the motor is stopped, there is no interval).
Starter code
uint32_t step_interval_us(uint32_t rpm, uint32_t steps_per_rev, uint32_t microstep) {
return 60000000u / (rpm * steps_per_rev);
}Example tests
60 RPM, full steps
show(step_interval_us(60, 200, 1));Expected output:
5000Microstepping shortens the interval
show(step_interval_us(60, 200, 16));Expected output:
313Learn it first
- Motors and motor control · DC motors and H-bridges, steppers, BLDC commutation and FOC.
More Motors problems
- Steps for an angle · Convert degrees into stepper steps, with microstepping, rounded to the nearest step.
- Robot arm: steps for a joint move · Convert a joint's move in tenths of a degree into stepper microsteps through a gearbox.