---
title: Problem set 10
heading: "Problem set 10: watchdogs, power, flash and control"
eyebrow: C12 · Problem set 10
type: problems
---

::: hook
These problems use lessons 41 to 47: watchdogs, power and sleep, keeping data through power-off, control loops in firmware, and the systems lab. Battery life is capacity over average current; flash sectors survive a rated number of erases; a sampled first-order plant has $a = e^{-T_s/\tau}$ and $b = G(1 - a)$.
:::

::: pool
pick: 12

::: check
kind: parts
given: g = 4 | 12 | 30; m = 2 | 3; O = 200 | 500

## A main loop's longest normal pass is {g} ms. The watchdog gets a {m}× margin, and the device may be out of action for at most {O} ms after a hang.

::: part
answer: m*g
unit: ms
tolerance: 0.5%

### What timeout does the margin give?

::: misses
- [any] Margin × longest pass.
:::
:::

::: part
answer: step(O - m*g)
tolerance: 0

### Does that meet the outage limit (1 for yes)?

::: misses
- [any] The hang is caught after at most one timeout.
:::
:::

::: part
answer: O/g
tolerance: 0.5%

### What is the largest margin the outage limit would allow?

::: misses
- [any] Outage ÷ longest pass.
:::
:::
:::

::: check
kind: parts
given: Is = 0.002 | 0.01; Ia = 2 | 5; ta = 20 | 100; It = 15 | 30; tt = 5 | 10; T = 10 | 60; Q = 220 | 1000

## A sensor node sleeps at {Is} mA. Every {T} s it wakes for {ta} ms at {Ia} mA, then transmits for {tt} ms at {It} mA. It runs from {Q} mAh.

::: part
answer: Is + ((Ia - Is)*ta + (It - Is)*tt)/1000/T
unit: mA
tolerance: 0.5%

### What is the average current?

::: misses
- [any] Sleep current plus each burst's extra, times its duty.
:::
:::

::: part
answer: Q/(Is + ((Ia - Is)*ta + (It - Is)*tt)/1000/T)/24
unit: days
tolerance: 0.5%

### How long does the battery last?

::: misses
- [any] Capacity ÷ average current ÷ 24.
:::
:::
:::

::: check
kind: parts
given: V = 3.6 | 5 | 9; I = 0.05 | 0.5 | 2; q = 20 | 100

## A linear regulator drops {V} V to 3.3 V for a load of {I} mA, and draws {q} µA of its own (quiescent) current.

::: part
answer: (V - 3.3)*I
unit: mW
tolerance: 0.5%

### What does it dissipate from the load current?

::: misses
- [any] $(V_\text{in} - V_\text{out})I$.
:::
:::

::: part
answer: 3.3*I/(V*(I + q/1000))*100
unit: %
tolerance: 0.5%

### What is its efficiency?

::: misses
- [3.3/V*100] Count the quiescent current too.
- [any] $P_\text{out}/P_\text{in}$.
:::
:::
:::

::: check
kind: parts
given: N = 100000 | 1000000; a = 0.3 | 0.5; k = 0.2 | 0.3

## A task needs {N} cycles. Active current is {a} mA plus {k} mA per MHz of clock, and the board can run at 2 or 10 MHz from 3.3 V.

::: part
answer: 3.3*(a + k*2)*N/2e6*1000
unit: µJ
tolerance: 0.5%

### What energy does the task take at 2 MHz?

::: misses
- [any] $V \times I(f) \times N/f$.
:::
:::

::: part
answer: 3.3*(a + k*10)*N/10e6*1000
unit: µJ
tolerance: 0.5%

### And at 10 MHz?

::: misses
- [any] The fixed part of the current costs less when the task ends sooner.
:::
:::
:::

::: check
kind: parts
given: r = 10 | 20 | 40; I = 10 | 15 | 30; V = 3.0 | 2.9

