Interrupt Operation

The basic keypad application makes the CPU continuously poll the column pins to see if a button has been pressed. Polling buttons with the CPU is inefficient use of both power and CPU resources.

To solve this problem, interrupts can be used. The tinyAVR® and megaAVR® devices feature pin sense interrupts for all of their GPIO pins. With pin sense interrupts enabled, the PORT peripheral will look over the pins and automatically notify the CPU if a change has been detected. This frees the CPU to perform different tasks while waiting for a key press, or to go to sleep to save power.

The pin sense interrupt features the following triggers:

When combining the pin sense interrupts with a sleep mode, further considerations must be made. Not all pin sense interrupt triggers are compatible with all sleep modes. In the low-power keypad application, the lowest possible power consumption is desired and, therefore, a trigger that can wake the device from Power-Down Sleep mode must be used. The BOTHEDGES and the LEVEL triggers are able to wake the device in the deepest sleep mode. In the application, the BOTHEDGES trigger has been selected.

Configuration of the BOTHEDGES interrupt trigger for the columns of the keypad is shown in the following code snippet:

/* Enable BOTHEDGES interrupts for columns */