Simvik

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:

50

Microstepping multiplies the pulses

show(steps_for_degrees(90, 200, 16));

Expected output:

800

Learn it first

More Motors problems