## A coin cell at {V} V has {r} Ω of internal resistance; a radio burst draws {I} mA, and the board resets below 2.6 V.

::: part
answer: V - I*r/1000
unit: V
tolerance: 0.5%

### What voltage does the board see during the burst?

::: misses
- [any] $V - Ir$.
:::
:::

::: part
answer: (V - 2.6)/r*1000
unit: mA
tolerance: 0.5%

### What is the largest burst current that avoids a reset?

::: misses
- [any] $(V - 2.6)/r$.
:::
:::
:::

::: check
kind: parts
given: C = 0.1 | 1 | 4.7; I = 0.01 | 0.5; V2 = 2.0 | 2.4

## A supercapacitor of {C} F charged to 3.3 V keeps a clock and RAM alive at {I} mA until the voltage falls to {V2} V.

::: part
answer: C*(3.3 - V2)/(I/1000)/3600
unit: h
tolerance: 0.5%

### How long does it last (constant current)?

::: misses
- [any] $C\Delta V/I$.
:::
:::

::: part
answer: 0.5*C*(3.3^2 - V2^2)
unit: J
tolerance: 0.5%

### How much energy does it give up?

::: misses
- [0.5*C*3.3^2] It only falls to {V2} V.
- [any] $\tfrac12C(V_1^2 - V_2^2)$.
:::
:::
:::

::: check
kind: parts
given: E = 10000 | 100000; S = 2048 | 4096; r = 16 | 64; n = 2 | 4; w = 24 | 1440

## A device logs {r}-byte records {w} times a day across {n} flash sectors of {S} bytes, each rated for {E} erases.

::: part
answer: n*floor(S/r)/w
unit: days
tolerance: 0.5%

### How long does one lap of the log take?

::: misses
- [any] Records in all sectors ÷ records per day.
:::
:::

::: part
answer: E*n*floor(S/r)/w/365.25
unit: years
tolerance: 0.5%

### How long until the flash wears out?

::: misses
- [any] Endurance × lap time.
:::
:::
:::

::: check
kind: parts
given: k = 1 | 5 | 20; E = 10000 | 100000

## A firmware bug resets a device {k} times a day, and each reset writes a crash record by erasing and rewriting one fixed sector rated for {E} erases.

::: part
answer: E/k/365.25
unit: years
tolerance: 0.5%

### How long until that sector wears out?

::: misses
- [any] Endurance ÷ resets per year.
:::
:::

::: part
answer: E*floor(4096/32)/k/365.25
unit: years
tolerance: 0.5%

### And if 32-byte crash records are appended to a 4 KB log in the same sector instead?

::: misses
- [any] 128 records per erase.
:::
:::
:::

::: check
kind: parts
given: t = 10 | 50; T = 0.5 | 1 | 2; G = 0.5 | 2

## A plant of gain {G} and time constant {t} ms is sampled every {T} ms.

::: part
answer: exp(-T/t)
tolerance: 0.5%

### What is $a$?

::: misses
- [any] $e^{-T_s/\tau}$.
:::
:::

::: part
answer: (1 + exp(-T/t))/(G*(1 - exp(-T/t)))
tolerance: 0.5%

### What is the largest stable proportional gain?

::: misses
- [(1 + exp(-T/t))/(1 - exp(-T/t))] Include the plant's gain: $b = G(1 - a)$.
- [any] $(1 + a)/b$.
:::
:::

::: part
answer: exp(-T/t)/(G*(1 - exp(-T/t)))
tolerance: 0.5%

### Above what gain does the response alternate sign each sample?

::: misses
- [any] Where the pole $a - bK$ crosses zero.
:::
:::
:::

::: check
kind: parts
given: c = 20 | 50 | 100; f = 2 | 5 | 10; d = 1.5 | 2; P = 50 | 60

## A loop was designed for {P}° of phase margin at a {c} Hz crossover, ignoring sampling. It runs at {f} kHz with {d} samples of total delay.

