C12 Embedded systems in MicroPython and C · Practice
Problem set 11: languages, testing and whole-system design
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 job makes 50 hardware calls, 10 times a second. In MicroPython each call takes 40 µs; in C each takes 10 instructions. The board draws 2 mA at 3.3 V while awake.
(a)
What average power does the MicroPython version spend awake?
Write units the way you normally would: 1.5 µW, 1500 nW and 0.0015 mW are the same answer.
(b)
How many times less awake time does C need?
Check
A chip has 512 KB of flash and 8 KB of RAM. MicroPython needs about 256 KB of flash and 16 KB of RAM before any program.
(a)
Can it run MicroPython (1 for yes)?
(b)
If so, how much RAM is left for the program and its heap (0 if not)?
Check
A chip with 256 KB of flash keeps a 16 KB bootloader and two equal firmware slots (A and B) for safe updates; 8 KB is reserved for a settings log.
(a)
How large can the firmware image be?
(b)
How long does writing a full image take, at 0.5 ms per 256-byte page plus 30 ms per 4 KB sector erased?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A conversion function takes a 12-bit input; each test on the board takes 5 µs.
(a)
How long would testing every input take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
(b)
How many tests are 0, 1, the two values around the middle, and the two at the top?
Check
An intermittent bug shows up in each test run with probability 0.05.
(a)
How many runs give a 0.99 chance of seeing it at least once?
(b)
How many runs does it take on average to see it the first time?
Check
A test checks a Q-format result (with 12 fraction bits) against a floating-point reference after 1 rounding step(s), each off by at most half an LSB.
(a)
What tolerance should the test allow?
(b)
In units of the last bit?
Check
An ISR's cycle budget is 300 cycles, and the team wants 10% margin. A test measures it at 700 cycles.
(a)
Does it pass (1 for yes)?
(b)
What is the most it may take?
Check
In a MicroPython program, a fraction 0.8 of the time is spent in one loop, which is rewritten in C and runs 20 times faster.
(a)
What is the whole program's speedup?
(b)
What is the most it could ever gain, however fast the C?
Check
A logger stores 8-byte records 1 times a second in 4 MB of flash.
(a)
How many days does the flash hold?
(b)
Does it hold 365 days without wrapping (1 for yes)?
Check
A sensor event's path: acquisition (0.01 ms), conversion and filtering (0.5 ms), a main loop that may be away for up to 5 ms, and a UART report (2 ms).
(a)
What is the worst-case latency from event to report?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What share of it is the main loop's wait?
Check
A state machine with 4 states and 3 events is tested off the board in a simulation that runs each transition test in 10 µs, against 20 ms each on the board.
(a)
How many transition tests are there?
(b)
How many times faster is the simulation?
Check
A MicroPython program allocates 100 small objects a second; each garbage collection pauses it for 2 ms and happens every 16 KB of allocations, each object taking 32 bytes.
(a)
How often does it collect?
(b)
What jitter does that add to a periodic task?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
100 devices in the field each reset by a rare bug at a rate of 0.5 per 1000 device-hours.
(a)
How many resets happen across the fleet each day?
(b)
What is the chance a single test device shows it within 1000 hours?
Check
A regression suite has 200 tests. On the board each takes 2 s, including flashing and reset; in a simulator each takes 2 ms.
(a)
How long does the suite take on the board?
(b)
And in the simulator?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A battery-powered data logger with 1000 mAh must last a year. It sleeps at 20 µA and is awake at 8 mA for 1% of the time; its sensor draws 100 µA continuously.
(a)
What is its average current?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
(b)
Does it last a year (1 for yes)?
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