Improve Cortex M4 MCU interrupt responses with an intelligent Peripheral Event System - Embedded.com

Improve Cortex M4 MCU interrupt responses with an intelligent Peripheral Event System

In this Product How-To design article, Atmel’s Andreas Eieland and Espen Krangnes describe how they improved interrupt response times and reduced device driver development time for developers of applications using the company’s Cortex M4 MCU based implementation with the use of an intelligent Peripheral Event System previously used on its 8- and 16-bit MCUs.

CPU cycles, energy, and days-to-launch are scarce resources in any embedded development project, but they become even more precious in applications where the microcontroller (MCU) must attend to one or more real-time events.

If the events are too frequent, or too complex, the CPU itself can quickly become a single-point bottleneck that consumes unexpectedly-large quantities of energy, instruction cycles, and programming resources.

These issues are most apparent in battery-powered applications where external interrupts that pull the MCU from its low-power sleep state can shorten operational life.

To solve this perennial dilemma, we’ve developed an advanced MCU architecture (Figure 1 ) which combines a traditional 8- or 32-bit RISC processor and a Peripheral Event System (PES). The PES is a distributed network of intelligent analog and digital I/O peripheral elements which operates independently of the CPU, traditional busses and the DMA system.

It can be configured to have its peripherals selectively react to external inputs and interact with each other without using any CPU resources, enabling them to autonomously perform complex functions such as data collection, timing, and communication, as well as respond to real-time events.

The PES operates in parallel with the CPU to ensure precisely-timed execution of critical real-time tasks or enter a so-called “SleepWalking” state which extends the PES’s capabilities into the MCU’s sleep domain. During SleepWalking, the PES’s configuration logic selects the peripherals which will continue to function when the MCU enters its low-power sleep state, and the conditions which will cause the peripherals to wake up the system.

Figure 1: The SAM4L MCU is based on the powerful 32-bit ARM CORTEX-M4 RISC processor core and includes a rich selection of I/O and other peripheral elements. Its Peripheral Event System (PES) controller allows the peripherals to interact without intervention from the CPU. When used in conjunction with SAM4L’s SleepWalking functions, the PES can execute complex functions while the ARM processor remains in a low-power sleep state.

The Peripheral Event System’s basic architecture has already been used and tested the Atmel AVR XMEGA series of 8-bit processors and in the 32-bit AVR UC3, allowing the MCU to be used in many applications in which the sensing, control, and communication tasks would normally require a more expensive and power-hungry CPU.

The addition of a PES system and picoPower energy conservation circuitry to Atmel’s SAM4L Cortex M4-based 32-bit MCU family brings powerful real-time capabilities, ultra-low-power operation, and simplified programming to applications such as intelligent sensor nodes, industrial transmitters, sensors and detectors, sport watches and portable healthcare devices, or any other design which requires the processing capabilities of the Cortex M4 and ultra low power consumption.

Smart peripheral cores: the next step in MCU evolution
Intelligent peripherals are a natural extension of the I/O controllers, algorithmic accelerators, and other specialized hardware modules already used in many MCUs. Even many of today’s low-cost 8-bit microcontrollers include specialized accelerator modules or state machines to offload compute-intensive tasks such as encryption, arithmetic’s, error correction, and supporting communication protocols from the main processor.

Nevertheless, the accelerator modules, communication ports, and other I/O all rely on the main processor (CPU) for some aspects of their operation and often compete with it for access to the memory bus and other shared resources.

As a result, many applications require carefully-written interrupt service routines , a Real Time Operating System or other software mechanisms to manage the conflicting demands of the CPU and its peripherals, and even then the CPU can end up as a bottleneck in the total program flow

As a simple example, an MCU is often required to execute event-related tasks at specific times, such as performing an analog to digital conversion when a timer/counter’s register signals an overflow, or capture the value in a Timer/Counter’s register at the instant a user presses a button.

A traditional MCU would require the developer to either continuously poll the counter/timer and the push button or, more likely to create an interrupt service routine (ISR) for each task and include it in the MCU’s firmware.

This can introduce problems if the MCU is being used in a power-constrained application where it minimizes the drain in its battery or energy harvesting source by spending most of its time in a sleep state because each button press or timer-based interrupt requires the MCU wake up and attend to the event.