::: part
answer: 360*c*d/(f*1000)
unit: °
tolerance: 0.5%

### How much margin does the delay take?

::: misses
- [any] $360° f_c T_d$.
:::
:::

::: part
answer: P - 360*c*d/(f*1000)
unit: °
tolerance: 0.5%

### What margin is left?

::: misses
- [any] Design margin less the delay's share.
:::
:::
:::

::: check
kind: parts
given: kp = 0.42 | 1.3; ki = 0.0007 | 0.003; q1 = 8 | 10; q2 = 16 | 20

## A PI controller stores $K_p$ = {kp} in Q{q1} and $K_iT_s$ = {ki} in Q{q2}.

::: part
answer: round(kp*2^q1)
tolerance: 0

### What integer holds $K_p$?

::: misses
- [any] $K_p \cdot 2^{q_1}$, rounded.
:::
:::

::: part
answer: round(ki*2^q2)
tolerance: 0

### And $K_iT_s$?

::: misses
- [any] $K_iT_s \cdot 2^{q_2}$, rounded.
:::
:::

::: part
answer: abs(round(ki*2^q2)/2^q2 - ki)/ki*100
unit: %
tolerance: 2%

### How far off is the stored integral gain, in percent?

::: misses
- [any] (stored − true)/true.
:::
:::
:::

::: check
kind: parts
given: g = 0.002 | 0.005; e = 200 | 1000; t = 2 | 20; T = 1 | 5

## A heater's PWM is pinned at 100% for {t} s with an error of {e} codes, sampled every {T} ms; each sample adds {g} × e to the integrator.

::: part
answer: g*e*t*1000/T
tolerance: 0.5%

### How much does the integrator wind up without anti-windup?

::: misses
- [any] Per-sample increment × samples.
:::
:::

::: part
answer: 0
tolerance: 0

### How much with conditional integration?

::: misses
- [any] It doesn't integrate while the output is limited and the error pushes the same way.
:::
:::
:::

::: check
kind: parts
given: K = 2 | 5 | 10; G = 1 | 0.5

## A proportional loop with gain {K} controls a plant of gain {G}; then an integrator is added.

::: part
answer: 100/(1 + K*G)
unit: %
tolerance: 0.5%

### What steady-state error does the proportional loop leave?

::: misses
- [any] $1/(1 + KG)$.
:::
:::

::: part
answer: 0
unit: %
tolerance: 0

### And with the integrator, once settled?

::: misses
- [any] An integrator keeps acting until the error is zero.
:::
:::
:::

::: check
kind: parts
given: a = 5 | 10; b = 20 | 40; L = 3 | 8 | 15; s = 0 | 30

## A windowed watchdog must be kicked between {a} and {b} ms after the last kick. A loop kicks once per pass; passes take {L} ms, and once a second a slow job adds {s} ms to one pass.

::: part
answer: step(L - a)*step(b - L)
tolerance: 0

### Are normal passes inside the window (1 for yes)?

::: misses
- [any] Between {a} and {b} ms.
:::
:::

::: part
answer: step(L - a)*step(b - L - s)
tolerance: 0

### Is the slow pass inside it too (1 for yes)?

::: misses
- [any] The slow pass takes {L} + {s} ms.
:::
:::
:::

::: check
kind: parts
given: Q = 220 | 1000 | 2400; Y = 1 | 5 | 10

## A device must last {Y} years on {Q} mAh.

::: part
answer: Q/(Y*8766)*1000
unit: µA
tolerance: 0.5%

### What average current may it draw?

::: misses
- [any] Capacity ÷ hours.
:::
:::

::: part
answer: Q*0.8/(Y*8766)*1000
unit: µA
tolerance: 0.5%

### And if 20% of the capacity is lost to self-discharge and cold?

::: misses
- [any] Use 80% of the capacity.
:::
:::
:::
:::
