IO4: Reliable firmware: interrupts, RTOS tasks, watchdogs and safe state

Lesson 1 of 5 · reading 15–25 minutes; practice and project time is on the module page

Interrupts: reacting on time

🎯You'll be able to

Use interrupts for events that can't wait, and keep interrupt handlers short and safe.

🏠The everyday picture

A teacher marking books stops when the fire bell rings. They don't finish the page first, but they also don't mark books during the fire drill: they deal with the bell, then go back.

📘What it really is

📝A worked example

Input: a float switch should wake JalSetu when the tank overflows.

Steps:

  1. Configure the switch's pin as a wake source and an interrupt on change.
  2. In the handler, record the time and set overflow = True; nothing else.
  3. In the main work, see the flag, send an alarm, and clear it. Ignore further changes within 50 ms (bounce).

Expected output: an overflow alarm that arrives within seconds, without waiting for the 15-minute timer.

🌍Where it's used

📝Case scenario

A water meter counted pulses in an interrupt handler that also wrote each count to flash. During heavy use, pulses arrived faster than flash writes finished and some were lost. Counting in the handler and saving totals every minute fixed it.

🖱️Try it

For three events (a button press, a sensor reading every 15 minutes, a byte arriving from a GPS module), decide whether to poll or use an interrupt, and why. Success: a choice and a reason for each.

⚠️Common mistakes

🛠️For your project

JalSetu wakes on a timer; the capstone design notes can add a pin wake for an overflow switch.

✅Quick check

What should an interrupt handler do?

Show the answer

Something short, such as setting a flag or queueing a value, leaving slow work for later.

Why debounce a mechanical switch?

Show the answer

It bounces and can trigger many times for one press.

← BackIO4
ProLearners Assist