C12 Embedded systems in MicroPython and C · Practice
Timers
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
A timer has PRESCALE = 9 and TOP = 99, on the 10 MHz clock. How long between wraps?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
At what rate does a timer with PRESCALE = 99 count?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
With PRESCALE = 9, what TOP makes the timer wrap every 2 ms?
Check
With PRESCALE = 9, by how much can the period be adjusted, at the finest?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A pin toggles at each timer wrap, making a square wave. With PRESCALE = 0, what TOP gives the closest to 440 Hz?
Check
A 32-bit cycle counter read 4,294,967,000 at one event and 1000 at the next, having wrapped through zero in between. How many cycles passed? (This is what t2 - t1 gives in unsigned 32-bit arithmetic.)
Check
Using the hardware timer and its flag (not a delay loop), toggle P0 every MS (5) ms.
C on the course's RISC-V board (10 MHz, no floating point). #include "board.h" for the registers; print(x) shows a number. Tab indents; press Esc and then Tab to move on.
Check
Blink the LED on P0 at 5 Hz using machine.Timer with a callback, not a sleeping loop.
MicroPython on the course's board: machine (Pin, PWM, ADC, DAC, UART, I2C, SPI, Timer, WDT) and time. Each call into the hardware takes about 40 µs. Tab indents; press Esc and then Tab to move on.
Check
The timer wraps at Hz, with PRESCALE = 9.
(a)
What TOP gives 100 Hz (nearest)?
(b)
What frequency does that give exactly?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
Check
A 16-bit counter ticking at 1 MHz read 65000 at the start and 16 at the end.
(a)
How long was the interval?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
What is the longest interval it can time unambiguously?
Check
Wrap period with PRESCALE 4, TOP 199?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
TOP for 5 ms with PRESCALE 9?
Check
TOP (PRESCALE 0) for a 440 Hz square wave?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12