C12 Embedded systems in MicroPython and C · Practice
Problem set 2: inputs, debouncing and debugging
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 keypad has 8 buttons, each pulling its own 4.7 kΩ pull-up to ground when pressed. A user holds one down for 24 hours a day.
(a)
What current does a pressed button draw?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
(b)
How much charge does that take from the battery each day?
(c)
What if all 8 were held at once?
Check
A 12 V logic signal must drive a 3.3 V pin through a divider: 10 kΩ in series, then a resistor to ground. Its high level should land at 3.0 V.
(a)
What resistor to ground?
Write units the way you normally would: 1.5 kΩ, 1500 Ω and 0.0015 MΩ are the same answer.
(b)
What source resistance does the pin then see?
Check
An open-drain line has a 4.7 kΩ pull-up to 3.3 V and 50 pF of capacitance. It's released from 0 V.
(a)
How long until it reads 1?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
If the line must be high at least half of each period and the rise takes up all of that half, what is the fastest square wave it can carry?
Check
A pin leaks up to 1 µA to ground, and its pull-up is 100 kΩ.
(a)
What voltage does the released pin sit at?
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
(b)
Does it still read 1 (1 for yes)?
(c)
What is the largest pull-up that keeps it reading 1?
Check
A button discharges a capacitor of 0.1 µF through 47 kΩ as a hardware debouncer; the pin starts at 3.3 V.
(a)
How long after the press does the pin fall below 0.99 V?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
If a bounce opens the contact once the pin has reached 0.1 V, how long must it stay open to recharge the pin past 0.99 V? (The pin then charges back toward 3.3 V through the same resistance.)
Check
A counter debouncer samples every 2 ms and accepts a new level after 4 equal samples. A switch bounces for up to 10 ms.
(a)
What is its worst-case delay after the bouncing ends?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
And after the first contact?
(c)
If each sample is a 30-cycle timer interrupt, what share of the 10 MHz processor does it take?
Check
A button bounces 10 times on each press and each release, so each press and release makes falling edges. A falling-edge interrupt of 40 cycles fires on every falling edge; it's pressed 6 times a second.
(a)
How many falling edges arrive per second?
(b)
What share of the 10 MHz processor do they use?
Check
An array of structs, each 12 bytes, starts at address 8192. A field sits at offset 8 in each struct.
(a)
What address holds the field of element 7?
(b)
A watchpoint covers aligned 4-byte words. What address does it watch?
Check
A conditional breakpoint if (j == 7) sits in an inner loop for j < 20 inside an outer loop for i < 10.
(a)
How many times does it stop?
(b)
How many times would an unconditional one stop?
Check
A memory view shows the bytes 52, 18, 7, 1 (in decimal, lowest address first) at the address of a uint32_t.
(a)
What value does it hold?
(b)
What does a uint16_t at the same address hold?
Check
A control loop has a 20 ms deadline. A debug print of 20 characters at 9600 baud is added to it, waiting for each character.
(a)
How long does the print take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
Does the print alone fit in the deadline (1 for yes)?
Check
A stack of 1024 bytes is painted at reset. After testing, 200 bytes at the bottom are untouched. The team wants a 50% margin over the high-water mark.
(a)
What is the high-water mark?
(b)
What stack size meets the margin?
(c)
How much RAM does resizing free (negative if more is needed)?
Check
A logic analyzer must catch pulses 2 µs wide with at least 4 samples each, over a 1 s capture.
(a)
What sample rate does it need?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
(b)
How many samples per channel does the capture hold?
Check
A 22 kΩ pull-up and a 10 pF pin are toggled by an open-drain output as a 5 kHz square wave.
(a)
How long does each rise take to reach a logic 1?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
What share of the high half-period does that delay take?
Check
A Schmitt-trigger input switches high above 1.8 V rising and low below 1.2 V falling. A slow sensor drives it with , τ = 10 ms.
(a)
When does it switch high?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What is the largest noise, peak to peak, that can't make it switch back once it's high and settled near its switching point?
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