In this lesson, you will learn why relying on the CPU to manually move data between peripherals and memory creates a performance ceiling in high-speed embedded systems.
The Cost of Programmed I/O
When using Programmed I/O (Polling), the CPU is trapped in a loop, constantly checking a peripheral's status register to see if new data has arrived. This is a massive waste of cycles. If you are sampling an ADC at high frequencies, the CPU spends 99% of its time asking "Are you ready yet?" instead of performing meaningful logic or signal processing. The CPU becomes a high-priced "wait-state machine," effectively bottlenecking the entire application.
The Interrupt Overhead Penalty
You might think Interrupt-Driven I/O is the solution, but it carries its own architectural tax. Every time a peripheral triggers an interrupt, the processor must perform a Context Switch:
- Saving State: The hardware pushes registers onto the stack.
- Branching: The CPU jumps to the Interrupt Service Routine (ISR).
- Processing: The CPU executes the data movement logic.
- Restoring State: The CPU pops the registers to resume the mainline code.
For high-speed data streams—like an ADC sampling at 100 kHz—the overhead of entering and exiting the ISR for every single byte or word consumes a significant percentage of available processing power. Even with features like Tail-Chaining, the CPU is still doing the heavy lifting of moving data from the peripheral register to a memory buffer.
Consider this inefficient pattern:
void ADC_IRQHandler(void) {
// Each sample causes a full context switch!
// The CPU is acting as a "glorified courier"
buffer[index++] = ADC->DR;
if (index >= MAX_SIZE) {
index = 0;
}
}
In this architecture, the CPU is tethered to the peripheral's speed. As sampling rates increase, the time spent inside ISRs leaves no headroom for your main control loops. This is why, when high-speed throughput is required, we offload this task to a Direct Memory Access (DMA) controller. DMA allows the hardware to move data autonomously, freeing the CPU to focus solely on high-level decision-making.
Key Takeaway: Programmed I/O and interrupt-driven data movement consume excessive CPU cycles because they force the processor to perform manual data handling, resulting in context-switch overhead that limits overall system throughput.