In addition, servicing real-time events adds another layer of challenges to software development. The speed with which the MCU can respond to an event will depend heavily on how many other interrupts are competing for its attention at that moment.

If, for example, the application in question had many other interrupt-driven peripherals to attend to, the count the MCU readings of the counter/timer’s output register might be much higher that it was at the instant of the actual button push.

Likewise, if the MCU took a few milliseconds too long to initiate the A/D conversion the signal it was trying to sample may have changed, or vanished entirely. As a result, great care must be taken to prioritize the peripheral inputs and their service routines so that the highest-priority events are attended to within their critical time window.

The Peripheral Event System eliminates these conflicts with an independent parallel network that allows peripherals to interact without intervention from the microcontroller’s CPU. It is an event-driven system where each event is an indication that a change of state within a peripheral has occurred in response to an internal or an external stimulus.

The PES’s Event Routing Network is a set of programmable multiplexers that connect events from an event generator to the appropriate event user (Figure 2 below ).

Each channel also includes programmable control and filtering logic that is used to define a peripheral’s behavior for a particular event, and the inputs required to produce it. This inter-peripheral communication allows actions to be triggered by external events, events generated by other peripherals, or by the CPU as a software-generated “manual” function.

Figure 2: – The Peripheral Event System
As shown in Figure 2, the PES can be configured so that individual or multiple peripheral elements can generate events simultaneously, often on the same conditions as interrupt requests.

These events are routed through the PES’s event routing system to other peripherals where they can be used to trigger subsequent actions. The CPU is only used for the initial setup phase, after this the peripherals and the PES operate completely independent of the CPU.

Using the earlier example, the PES could easily be configured to react on a timer/counter value or trigger an A/D conversion at a specific time, and without the CPU’s intervention.

In addition, either (or both) of these events can be triggered without ever bringing the MCU out of its sleep state, allowing the system’s limited battery capacity to be spared. The PES can also add more intelligence to the application by adding a sequence of events which wake the CPU if the timer/counter or the A/D reading it captures falls above or below a preset threshold value.

Even this relatively simple example illustrates how a peripheral event system can reduce an embedded system’s energy consumption, improve its ability to respond to real-time events, and simplify its software.

PES + ARM = Low Power + Real Time Performance
The SAM4L MCU’s Cortex M4 RISC processor is augmented with a Peripheral Event System that adds intelligence and autonomy to all its critical peripheral functions including:

*GPIO
*Asynchronous Timer (RTC)
*General-Purpose Timer /Counters
*Two-Wire Interface (TWI)
*Power Manager
*Analog Comparators and ADCs
*Capacitive Touch controller
*Peripherals and their associated multiplexer/filter logic is programmed by writing the appropriate data to each peripheral’s control registers.
* The code for the configuration sequence can also be created using a visual interface that’s available in Atmel’s Studio6 integrated development environment.

SleepWalking reduces power consumption and increases throughput. Once configured, the PES allows the SAM4L to spend most of its time in a “SleepWalking” state where its 32-bit ARM Cortex-M4 CPU remains asleep while it peripherals detect and respond to events, control I/O, energy management, and execute other routine functions.

It is also possible to configure the SAM4L’s Peripheral Event System to perform complex operations, with very little intervention from the Cortex M4 CPU, saving both valuable program memory and execution time. For example, it is possible to:

• Use a complex set of trigger conditions to start conversions on two ADCs at the same time

• Simultaneously perform an input capture and start an ADC conversion, in order to accurately time-stamp the conversion data.

• Simultaneously start two timers to ensure an identical time base without any offset

• Trigger a Timer/Counter input capture when a user presses a button

• Start an analog-to-digital conversion on the occurrence of a timer/counter overflow condition.

• Create responses based on virtually any other combination of ADC, DAC, Timer/counter and DMA events.

The PES’s intelligent peripherals can also be programmed to quickly bring the CPU out of its low-power SleepWalking mode to perform routine operations or respond to specific real-time events and alarm conditions which require its attention.

