Improving the super-loop with interrupts
Even though a basic super-loop can only step through functions sequentially, there are still ways to achieve concurrency and meet critical time-constraints. MCUs have some features to aid in responding to events in a timely fashion. This section will introduce those features and describe how they can be used in a super-loop-style program.
Introducing interrupts
As mentioned before, making the super-loop execute at the frequency of the fastest event may be difficult in complex systems. Also, polling for a single event can be wasteful in terms of CPU cycles and power use. And, polling may result in a system that cannot be responsive to anything else, which generally should be avoided. So then, how can we get a single-core processor to do things in parallel? Well, we can’t–there’s only one processor after all. But, when a processor is capable of running millions of instructions per second, it is possible to get the...