Steps for an angle
Convert degrees into stepper steps, with microstepping, rounded to the nearest step. An easy embedded C problem (Motors), run and graded in the browser.
easy · Motors · motors · stepper · arithmetic
A stepper motor has steps_per_rev full steps per revolution (200 for a 1.8° motor). A driver can split each full step into microstep smaller ones (1, 2, 4, 8 or 16).
Write steps_for_degrees(degrees, steps_per_rev, microstep): how many step pulses turn the shaft by degrees, rounded to the nearest whole pulse.
Starter code
uint32_t steps_for_degrees(uint32_t degrees, uint32_t steps_per_rev, uint32_t microstep) {
return degrees * steps_per_rev / 360u;
}Example tests
A quarter turn, full steps
show(steps_for_degrees(90, 200, 1));Expected output:
50Microstepping multiplies the pulses
show(steps_for_degrees(90, 200, 16));Expected output:
800Learn it first
- Motors and motor control · DC motors and H-bridges, steppers, BLDC commutation and FOC.
More Motors problems
- Step interval for a speed · Compute the time between step pulses for a target speed in RPM.
- Robot arm: steps for a joint move · Convert a joint's move in tenths of a degree into stepper microsteps through a gearbox.