Building Hard Real-Time Systems on AVR Microprocessors

Wide availability, versatility, and modest power requirements of 8-bit AVR microcontrollers, as well as the plethora of available low-power peripherals, make 8-bit AVR ideal for embedded systems. However, relatively small RAM and Flash memory (especially on the lower-power chips) make parallel sensor interrogation challenging due to the overhead of running a multi-processing environment. On the other hand, serial IO may result in the lack of a guaranteed system response time that is a mandatory requirement for hard real-time systems. This is especially true for peripherals with variable response times.

As requested by my "embedded systems" interest group, here I will share my preferred "universal" solution for the asynchronous IO that allows real-time interaction with multiple peripherals.

The approach is demonstrated on a test-stand with an ATmega328 and 3 peripheral interfaces: a photo-resistor (short response time), a buzzer (medium response time), and an OLED display (delayed response). The main routine (main loop) handles only the HID, displaying ambient lighting conditions on the OLED and playing a tone of the correspondingly higher or lower pitch. The photo-resistor state is polled by a separate interrogator routine driven by hardware interrupts from the ATmega328 internal clock. Readings are entered into a FIFO buffer that is parsed by the main loop independently from the photo-resistor interrogator.

Check the video link on the left for a demonstration of how fast-changing photo-resistor readings are being buffered by the interrogator and later displayed by the main routine. Note that buffered readings continue to be displayed after the ambient lighting conditions stop changing, effectively capturing all of the intermediate photo-resistor states.

Detailed schematics and source codes to be provided shortly.