C12 · Problem set 9
Problem set 9: structure, timing, power and storage
These problems use lessons 36 to 44: state machines, superloops and cooperative scheduling, preemptive scheduling, latency, jitter and deadlines, watchdogs, power budgets, keeping data in flash, and bootloaders. The board runs at 10 MHz; it draws 2 mA running, 0.5 mA asleep and 0.002 mA in deep sleep, plus its peripherals and loads.
Check
A state machine has 6 states and 2 kinds of event.
(a)
How many bits does its state need?
(b)
How many entries are in its full transition table?
Check
A crossing holds green for at least 1500 ms, then yellow 400 ms, walk 1200 ms and red 500 ms. The button is pressed 2500 ms into green.
(a)
When does green end?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
When does green come back?
Check
A superloop runs task 1 (0.2 ms every 4 ms) and task 2 (25 ms every 500 ms).
(a)
What's the utilization?
(b)
Task 2's turn can delay task 1 by its whole run time. How many of task 1's periods is that?
Check
A task's 120 ms of work is split into 1 ms pieces, one per superloop turn.
(a)
How many turns does it take?
(b)
How long can it now delay another task, at most?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A job is started by polling in a loop whose passes take 0.1 to 0.8 ms; it runs for 0.5 ms and must finish within 3 ms of its trigger.
(a)
What's its worst-case latency?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How much margin is left at worst (negative if it misses)?
Check
A 60 Hz signal of amplitude 1 V is sampled with 50 µs of jitter.
(a)
How large can a sample's error be?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
(b)
As a percentage of the amplitude?
Check
A main loop's longest normal pass is 6 ms; the watchdog gets a 3× margin.
(a)
What timeout?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What WDT_LOAD, in cycles?
Check
A program hangs 80 ms after each start; its watchdog fires 30 ms after the last kick.
(a)
How many resets happen in 4 s?
(b)
What fraction of the time is it doing useful work?
Check
A device draws 2 mA awake (20% of the time) and 0.05 mA asleep, from a 1200 mAh battery.
(a)
What's its average current?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
(b)
How many days does the battery last?
Check
A device wakes 1 times a second for 0.5 ms each time, drawing 2 mA while awake.
(a)
What fraction of the time is it awake?
(b)
What do the wake-ups add to the average current?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
Check
A status LED drawing 3.9 mA flashes for 10 ms every 30 s.
(a)
What does it add to the average?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
(b)
How long would it alone take to drain a 220 mAh cell?
Check
A fault resets a device 3 times a day; each reset takes 100 ms to recover from.
(a)
How long is it out of action each day?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
(b)
What percentage of the day is that?
Check
Under a preemptive scheduler, task 1 runs 1 ms every 4 ms at high priority; task 2 needs 7 ms.
(a)
What is task 2's worst-case response time?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
In a superloop that runs task 1 and then task 2, how long can task 1 wait between the end of one run and the start of the next?
Check
A thermostat saves its schedule 60 times a day as 32-byte records appended to a log over 4 4 KB flash sector(s) rated for 10000 erases.
(a)
How long does the flash last?
(b)
How long if it erased a sector for every save instead?
Check
A high-priority task needs a mutex that a low-priority task holds for 1 ms; a medium-priority task runs for 10 ms.
(a)
How long can the high task be blocked without priority inheritance?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
And with it?
Check
A device has 512 KB of flash and a 16 KB bootloader, and receives a 150 KB update over a 921600-baud UART.
(a)
How large can each A/B slot be?
(b)
How long does the transfer take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.
Practice
Keep practicing
16 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.