Debugging and integration
Đã giới thiệu| English | Ý nghĩa |
|---|---|
| boundary probe | boundary probe |
| bisection/baɪˈsekʃn/ | bisection |
| debounce | chống rung |
| watchdog | chó giữ cửa |
Reproduce, bisect, fix one, re-verify
- The debug loop: reproduce with the smallest input; place a boundary probe (LED, breakpoint, one UART print) between trusted and suspected code; fix ONE thing; re-verify.
- Each probe halves the range, so $\log_{2}$ probes bound the hunt — ten for a thousand instructions.

1 024 suspicious instructions: probe at 512, then 256, 128, … — ten runs bound the bug to one instruction. Bisection beats rereading the code because $2^{10} = 1024$.
{exercise:uni-ee0871-bisect}
Bisecting 512 suspicious instructions needs at most —
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Each probe halves the range: 512 → 256 → … → 1 is log2(512) = 9 probes. The halving is the algorithm.
Debounce and the watchdog
- Debounce: require two consecutive equal readings — the trace 1, 0, 0, 1 declares stable 0 at t = 20 ms and correctly ignores the single 1 after.
- A watchdog resets a hung system: kick it in the main loop only, never in an ISR.
{exercise:uni-ee0872-debounce}
Samples 1, 0, 0, 1 arrive every 10 ms. With a two-consecutive rule, when is a stable state declared?
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
t = 10 gives one 0 (no verdict); t = 20 gives the second 0 → stable 0. The 1 at t = 30 is a single sample, not yet stable.
Kicking the watchdog inside an ISR is wrong because —
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
If an ISR kicks the watchdog, the main loop can hang while interrupts keep feeding the dog — the reset you need never comes. Kick it in the main loop only.