C12 Embedded systems in MicroPython and C · Practice
Problem set 3: inputs, timers and interrupts
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 button to ground has a 40 kΩ pull-up; the pin and its wire have 20 pF.
(a)
What current flows while it's pressed?
Write units the way you normally would: 1.5 µA, 1500 nA and 0.0015 mA are the same answer.
(b)
After release, how long until the pin crosses 70% of 3.3 V?
Check
A button's contacts bounce 2 times on every press and on every release; it's pressed 5 times.
(a)
How many falling edges does a fast program see?
(b)
How many does a correct debouncer count?
Check
A debouncer samples every 2 ms and accepts a level after 4 equal samples; the bounce lasts 8 ms.
(a)
How long does it take to accept a settled level?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
About how long after the first contact does it report the press?
Check
An array of 16 elements of 2 bytes starts at 1000, and a loop runs from 0 to 16 inclusive.
(a)
What address does its last pass read, in hex?
(b)
How many bytes past the end of the array does that read start?
Check
A timer has PRESCALE = 99 and TOP = 499, and a pin toggles at each wrap.
(a)
How long between wraps?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What frequency is the pin's square wave?
Check
A pin must square-wave at 1000 Hz from a timer with PRESCALE = 0.
(a)
What TOP comes closest?
(b)
What frequency does it actually make?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
Check
An ISR takes 300 cycles and fires 2 thousand times a second.
(a)
What share of the processor does it use?
(b)
What rate would use all of it?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
An ISR saves and restores 6 registers and takes 3 cycles to reach its first useful instruction after that.
(a)
How many cycles from entering the ISR to its first useful instruction?
(b)
And in microseconds?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
count is 19. While main does count = count + 1 (load, add, store), 2 ISR increments land between its load and its store.
(a)
What is count afterwards?
(b)
How many increments were lost?
Check
A 32-bit cycle counter read 4294966000 at one event and 300 at the next, wrapping in between.
(a)
How many cycles passed?
(b)
How long is that?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A debug print sends 30 characters over the UART at 9600 baud, waiting for each.
(a)
How long does it take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How many clock cycles is that?
Check
A breakpoint sits in the innermost of three nested loops of 3, 10 and 4 passes.
(a)
How many times does it stop the program?
(b)
And a breakpoint in the middle loop's body, outside the inner loop?
Check
A 16-bit capture timer runs at Hz with PRESCALE = 0 and records edges 5000 counts apart.
(a)
What frequency is that?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
(b)
What is the lowest frequency it can measure without counting overflows?
Check
A 360-line quadrature encoder is decoded 4× and turns at 60 rpm.
(a)
How many counts per revolution?
(b)
What angle is one count?
(c)
How many counts per second?
Check
An ultrasonic echo returns 2.9 ms after the ping at 15 °C (sound at m/s), timed by a 1 MHz capture.
(a)
How far is the target?
Write units the way you normally would: 1.5 mm, 1500 µm and 0.0015 m are the same answer.
(b)
How much would the reading be off if the firmware assumed a temperature 5 °C too low?
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