
- #CODEVISIONAVR XMEGA IO INPUT HOW TO#
- #CODEVISIONAVR XMEGA IO INPUT PORTABLE#
PORTA.PIN4CTRL = PORT_OPC_PULLUP_gc | PORT_ISC_LEVEL_gc //low-level triggered interrupt PORTA.INTCTRL = PORT_INT0LVL_HI_gc //enable PORTA interrupt _delay_ms(100) //allow some time for bounce While (BUTTON_DOWN) //wait for button release disable all possible external components hereĬCP = CCP_IOREG_gc //unclock watchdog access This single-button approach has the benefit that the device is very simple to operate, no extra switches, nor PCB tracks are necessary.
Software function – short press (while the device is running, not relevant for the power control driver). Power off – long hold (until all LEDs light up) and release (all LEDs go off). The single button has the following functions: Schematic is not necessary to understand everything – just imagine an XMEGA32A4U, 3,3V LDO from battery to the MCU and a single button from any XMEGA IO pin to GND. In this case a button wake up happens via the asynchronous port interrupt, so no clocks are necessary and “power down” mode can be used. The deeper the sleep mode – the lower power consumption and less clocks (and peripherals) running. Most of the information applies equally to all AVR MCUs. I wanted to keep the design as simple as possible, so there is just one button connected to the MCU and no separate power switch. I am working on a portable device that is powered from a Li-Ion cell, has an USB socket for charging, MCU, couple of LEDs and a button.
This post describes how to implement firmware-controlled device power switching on an XMEGA.