Simvik

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:

5000

Microstepping shortens the interval

show(step_interval_us(60, 200, 16));

Expected output:

313

Learn it first

More Motors problems