Improved Interrupt Handling in Microchip’s ATtiny817

Discover the new features of ATtiny 817, Microchip’s newest microcontroller, and find out how you can use this feature-rich solution for your applications.

Interrupt handling in the new ATtiny817

Written by: Arild Rodland, product marketing for MCU08 division of Microchip Technology Inc.

Interrupt handling got a whole lot smarter in the new AVR® microcontrollers (MCUs), and the ATtiny817 from Microchip is the first AVR device to take advantage of these changes.

Those familiar with the different AVR families should know that, traditionally, interrupt handling for tinyAVR® and megaAVR® devices has been very straight forward where all interrupts have a predefined priority, in which the lowest interrupt vector address will have highest priority. For the bigger XMEGA® MCU family, the interrupt system contains a programmable multilevel controller (PMIC), which allows the user to assign interrupts to three priority levels, making it possible to tailor the priority queue.

The new interrupt controller on the ATtiny817 is a cross between these two. So let’s look at it and find out what is new.

Interrupt Priority

Default settings on the ATtiny817 will be set up with an interrupt vector table with static priority where the lowest interrupt vector address has highest priority. See Figure 1. This is identical to other tinyAVRs.

FIGURE 1: INTERRUPT PRIORITY USING STATIC PRIORITY SCHEME

There are a couple of potential issues with static priority. First, if you have many interrupts with high priority, you may come into a situation where high-priority interrupt constantly blocks low-priority interrupts. The result is interrupt starvation. This means you do not have enough time to service all interrupts, and the lowest priority ones will never get any service. To fix this, ATtiny817 allows for a dynamic (round-robin) priority scheme. If you enable this round-robin scheme, the last serviced interrupt will get lowest priority next time an interrupt occurs. See Figure 2.

FIGURE 2: DYNAMIC ROUND-ROBIN PRIORITY SCHEME

Two Level Interrupt Controller

The round-robin priority scheme solves interrupt starvation, but what should be done if you want to give a peripheral higher priority than is defined in the interrupt vector table?

Even though the design team has made a very sensible, hardwired priority between the peripherals, we do understand that there is always the possibility that some people need to give an interrupt higher priority than what is defined by the default interrupt priority.

In the ATtiny817 we have the option to elevate a selectable interrupt vector to have priority over all others. To use this feature, simply write the desired vector address to the LVL1VEC register and this interrupt will have priority.

Compact Vector Table

There is a new feature on tinyAVR, called Compact Vector Table (CVT). Using this feature will truncate all interrupts into three vectors. One for non-maskable interrupts (for ATtiny817: CRC error interrupt) one for all Level0 interrupts (for ATiny817: All interrupts are default level0) and one for level1 interrupts (for ATtiny817: A single interrupt can be given higher priority by inputting its vector address into the LVL1VEG register).

This can be a useful feature when you only use a few interrupts. Reducing the vector table to only three vectors means that the interrupt table will occupy fewer Flash locations, essentially freeing this space to be used for user code. Be aware however, if you use this approach, you will need to add additional code in the interrupt handler to find out which interrupt is actually requesting service. This will add time, for both code writing and verification testing, to the completion of your design. For this reason, the compact vector table is most useful if only a few interrupts are used.

Advanced Feature: If round-robin is not enabled, the LVL0PRI register is still active, and will still define the starting point for the lowest priority interrupt, so if you want, you can statically shift the priority in the vector table. As an example, you could shift it to give USART the highest priority. Default value of this register is 0x00, so after reset, the lowest interrupt vector will have highest priority as expected.

Shifting the Vector Table Priority

I will round out this article with a trick/feature not explicitly mentioned in the datasheet. When using round-robin priority, there is a register called LVL0PRI which will contain the address of the last executed interrupt. This will be the interrupt with the lowest priority when selecting which interrupt to execute next. If we change this value, we directly affect which interrupts have lowest and highest priority.

As shown here, the new ATtiny187 MCU offers powerful interrupt management features that allow designers to control interrupt priority and response time to fit their design requirements. Now the only question is, what will you create to leverage these capabilities?

See related product

ATTINY817-XPRO

Microchip Technology Embedded System Development Boards and Kits View

microchip technology logo

Latest News

Sorry, your filter selection returned no results.

We've updated our privacy policy. Please take a moment to review these changes. By clicking I Agree to Arrow Electronics Terms Of Use  and have read and understand the Privacy Policy and Cookie Policy.

Our website places cookies on your device to improve your experience and to improve our site. Read more about the cookies we use and how to disable them here. Cookies and tracking technologies may be used for marketing purposes.
By clicking “Accept”, you are consenting to placement of cookies on your device and to our use of tracking technologies. Click “Read More” below for more information and instructions on how to disable cookies and tracking technologies. While acceptance of cookies and tracking technologies is voluntary, disabling them may result in the website not working properly, and certain advertisements may be less relevant to you.
We respect your privacy. Read our privacy policy here