Advantages of peripheral event controlThe SAM4L’s PES-enhanced Cortex M4 architecture allows developers to create products that enjoy superior energy efficiency and real-time performance without the added costs and complexity associated with a traditional RTOS.

The SAM4L uses Atmel proprietary low power embedded Flash and the latest semiconductor processes and several architectural refinements to deliver industry-leading energy efficiency in both active and sleep modes (Figure 3 below ).


Figure 3: This graph compares the power consumption of MCUs utilizing Atmel’s SleepWalking mechanisms with that of competitive MCUS.

Additional energy saving are realized thanks to its SleepWalking mode, the SAM4L is able to spend a greater percentage of its time in a deep sleep while the Peripheral Event System handles most routine tasks. The PES’s autonomous peripherals only enter their active mode when an event occurs which meets their pre-programmed trigger criteria (Figure 4 below ).

When used in conjunction with the Cortex M4 CPU’s low operating power and rapid wake-up characteristics, the SAM4L produces a dramatically smaller energy footprint than conventional MCUs while delivering superior 32-bit performance for conventional and real-time applications.

Figure 4 : The SAM4 MCU’s architecture is designed to minimize energy consumption in both its operating and sleep modes. In this illustration a single power cycle is reflected where the device is in sleep, wakes up and performs a cycle, and then returns to sleep again. The light blue bar reflects the regular intervals of a power cycle on a traditional MCU. The turquoise bar reflects how the picoPower in the SAM4L reduces the wake-up time and power consumption per MHz, along with increased processing performance. And, the dark blue bars reflect how the peripheral event system, DMA, power management and dynamic clock scale can perform many operations more efficiency by offloading the CPU in active mode.

In addition to energy savings, the PES provides several other distinct advantages over conventional MCU architectures. Some of the most notable include:

*The Peripheral Event System execute its functions in 2 clock cycles, enabling event processing with deterministic latency without an RTOS.

*The PES’s low-latency event handling provides reliable fault detection with 100% predictable reaction time.

*Autonomous peripherals simplify, and in many cases, eliminate complex interrupt routines for cleaner, less fragile code and shorter development/debug cycles.

*Simplified software with less real-time dependencies retires risk in software development and update cycles.

*Designs are simper to implement and test.

*Intelligent peripherals reduce CPU’s overhead load, freeing processor resources for use in other applications or features.

Conclusion
Embedded systems designers face a daunting set of challenges as the products they design are expected to deliver more intelligence and increased functionality, often on a very limited power budget.

Microcontrollers equipped with a network of autonomous peripherals, such as the Peripheral Event System (PES) can help designers meet those challenges by autonomously performing complex functions such as data collection, timing, and communication, as well as respond to real-time events without involving the device’s main processor.

This distributed network of intelligent analog and digital I/O peripheral elements which operates independently of the CPU and its DMA system and can be configured to have its peripherals selectively react to external inputs and interact with each other without using any CPU resources.

In addition to dramatically reducing the MCU’s energy consumption, the PES eliminates the need for most interrupt service routines (ISRs), enabling deterministic response to real-time events and greatly simplifying software development.

The Peripheral Event System’s basic architecture has already been used in Atmel’s AVR XMEGA series of 8-bit processors and in the 32-bit AVR UC3, and has recently been incorporated in Atmel’s SAM4L Cortex M4-based 32-bit MCU family.

This new family of PES-augmented MCUs brings powerful real-time capabilities, ultra-low-power operation, and simplified programming to applications such as intelligent sensor nodes for HVAC & alarm systems, glucose monitors, and point-of-sale terminals, or any other design which requires the processing capabilities of the Cortex M4.

Espen Krangnes is an AVR product marketing manager at Atmel Corporation, which he joined in 2004. He works on a variety of projects. Espen has a master of science degree in engineering cybernetics from the Norwegian University of Science and Technology. His master’s thesis involved using an Atmel AVR ATtiny26 to create a fully automated juvenile lobster larvae sorting machine.

Andreas Eieland is Senior Product Marketing Manager for Flash Microcontrollers at Atmel. Prior to this position, Mr. Eieland worked as an AVR Product Marketing Manager and Applications Engineer at Atmel's AVR Products Center. He holds a Master of Science degree from the Norwegian University of Science and Technology.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.