Simvik

Driver: a millisecond delay on a hardware timer

Program a timer's prescaler and auto-reload, and wait for exactly one period. A medium embedded C problem (Timers and PWM), run and graded in the browser.

medium · Timers and PWM · driver · registers · timer · prescaler

Write timer_delay_ms(ms), a blocking delay of ms milliseconds (1 to 65535) on TIM3, against the register map under Provided. The timer is simulated like an STM32's: its input clock is TIM_CLOCK, and the tests time each call with the cycle counter, which must read at least ms × 1000 µs and not much more.

Set the prescaler so the counter ticks once a millisecond and the auto-reload so one period lasts ms ticks, start the timer, wait for the update flag, and stop it again. Every call must be accurate, the first one included.

Starter code

void timer_delay_ms(uint32_t ms) {
}

Example tests

Two delays in a row

check(2);
check(2);

Expected output:

delay_ms(2): ok
delay_ms(2): ok

Learn it first

  • Timers and PWM · Prescalers, auto-reload, input capture, output compare and dead time.

More Timers and PWM problems