0
0
Embedded Cprogramming~3 mins

Polling vs interrupt-driven execution in Embedded C - When to Use Which

Choose your learning style9 modes available
The Big Idea

What if your program could stop wasting time waiting and only act exactly when needed?

The Scenario

Imagine you are watching a pot on the stove, checking every few seconds if the water is boiling. You keep staring at the pot, unable to do anything else until it boils.

The Problem

This constant checking wastes your time and attention. You might miss other important tasks or slow down your work because you are stuck waiting and watching.

The Solution

Interrupt-driven execution is like having a timer that rings when the water boils. You can do other things freely, and only when the timer rings do you stop and check the pot. This saves time and makes your program more efficient.

Before vs After
Before
while(1) {
  if (device_ready()) {
    handle_device();
  }
}
After
void ISR_device() {
  handle_device();
}
// main program continues without waiting
What It Enables

It allows your program to respond immediately to important events without wasting time constantly checking.

Real Life Example

In a traffic light system, instead of constantly checking if a car is waiting, sensors trigger an interrupt to change the light only when needed, saving energy and improving traffic flow.

Key Takeaways

Polling wastes time by constantly checking for events.

Interrupts let the system react only when needed.

This improves efficiency and responsiveness in embedded systems.