8-Bit Xmega A Microcontroller Xmega A Manual
8-Bit Xmega A Microcontroller Xmega A Manual
8-Bit Xmega A Microcontroller Xmega A Manual
the AVR® XMEGATM A Microcontroller family. The XMEGA A is a family of low power,
high performance and peripheral rich CMOS 8/16-bit microcontrollers based on the
AVR enhanced RISC architecture. The available XMEGA A modules described in this
manual are:
• AVR CPU
• Memories
• DMA - Direct Memory Access Controller
• Event System
8-bit
•
•
System Clock and Clock options
Power Management and Sleep Modes
XMEGA A
• System Control and Reset Microcontroller
• Battery Backup System
• WDT - Watchdog Timer
• Interrupts and Programmable Multi-level Interrupt Controller
• PORT - I/O Ports XMEGA A
• TC - 16-bit Timer/Counter
• AWeX - Advanced Waveform Extension
MANUAL
• Hi-Res - High Resolution Extension
• RTC - Real Time Counter
• RTC32 - 32-bit Real Time Counter
• TWI - Two Wire Serial Interface
• SPI - Serial Peripheral Interface
• USART - Universal Synchronous and Asynchronous Serial Receiver and Transmitter
• IRCOM - IR Communication Module Preliminary
• AES and DES Crypto Engine
• EBI - External Bus Interface
• ADC - Analog to Digital Converter
• DAC - Digital to Analog Converter
• AC - Analog Comparator
• IEEE 1149.1 JTAG Interface
• PDI - Program and Debug Interface
• Memory Programming
• Peripheral Address Map
• Register Summary
• Interrupt Vector Summary
• Instruction Set Summary
8077H- AVR-12/09
XMEGA A
1.2 Resources
A comprehensive set of development tools, application notes and datasheets are available for
download on http://www.atmel.com/avr.
This manual only contains general modules and peripheral descriptions. The XMEGA A device
datasheet contains device specific information. The XMEGA application notes contain example
code and show applied use of the modules and peripherals.
For new users it is recommended to read the AVR1000 - Getting Started Writing C-code for
XMEGA, and AVR1900 - Getting started with ATxmega128A1 application notes.
2
8077H–AVR–12/09
XMEGA A
2. Overview
The XMEGA A is a family of low power, high performance and peripheral rich CMOS 8/16-bit
microcontrollers based on the AVR enhanced RISC architecture. By executing powerful instruc-
tions in a single clock cycle, the XMEGA A achieves throughputs approaching 1 Million
Instructions Per Second (MIPS) per MHz allowing the system designer to optimize power con-
sumption versus processing speed.
The AVR CPU combines a rich instruction set with 32 general purpose working registers. All the
32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent
registers to be accessed in one single instruction, executed in one clock cycle. The resulting
architecture is more code efficient while achieving throughputs many times faster than conven-
tional single-accumulator or CISC based microcontrollers.
The XMEGA A devices provide the following features: In-System Programmable Flash with
Read-While-Write capabilities, Internal EEPROM and SRAM, four-channel DMA Controller,
eight-channel Event System and Programmable Multi-level Interrupt Controller, up to 78 general
purpose I/O lines, 16- or 32-bit Real Time Counter (RTC), up to eight flexible 16-bit Timer/Coun-
ters with compare modes and PWM, up to eight USARTs, up to four I2C and SMBUS compatible
Two Wire Serial Interfaces (TWIs), up to four Serial Peripheral Interfaces (SPIs), AES and DES
crypto engine, up to two 8-channel, 12-bit ADCs with optional differential input with programma-
ble gain, up to two 2-channel, 12-bit DACs, up to four analog comparators with window mode,
programmable Watchdog Timer with separate Internal Oscillator, accurate internal oscillators
with PLL and prescaler and programmable Brown-Out Detection.
The Program and Debug Interface (PDI), a fast 2-pin interface for programming and debugging,
is available. The devices also have an IEEE std. 1149.1 compliant JTAG test interface, and this
can also be used for On-chip Debug and programming.
The XMEGA A devices have five software selectable power saving modes. The Idle mode stops
the CPU while allowing the SRAM, DMA Controller, Event System, Interrupt Controller and all
peripherals to continue functioning. The Power-down mode saves the SRAM and register con-
tents but stops the oscillators, disabling all other functions until the next TWI or pin-change
interrupt, or Reset. In Power-save mode, the asynchronous Real Time Counter continues to run,
allowing the application to maintain a timer base while the rest of the device is sleeping. In
Standby mode, the Crystal/Resonator Oscillator is kept running while the rest of the device is
sleeping. This allows very fast start-up from external crystal combined with low power consump-
tion. In Extended Standby mode, both the main Oscillator and the Asynchronous Timer continue
to run. To further reduce power consumption, the peripheral clock to each individual peripheral
can optionally be stopped in Active mode and Idle sleep mode.
The devices are manufactured using Atmel's high-density nonvolatile memory technology. The
program Flash memory can be reprogrammed in-system through the PDI or JTAG. A Bootloader
running in the device can use any interface to download the application program to the Flash
memory. The Bootloader software in the Boot Flash section will continue to run while the Appli-
cation Flash section is updated, providing true Read-While-Write operation. By combining an
8/16-bit RISC CPU with In-System Self-Programmable Flash, the Atmel XMEGA A is a powerful
microcontroller family that provides a highly flexible and cost effective solution for many embed-
ded applications.
The XMEGA A devices are supported with a full suite of program and system development tools
including: C compilers, macro assemblers, program debugger/simulators, programmers, and
evaluation kits.
3
8077H–AVR–12/09
XMEGA A
PP[0..7] PN[0..7]
XTAL2 TOSC2
PORT Q (8)
PORT R (2)
PORT N (8)
PORT P (8)
Oscillator Watchdog
Circuits/ Oscillator
Clock
Generation
Real Time Watchdog
Counter Timer
EVENT ROUTING NETWORK
DATA BUS
Power VCC
DACA Supervision
Event System Oscillator POR/BOD &
Controller Control RESET GND
PA[0..7] PORT A (8)
SRAM
DMA Sleep
ACA Controller Controller RESET/
PDI_CLK
PDI
ADCA PDI_D
BUS Prog/Debug
AREFA Controller Controller
Int. Ref.
AREFB CPU
PORT L (8) PL[0..7]
Interrupt
ADCB AES
Controller
PORT K (8) PK[0..7]
ACB
PB[0..7]/
JTAG PORT J (8) PJ[0..7]
NVM Controller
PORT B (8)
EBI
DACB Flash EEPROM
PORT H (8) PH[0..7]
USARTD0:1
USARTE0:1
USARTF0:1
TCC0:1
TCD0:1
TCE0:1
TCF0:1
TWIC
TWID
TWIE
TWIF
SPIC
SPID
SPIE
SPIF
PORT C (8)
PORT D (8)
PORT E (8)
PORT F (8)
4
8077H–AVR–12/09
XMEGA A
3. AVR CPU
3.1 Features
• 8/16-bit high performance AVR RISC CPU
– 138 instructions
– Hardware multiplier
• 32x8-bit registers directly connected to the ALU
• Stack in RAM
• Stack Pointer accessible in I/O memory space
• Direct addressing of up to 16M bytes of program memory and 16M bytes of data memory
• True 16/24-bit access to 16/24-bit I/O registers
• Efficient support for both 8-, 16- and 32-bit Arithmetic
• Configuration Change Protection of system critical features
3.2 Overview
XMEGA uses the 8/16-bit AVR CPU. The main function of the CPU is to ensure correct program
execution. The CPU is able to access memories, perform calculations and control peripherals.
Interrupt handling is described in a separate section, refer to ”Interrupts and Programmable
Multi-level Interrupt Controller” on page 123 for more details on this.
5
8077H–AVR–12/09
XMEGA A
DATA BUS
Flash
Program
Program
Counter
Memory
32 x 8 General
Purpose
Instruction Registers
OCD
Register
STATUS/ Instruction
CONTROL Decode
Multiplier/
ALU DES
DATA BUS
Peripheral Peripheral
SRAM EEPROM PMIC
Module 1 Module n
The Arithmetic Logic Unit (ALU) supports arithmetic and logic operations between registers or
between a constant and a register. Single register operations can also be executed in the ALU.
After an arithmetic operation, the Status Register is updated to reflect information about the
result of the operation.
The ALU is directly connected to the fast-access Register File. The 32 x 8-bit general purpose
working registers all have single clock cycle access time allowing single-cycle Arithmetic Logic
Unit (ALU) operation between registers or between a register and an immediate. Six of the 32
registers can be used as three 16-bit address pointers for program and data space addressing -
enabling efficient address calculations.
The memory spaces are all linear and regular memory maps. The Data Memory space and the
Program Memory space are two different memory spaces.
The Data Memory space is divided into I/O registers and SRAM. In addition the EEPROM can
be memory mapped in the Data Memory.
All I/O status and control registers reside in the lowest 4K bytes addresses of the Data Memory.
This is referred to as the I/O Memory space. The lowest 64 addresses can be accessed directly,
or as the data space locations from 0x00 - 0x3F. The rest is the Extended I/O Memory space,
ranging from 0x40 to 0x1FFF. I/O registers here must be access as data space locations using
load (LD/LDS/LDD) and store (ST/STS/STD) instructions.
6
8077H–AVR–12/09
XMEGA A
The SRAM holds data, and code cannot be executed from here. It can easily be accessed
through the five different addressing modes supported in the AVR architecture. The first SRAM
address is 0x2000.
Data address 0x1000 to 0x1FFF is reserved for memory mapping of EEPROM.
The Program Memory is divided in two sections, the Application Program section and the Boot
Program section. Both sections have dedicated Lock bits for write and read/write protection. The
SPM instruction that is used for self-programming of the Application Flash memory must reside
in the Boot Program section. A third section exists inside the Application section. This section,
the Application Table section, has separate Lock bits for write and read/write protection. The
Application Table section can be used for storing non-volatile data or application software.
7
8077H–AVR–12/09
XMEGA A
When an enabled interrupt occurs, the Program Counter is vectored to the actual interrupt vector
in order to execute the interrupt handling routine. Hardware clears the corresponding interrupt
flag automatically.
A flexible interrupt controller has dedicated control registers with an additional Global Interrupt
Enable bit in the Status Register. All interrupts have a separate interrupt vector, starting from the
Reset Vector at address 0 in the Program Memory. All interrupts have a programmable interrupt
level. Within each level they have priority in accordance with their interrupt vector position where
the lower interrupt vector address has the higher priority.
clkCPU
1st Instruction Fetch
1st Instruction Execute
2nd Instruction Fetch
2nd Instruction Execute
3rd Instruction Fetch
3rd Instruction Execute
4th Instruction Fetch
Figure 3-3 on page 8 shows the internal timing concept for the Register File. In a single clock
cycle an ALU operation using two register operands is executed, and the result is stored back to
the destination register.
clkCPU
Total Execution Time
8
8077H–AVR–12/09
XMEGA A
9
8077H–AVR–12/09
XMEGA A
7 0 Addr.
R0 0x00
R1 0x01
R2 0x02
…
R13 0x0D
General R14 0x0E
Purpose R15 0x0F
Working R16 0x10
Registers R17 0x11
…
R26 0x1A X-register Low Byte
R27 0x1B X-register High Byte
R28 0x1C Y-register Low Byte
R29 0x1D Y-register High Byte
R30 0x1E Z-register Low Byte
R31 0x1F Z-register High Byte
Most of the instructions operating on the Register File have direct access to all registers, and
most of them are single cycle instructions.
The Register File is located in a separate address space, so the registers are not accessible as
data memory.
Bit (X-register) 15 8 7 0
Bit (Y-register) 15 8 7 0
Bit (Z-register) 15 8 7 0
The lowest register address holds the least significant byte (LSB). In the different addressing
modes these address registers have functions as fixed displacement, automatic increment, and
automatic decrement (see the instruction set reference for details).
10
8077H–AVR–12/09
XMEGA A
Bit (Individually) 7 0 7 0 7 0
RAMPX XH XL
Bit (X-pointer) 23 16 15 8 7 0
Bit (Individually) 7 0 7 0 7 0
RAMPY YH YL
Bit (Y-pointer) 23 16 15 8 7 0
Bit (Individually) 7 0 7 0 7 0
RAMPZ ZH ZL
Bit (Z-pointer) 23 16 15 8 7 0
When reading (ELPM) and writing (SPM) program memory locations above the first 128K bytes
of the program memory, RAMPZ is concatenated with the Z-register to form the 24-bit address.
LPM is not affected by the RAMPZ setting.
Bit (Individually) 7 0 15 0
RAMPD K
Bit (D-pointer) 23 16 15 0
Bit (Individually) 7 0 7 0 7 0
EIND ZH ZL
Bit (D-pointer) 23 16 15 8 7 0
11
8077H–AVR–12/09
XMEGA A
12
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
13
8077H–AVR–12/09
XMEGA A
data addresses below 64K bytes, this register is not in use. This register is not available if the
data memory including external memory is less than 64K bytes.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
14
8077H–AVR–12/09
XMEGA A
first 64K bytes, and writing (SPM) program memory locations above the first 128K bytes of the
program memory.
When accessing data addressees below 64K bytes, reading program memory locations below
64K bytes and writing program memory locations below 128K bytes, this register is not in use.
This register is not available if the data memory including external memory and program mem-
ory in the device is less than 64K bytes.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
(1)
Initial Value 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
15
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
(1)
Initial Value 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
+0x0F I T H S V N Z C SREG
Initial Value 0 0 0 0 0 0 0 0
16
8077H–AVR–12/09
XMEGA A
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 Reserved - - - - - - - -
+0x01 Reserved - - - - - - - -
+0x02 Reserved - - - - - - - -
+0x03 Reserved - - - - - - - -
+0x04 CCP CCP[7:0] 13
+0x05 Reserved - - - - - - - -
+0x06 Reserved - - - - - - - -
+0x07 Reserved - - - - - - - -
+0x08 RAMPD RAMPD[7:0] 13
+0x09 RAMPX RAMPX[7:0] 14
+0x0A RAMPY RAMPY[7:0] 14
+0x0B RAMPZ RAMPZ[7:0] 14
+0x0C EIND EIND[7:0] 15
+0x0D SPL SPL[7:0] 15
+0x0E SPH SPH[7:0] 16
+0x0F SREG I T H S V N Z C 16
17
8077H–AVR–12/09
XMEGA A
4. Memories
4.1 Features
• Flash Program Memory
– One linear address space
– In-System Programmable
– Self-Programming and Bootloader support
– Application Section for application code
– Application Table Section for application code or data storage
– Boot Section for application code or bootloader code
– Separate lock bits and protection for all sections
– Built in fast CRC check of a selectable flash program memory section
• Data Memory
– One linear address space
– Single cycle access from CPU
– SRAM
– EEPROM
Byte and page accessible
Optional memory mapping for direct load and store
– I/O Memory
Configuration and Status registers for all peripherals and modules
16 bit-accessible General Purpose Register for global variables or flags
– External Memory support
SRAM
SDRAM
Memory mapped external hardware
– Bus arbitration
Safe and deterministic handling of CPU and DMA Controller priority
– Separate buses for SRAM, EEPROM, I/O Memory and External Memory access
Simultaneous bus access for CPU and DMA Controller
• Production Signature Row Memory for factory programmed data
Device ID for each microcontroller device type
Serial number for each device
Oscillator calibration bytes
ADC, DAC and temperature sensor calibration data
• User Signature Row
One flash page in size
Can be read and written from software
Content is kept after chip erase
4.2 Overview
This section describes the different memories in XMEGA. The AVR architecture has two main
memory spaces, the Program Memory and the Data Memory. Executable code can only reside
in the Program Memory, while data can be stored both in the Program Memory and the Data
Memory. The Data Memory includes both SRAM, and an EEPROM Memory for non-volatile data
storage. All memory spaces are linear and require no paging. Non-Volatile Memory (NVM)
18
8077H–AVR–12/09
XMEGA A
spaces can be locked for further write and read/write operations. This prevents unrestricted
access to the application software.
A separate memory section contains the Fuse bytes. These are used for setting important sys-
tem functions, and write access is only possible from an external programmer.
0x000000
Read-While-Write Section
Application Flash
Section
Application Table
Flash Section
End RWW, End Application
No Read-While-
Write Section
19
8077H–AVR–12/09
XMEGA A
20
8077H–AVR–12/09
XMEGA A
The Lock bits are used to set protection level on the different flash sections. They are used to
block read and/or write access of the code. Lock bits can be written from en external program-
mer and from the application software to set a more strict protection level, but not to set a less
strict protection level. Chip erase is the only way to erase the lock bits. The lock bits are erased
after the rest of the flash memory is erased.
An unprogrammed fuse or lock bit will have the value one, while a programmed flash or lock bit
will have the value zero.
Both fuses and lock bits are reprogrammable like the Flash Program memory.
21
8077H–AVR–12/09
XMEGA A
Start/End
Data Memory
Address
0x000000
I/O Memory
(Up to 4 KB)
0x001000
EEPROM
(Up to 4 KB)
0x002000
Internal SRAM
External Memory
(0 to 16 MB)
0xFFFFFF
I/O Memory, EEPROM and SRAM will always have the same start addresses for all XMEGA
devices. External Memory (if exist) will always start at the end of Internal SRAM and end at
address 0xFFFFFF.
22
8077H–AVR–12/09
XMEGA A
4.7 EEPROM
XMEGA has EEPROM memory for non-volatile data storage. It is addressable either in as a sep-
arate data space (default), or it can be memory mapped and accessed in normal data space.
The EEPROM memory supports both byte and page access.
23
8077H–AVR–12/09
XMEGA A
EEPROM
DMA Controller
Read
SRAM
DMA Controller
Write External
Memory
4.12 Device ID
Each device has a three-byte device ID which identifies the device. These registers identify
Atmel as the manufacturer of the device and the device type. A separate register contains the
revision number of the device.
24
8077H–AVR–12/09
XMEGA A
from the application software. As long as JTAG is disabled the I/O pins required for JTAG can be
used as normal I/O pins.
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
25
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
• Bit 7 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
26
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R S
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
27
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
28
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 1 1 1 1 1 1 1 1
This register is a direct mapping of the NVM Lockbits into the IO Memory Space, in order to
enable direct read access from the application software. Refer to ”LOCKBITS - Non-Volatile
Memory Lock Bit Register” on page 34 for description of the Lock Bits.
29
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 1 1 1 1 1 1 1 1
• Bit 7 - Reserved
This fuse bit is reserved. For compatibility with future devices, always write this bit to one when
this register is written.
30
8077H–AVR–12/09
XMEGA A
Initial Value 1 1 1 1 1 1 1 0
31
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 1 1 - - - - - -
32
8077H–AVR–12/09
XMEGA A
Changing of the EESAVE fuse bit takes effect immediately after the write time-out elapses.
Hence, it is possible to update EESAVE and perform a chip erase according to the new setting
of EESAVE without leaving and re-entering programming mode
Bit 7 6 5 4 3 2 1 0
Initial Value 1 1 1 1 1 1 1 1
33
8077H–AVR–12/09
XMEGA A
Table 4-8. Boot Lock Bit for The Boot Loader Section
BLBB[1:0] Group Configuration Description
No Lock, no restrictions for SPM and (E)LPM accessing
11 NOLOCK
the Boot Loader section.
Write Lock, SPM is not allowed to write the Boot Loader
10 WLOCK
section
Read Lock, (E)LPM executing from the Application
section is not allowed to read from the Boot Loader
section.
01 RLOCK
If the interrupt vectors are placed in the Application
section, interrupts are disabled while executing from the
Boot Loader section.
Read and Write Lock, SPM is not allowed to write to the
Boot Loader section and (E)LPM executing from the
Application section is not allowed to read from the Boot
00 RWLOCK Loader section.
If the interrupt vectors are placed in the Application
section, interrupts are disabled while executing from the
Boot Loader section
34
8077H–AVR–12/09
XMEGA A
Table 4-10. Boot Lock Bit for the Application Table Section
BLBAT[1:0] Group Configuration Description
No Lock, no restrictions for SPM and (E)LPM accessing
11 NOLOCK
the Application Table Section.
Write Lock, SPM is not allowed to write the Application
10 WLOCK
Table
Read Lock, (E)LPM executing from the Boot Loader
Section is not allowed to read from the Application Table
Section.
01 RLOCK
If the interrupt vectors are placed in the Boot Loader
Section, interrupts are disabled while executing from the
Application Section.
Read and Write Lock, SPM is not allowed to write to the
Application Table Section and (E)LPM executing from
the Boot Loader Section is not allowed to read from the
00 RWLOCK Application Table Section.
If the interrupt vectors are placed in the Boot Loader
Section, interrupts are disabled while executing from the
Application Section.
35
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
36
8077H–AVR–12/09
XMEGA A
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
37
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 x x x x x
Read/Write R R R R R R R R
Initial Value x x x x x x x x
38
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Read/Write R R R R R R R R
Initial Value x x x x x x x x
39
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Read/Write R R R R R R R R
Initial Value x x x x x x x x
40
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 x x x x
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 x x x x
41
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 x x x x
Bit 7 6 5 4 3 2 1 0
+n GPIORn[7:0] GPIORn
Initial Value 0 0 0 0 0 0 0 0
This is a general purpose register that can be used to store data such as global variables in the
bit accessible I/O memory space.
Read/Write R R R R R R R R
Initial Value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
42
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
43
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
• Bit 4 - EVSYS1LOCK:
Setting this bit will lock all registers in the Event System related to event channels 4 to 7 for fur-
ther modifications. The following registers in the Event System are locked: CH4MUX,
CH4CTRL, CH5MUX, CH5CTRL, CH6MUX, CH6CTRL, CH7MUX, CH7CTRL. This bit is pro-
tected by the Configuration Change Protection mechanism, for details refer to Section 3.12
”Configuration Change Protection” on page 12.
• Bit 0 - EVSYS0LOCK:
Setting this bit will lock all registers in the Event System related to event channels 0 to 3 for fur-
ther modifications. The following registers in the Event System are locked: CH0MUX,
CH0CTRL, CH1MUX, CH1CTRL, CH2MUX, CH2CTRL, CH3MUX, CH3CTRL. This bit is pro-
44
8077H–AVR–12/09
XMEGA A
tected by the Configuration Change Protection mechanism, for details refer to Section 3.12
”Configuration Change Protection” on page 12.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
• Bit 1 - Reserved
This bit is reserved and will always be read as zero. For compatibility with future devices, always
write this bit to zero when this register is written.
45
8077H–AVR–12/09
XMEGA A
46
8077H–AVR–12/09
XMEGA A
47
8077H–AVR–12/09
XMEGA A
48
8077H–AVR–12/09
XMEGA A
5.1 Features
• The DMA Controller allows high-speed transfers with minimal CPU intervention
– from one memory area to another
– from memory area to peripheral
– from peripheral to memory area
– from peripheral to another peripheral
• Four DMA Channels with separate
– transfer triggers
– interrupt vectors
– addressing modes
• From 1 byte to 16M bytes data transfer in a single transaction
• Up to 64 KByte block transfers with repeat
• 1, 2, 4, or 8 byte burst transfers
• Internal and external transfer triggers
• Multiple addressing modes
– Static
– Increment
– Decrement
• Optional reload of source and destination address at the end of each
– Burst
– Block
– Transaction
• Optional Interrupt on end of transaction
• Programmable channel priority
5.2 Overview
The XMEGA Direct Memory Access (DMA) Controller is a highly flexible DMA Controller capable
of transferring data between memories and peripherals with minimal CPU intervention. The
DMA controller has flexible channel priority selection, several addressing modes, double buffer-
ing capabilities and large block sizes.
The DMA Controller can move data between memories and peripherals, between memories and
between peripheral registers directly.
There are four DMA channels that have individual source, destination, triggers and block sizes.
The different channels also have individual control settings and individual interrupt settings and
interrupt vectors. Interrupt requests may be generated both when a transaction is complete or if
the DMA Controller detects an error on a DMA channel. When a DMA channel requests a data
transfer, the bus arbiter will wait until the AVR CPU is not using the data bus and permit the DMA
Controller to transfer data. Transfers are done in bursts of 1, 2, 4 or 8 bytes. Addressing can be
static, incremental or decremental. Automatic reload of source and/or destination address can
be done after each burst transfer, block transfer, when transmission is complete, or disabled.
Both application software, peripherals and Events can trigger DMA transfers.
49
8077H–AVR–12/09
XMEGA A
DMA transaction
50
8077H–AVR–12/09
XMEGA A
By default, a trigger starts a block transfer operation. The transfer continues until one block is
transferred. When the block is transferred, the channel will wait for the next trigger to arrive
before it start transferring the next block. It is possible to select the trigger to start a burst transfer
instead of a block transfer. This is called a single shot transfer. A new trigger will then start a new
burst transfer. When repeat mode is enabled, the start of transfer of the next block does not
require a transfer trigger. It will start as soon as the previous block is done.
If the trigger source generates a transfer request during an ongoing transfer this will be kept
pending, and the transfer can start when the ongoing one is done. Only one pending transfer
can be kept, so if the trigger source generates more transfer requests when one is already pend-
ing, these will be lost.
5.5 Addressing
The source and destination address for a DMA transfer can either be static, incremental or dec-
remental with individual selections for source and destination. When address increment or
decrement is used, the default behaviour is to update the address after each access. The origi-
nal source and destination address is stored by the DMA controller, so the source and
destination addresses can be individually configured to be reloaded at the following points:
• End of each burst transfer
• End of each block transfer
• End of transaction
• Never reload
51
8077H–AVR–12/09
XMEGA A
5.11 Protection
In order to insure safe operation some of the channel registers are protected during a transac-
tion. When the DMA channel Busy flag (CHnBUSY) is set for a channel, the user can only
modify these registers and bits:
• CTRL register
• INTFLAGS register
• TEMP registers
• CHEN, CHRST, TRFREQ, REPEAT bits of the Channel CTRL register
• TRIGSRC register
5.12 Interrupts
The DMA Controller can generate interrupts when an error is detected on a DMA channel or
when a transaction is complete for a DMA channel. Each DMA channel has a separate interrupt
vector, and there are different interrupt flags for error and transaction complete.
If repeat is not enabled the transaction complete flag is set at the end of the Block Transfer. If
unlimited repeat is enabled, the transaction complete flag is also set at the end of each Block
Transfer.
52
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
53
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
+0x04 CH3ERRIF CH2ERRIF CH1ERRIF CH0ERRIF CH3TRNFIF CH2TRNFIF CH1TRNFIF CH0TRNFIF INTFLAGS
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x05 CH3BUSY CH2BUSY CH1BUSY CH0BUSY CH3PEND CH2PEND CH1PEND CH0PEND STATUS
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
54
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
• Bit 3 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
55
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
56
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
57
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
58
8077H–AVR–12/09
XMEGA A
Table 5-8. DMA Trigger Sources, base value for all modules and peripherals
TRIGSRC base value Group Configuration Description
0x00 OFF Software triggers only
0x01 SYS System DMA triggers base value
0x10 ADCA ADCA DMA triggers base value
0x15 DACA DACA DMA trigger bas
0x20 ADCB ADCB DMA triggers base value
0x25 DACB DACB DMA triggers base value
0x40 TCC0 Timer/Counter C0 DMA triggers base value
0x46 TCC1 Timer/Counter C1 triggers base value
0x4A SPIC SPI C DMA triggers value
0x4B USARTC0 USART C0 DMA triggers base value
0x4E USARTC1 USART C1 DMA triggers base value
0x60 TCD0 Timer/Counter D0 DMA triggers base value
0x66 TCD1 Timer/Counter D1 triggers base value
0x6A SPID SPI D DMA triggers value
0x6B USARTD0 USART D0 DMA triggers base value
0x6E USARTD1 USART D1 DMA triggers base value
0x80 TCE0 Timer/Counter E0 DMA triggers base value
0x86 TCE1 Timer/Counter E1 triggers base value
0x8A SPIE SPI E DMA triggers value
0x8B USARTE0 USART E0 DMA triggers base value
0x8E USARTE1 USART E1 DMA triggers base value
0xA0 TCF0 Timer/Counter F0 DMA triggers base value
0xA6 TCF1 Timer/Counter F1 triggers base value
0xAA SPIF SPI F DMA trigger value
0xAB USARTF0 USART F0 DMA triggers base value
0xAE USARTF1 USART F1 DMA triggers base value
Table 5-9. DMA Trigger sources, offset values for Event System triggers
TRGSRC offset value Group Configuration Description
+0x00 CH0 Event Channel 0
+0x01 CH1 Event Channel 1
+0x02 CH2 Event Channel 2
59
8077H–AVR–12/09
XMEGA A
Table 5-10. DMA Trigger sources, offset values for DAC and ADC triggers
TRGSRC offset value Group Configuration Description
+0x00 CH0 ADC/DAC Channel 0
+0x01 CH1 ADC/DAC Channel 1
(1)
+0x02 CH2 ADC Channel 2
+0x03 CH3 ADC Channel 3
(2)
+0x04 CH4 ADC Channel 0, 1, 2, 3
Notes: 1. For DAC only Channel 0 and 1 exists and can be used as triggers
2. Channel 4 equals ADC Channel 0 to 3 OR'ed together.
Table 5-11. DMA Trigger sources, offset values for Timer/ Counter triggers
TRGSRC offset value Group Configuration Description
+0x00 OVF Overflow/Underflow
+0x01 ERR Error
+0x02 CCA Compare or Capture Channel A
+0x03 CCB Compare or Capture Channel B
(1)
+0x04 CCC Compare or Capture Channel C
+0x05 CCD Compare or Capture Channel D
Table 5-12. DMA Trigger sources, offset values for USART triggers
TRGSRC offset value Group Configuration Description
0x00 RXC Receive complete
0x01 DRE Data Register Empty
The Group Configuration is the “base_offset”, for example TCC1_CCA for the Timer/Counter C1
CC Channel A the transfer trigger.
Initial Value 0 0 0 0 0 0 0 0
60
8077H–AVR–12/09
XMEGA A
• Bit 7:0 - TRFCNT[15:8]: DMA Channel n Block Transfer Count Register High byte
These bits hold the 8 MSB of the 16-bits block transfer count.
The default value of this register is 0x1. If a user write 0x0 to this register and fire a DMA trigger,
DMA will be doing 0xFFFF transfers.
Bit 7 6 5 4 3 2 1 0
Initial Value 1 1 1 1 1 1 1 1
• Bit 7:0 - TRFCNT[7:0]: DMA Channel n Block Transfer Count Register Low byte
These bits hold the 8 LSB of the 16-bits block transfer count.
The default value of this register is 0x1. If a user write 0x0 to this register and fire a DMA trigger,
DMA will be doing 0xFFFF transfers.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
REPCNTcounts how many times a block transfer is performed. For each block transfer this reg-
ister will be decremented.
When repeat mode is enabled (see REPEAT bit in ”ADDRCTRL - DMA Channel Address Con-
trol Register” on page 57), this register is used to control when the transaction is complete. The
counter is decremented after each block transfer if the DMA has to serve a limited number of
repeated block transfers. When repeat mode is enabled the channel is disabled when REPCNT
reaches zero, and the last block transfer is completed. Unlimited repeat is achieved by setting
this register to zero.
Initial Value 0 0 0 0 0 0 0 0
61
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
62
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
63
8077H–AVR–12/09
XMEGA A
64
8077H–AVR–12/09
XMEGA A
6. Event System
6.1 Features
• Inter peripheral communication and signalling
• CPU and DMA independent operation
• 8 Event Channels allows for up to 8 signals to be routed at the same time
• 100% predictable timing between peripherals
• Events can be generated by
– Timer/Counters (TCxn)
– Real Time Counter (RTC)
– Analog to Digital Converters (ADCx)
– Analog Comparators (ACx)
– Ports (PORTx)
– System Clock (ClkSYS)
• Events can be used by
– Timer/Counters (TCxn)
– Analog to Digital Converters (ADCx)
– Digital to Analog Converters (DACx)
– DMA (DMA) Controller
– Ports
• Advanced Features
– Manual Event Generation from software (CPU)
– Quadrature Decoding
– Digital Filtering
• Operative in Active and Idle mode
6.2 Overview
The Event System is a set of features for inter peripheral communication. It enables the possibil-
ity for a change of state in one peripheral to automatically trigger actions in other peripherals.
The change of state in a peripheral that will trigger actions in other peripherals is configurable in
software. It is a simple, but powerful system as it allows for autonomous control of peripherals
without any use of interrupt, CPU or DMA resources.
The indication of a change of state in a peripheral is referred to as an event. The events are
passed between peripherals using a dedicated routing network called the Event Routing Net-
work. Figure 6-1 on page 66 shows a basic block diagram of the Event System with the Event
Routing Network and the peripherals that are connected.
65
8077H–AVR–12/09
XMEGA A
PORTx ClkSYS
CPU
ADCx RTC
Event Routing
Network
DACx ACx
IRCOM DMA
T/Cxn
The CPU is not part of the Event System, but it indicates that it is possible to manually generate
events from software or by using the on-chip debug system.
The Event System works in active and idle mode.
6.3 Events
In the context of the Event System, an indication that a change of state within a peripheral has
occurred is called an event. There are two main types of events: Signaling events and data
events. Signaling events only indicate a change of state while data events contain additional
information on the event.
The peripheral from where the event origin is called the Event Generator. Within each periph-
eral, for example a Timer/Counter, there can be several event sources, such as a timer compare
match or timer overflow. The peripheral using the event is called the Event User, and the action
that is triggered is called the Event Action.
Timer/Counter ADC
Compare Match
Event Channel Sweep
Over-/Underflow
| Routing
Network Single
Conversion
Error
66
8077H–AVR–12/09
XMEGA A
Events can be manually generated by writing to the STROBE and DATA registers.
67
8077H–AVR–12/09
XMEGA A
Event Channel 7
Event Channel 6
Event Channel 5
Event Channel 4
Event Channel 3
Event Channel 2
Event Channel 1
Event Channel 0
(PORTC)
(16)
(8) TCC0 (8)
TCC1 (8)
CH0CTRL[7:0]
(PORTD) CH0MUX[7:0]
(16)
(8) TCD0 (8)
TCD1 (8)
CH1CTRL[7:0]
(PORTE)
(16)
CH1MUX[7:0]
(8) TCE0 (8)
TCE1 (8)
(PORTF) CH2CTRL[7:0]
(8) TCF0 (8) (16)
CH2MUX[7:0]
TCF1 (8)
(13)
(8) ADCA (4)
CH3CTRL[7:0]
(8) ADCB (4)
CH3MUX[7:0]
(8) DACA
(8) DACB
CH4CTRL[7:0]
AC0
CH4MUX[7:0]
AC1
AC2
AC3
CH5CTRL[7:0]
RTC CH5MUX[7:0]
(48)
PORTA (8)
PORTB (8)
CH6CTRL[7:0]
PORTC (8)
CH6MUX[7:0]
PORTD (8)
PORTE (8)
PORTF (8)
CH7CTRL[7:0]
CH7MUX[7:0]
Having eight multiplexers means that it is possible to route up to eight events at the same time.
It is also possible to route one event through several multiplexers.
Not all XMEGA parts contain all peripherals. This only means that peripheral is not available for
generating or using events. The network configuration itself is compatible between all devices.
68
8077H–AVR–12/09
XMEGA A
6.6 Filtering
Each event channel includes a digital filter. When this is enabled for an event channel, an event
must be sampled with the same value for configurable number of system clock cycles before it is
accepted. This is primarily intended for pin change events.
69
8077H–AVR–12/09
XMEGA A
Forward Direction
QDPH0
QDPH90
QDINDX
00 10 11 01
Backward
Direction
QDPH0
QDPH90
QDINDX
01 11 10 00
Figure 6-4 shows typical quadrature signals from a rotary encoder. The signals QDPH0 and
QDPH90 are the two quadrature signals. When QDPH90 leads QDPH0, the rotation is defined
as positive or forward. When QDPH0 leads QDPH90, the rotation is defined as negative, or
reverse. The concatenation of the two phase signals is called the quadrature state or the phase
state.
In order to know the absolute rotary displacement a third index signal (QDINDX) can be used.
This gives an indication once per revolution.
70
8077H–AVR–12/09
XMEGA A
• Set the period register of the Timer/Counter to ('line count' * 4 - 1). (The line count of the
quadrature encoder).
• Enable the Timer/Counter by setting CLKSEL to a CLKSEL_DIV1.
The angle of a quadrature encoder attached to QDPH0, QDPH90 (and QINDX) can now be read
directly from the Timer/Counter Count register. If the Count register is different from BOTTOM
when the index is recognized, the Timer/Counter error flag is set. Similarly the error flag is set if
the position counter passes BOTTOM without the recognition of the index.
CHnMUX[7:0] CHnMUX
Initial Value 0 0 0 0 0 0 0 0
71
8077H–AVR–12/09
XMEGA A
Note: 1. The description of how PORTS generate events are described in ”Port Event” on page 136.
72
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
• Bit 7 - Reserved
This bit is reserved and will always be read as zero. For compatibility with future devices, always
write this bit to zero when this register is written.
73
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
74
8077H–AVR–12/09
XMEGA A
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CH0MUX CH0MUX[7:0] 71
+0x01 CH1MUX CH1MUX[7:0] 71
+0x02 CH2MUX CH2MUX[7:0] 71
+0x03 CH3MUX CH3MUX[7:0] 71
+0x04 CH4MUX CH4MUX[7:0] 71
+0x05 CH5MUX CH5MUX[7:0] 71
+0x06 CH6MUX CH6MUX[7:0] 71
+0x07 CH7MUX CH7MUX[7:0] 71
+0x08 CH0CTRL - QDIRM[1:0] QDIEN QDEN DIGFILT[2:0] 73
+0x09 CH1CTRL - - - - - DIGFILT[2:0] 73
+0x0A CH2CTRL - QDIRM[1:0] QDIEN QDEN DIGFILT[2:0] 73
+0x0B CH3CTRL - - - - - DIGFILT[2:0] 73
+0x0C CH4CTRL - QDIRM[1:0] QDIEN QDEN DIGFILT[2:0] 73
+0x0D CH5CTRL - - - - - DIGFILT[2:0] 73
+0x0E CH6CTRL - - - - - DIGFILT[2:0] 73
+0x0F CH7CTRL - - - - - DIGFILT[2:0] 73
+0x10 STROBE STROBE[7:0] 74
+0x11 DATA DATA[7:0] 74
75
8077H–AVR–12/09
XMEGA A
7.1 Features
• Fast start-up time
• Safe run-time clock switching
• Internal Oscillators:
– 32 MHz run-time calibrated RC oscillator
– 2 MHz run-time calibrated RC oscillator
– 32.768 kHz calibrated RC oscillator
– 32 kHz Ultra Low Power (ULP) oscillator with 1 kHz output
• External clock options
– 0.4 - 16 MHz Crystal Oscillator
– 32.768 kHz Crystal Oscillator
– External clock
• PLL with internal and external clock options with 1 to 31x multiplication
• Clock Prescalers with 1 to 2048x division
• Fast peripheral clock running at 2 and 4 times the CPU clock speed
• Automatic Run-Time Calibration of internal oscillators
• Crystal Oscillator failure detection
7.2 Overview
XMEGA has a flexible clock system, supporting a large number of clock sources. It incorporates
both accurate integrated oscillators, and external crystal oscillators and resonators. A high fre-
quency Phase Locked Loop (PLL) and clock prescalers can be used to generate a wide range of
clock frequencies. A calibration feature (DFLL) is available, and can be used for automatic run-
time calibration of the internal oscillators. A Crystal Oscillator Failure Monitor can be enabled to
issue a Non-Maskable Interrupt and switch to internal oscillator if the external oscillator fails.
After reset, the device will always start up running from the 2 MHz internal oscillator. During nor-
mal operation, the System Clock source and prescalers can be changed from software at any
time.
Figure 7-1 on page 77 presents the principal clock system in the XMEGA. All of the clocks do not
need to be active at a given time. The clocks to the CPU and peripherals can be stopped using
sleep modes and power reduction registers as described in ”Power Management and Sleep” on
page 95.
76
8077H–AVR–12/09
XMEGA A
Figure 7-1. The Clock system, clock sources and clock distribution
Real Time Non-Volatile
Peripherals RAM AVR CPU
Counter Memory
clkCPU
clkPER
clkPER2
clkPER4
clkrtc
System Clock
Prescalers
Brown-out Watchdog
Detection Timer
clkSYS
PLL
DIV32
DIV32
DIV4
XTAL1
TOSC2
TOSC1
77
8077H–AVR–12/09
XMEGA A
78
8077H–AVR–12/09
XMEGA A
C1
XTAL1
GND
Two capacitors, C1 and C2, may be added to match the required load capacitance for the con-
nected crystal.
G e n e ra l
P u rp o s e XTAL2
I/O
E x te rn a l
C lo c k XTAL1
S ig n a l
79
8077H–AVR–12/09
XMEGA A
7-4 on page 80. A low power mode with reduced voltage swing on TOSC2 is available. This
oscillator can be used as clock source for the System Clock, RTC and as the DFLL reference.
C2
TO SC2
C1
TO SC1
GND
Two capacitors, C1 and C2, may be added to match the required load capacitance for the con-
nected crystal.
Prescaler A divides the System Clock and the resulting clock is the clkPER4. Prescaler B and
prescaler C can be enabled to divide the clock speed further and enable peripheral modules to
run at twice or four times the CPU Clock frequency. If Prescaler B and C are not used all the
clocks will run at the same frequency as output from Prescaler A.
80
8077H–AVR–12/09
XMEGA A
The System Clock selection and prescaler registers are protected by the Configuration Change
Protection mechanism, employing a timed write procedure for changing the system clock and
prescaler settings. For details refer to ”Configuration Change Protection” on page 12.
f OUT = f IN ⋅ PLL_FAC
Four different reference clock sources can be chosen as input to the PLL:
• 2 MHz internal oscillator
• 32 MHz internal oscillator divided by 4
• 0.4 - 16 MHz Crystal Oscillator
• External clock
81
8077H–AVR–12/09
XMEGA A
DFLL
DFLL
When the DFLL is enabled it will count each oscillator clock cycle, and for each reference clock
edge, the counter value is compared to the fixed ideal relationship between the reference clock
and the 1kHz reference frequency. If the internal oscillator runs too fast or too slow, the DFLL
will decrement or increment the corresponding DFLL Calibration Register value by one to adjust
the oscillator frequency slightly. When the DFLL is enabled the DFLL Calibration Register can-
not be written from software.
The ideal counter value representing the number of oscillator clock cycles for each reference
clock cycle is loaded to the DFLL Oscillator Compare Register during reset. The register can
also be written from software to change the frequency the internal oscillator is calibrated to.
The DFLL will stop when entering a sleep-mode where the oscillators are stopped. After wake-
up the DFLL will continue with the calibration value found before entering sleep. For the DFLL
Calibration Register to be reloaded with the default value it has after reset, the DFLL must dis-
abled before entering sleep and enabled the again after leaving sleep.
The active reference cannot be disabled when the DFLL is enabled.
When the DFLL is disabled the DFLL calibration Register can be written from software for man-
ual run-time calibration of the oscillator.
For details on internal oscillator accuracy when the DFLL is enabled, refer to the device data
sheet.
82
8077H–AVR–12/09
XMEGA A
clock or oscillator is used to derive the System Clock (i.e clock reference for the PLL when this is
used as the active system clock) and an clock or oscillator fails (stops), the device will:
• Switch to the 2 MHz internal oscillator, independently of any clock system lock setting.
• Reset the Oscillator Control Register and System Clock Selection Register to their default
values.
• Set the External Clock Source Failure Detection Interrupt Flag.
• Issue a non-maskable interrupt (NMI).
If the external oscillator fails when it is not used as the System Clock source, the external oscil-
lator is automatically disabled while the system clock will continue to operate normally.
If the external clock is below 32 kHz then the failure monitor mechanism should not be enabled
in order to avoid unintentional fail detection.
When the failure monitor is enabled, it cannot be disabled until next reset.
The failure monitor is automatically disabled in all sleep modes where the external clock or oscil-
lator is stopped. During wake-up from sleep it is automatically enabled again.
The External Clock Source Failure Monitor setting is protected by the Configuration Change Pro-
tection mechanism, employing a timed write procedure for changing the system clock and
prescaler settings. For details refer to ”Configuration Change Protection” on page 12.
83
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
• Bit 7 - Reserved
This bit is reserved and will always be read as zero. For compatibility with future devices, always
write this bit to zero when this register is written.
84
8077H–AVR–12/09
XMEGA A
85
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
86
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 1
87
8077H–AVR–12/09
XMEGA A
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
88
8077H–AVR–12/09
XMEGA A
• Bit 4 - Reserved
This bit is reserved and will always be read as zero. For compatibility with future devices, always
write this bit to zero when this register is written.
Notes: 1. This option should only be used when frequency stability at start-up is not important for the
application. The option is not suitable for crystals.
2. This option is intended for use with ceramic resonators and will ensure frequency stability at
start-up. It can also be used when the frequency stability at start-up is not important for the
application.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
89
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value x x x x x x x x
Initial Value 0 0 0 0 0 0 0 0
90
8077H–AVR–12/09
XMEGA A
Notes: 1. 32 kHz TOSC cannot be selected as source for the PLL. An external clock must be minimum
0.4 MHz to be used as source clock.
• Bit 5 - Reserved
This bit is reserved and will always be read as zero. For compatibility with future devices, always
write this bit to zero when this register is written.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
91
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 1 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 x x x x x
92
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
7.11.6.1 COMP2 - Oscillator Compare Register 2, 2 MHz DFLL /32 MHz DFLL
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
93
8077H–AVR–12/09
XMEGA A
94
8077H–AVR–12/09
XMEGA A
8.1 Features
• 5 sleep modes
– Idle
– Power-down
– Power-save
– Standby
– Extended standby
• Power Reduction register to disable clock to unused peripherals
8.2 Overview
XMEGA provides various sleep modes and software controlled clock gating in order to tailor
power consumption to the application's requirement. Sleep modes enables the microcontroller to
shut down unused modules to save power. When the device enters sleep mode, program exe-
cution is stopped and interrupts or reset is used to wake the device again. The individual clock to
unused peripherals can be stopped during normal operation or in sleep, enabling a much more
fine tuned power management than sleep modes alone.
95
8077H–AVR–12/09
XMEGA A
Table 8-1 on page 96 shows the different sleep modes and the active clock domains, oscillators
and wake-up sources.
Table 8-1. Active clock domains and wake-up sources in the different sleep modes.
Active clock domain Oscillators Wake-up sources
All interrupts
CPU clock
RTC clock
interrupts
Interrupts
Sleep modes
Idle X X X X X X X X
Power-down X X
Power-save X X X X X
Standby X X X
Extended Standby X X X X X X
The wake-up time for the device is dependent on the sleep mode and the main clock source.
The start-up time for the system clock source must be added to the wake-up time for sleep
modes where the clock source is stopped. For details on the start-up time for the different oscil-
lators options refer to ”System Clock and Clock options” on page 76.
The content of the Register File, SRAM and registers are kept during sleep. If a reset occurs
during sleep, the device will reset, start up and execute from the Reset Vector.
96
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
97
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
98
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Note: Disabling of analog modules stops the clock to the analog blocks themselves and not only the
interfaces.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
• Bit 7 - Reserved
This bit is reserved and will always be read as zero. For compatibility with future devices, always
write this bit to zero when this register is written.
• Bit 5 - USART1
Setting this bit stops the clock to the USART1. When the bit is cleared the peripheral should be
reinitialized to ensure proper operation.
• Bit 4 - USART0
Setting this bit stops the clock to the USART0. When the bit is cleared the peripheral should be
reinitialized to ensure proper operation.
99
8077H–AVR–12/09
XMEGA A
100
8077H–AVR–12/09
XMEGA A
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRL - - - - SMODE[2:0] SEN 97
+0x01 Reserved - - - - - - - -
+0x02 Reserved - - - - - - - -
+0x03 Reserved - - - - - - - -
+0x04 Reserved - - - - - - - -
+0x05 Reserved - - - - - - - -
+0x06 Reserved - - - - - - - -
+0x07 Reserved - - - - - - - -
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 PRGEN - - - AES EBI RTC EVSYS DMA 98
+0x01 PRPA - - - - - DAC ADC AC 99
+0x02 PRPB - - - - - DAC ADC AC 99
+0x03 PRPC - TWI USART1 USART0 SPI HIRES TC1 TC0 99
+0x04 PRPD - TWI USART1 USART0 SPI HIRES TC1 TC0 99
+0x05 PRPE - TWI USART1 USART0 SPI HIRES TC1 TC0 99
+0x06 PRPF - TWI USART1 USART0 SPI HIRES TC1 TC0 99
+0x07 Reserved - - - - - - - -
101
8077H–AVR–12/09
XMEGA A
9. Reset System
9.1 Features
• Power-on reset source
• Brown-out reset source
• Software reset source
• External reset source
• Watchdog reset source
• Program and Debug Interface reset source
9.2 Overview
The Reset System will issue a system reset and set the device to its initial state if a reset source
goes active. All IO registers will be set to their initial value, and the program counter is reset to
the Reset Vector location. The reset controller is asynchronous, hence no running clock is
required to reset the device.
XMEGA has seven different reset sources. If more than one reset source is active, the device
will be kept in reset until all reset sources have released their reset. After reset is released from
all reset sources, the default oscillator is started and calibrated before the internal reset is
released and the device starts running.
The reset system has a status register with individual flags for each reset source. The Status
register is cleared at Power-on Reset, hence this register will show which source(s) that has
issued a reset since the last power-on. A software reset feature makes it possible to issue a sys-
tem reset from the user software.
An overview of the reset system is shown in Figure 9-1 on page 103.
102
8077H–AVR–12/09
XMEGA A
Power - On
Detection
Reset
Brown - Out
Detection Reset
External Reset
Watchdog
Reset
R
Internal Reset
S
Software Reset
103
8077H–AVR–12/09
XMEGA A
104
8077H–AVR–12/09
XMEGA A
ality and not to ensure safe operation. The Brown-out detection (BOD) must be enabled to
ensure safe operation and detect if VCC voltage drops below minimum operating voltage.
Only the Power-on reset Flag will be set after Power-on reset. The Brown-out Reset Flag is not
set even though the BOD circuit is used.
VPOT VBOT
VCC
tTOUT
TIMEOUT
INTERNAL
RESET
V
dV
VCC dt
VPOSR,MAX
VCC
VPOT
For characterization data on the VPOT level for rising and falling VCC, and VPOSR slope consult the
device data sheet.
Note that the Power-on detection circuit is not designed to detect drops in the VCC voltage.
Brown-out detection must be enabled to detect falling VCC voltage, even if the VCC level falls
below the VPOT level.
105
8077H–AVR–12/09
XMEGA A
tBOD
VCC VBOT+
VBOT-
TIME-OUT tTOUT
INTERNAL
RESET
For characterization data on tBOD consult the device data sheet. The trigger level is determined
by a programmable BODLEVEL setting, see Table 9-2.
Notes: 1. The values here are nominal values only. For typical, maximum and minimum numbers consult
the device data sheet.
2. Changing these fuse bits will have no effect until leaving programming mode.
The BOD circuit has 3 modes of operation:
• Disabled: In this mode there is no monitoring of the VCC level, and hence it is only
recommended for applications where the power supply is stable.
• Enabled: In this mode the VCC level is continuously monitored, and a drop in VCC below VBOT
for at least tBOD will give a brown-out reset.
106
8077H–AVR–12/09
XMEGA A
• Sampled: In this mode the BOD circuit will sample the VCC level with a period identical to
the 1 kHz output from the Ultra Low Power (ULP) oscillator. Between each sample the BOD is
turned off. This mode will reduce the power consumption compared to the enabled mode, but
a fall in the VCC level between 2 positive edges of the 1 kHz ULP output will not be detected.
If a brown-out is detected in this mode, the BOD circuit is set in enabled mode to ensure that
the device is kept in reset until VCC is above VBOT again.
The BODACT fuse determines the BOD setting for active mode and idle mode, while the
BODPD fuse determines the brown-out detection setting for all sleep modes except idle mode.
t EXT
For characterization data on VRST and tEXT and pull-up resistor values consult the device data
sheet.
107
8077H–AVR–12/09
XMEGA A
For information on configuration and use of the WDT, refer to the Section 11. ”WDT – Watchdog
Timer” on page 117.
108
8077H–AVR–12/09
XMEGA A
Initial Value - - - - - - - -
• Bit 7 – 6: Reserved
These bits are reserved and will always be read as zero. For compatibility with future devices,
always write these bits to zero when this register is written.
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
109
8077H–AVR–12/09
XMEGA A
110
8077H–AVR–12/09
10. Battery Backup System
10.1 Features
• Battery Backup voltage supply from dedicated VBAT power pin for:
– One Ultra Low-power 32-bit Real Time Counter
– One 32.768 kHz crystal oscillator with failure detection monitor
– Two Battery Backup Registers
• Automatic switching from main power to battery backup power at:
– Brown-Out Detection (BOD)
• Automatic switching from battery backup power to main power:
– Device reset after Brown-Out Reset (BOR) is released
– Device reset after Power-On Reset (POR) and BOR is released
10.2 Overview
The Battery Backup System includes functionality that enables automatic power switching
between main power and a battery backup power. Figure 10-1 on page 112 shows an overview
of the system.
The Battery Backup Module supports connection of a backup battery to the dedicated V BAT
power pin. This will ensure power to the 32-bit Real Time Counter, a 32.768 kHz crystal oscilla-
tor with failure detection monitor and two battery backup registers when the main power source
is unavailable.
Upon main power loss the device will detect this and automatically switch the Battery Backup
Module to be powered from the VBAT pin. After main power has been restored and both main
POR and BOR are released, the Battery Backup Module will automatically switch back to be
powered from main power again. The main BOD is used to detect the Vcc voltage levels, and
this must be enabled for the power switching to work.
The 32-bit Real Time Counter (RTC) must be clocked from the 1 Hz or 1.024 kHz output of a
32.768 kHz crystal oscillator connected between the TOSC1 and TOSC2 pins when running
from VBAT. For more details on the 32-bit RTC refer to the “32-bit Real Time Counter” section in
the XMEGA A Manual.
XMEGA A
Figure 10-1. Battery Backup Module and its power domain implementation
TOSC2
FLASH,
RTC Internal
EEPROM
RAM
& Fuses
Backup
Registers
The Battery Backup Power-On Detection circuit will set the POD Flag (BBPODF) when power is
connected to the VBAT pin.
112
8077H–AVR–12/09
The the 32-kHz crystal oscillator, oscillator failure detection and Real Time Counter must be
enabled from software before they can be used.
10.3.2 Battery Backup Brown-Out Detection
The Battery Backup Brown-Out Detector (BBBOD) ensures detection of falling power in the Bat-
tery Backup Module before the oscillator stops. When the VBAT pin voltage drops below the
BBBOD threshold voltage, the BOD Flag (BBBODF) will be set.
The BBBOD is sampled from the 1 Hz output of an ultra low power oscillator, and only designed
for detecting slow changes in the VBAT pin voltage level.
The BBBOD is turned off when the device runs from the main power. It is enabled when the Bat-
tery Backup Module is switched to be powered from the VBAT pin after a main power BOD.
If BBPODF and/or BBBODF is not set, it indicates that the Battery Backup Modules has not had
any power loss. Then the device should:
1. Set the Access Enable (ACCEN) bit
2. Check for 32-Khz Crystal Oscillator failure by reading the XOSC Failure flag.
If the XOSC Failure flag is cleared no further actions is required.
If the XOSC Failure flag is set, this indicates a failure on the external oscillator in the Battery
Backup Module. The software should assume that the RTC counter value is invalid and take
appropriate action.
10.5.2 Battery Backup failed and not enabled
If BBPODF and/or BBBODF is set this indicate that voltage on the VBAT pin has had a drop
sometime during the period when the rest of the device was unpowererd. The following proce-
dure should be followed:
XMEGA A
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
114
8077H–AVR–12/09
XMEGA A
These bits are protected by the Configuration Change Protection mechanism, for detailed
description refer to ”Configuration Change Protection” on page 12.
10.6.2 STATUS: Battery Backup Status Register
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 x x 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value x x x x x x x x
115
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Reset Value x x x x x x x x
116
8077H–AVR–12/09
XMEGA A
11.1 Features
• 11 selectable timeout period, from 8 ms to 8s
• Two operation modes
– Standard mode
– Window mode
• Runs from 1 kHz Ultra Low Power clock reference
• Configuration lock
11.2 Overview
The Watchdog Timer (WDT) is a system function for monitoring correct program operation, mak-
ing it possible to recover from error situations, for instance run-away code. The WDT is a timer,
configured to a predefined timeout period and is constantly running when enabled. If the WDT is
not reset within the timeout period, it will issue a system reset. The WDT is reset by executing
the WDR (Watchdog Timer Reset) instruction from the application code.
The WDT also has a window mode that enables the user to define a time slot where WDT must
be reset within. If the WDT is reset too early or too late, a system reset will be issued.
The WDT will run in all power modes if enabled. It runs from a CPU independent clock source,
and will continue to operate to issue a system reset even if the main clocks fail.
The Configuration Change Protection mechanism ensures that the WDT settings cannot be
changed by accident. In addition the settings can be locked by a fuse.
WDT Timeout
5 10 15 20 25 30 35 t [ms]
TOWDT
117
8077H–AVR–12/09
XMEGA A
TOWDTW = 8
Closed
System Reset
5 10 15 20 25 30 35 t [ms]
TOWDTW TOWDT
118
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write
R R R/W R/W R/W R/W R/W R/W
(unlocked)
Read/Write
R R R R R R R R
(locked)
Initial Value
0 0 X X X X X 0
(x = fuse)
119
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write
R R R/W R/W R/W R/W R/W R/W
(unlocked)
Read/Write
R R R R R R R/W R/W
(locked)
Initial Value
0 0 X X X X X 0
(x = fuse)
120
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
• Bit 0 - SYNCBUSY
When writing to the CTRL or WINCTRL registers, the WDT needs to be synchronized to the
other clock domains. During synchronization the SYNCBUSY bit will be read as one. This bit is
automatically cleared after the synchronization is finished. Synchronization will only take place
when the ENABLE bit for the Watchdog Timer is set.
121
8077H–AVR–12/09
XMEGA A
122
8077H–AVR–12/09
XMEGA A
12.1 Features
• Separate interrupt vector for each interrupt
• Short, predictable interrupt response time
• Programmable Multi-level Interrupt Controller
– 3 programmable interrupt levels
– Selectable priority scheme within low level interrupts (round-robin or fixed)
– Non-Maskable Interrupts (NMI)
• Interrupt vectors can be moved to the start of the Boot Section.
12.2 Overview
Interrupts signal a change of state in peripherals, and this can be used to alter program execu-
tion. Peripherals can have one or more interrupts, and all are individually enabled. When the
interrupt is enabled and the interrupt condition is present this will generate a corresponding inter-
rupt request. All interrupts have a separate interrupt vector address.
The Programmable Multi-level Interrupt Controller (PMIC) controls the handling of interrupt
requests, and prioritizing between the different interrupt levels and interrupt priorities. When an
interrupt request is acknowledged by the PMIC, the program counter is set to point to the inter-
rupt vector, and the interrupt handler can be executed.
All peripherals can select between three different priority levels for their interrupts; low, medium
or high. Medium level interrupts will interrupt low level interrupt handlers. High level interrupts
will interrupt both medium and low level interrupt handlers. Within each level, the interrupt prior-
ity is decided from the interrupt vector address, where the lowest interrupt vector address has
the highest interrupt priority. Low level interrupts have an optional round-robin scheduling
scheme to ensure that all interrupts are serviced within a certain amount of time.
Non-Maskable Interrupts (NMI) are also supported.
12.3 Operation
Interrupts must be globally enabled for any interrupts to be generated. This is done by setting
the global interrupt enable bit (I-bit) in the CPU Status Register. The I-bit will not be cleared
when an interrupt is acknowledged. Each interrupt level must also be enabled before interrupts
with the corresponding level can be generated.
When an interrupt is enabled and the interrupt condition is present, the PMIC will receive the
interrupt request. Based on the interrupt level and interrupt priority of any ongoing interrupts, the
interrupt is either acknowledged or kept pending until it has priority. When the interrupt request
is acknowledged, the program counter is updated to point to the interrupt vector. The interrupt
vector is normally a jump to the interrupt handler; the software routine that handles the interrupt.
After returning from the interrupt handler, program execution continues from where it was before
the interrupt occurred. One instruction is always executed before any pending interrupt is
served.
The PMIC status register contains state information that ensures that the PMIC returns to the
correct interrupt level when the RETI (interrupt return) instruction is executed at the end of an
interrupt handler. Returning from an interrupt will return the PMIC to the state it had before enter-
ing the interrupt. The Status Register (SREG) is not saved automatically upon an interrupt
123
8077H–AVR–12/09
XMEGA A
request. The RET (subroutine return) instruction cannot be used when returning from the inter-
rupt handler routine, as this will not return the PMIC to its right state.
12.4 Interrupts
All interrupts and the reset vector each have a separate program vector address in the program
memory space. The lowest address in the program memory space is the reset vector. All inter-
rupts are assigned individual control bits for enabling and setting the interrupt level, and this is
set in the control registers for each peripheral that can generate interrupts. Details on each inter-
rupt are described in the peripheral where the interrupt is available.
All interrupts have an interrupt flag associated to it. When the interrupt condition is present, the
interrupt flag will be set, even if the corresponding interrupt is not enabled. For most interrupts,
the interrupt flag is automatically cleared when executing the interrupt vector. Writing a logical
one to the interrupt flag will also clear the flag. Some interrupt flags are not cleared when execut-
ing the interrupt vector, and some are cleared automatically when an associated register is
accessed (read or written). This is described for each individual interrupt flag.
If an interrupt condition occurs while another higher priority interrupt is executing or pending, the
interrupt flag will be set and remembered until the interrupt has priority. If an interrupt condition
occurs while the corresponding interrupt is not enabled, the interrupt flag will be set and remem-
bered until the interrupt is enabled, or the flag is cleared by software. Similarly, if one or more
interrupt conditions occur while global interrupts are disabled, the corresponding interrupt flag
will be set and remembered until global interrupts are enabled. All pending interrupts are then
executed according to their order of priority.
Interrupts can be blocked when executing code from a locked section, e.g. when the Boot Lock
bits are programmed. This feature improves software security, refer to memory programming for
details on lock bit settings.
Interrupts are automatically disabled for up to 4 CPU clock cycles when the Configuration
Change Protection register is written with the correct signature, refer to Section 3.12 ”Configura-
tion Change Protection” on page 12 for more details.
124
8077H–AVR–12/09
XMEGA A
rupt execution response time is increased by five clock cycles. In addition the response time is
increased by the start-up time from the selected sleep mode.
A return from an interrupt handling routine takes five clock cycles. During these five clock cycles,
the program counter is popped from the stack and the stack pointer is incremented.
The interrupt level of an interrupt request is compared against the current level and status of the
interrupt controller. An interrupt request on higher level will interrupt any ongoing interrupt han-
dler from a lower level interrupt. When returning from the higher level interrupt handler, the
execution of the lower level interrupt handler will continue.
125
8077H–AVR–12/09
XMEGA A
:
:
:
IVEC x
IVEC x+1
:
:
:
IV EC 0 IV EC 0
: :
: :
: :
IV EC N IV EC N
126
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
127
8077H–AVR–12/09
XMEGA A
change the priority queue. This register is not reinitialized to its initial value if round-robing
scheduling is disabled, so if default static priority is needed the register must be written to zero.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
128
8077H–AVR–12/09
XMEGA A
13.1 Features
• Selectable input and output configuration for each pin individually
• Flexible pin configuration through dedicated Pin Configuration Register
• Synchronous and/or asynchronous input sensing with port interrupts and events
• Asynchronous wake-up signalling
• Highly configurable output driver and pull settings:
– Totem-pole
– Pull-up/-down
– Wired-AND
– Wired-OR
– Bus keeper
– Inverted I/O
• Slew rate control
• Flexible pin masking
• Configuration of multiple pins in a single operation
• Read-Modify-Write (RMW) support
• Toggle/clear/set registers for OUT and DIR registers
• Clock output on port pin
• Event Channel 0 output on port pin 7
• Mapping of port registers (virtual ports) into bit accessible I/O memory space
13.2 Overview
XMEGA has flexible General Purpose I/O (GPIO) Ports. A port consists of up to 8 pins ranging
from pin 0 to 7, where each pin can be configured as input or output with highly configurable
driver and pull settings. The ports also implement several functions including interrupts, synchro-
nous/asynchronous input sensing and asynchronous wake-up signalling.
All functions are individual per pin, but several pins may be configured in a single operation. All
ports have true Read-Modify-Write (RMW) functionality when used as general purpose I/O ports.
The direction of one port pin can be changed without unintentionally changing the direction of
any other pin. The same applies when changing drive value when configured as output, or
enabling/disabling of pull-up or pull-down resistors when configured as input.
Figure 13-1 on page 130 shows the I/O pin functionality, and the registers that is available for
controlling a pin.
129
8077H–AVR–12/09
XMEGA A
Pull Enable
Pull Keep
Pull Direction
PINnCTRL
D Q
Input Disable
Wired AND/OR
Slew Rate Limit
Inverted I/O
OUTn
Pxn
D Q
DIRn
D Q
Synchronizer
INn
Q D Q D
R R
Analog Input/Output
130
8077H–AVR–12/09
XMEGA A
13.4.1 Totem-pole
When configured for Totem-pole (push-pull), the pin is driven low or high according to the corre-
sponding bit setting in OUT. In this configuration there is no current limitation for sink or source
other than what the pin is capable of. If the pin is configured for input, the pin will float if no exter-
nal pull is connected.
DIRn
OUTn Pn
INn
Figure 13-3. I/O pin configuration - Totem-pole with pull-down (on input)
DIRn
OUTn Pn
INn
131
8077H–AVR–12/09
XMEGA A
Figure 13-4. I/O pin configuration - Totem-pole with pull-up (on input).
DIRn
OUTn Pn
INn
13.4.2 Bus-keeper
When the pin is configured for bus-keeper, it provides a weak bus-keeper that will keep the pin
at its logic level when the pin is no longer driven to any logic state. If last level on the pin/bus was
1, the bus-keeper will use the internal pull resistor to keep the bus high. If last logic level on the
pin/bus was 0, the bus-keeper will use the internal pull resistor to keep the bus high.
The bus-keeper’s week output produces the same logical level as the last output level. It acts as
a pull-up if the last level was '1', and pull-down if the last level was '0'.
DIRn
OUTn Pn
INn
13.4.3 Wired-OR
With Wired-OR configuration, the pin will be driven high when the corresponding bit in OUT is
written to one. When OUT is set to zero, the pin is released allowing the pin to be pulled low with
the internal or an external pull-resistor. If internal pull-down is used, this is also active if the pin is
set as input.
132
8077H–AVR–12/09
XMEGA A
OUTn
Pn
INn
13.4.4 Wired-AND
With Wired-AND configuration, the pin will be driven low when the corresponding bit in OUT is
written to zero. When OUT is set to one, the pin is released allowing the pin to be pulled low with
the internal or an external pull-resistor. If internal pull-up is used, this is also active if the pin is
set as input.
INn
Pn
OUTn
133
8077H–AVR–12/09
XMEGA A
PERIPHERAL CLK
SYNC FLIPFLOP
IN
tpd, min
EDGE
Interrupt
DETECT IREQ
Control
Synchronous sensing
Pn Synchronizer
INn
EDGE
D QD Q
DETECT Event
INVERTED I/O R R
134
8077H–AVR–12/09
XMEGA A
135
8077H–AVR–12/09
XMEGA A
136
8077H–AVR–12/09
XMEGA A
Pull Enable
Pull Keep
Pull Direction
PINnCTRL
D Q
Wired AND/OR
Slew Rate Limit
Inverted I/O
OUTn
D Q
Pxn
DIRn
D Q
Synchronizer
INn
Q D Q D
R R
Analog Input/Output
137
8077H–AVR–12/09
XMEGA A
be visible on the port pin as long as the event last. Normally this is one peripheral clock cycle
only.
13.12 Multi-configuration
MPCMASK can be used to set a bit mask for the pin configuration registers. When setting bit n in
MPCMASK, PINnCTRL is added to the pin configuration mask. During the next write to any of
the port's pin configuration registers, the same value will be written to all the port's pin configura-
tion registers set by the mask. The MPCMASK register is cleared automatically after the write
operation to the pin configuration registers is finished.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
138
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
139
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x08 IN[7:0] IN
Initial Value 0 0 0 0 0 0 0 0
140
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
141
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
142
8077H–AVR–12/09
XMEGA A
Note: 1. A low pin value will not generate events, and a high pin value will continuously generate
events.
2. Only Port A - F supports the input buffer disable option.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
143
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
144
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
145
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 IN[7:0] IN
Initial Value 0 0 0 0 0 0 0 0
146
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
147
8077H–AVR–12/09
XMEGA A
148
8077H–AVR–12/09
XMEGA A
14.1 Features
• 16-bit Timer/Counter
• Double Buffered Timer Period Setting
• Up to 4 Combined Compare or Capture (CC) Channels (A, B, C, and D)
• All Compare or Capture Channels are Double Buffered
• Waveform Generation:
– Single Slope Pulse Width Modulation
– Dual Slope Pulse Width Modulation
– Frequency Generation
• Input Capture:
– Input Capture with Noise Cancelling
– Frequency capture
– Pulse width capture
• 32-bit input capture Direction Control
• Timer Overflow and Timer Error Interrupts / Events
• One Compare Match or Capture Interrupt / Event per CC Channel
• Supports DMA Operation
• Hi-Res- Hi-Resolution Extension
– Increases PWM/FRQ Resolution by 2-bits (4x)
• AWeX - Advanced Waveform Extension
– 4 Dead-Time Insertion (DT) Units with separate high- and low-side settings
– Event controlled fault protection
– Single channel multiple output operation
– Pattern Generation
14.2 Overview
XMEGA has a set of high-end and very flexible 16-bit Timer/Counters (TC). Their basic capabili-
ties include accurate program execution timing, frequency and waveform generation, event
management, and time measurement of digital signals. The Hi-Resolution Extension (Hi-Res)
and Advanced Waveform Extension (AWeX) can be used together with a Timer/Counter to ease
implementation of more advanced and specialized frequency and waveform generation
features.
A block diagram of the 16-bit Timer/Counter with extensions and closely related peripheral mod-
ules (in grey) is shown in Figure 14-1 on page 150.
149
8077H–AVR–12/09
XMEGA A
Timer/Counter
Base Counter Prescaler clkPER
Timer Period
Control Logic
Counter Event
System
clkPER4
Compare/Capture Channel D
Compare/Capture Channel C
AWeX
Compare/Capture Channel B
PORTS
Hi-Res
Pattern
Compare/Capture Channel A DTI
Generation
Capture
Dead-Time Fault
Comparator
Control Insertion Protection
Waveform
Buffer
Generation
The Timer/Counter consists of a Base Counter and a set of Compare or Capture (CC) channels.
The Base Counter can be used to count clock cycles or events. It has direction control and
period setting that can be used for timing. The CC channels can be used together with the Base
Counter to do compare match control, waveform generation (FRQ or PWM) or various input cap-
ture operations.
Compare and capture cannot be done at the same time, i.e. a single Timer/Counter cannot
simultaneously perform both waveform generation and capture operation. When used for com-
pare operations, the CC channels is referred to as compare channels. When used for capture
operations, the CC channels are referred to as capture channels.
The Timer/Counter comes in two versions: Timer/Counter 0 that has four CC channels, and
Timer/Counter 1 that has two CC channels. Hence, all registers and register bits that are related
to CC channel 3 and CC channel 4 will only exist in Timer/Counter 0.
All Timer/Counter units are connected to the common peripheral clock prescaler, the Event Sys-
tem, and their corresponding general purpose I/O port.
Some of the Timer/Counters will have Extensions. The function of the Timer/Counter Extensions
can only be performed by these Timers. The Advanced Waveform Extension (AWeX) can be
used for Dead Time Insertion, Pattern Generation and Fault Protection. The AWeX Extension is
only available for Timer/Counter 0.
Waveform outputs from a Timer/Counter can optionally be passed through to a Hi-Resolution
(Hi-Res) Extension before forwarded to the port. This extension, running at up to four times the
Peripheral Clock frequency, to enhance the resolution by four times. All Timer/Counters will
have the Hi-Res Extention.
150
8077H–AVR–12/09
XMEGA A
14.2.1 Definitions
The following definitions are used extensively throughout the Timer/Counter documentation:
In general the term Timer is used when the Timer/Counter clock control is handled by an internal
source and the term Counter is used if the clock is given externally (from an event).
151
8077H–AVR–12/09
XMEGA A
Base Counter
V PERBUF CKSEL
Clock Select
EVSEL
PER Event Select
"count"
Counter
"clear"
OVF/UNF
(INT/DMA Req.)
"load"
CNT Control Logic
"direction"
ERRIF
(INT Req.)
I/O Data Bus (16-bit)
TOP
UPDATE
=
"ev"
BOTTOM
=0
Compare/Capture
(x = {A,B,C,D})
"capture"
V CCxBUF Control Logic
CCx
Waveform
Generation
OCx Out
"match" CCxIF
= (INT/DMA
Req.)
CTRL INTCTRL
Bus Bridge TEMP INTFLAGS
A B C D E G A B
The Counter Register (CNT), the Period Registers w/buffer (PER and PERBUF), and the com-
pare and Capture registers w/buffers (CCx and CCxBUF) are 16-bit registers.
During normal operation the counter value is continuously compared to zero and the period
(PER) value to determine whether the counter has reached TOP or BOTTOM.
The counter value is also compared to the CCx registers. These comparators can be used to
generate interrupt requests or request DMA transactions. They also generate events for the
Event System. The waveform generator modes use the comparators to set the waveform period
or pulse width.
A prescaled peripheral clock and events from the Event System can be used for controlling the
counter. The Event System is also used as source to the input capture. Combined with the
Quadrature Decoding functionality in the Event System QDEC, the Timer/Counter can be used
for high speed Quadrature Decoding.
152
8077H–AVR–12/09
XMEGA A
Common clkPER /
clkPER Event System events
Prescaler 2{0,...,15}
clk /
{1,2,4,8,64,256,1024} event channels
CLKSEL
Control Logic
EVSEL
CNT
EVACT (Encoding)
The Peripheral Clock is fed into the Common Prescaler (common for all Timer/Counters in a
device). A selection of the prescaler outputs is directly available for the Timer/Counter. In addi-
tion the whole range from 1 to 215 times prescaling is available through the Event System.
Each Timer/Counter has separate clock selection (CLKSEL), to select one of the prescaler out-
puts directly or an event channel as the Counter (CNT) input. This is referred to as Normal
Operation for the Counter, for details refer to ”Normal Operation” on page 155. By using the
Event System, any event source such as an external clock signal on any I/O pin can be used as
clock input.
In addition the Timer/Counter can be controlled via the Event System. The Event Selection
(EVSEL) and Event Action (EVACT) settings can be used to trigger an event action from one or
more events. This is referred to as Event Action Controlled Operation for the Counter, for details
refer to ”Event Action Controlled Operation” on page 155. When Event Action Controlled Opera-
tion is used, the clock selection must be set to us an event channel as the Counter input.
By default no clock input is selected and the Timer/Counter is not running (OFF state).
153
8077H–AVR–12/09
XMEGA A
"write enable"
BV EN CCxBUF
EN CCx
UPDATE
CNT
"match"
=
When the CC channels is used for capture operation a similar Double buffering mechanism is
used, but the Buffer Valid flag is set on the capture event as shown in Figure 14-5. For capture
the buffer and the corresponding CCx register acts like a FIFO. When the CC register is empty
or read, any contents in the buffer is passed to the CC register. The Buffer valid flag is passed to
the CCx Interrupt Flag (IF) which is them set and the optional interrupt is generated.
"capture" CNT
IF EN CCx
"INT/DMA
request"
Both the CCx and CCxBUF registers are available in the I/O register address map. This allows
initialization and bypassing of the buffer register, and the double buffering feature.
154
8077H–AVR–12/09
XMEGA A
MAX
"update"
TOP
CNT
BOT
DIR
As shown in Figure 14-6 changing the counter value while the counter is running is possible. The
write access has higher priority than count, clear, or reload and will be immediate. The direction
of the Counter can also be changed during normal operation.
Normal operation must be used when using the counter as timer base for the capture channels.
155
8077H–AVR–12/09
XMEGA A
MAX
"update"
"write"
CNT
BOT
When double buffering is used, the buffer can be written at any time, but the Period Register is
always updated on the “update” condition as shown in Figure 14-8. This prevents wraparound
and generation of odd waveforms.
MAX
"update"
"write"
CNT
BOT
156
8077H–AVR–12/09
XMEGA A
Event System
CCA capture
CH0MUX Event channel 0
CH1MUX Event channel 1 CCB capture
CCC capture
CH7MUX Event channel 7
CCD capture
Rotate
The Event Action setting in the Timer/Counter will determine the type of capture that is done.
The CC channel to use must be enabled individually before capture can be done. When the cap-
ture condition occur, the Timer/Counter will time-stamp the event by copying the current value in
the Count register into the enabled CC channel register.
When an I/O pin is used as event source for the Capture, the pin must be configured for edge
sensing. For details on sense configuration on I/O pins, refer to ”Input Sense Configuration” on
page 134. If the Period register value is set lower than 0x8000, the polarity of the I/O pin edge
will be stored in the Most Significant Bit (MSB) of the Capture register after a Capture. If the
MSB of the Capture register is zero, a falling edge generated the Capture. If the MSB is one, a
rising edge generated the Capture.
Three different types of capture are available.
events
TOP
CNT
BOT
157
8077H–AVR–12/09
XMEGA A
Figure 14-10 on page 158 shows an example where the Period is measured twice for an exter-
nal signal.
Period (T)
external signal
events
MAX
"capture"
CNT
BOT
Since all capture channels uses the same Counter (CNT), only one capture channels must be
enabled at a time. If two capture channels are used with different source, the Counter will be
restarted on positive edge events from both input sources, and the result from the input capture
will have no meaning.
158
8077H–AVR–12/09
XMEGA A
external signal
events
MAX
"capture"
CNT
BOT
159
8077H–AVR–12/09
XMEGA A
MAX
"update"
TOP
CNT
BOT
WG Output
The waveform generated will have a maximum frequency of half of the Peripheral clock fre-
quency (f PER ) when CCA is set to zero (0x0000). This also applies when using the Hi-Res
Extension since this only increase the resolution and not the frequency. The waveform fre-
quency (fFRQ)is defined by the following equation:
f PER
f FRQ = -------------------------------
-
2N ( CCA+1 )
where N represents the prescaler divider used (1, 2, 4, 8, 64, 256, 1024, or event channel n).
160
8077H–AVR–12/09
XMEGA A
CNT
CCx
BOT
WG Output
The PER register defines the PWM resolution. The minimum resolution is 2-bit (PER=0x0003),
and maximum resolution is 16-bit (PER=MAX).
The following equation can be used for calculate the exact resolution for single-slope PWM
(RPWM_SS):
( PER + 1 )-
R PWM_SS = log
----------------------------------
log ( 2 )
The single slow PWM frequency (fPWM_SS) depends on the period setting (PER) and the Periph-
eral clock frequency (fPER), and can be calculated by the following equation:
f PER
f PWM_SS = ------------------------------
-
N ( PER + 1 )
where N represents the prescaler divider used (1, 2, 4, 8, 64, 256, 1024, or event channel n).
161
8077H–AVR–12/09
XMEGA A
CCx
TOP
CNT
BOT
WG Output
Using dual-slope PWM result in a lower maximum operation frequency compared to the single-
slope PWM operation.
The period register (PER) defines the PWM resolution. The minimum resolution is 2-bit
(PER=0x0003), and maximum resolution is 16-bit (PER=MAX).
The following equation can be used for calculate the exact resolution for dual-slope PWM
(RPWM_DS):
( PER + 1 )-
R PWM_DS = log
----------------------------------
log ( 2 )
The PWM frequency depends on the period setting (PER) and the Peripheral Clock frequency
(fPER), and can be calculated by the following equation:
f PER
f PWM_DS = -------------------
-
2NPER
N represents the prescaler divider used (1, 2, 4, 8, 64, 256, 1024, or event channel n).
162
8077H–AVR–12/09
XMEGA A
OUTx0
Px0
OC0A
WG 0A
CCENA INVENx0
CCENB INVENx1
Px1
WG 0B
OC0B
OUTx1
OUTx2
Px2
OC0C
WG 0C
CCENC INVENx2
CCEND INVENx3
Px3
WG 0D
OC0D
OUTx3
OUTx4
Px4
OC1A
WG 1A
CCENA INVENx4
CCENB INVENx5
Px5
WG 1B
OC1B
OUTx5
163
8077H–AVR–12/09
XMEGA A
164
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
165
8077H–AVR–12/09
XMEGA A
• Bit 3 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
166
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Selecting the any of the capture event action changes the behavior of the CCx registers and
related status and control bits to be used as for capture. The error status flag (ERRIF) will in this
configuration indicate a buffer overflow.
167
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
168
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
This register is mapped into two I/O memory locations, one for clearing (CTRLxCLR) and one for
setting the register bits (CTRLxSET) when written. Both memory locations yield the same result
when read.
The individual status bit can be set by writing a one to its bit location in CTRLxSET, and cleared
by writing a one to its bit location in CTRLxCLR. This each bit to be set or cleared without using
of a Read-Modify-Write operation on a single register.
169
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Refer to section ”CTRLFCLR/CTRLFSET - Control Register F Clear/Set” on page 169 for infor-
mation on how to access this type of status register.
170
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
171
8077H–AVR–12/09
XMEGA A
For more details refer to Section 3.11 ”Accessing 16-bits Registers” on page 12.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 1 1 1 1 1 1 1 1
172
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
CCx[15:8] CCxH
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
CCx[7:0] CCxL
Initial Value 0 0 0 0 0 0 0 0
173
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
Initial Value 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
CCxBUF[15:8] CCxBUFH
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
CCxBUFx[7:0] CCxBUFL
Initial Value 0 0 0 0 0 0 0 0
174
8077H–AVR–12/09
XMEGA A
175
8077H–AVR–12/09
XMEGA A
15.1 Features
• 4 Dead-Time Insertion (DTI) Units (8-pin)
– 8-bit Resolution
– Separate High and Low Side Dead-Time Setting
– Double Buffered Dead-Time
– Halts Timer During Dead-Time (Optional)
• Event Controlled Fault Protection
• Single Channel Multiple Output Operation (for BLDC control)
• Double Buffered Pattern Generation
• The Hi-Resolution Timer Extension Increases PWM/FRQ Resolution by 2-bits (4x)
15.2 Overview
The Advanced Waveform Extention (AWeX) provides extra features to the Timer/Counter in
Waveform Generation (WG) modes. The AWeX enables easy and robust implementation of
advanced motor control (AC, BLDC, SR, and Stepper) and power control applications.
Figure 15-1. Advanced Waveform eXtention and closely related peripherals (grey)
AWeX
Pattern
Generation
Timer/Counter 0 PORTx
INVEN Px0
WG DTI
Channel A Channel A
INVEN Px1
INVEN Px2
WG DTI
Channel B Channel B
INVEN Px3
Port
Override
INVEN Px4
WG DTI
Channel C Channel C
INVEN Px5
INVEN Px6
WG DTI
Channel D Channel D
INVEN Px7
Event Fault
System Protection
As shown in Figure 15-1 on page 176 each of the waveform generator outputs from the
Timer/Counter 0 are split into a complimentary pair of outputs when any AWeX features is
enabled. These output pairs go through a Dead-Time Insertion (DTI) unit that enables genera-
tion of the non-inverted Low Side (LS) and inverted High Side (HS) of the WG output with dead
time insertion between LS and HS switching. The DTI output will override the normal port value
according to the port override setting. Optionally the final output can be inverted by using the
invert I/O (INVEN) bit setting for the port pin (Pxn).
176
8077H–AVR–12/09
XMEGA A
The Pattern Generation unit can be used to generate a synchronized bit pattern on the port it is
connected to. In addition, the waveform generator output from the Compare Channel A can be
distributed to and override all the port pins. When the Pattern Generator unit is enabled the DTI
unit is bypassed.
The Fault Protection unit is connected to the Event System, enabling any event to trigger a fault
condition that will disable the AWeX output.
177
8077H–AVR–12/09
XMEGA A
D TIE N A
C hannel
W G 0A
A
OOE1
C C EN B IN V x1
HS
Px1
O C 0B
OCHSA
W G 0B PO R Tx1
W G 0C PO R Tx2
Px2
O C 0C
O C LSB
D TI C C EN C IN V x2
LS
OOE2
D TIE N B
C hannel
W G 0B
B
OOE3
C C EN D IN V x3
HS
Px3
O C 0D
OCHSB
W G 0D PO R Tx3
W G 1A PO R Tx4
Px4
O C 1A
O C LSC
D TI C C EN A IN V x4
LS
OOE4
D TIE N C
C hannel
W G 0C
C
OOE5
C C EN B IN V x5
HS
Px5
O C 1B
OCHSC
W G 1B PO R Tx5
PO R Tx6
Px6
O C LSD
D TI "0" IN V x6
LS
OOE6
D TIE N D
C hannel
W G 0D
D
OOE7
"0" IN V x7
HS
Px7
OCHSD
PO R Tx7
178
8077H–AVR–12/09
XMEGA A
DTILS DTIHS
Dead Time Generator
LOAD
Counter ("dti_cnt")
E
=0
"dtls"
WG output D Q (To PORT)
"dths"
Edge Detect (To PORT)
As shown in Figure 15-4 on page 180, the 8-bit Dead Time Counter (dti_cnt) is decremented by
one for each peripheral clock cycle until it reaches zero. A non-zero counter value will force both
the Low Side and High Side outputs into their “off” state. When a change is detected on the WG
output, the Dead Time Counter is reloaded with the DTx register value according to the edge of
the input. Positive edge initiates a counter reload of the DTLS Register and a negative edge a
reload of DTHS Register.
179
8077H–AVR–12/09
XMEGA A
"dti_cnt"
T
tP
tDTILS tDTIHS
"WG output"
"dtls"
"dths"
Timer/Counter 0 (TCx0)
UPDATE CCA WG output
V DTIBLS V DTIBHS 1 to 8
Expand
EN DTIOE[7:0] EN PORTx[7:0]
Px[7:0]
A block diagram of the pattern generator is shown in Figure 15-5 on page 180. For each port pin
where the corresponding OOE bit is set the multiplexer will output the waveform from CCA.
As for all other types of the Timer/Counter double-buffered registers the register update is syn-
chronized to the UPDATE condition set by the waveform generation mode. If the
synchronization provided is not required by the application, the application code can simply
access the DTIOE and PORTx registers directly.
The pins direction must be set for any output from the pattern generator to be visible on the port.
180
8077H–AVR–12/09
XMEGA A
181
8077H–AVR–12/09
XMEGA A
Lock Register. For more details refer to ”IO Memory Protection” on page 25 and ”AWEXLOCK –
Advanced Waveform Extension Lock Register” on page 45.
When the lock bit is set, the Control Register A, the Output Override Enable Register and the
Fault Dedec.tion Event Mask register cannot be changed.
To avoid unintentional changes in the fault event setup it is possible to lock the Event System
channel configuration by writing the corresponding Event System Lock Register. For more
details refer to ”IO Memory Protection” on page 25 and ”EVSYSLOCK – Event System Lock
Register” on page 44.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
182
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
183
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
184
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
185
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Note: 1. Can only be written if the fault detect flag (FDF) is zero.
186
8077H–AVR–12/09
XMEGA A
187
8077H–AVR–12/09
XMEGA A
16.1 Features
• Increases Waveform Generator Resolution by 4x (2 bits)
• Supports Frequency generation, and single and dual-slope PWM operation
• Supports Dead-Time Insertion (AWeX)
• Supports Pattern Generation (AWeX)
16.2 Overview
The High-Resolution (Hi-Res) Extension can be used to increase the resolution of the waveform
generation output from a Timer/Counter by four (two bits). It can be used during Frequency and
PWM generation, and also in combination with the corresponding AWeX.
The Hi-Res Extension uses the Peripheral 4x Clock. The System Clock prescalers must be set
up so the Peripheral 4x Clock frequency is four times higher than the Peripheral and CPU clock
frequency (see ”System Clock Selection and Prescalers” on page 80) when the Hi-Res
Extension is enabled.
PER[15:2] 0
clkPER clkPER4
CNT[15:2] 0
=0 =
BOTTOM TOP
CCBUFx[15:0]
Time/Counter
The Hi-Res Extension is implemented by letting the Timer/Counter run at 4x its normal speed.
When Hi-Res Extension is enabled, the counter will ignore its two lowest significant bits (LSB)
and count by four for each Peripheral clock cycle. Overflow/Underflow and Compare match of
the 14 most significant bits (LSB) is done in the Timer/Counter. Count and Compare of the two
LSB is then handled and compared in the Hi-Res Extension running from the Peripheral 4x
clock.
The two LSB of the Period register must always be set to zero to ensure correct operation. If the
Count register is read, the two LSB will always be read as zero since the Timer/Counter run from
the Peripheral clock.
The Hi-Res Extension has narrow pulse deletion preventing output of any pulse shorter than one
Peripheral clock cycle, e.g. a compare value lower than foure will have no visible output.
188
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRLA HREN[1:0] 189
189
8077H–AVR–12/09
XMEGA A
17.1 Features
• 16-bit resolution
• Selectable clock reference
– 32.768 kHz
– 1.024 kHz
• Programmable prescaler
• 1 Compare register
• 1 Period register
• Clear Timer on overflow
• Optional Interrupt/ Event on overflow and compare match
17.2 Overview
The Real Time Counter (RTC) is a 16-bit counter, counting reference clock cycles and giving an
event and/or an interrupt request when it reaches a configurable compare and/or top value. The
reference clock is typically generated from a high accuracy crystal of 32.768 kHz, and the design
is optimized for low power consumption. The RTC typically operate in low power sleep modes,
keeping track of time and waking up the device at regular intervals.
The RTC reference clock may be taken from an 32.768 kHz or 1.024 kHz input. Both an external
32.768 kHz crystal oscillator or the 32 kHz internal RC oscillator can be selected as clock
source. For details on reference clock selection to the RTC refer to ”RTCCTRL - RTC Control
Register” on page 86 in the Clock System section. The RTC has a programmable prescaler to
scale down the reference clock before it reaches the Counter.
The RTC can generate both compare and overflow interrupt request and/or events.
16-bit Period
Overflow
32.768 kHz =
10-bit
16-bit Counter
prescaler
1.024 kHz =
Compare Match
16-bit Compare
190
8077H–AVR–12/09
XMEGA A
The RTC is asynchronous, meaning it operates from a different clock source and independently
of the main System Clock and its derivative clocks such as the Peripheral Clock. For Control and
Count register updates it will take a number of RTC clock and/or Peripheral clock cycles before
an updated register value is available or until a configuration change has effect on the RTC. This
synchronization time is described for each register.
17.2.2 Interrupts and events
The RTC can generate both interrupts and events. The RTC will give a compare interrupt
request and/or event when the counter value equals the Compare register value. The RTC will
give an overflow interrupt request and/or event when the counter value equals the Period regis-
ter value. The overflow will also reset the counter value to zero.
Due to the asynchronous clock domains event will only will only be generated for every third
overflow or compare if the period register is zero. If the period register is one, events will only be
generated for every second overflow or compare. When the period register is equal to or above
two, events will trigger at every overflow or compare just as the interrupt request.
Initial Value 0 0 0 0 0 0 0 0
191
8077H–AVR–12/09
XMEGA A
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
192
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
193
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 1 1 1 1 1 1 1 1
Initial Value 1 1 1 1 1 1 1 1
194
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
• Bits 7:0 - COMP[15:8]: Real Time Counter Compare Register High byte
These bits hold the 8 MSB of the 16-bit RTC compare value.
Initial Value 0 0 0 0 0 0 0 0
• Bits 7:0 - COMP[7:0]: Real Time Counter Compare Register Low byte
These bits hold the 8 LSB of the 16-bit RTC compare value.
195
8077H–AVR–12/09
XMEGA A
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRL - - - - - PRESCALER[2:0] 191
+0x01 STATUS - - - - - - - SYNCBUSY 192
+0x02 INTCTRL - - - - COMPINTLVL[1:0] OVFINTLVL[1:0] 192
+0x03 INTFLAGS - - - - - - COMPIF OVFIF 193
+0x04 TEMP TEMP[7:0] 193
+0x08 CNTL CNT[7:0] 193
+0x09 CNTH CNT[15:8] 194
+0x0A PERL PER[7:0] 194
+0x0B PERH PER[15:8] 194
+0x0C COMPL COMP[7:0] 195
+0x0D COMPH COMP[15:8] 195
196
8077H–AVR–12/09
18. RTC32 - 32-bit Real Time Counter
18.1 Features
• 32-bit resolution
• Selectable clock reference
– 1.024 kHz
– 1 Hz
• One Compare register
• One Period register
• Clear Timer on overflow
• Optional Interrupt/ Event on overflow and compare match
• Isolated VBAT power domain with dynamic switch over from/to VCC power domain
18.2 Overview
The 32-bit Real Time Counter is a 32-bit counter, counting reference clock cycles and giving an
event and/or an interrupt request when it reaches a configurable compare and/or top value. The
reference clock is generated from a high accuracy 32.768 kHz crystal, and the design is opti-
mized for low power consumption. The Real Time Counter (RTC) typically operates in low power
sleep modes, keeping track of time and waking up the device at regular intervals.
The RTC input clock can be taken from a 1.024 kHz or 1 Hz prescaled output from the 32.768
kHz reference clock. The RTC will give a compare interrupt request and/or event when the coun-
ter value equals the Compare register value. The RTC will give an overflow interrupt request
and/or event when the counter value equals the Period register value. Counter overflow will also
reset the counter value to zero.
The RTC can generate both compare and overflow interrupt request and/or events.
32-bit Period
Overflow
=
1 Hz
32-bit Counter
1.024 kHz
=
Compare Match
32-bit Compare
XMEGA A
An external 32.768 kHz crystal oscillator must be used as clock source. Two different frequency
outputs are available form this, and the RTC clock input can be 1.024 kHz or 1 Hz.
18.2.2 Clock domains
The RTC is asynchronous, meaning it operates from a different clock source and independently
of the main System Clock and its derivative clocks such as the Peripheral Clock. For Control and
Count register updates it will take a number of RTC clock and/or Peripheral clock cycles before
an updated register value is available or until a configuration change has effect on the RTC. This
synchronization time is described for each register.
The Peripheral clock must be eight times faster than the RTC clock (1.024 kHz or 1 Hz) when
any the Control and Count register is accessed (read or written), expect 12 times faster when
the Count register is written.
18.2.3 Power domains
For devices where the RTC is located in the VBAT power domain this enables the RTC to function
correctly with no VCC available. When running from the VBAT power domain, only the 1 Hz clock
source is available. A dynamic power-switch is used to automatically switch from VCC domain to
the VBAT domain if VCC falls below the operating voltage level for the device. When the VCC volt-
age is restored, the power is automatically switched back to VCC.
18.2.4 Interrupts and events
The RTC can generate both interrupts and events. The RTC will give a compare interrupt
request and/or event when the counter value equals the Compare register value. The RTC will
give an overflow interrupt request and/or event when the counter value equals the Period regis-
ter value. The overflow will also reset the counter value to zero.
Due to the asynchronous clock domains event will only will only be generated for every third
overflow or compare if the period register is zero. If the period register is one, events will only be
generated for every second overflow or compare. When the period register is equal to or above
two, events will trigger at every overflow or compare just as the interrupt request.
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R/W
Reset Value 0 0 0 0 0 0 0 0
198
8077H–AVR–12/09
• Bit 0 - ENABLE: RTC Enable
Setting this bit enables the RTC. The synchronization time between the RTC and the System
Clock domains is one half RTC clock cycle from writing the register and until this has effect in
RTC clock domain, i.e until the RTC starts.
For the RTC to start running the PER Register must also be set to a different value that zero.
18.3.2 SYNCCTRL - Synchronisation Control/Status Register
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
CNT3, CNT2, CNT1 and CNT0 registers represent the 32-bit value CNT. CNT counts positive
clock edges on the RTC clock.
Synchronization of a new CNT value to the RTC domain is triggered by writing CNT3. The syn-
chronization time is up to 12 Peripheral clock cycles from updating the register until this has an
effect in RTC domain. Write operations to CNT register will be blocked if the SYNCBUSY flag is
set.
The Synchronization of CNT value from RTC domain to System Clock domain can be done by
writing one to the SYNCCNT bit in the CTRL register. The updated and synchronized CNT regis-
ter value is available after eight Peripheral Clock cycles.
After writing to the high byte of the CNT register, the condition for setting OVFIF and COMPIF,
as well as the Overflow and Compare Match Wakeup condition, will be disabled for the following
two RTC clock cycles.
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
200
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
PER3, PER2, PER1 and PER0 registers represent the 32-bit value PER. PER is constantly
compared with the counter value (CNT). A compare match will set the OVFIF in the INTFLAGS
register, and CNT will be set to zero in the next RTC clock cycle.
The PER register can only be written if the RTC is disabled and not currently synchronizing, i.e
when both ENABLE and SYNCBUSY are zero.
After writing a byte in the PER register the condition for setting OVFIF and the Overflow Wakeup
condition is disabled for the following two RTC clock cycles.
After reset this register is 0x0000, and it must be set to a value different that zero before the
enabled RTC starts counting.
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
201
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
The COMP0, COMP1, COMP2 and COMP3 registers represents the 32-bit value COMP. COMP
is constantly compared with the counter value (CNT). A compare match will set the COMPIF in
the INTFLAGS register, and the optional interrupt is generated.
If the COMP value is higher than the PER value, no RTC Compare Match interrupt requests or
events will be generated
After writing the high byte of the COMP register, the condition for setting OVFIF and COMPIF,
as well as the Overflow and Compare Match Wakeup condition, will be disabled for the following
two RTC clock cycles.
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
202
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Reset Value 0 0 0 0 0 0 0 0
203
8077H–AVR–12/09
XMEGA A
204
8077H–AVR–12/09
XMEGA A
19.1 Features
• Fully Independent Master and Slave Operation
• Multi-Master, Single Master, or Slave Only Operation
• Phillips I2C compatible
• SMBus compatible
• 100 kHz and 400 kHz support at low system clock frequencies
• Slew-Rate Limited Output Drivers
• Input Filter provides noise suppression
• 7-bit, and General Call Address Recognition in Hardware
• Address mask register for address masking or dual address match
• 10-bit addressing supported
• Optional Software Address Recognition Provides Unlimited Number of Slave Addresses
• Slave can operate in all sleep modes, including Power Down
• Support for Arbitration between START/Repeated START and Data Bit (SMBus)
• Slave Arbitration allows support for Address Resolve Protocol (ARP) (SMBus)
19.2 Overview
The Two Wire Interface (TWI) is bi-directional 2-wire bus communication, which is I2C and
SMBus compatible.
A device connected to the bus must act as a master or slave.The master initiates a data transac-
tion by addressing a slave on the bus, and telling whether it wants to transmit or receive data.
One bus can have several masters, and an arbitration process handles priority if two or more
masters try to transmit at the same time.
The TWI module in XMEGA implements both master and slave functionality. The master and
slave functionality are separated from each other and can be enabled separately. They have
separate control and status register, and separate interrupt vectors. Arbitration lost, errors, colli-
sion and clock hold on the bus will be detected in hardware and indicated in separate status
flags available in both master and slave mode.
The master module contains a baud rate generator for flexible clock generation. Both 100 kHz
and 400 kHz bus frequency at low system clock speed is supported. Quick Command and Smart
Mode can be enabled to auto trigger operations and reduce software complexity.
For the slave, 7-bit and general address call recognition is implemented in hardware. 10-bit
addressing is also supported. A dedicated address mask register can act as a second address
match register or as a mask register for the slave address to match on a range of addresses.
The slave logic continues to operate in all sleep modes, including Power down. This enables the
slave to wake up from sleep on TWI address match. It is possible to disable the address match-
ing and let this be handled in software instead. This allows the slave to detect and respond to
several addresses. Smart Mode can be enabled to auto trigger operations and reduce software
complexity.
The TWI module includes bus state logic that collects information to detect START and STOP
conditions, bus collision and bus errors. This is used to determine the bus state (idle, owner,
busy or unknown) in master mode. The bus state logic continues to operate in all sleep modes
including Power down.
205
8077H–AVR–12/09
XMEGA A
It is possible to disable the internal TWI drivers in the device, and enabling a 4-wire interface for
connecting external bus drivers.
VCC
RS RS RS RS RS RS
SDA
SCL
Note: RS is optional
A unique address is assigned to all slave devices connected to the bus, and the master will use
this to address a slave and initiate a data transaction. 7-bit or 10-bit addressing can be used.
Several masters can be connected to the same bus, and this is called a multi-master environ-
ment. An arbitration mechanism is provided for resolving bus ownership between masters since
only one master device may own the bus at any given time.
A device can contain both master and slave logic, and can emulate multiple slave devices by
responding to more than one address.
A master indicates the start of transaction by issuing a START condition (S) on the bus. An
address packet with a slave address (ADDRESS) and an indication whether the master wishes
to read or write data (R/W), is then sent. After all data packets (DATA) are transferred, the mas-
ter issues a STOP condition (P) on the bus to end the transaction. The receiver must
acknowledge (A) or not-acknowledge (A) each byte received.
Figure 19-2 shows a TWI transaction.
206
8077H–AVR–12/09
XMEGA A
SDA
Direction
Transaction
The master provides the clock signal for the transaction, but a device connected to the bus is
allowed to stretch the low level period of the clock to decrease the clock speed.
SDA
SCL
S P
START STOP
Condition Condition
Multiple START conditions can be issued during a single transaction. A START condition not
directly following a STOP condition, are named a Repeated START condition (Sr).
207
8077H–AVR–12/09
XMEGA A
SDA
SCL
DATA Change
Valid Allowed
Combining bit transfers results in the formation of address and data packets. These packets
consist of 8 data bits (one byte) with the most significant bit transferred first, plus a single bit not-
acknowledge (NACK) or acknowledge (ACK) response. The addressed device signals ACK by
pulling the SCL line low, and NACK by leaving the line SCL high during the ninth clock cycle.
19.3.6 Transaction
A transaction is the complete transfer from a START to a STOP condition, including any
Repeated START conditions in between. The TWI standard defines three fundamental transac-
tion modes: Master Write, Master Read, and combined transaction.
Figure 19-5 illustrates the Master Write transaction. The master initiates the transaction by issu-
ing a START condition (S) followed by an address packet with direction bit set to zero
(ADDRESS+W).
208
8077H–AVR–12/09
XMEGA A
Transaction
Address Packet Data Packet
N data packets
Given that the slave acknowledges the address, the master can start transmitting data (DATA)
and the slave will ACK or NACK (A/A) each byte. If no data packets are to be transmitted, the
master terminates the transaction by issuing a STOP condition (P) directly after the address
packet. There are no limitations to the number of data packets that can be transferred. If the
slave signal a NACK to the data, the master must assume that the slave cannot receive any
more data and terminate the transaction.
Figure 19-6 illustrates the Master Read transaction. The master initiates the transaction by issu-
ing a START condition followed by an address packet with direction bit set to one (ADRESS+R).
The addressed slave must acknowledge the address for the master to be allowed to continue
the transaction.
Transaction
Address Packet Data Packet
N data packets
Given that the slave acknowledges the address, the master can start receiving data from the
slave. There are no limitations to the number of data packets that can be transferred. The slave
transmits the data while the master signals ACK or NACK after each data byte. The master ter-
minates the transfer with a NACK before issuing a STOP condition.
Figure 19-7 illustrates a combined transaction. A combined transaction consists of several read
and write transactions separated by a Repeated START conditions (Sr).
Transaction
Address Packet #1 N Data Packets Address Packet #2 M Data Packets
Direction Direction
209
8077H–AVR–12/09
XMEGA A
SCL
S
If the device is in a sleep mode and a START condition is detected the clock is stretched during
the wake-up period for the device.
A slave device can slow down the bus frequency by stretching the clock periodically on a bit
level. This allows the slave to run at a lower system clock frequency. However, the overall per-
formance of the bus will be reduced accordingly. Both the master and slave device can
randomly stretch the clock on a byte level basis before and after the ACK/NACK bit. This pro-
vides time to process incoming or prepare outgoing data, or performing other time critical tasks.
In the case where the slave is stretching the clock the master will be forced into a wait-state until
the slave is ready and vice versa.
19.3.8 Arbitration
A master can only start a bus transaction if it has detected that the bus is idle. As the TWI bus is
a multi master bus, it is possible that two devices initiate a transaction at the same time. This
results in multiple masters owning the bus simultaneously. This is solved using an arbitration
scheme where the master loses control of the bus if it is not able to transmit a high level on the
SDA line. The masters who lose arbitration must then wait until the bus becomes idle (i.e. wait
for a STOP condition) before attempting to reacquire bus ownership. Slave devices are not
involved in the arbitration procedure.
210
8077H–AVR–12/09
XMEGA A
DEVICE1_SDA
DEVICE2_SDA
SDA
bit 7 bit 6 bit 5 bit 4
(wired-AND)
SCL
S
Figure 19-9 shows an example where two TWI masters are contending for bus ownership. Both
devices are able to issue a START condition, but DEVICE1 loses arbitration when attempting to
transmit a high level (bit 5) while DEVICE2 is transmitting a low level.
Arbitration between a repeated START condition and a data bit, a STOP condition and a data
bit, or a repeated START condition and STOP condition are not allowed and will require special
handling by software.
19.3.9 Synchronization
A clock synchronization algorithm is necessary for solving situations where more than one mas-
ter is trying to control the SCL line at the same time. The algorithm is based on the same
principles used for clock stretching previously described. Figure 19-10 shows an example where
two masters are competing for the control over the bus clock. The SCL line is the wired-AND
result of the two masters clock outputs.
DEVICE1_SCL
DEVICE2_SCL
SCL
(wired-AND)
A high to low transition on the SCL line will force the line low for all masters on the bus and they
start timing their low clock period. The timing length of the low clock period can vary between the
masters. When a master (DEVICE1 in this case) has completed its low period it releases the
SCL line. However, the SCL line will not go high before all masters have released it. Conse-
quently the SCL line will be held low by the device with the longest low period (DEVICE2).
Devices with shorter low periods must insert a wait-state until the clock is released. All masters
start their high period when the SCL line is released by all devices and has become high. The
211
8077H–AVR–12/09
XMEGA A
device which first completes its high period (DEVICE1) forces the clock line low and the proce-
dure are then repeated. The result of this is that the device with the shortest clock period
determines the high period while the low period of the clock is determined by the longest clock
period.
RESET
UNKNOWN
(0b00)
P + Timeout
S
Sr
IDLE BUSY
(0b01) P + Timeout (0b11)
Command P
Arbitration
Write ADDRESS Lost
(S) OWNER
(0b10)
Write
ADDRESS(Sr)
After a system reset, the bus state is unknown. From this the bus state machine can be forced to
enter idle by writing to the Bus State bits accordingly. If no state is set by application software
the bus state will become idle when a STOP condition is detected. If the Master Inactive Bus
Timeout is enabled the bus state will change to idle on the occurrence of a timeout. After a
known bus state is established the bus state will not re-enter the unknown state from any of the
other states. Only a system reset or disabling the TWI master will set the state to unknown.
When the bus is idle it is ready for a new transaction. If a START condition generated externally
is detected, the bus becomes busy until a STOP condition is detected. The STOP condition will
change the bus state to idle. If the Master Inactive Bus Timeout is enabled bus state will change
from busy to idle on the occurrence of a timeout.
212
8077H–AVR–12/09
XMEGA A
If a START condition is generated internally while in idle state the owner state is entered. If the
complete transaction was performed without interference, i.e. no collisions are detected, the
master will issue a STOP condition and the bus state changes back to idle. If a collision is
detected the arbitration is assumed lost and the bus state becomes busy until a STOP condition
is detected. A Repeated START condition will only change the bus state if arbitration is lost dur-
ing the issuing of the Repeated START.
M1 M2 M3 M4
Wait for
SW
IDLE
R/W A SW P IDLE M2
W A SW Sr M3 BUSY M4
SW DATA A/A
SW Driver software
MASTER READ INTERRUPT + HOLD
The master provides data
on the bus
A/A Sr M3
Mn Diagram connections
A/A
R A DATA
The number of interrupts generated is kept at a minimum by automatic handling of most condi-
tions. Quick Command and Smart Mode can be enabled to auto trigger operations and reduce
software complexity.
213
8077H–AVR–12/09
XMEGA A
19.5.1.1 Case M1: Arbitration lost or bus error during address packet
If arbitration is lost during the sending of the address packet the master Write Interrupt Flag and
Arbitration Lost flag are both set. Serial data output to the SDA line is disabled and the SCL line
is released. The master is no longer allowed to perform any operation on the bus until the bus
state has changed back to idle.
A bus error will behave in the same way as an arbitration lost condition, but the Error flag is set
in addition to Write Interrupt Flag and Arbitration Lost flag.
19.5.1.2 Case M2: Address packet transmit complete - Address not acknowledged by slave
If no slave device responds to the address the master Write Interrupt Flag is set and the master
Received Acknowledge flag is set. The clock hold is active at this point preventing further activity
on the bus.
19.5.1.3 Case M3: Address packet transmit complete - Direction bit cleared
If the master receives an ACK from the slave, the master Write Interrupt Flag is set, and the
master Received Acknowledge flag is cleared. The clock hold is active at this point preventing
further activity on the bus.
19.5.1.4 Case M4: Address packet transmit complete - Direction bit set
If the master receives an ACK from the slave, the master proceeds receiving the next byte of
data from the slave. When the first data byte is received the master Read Interrupt Flag is set
and the master Received Acknowledge flag is cleared. The clock hold is active at this point pre-
venting further activity on the bus.
214
8077H–AVR–12/09
XMEGA A
since arbitration can be lost during the transmission. If a collision is detected the master looses
arbitration and the Arbitration Lost flag is set.
P S2
S1 S3 A S1 Sr S3
P S2
A S1 Sr S3
SW Driver software
W SW A/A DATA SW A/A
The master provides data
on the bus
Interrupt on STOP
SW
Condition Enabled
Slave provides data on
the bus Collision Release
(SMBus)
SW
Hold S1
Sn Diagram connections
The number of interrupts generated is kept at a minimum by automatic handling of most condi-
tions. Quick Command can be enabled to auto trigger operations and reduce software
complexity.
Promiscuous Mode can be enabled to allow the slave to respond to all received addresses.
215
8077H–AVR–12/09
XMEGA A
The R/W Direction flag reflects the direction bit received with the address. This can be read by
software to determine the type of operation currently in progress.
Depending on the R/W direction bit and bus condition one of four distinct cases (1 to 4) arises
following the address packet. The different cases must be handled in software.
216
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
217
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
218
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Writing a command to the CMD bits will clear the master interrupt flags and the CLKHOLD flag.
219
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
220
8077H–AVR–12/09
XMEGA A
Writing 01 to the BUSSTATE bits forces the bus state logic into idle state. The bus state logic
cannot be forced into any other state. When the master is disabled, and after reset the Bus State
logic is disabled and the bus state is unknown.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
The Baud Rate (BAUD) register defines the relation between the system clock and the TWI Bus
Clock (SCL) frequency. The frequency relation can be expressed by using the following
equation:
f sys
f TWI = ---------------------------------------- [Hz] [1]
2(5 + TWMBR)
The BAUD register must be set to a value that results in a TWI bus clock frequency (fTWI) equal
or less 100 kHz or 400 kHz dependent on standard used by the application. The following equa-
tion [2] expresses equation [1] with respect to the BAUD value:
f sys
- – 5 [2]
TWMBR = -------------
2f TWI
221
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
When the Address (ADDR) register is written with a slave address and the R/W-bit while the bus
is idle, a START condition is issued, and the 7-bit slave address and the R/W-bit are transmitted
on the bus. If the bus is already owned when ADDR is written, a Repeated START is issued. If
the previous transaction was a Master Read and no acknowledge is sent yet, the Acknowledge
Action is sent before the Repeated START condition.
After completing the operation and the acknowledge bit from the slave is received, the SCL line
is forced low if arbitration was not lost. The WIF is set.
If the Bus State is unknown when ADDR is written. The WIF is set, and the BUSERR flag is set.
All TWI master flags are automatically cleared when ADDR is written. This includes BUSERR,
ARBLOST, RIF, and WIF. The Master ADDR can be read at any time without interfering with
ongoing bus activity.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
The data (DATA) register is used when transmitting and receiving data. During data transfer,
data is shifted from/to the DATA register and to/from the bus. This implies that the DATA register
cannot be accessed during byte transfers, and this is protected in hardware. The Data register
can only be accessed when the SCL line is held low by the master, i.e. when CLKHOLD is set.
In Master Write mode, writing the DATA register will trigger a data byte transfer, followed by the
master receiving the acknowledge bit from the slave. The WIF and the CLKHOLD flag are set.
In Master Read mode the RIF and the CLKHOLD flag are set when one byte is received in the
DATA register. If Smart Mode is enabled, reading the DATA register will trigger the bus opera-
tion as set by the ACKACT bit. If a bus error occurs during reception the WIF and BUSERR flag
are set instead of the RIF.
Accessing the DATA register will clear the master interrupt flags and the CLKHOLD flag.
222
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
223
8077H–AVR–12/09
XMEGA A
Writing the CMD bits will automatically clear the slave interrupt flags, the CLKHOLD flag and
release the SCL line. The ACKACT bit and CMD bits can be written at the same time, and then
the Acknowledge Action will be updated before the command is triggered.
Initial Value 0 0 0 0 0 0 0 0
224
8077H–AVR–12/09
XMEGA A
225
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
This register contains the TWI slave address used by the slave address match logic to deter-
mine if a master has addressed the slave. The 7 most significant bits (ADDR[7:1]) represents the
slave address and the least significant bit (ADDR[0]) is used for general call address recognition.
When ADDR[0] is set this enables general call address recognition logic so the device can
respond to a general address call that addresses all devices on the bus.
When using 10-bit addressing the address match logic only support hardware address recogni-
tion of the first byte of a 10-bit address. By setting ADDR[7:1] = "0b11110nn", 'nn' represents bit
9 and 8 for the slave address. The next byte received is bit 7 to 0 in the 10-bit address, and this
must be handled by software.
When the address match logic detects that a valid address byte is received, the APIF is set, and
the DIR flag is updated.
If the PMEN bit in CTRLA is set, the address match logic responds to all addresses transmitted
on the TWI bus. The ADDR register is not used in this mode.
Initial Value 0 0 0 0 0 0 0 0
The data (DATA) register is used when transmitting and received data. During data transfer,
data is shifted from/to the DATA register and to/from the bus. This implies that the DATA register
cannot be accessed during byte transfers, and this is protected in hardware. The Data register
can only be accessed when the SCL line is held low by the slave, i.e. when CLKHOLD is set.
When a master is reading data from the slave, data to send must be written to the DATA regis-
ter. The byte transfer is started when the Master start to clock the data byte from the slave,
followed by the slave receiving the acknowledge bit from the master. The DIF and the CLKHOLD
flag are set.
When a master write data to the slave the DIF and the CLKHOLD flag are set when one byte is
received in the DATA register. If Smart Mode is enabled, reading the DATA register will trigger
the bus operation as set by the ACKACT bit.
226
8077H–AVR–12/09
XMEGA A
Accessing the DATA register will clear the slave interrupt flags and the CLKHOLD flag.
Initial Value 0 0 0 0 0 0 0 0
227
8077H–AVR–12/09
XMEGA A
228
8077H–AVR–12/09
XMEGA A
20.1 Features
• Full-duplex, Three-wire Synchronous Data Transfer
• Master or Slave Operation
• LSB First or MSB First Data Transfer
• Eight Programmable Bit Rates
• End of Transmission Interrupt Flag
• Write Collision Flag Protection
• Wake-up from Idle Mode
• Double Speed (CK/2) Master SPI Mode
20.2 Overview
The Serial Peripheral Interface (SPI) is a high-speed synchronous data transfer interface using
three or four pins. It allows fast communication between an XMEGA device and peripheral
devices or between several AVR devices. The SPI supports full duplex communication.
A device connected to the bus must act as a master or slave.The master initiates and controls all
data transactions. The interconnection between Master and Slave CPUs with SPI is shown in
Figure 20-1 on page 229. The system consists of two shift Registers, and a Master clock gener-
ator. The SPI Master initiates the communication cycle when pulling low the Slave Select (SS)
pin of the desired Slave. Master and Slave prepare the data to be sent in their respective Shift
Registers, and the Master generates the required clock pulses on the SCK line to interchange
data. Data is always shifted from Master to Slave on the Master Out - Slave In (MOSI) line, and
from Slave to Master on the Master In - Slave Out (MISO) line. After each data packet, the Mas-
ter can synchronize the Slave by pulling high the SS line.
SHIFT
ENABLE
The XMEGA SPI module is single buffered in the transmit direction and double buffered in the
receive direction. This means that bytes to be transmitted cannot be written to the SPI Data Reg-
ister before the entire shift cycle is completed. When receiving data, a received character must
be read from the Data register before the next character has been completely shifted in. Other-
wise, the first byte is lost.
229
8077H–AVR–12/09
XMEGA A
In SPI Slave mode, the control logic will sample the incoming signal of the SCK pin. To ensure
correct sampling of this clock signal, the minimum low and high periods must be:
Low period: longer than 2 CPU clock cycles.
High period: longer than 2 CPU clock cycles.
When the SPI module is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is
overridden according to Table 20-1. The pins with user defined direction, must be configured
from software to have the correct direction according to the application.
230
8077H–AVR–12/09
XMEGA A
As the SS pin is used to signal start and end of transfer, it is also useful for doing packet/byte
synchronization, keeping the Slave bit counter synchronous with the Master clock generator.
Leading edge is the first clock edge in a clock cycle. Trailing edge is the last clock edge in a
clock cycle.
Mode 0
Mode 2
SAMPLE I
MOSI/MISO
CHANGE 0
MOSI PIN
CHANGE 0
MISO PIN
SS
MSB first (DORD = 0) MSB Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 LSB
LSB first (DORD = 1) LSB Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 MSB
Mode 1
Mode 3
SAMPLE I
MOSI/MISO
CHANGE 0
MOSI PIN
CHANGE 0
MISO PIN
SS
MSB first (DORD = 0) MSB Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 LSB
LSB first (DORD = 1) LSB Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 MSB
231
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
232
8077H–AVR–12/09
XMEGA A
Table 20-4. Relationship Between SCK and the Peripheral Clock (clkPER) frequency
CLK2X PRESCALER[1:0] SCK Frequency
0 00 clkPER/4
0 01 clkPER/16
0 10 clkPER/64
0 11 clkPER/128
1 00 clkPER/2
1 01 clkPER/8
1 10 clkPER/32
1 11 clkPER/64
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
233
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
The DATA register used for sending and receiving data. Writing to the register initiates the data
transmission, and the byte written to the register will be shifted out on the SPI output line. Read-
ing the register causes the Shift Register Receive buffer to be read, and return the last bytes
successfully received.
234
8077H–AVR–12/09
XMEGA A
21. USART
21.1 Features
• Full Duplex Operation (Independent Serial Receive and Transmit Registers)
• Asynchronous or Synchronous Operation
• Master or Slave Clocked Synchronous Operation
• Enhanced Baud Rate Generator
• Supports Serial Frames with 5, 6, 7, 8, or 9 Data Bits and 1 or 2 Stop Bits
• Odd or Even Parity Generation and Parity Check Supported by Hardware
• Data OverRun and Framing Error Detection
• Noise Filtering Includes False Start Bit Detection and Digital Low Pass Filter
• Separate Interrupts on TX Complete, TX Data Register Empty and RX Complete
• Multi-processor Communication Mode
• Double Speed Asynchronous Communication Mode
• Master SPI mode, Three-wire Synchronous Data Transfer
– Supports all four SPI Modes of Operation (Mode 0, 1, 2, and 3)
– LSB First or MSB First Data Transfer (Configurable Data Order)
– Queued Operation (Double Buffered)
– High Speed Operation (fXCK,max = fPER/2)
• IRCOM Module for IrDA compliant pulse modulation/demodulation
21.2 Overview
The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a
highly flexible serial communication module. The USART supports full duplex communication,
and both asynchronous and clocked synchronous operation. The USART can be set in Master
SPI compliant mode and be used for SPI communication.
Communication is frame based, and the frame format can be customized to support a wide
range of standards. The USART is buffered in both direction, enabling continued data transmis-
sion without any delay between frames. There are separate interrupt vectors for receive and
transmit complete, enabling fully interrupt driven communication. Frame error and buffer over-
flow are detected in hardware and indicated with separate status flags. Even or odd parity
generation and parity check can also be enabled.
A block diagram of the USART is shown in Figure 21-1 on page 236. The main parts are the
Clock Generator, the Transmitter and the Receiver, indicated in dashed boxes.
235
8077H–AVR–12/09
XMEGA A
Transmitter
TX
DATA(Transmit)
CONTROL
PARITY
GENERATOR
DATA BUS
PIN
TRANSMIT SHIFT REGISTER TxD
CONTROL
Receiver
CLOCK RX
RECOVERY CONTROL
DATA PIN
RECEIVE SHIFT REGISTER RxD
RECOVERY CONTROL
PARITY
DATA(Receive)
CHECKER
The Clock Generation logic has a fractional baud rate generator that is able to generate a wide
range of USART baud rates. It also includes synchronization logic for external clock input in syn-
chronous slave operation.
The Transmitter consists of a single write buffer (DATA), a shift register, Parity Generator and
control logic for handling different frame formats. The write buffer allows continuous data trans-
mission without any delay between frames.
The Receiver consists of a two level FIFO receive buffer (DATA), and a shift register. Data and
clock recovery units ensure robust synchronization and noise filtering during asynchronous data
reception. It includes frame error, buffer overflow and parity error detection.
When the USART is set in Master SPI compliant mode, all USART specific logic is disabled,
leaving the transmit and receive buffers, shift registers, and Baud Rate Generator enabled. Pin
control and interrupt generation is identical in both modes. The registers are used in both
modes, but the functionality differs for some control settings.
An IRCOM Module can be enabled for one USART to support IrDA 1.4 physical compliant pulse
modulation and demodulation for baud rates up to 115.2 kbps. For details refer to Section 22.
”IRCOM - IR Communication Module” on page 256 for details.
236
8077H–AVR–12/09
XMEGA A
BSEL
CLK2X
fBAUD
Baud Rate
/2 /4 /2
Generator 0
1
0
fOSC txclk
1
DDR_XCK
PORT_INV
Sync Edge
xcki Register Detector 0
XCK UMSEL [1]
xcko 1
Pin
DDR_XCK 1
rxclk
0
237
8077H–AVR–12/09
XMEGA A
Note: 1. The baud rate is defined to be the transfer rate in bit per second (bps)
f PER
f XCK < -----------
4
Each high and low period the XCK clock cycles must be sampled twice by the Peripheral Clock.
If the XCK clock has jitter, or the high/low period duty cycle is not 50/50, the maximum XCK
clock speed must be reduced accordingly.
238
8077H–AVR–12/09
XMEGA A
RxD / TxD
Sample
INVEN = 0 XCK
RxD / TxD
Sample
Using the Inverted I/O (INVEN) setting in the Pin Configuration Register for the corresponding
XCK port pin, it is selectable which XCK clock edge is used for data sampling and which is used
for data change. If inverted I/O is disabled (INVEN=0) data will be changed at rising XCK clock
edge and sampled at falling XCK clock edge. If inverted I/O is enabled (INVEN=1) data will be
changed at falling XCK clock edge and sampled at rising XCK clock edge. For more details, see
in “I/O Ports” on page 106.
239
8077H–AVR–12/09
XMEGA A
Leading edge is the first clock edge in a clock cycle. Trailing edge is the last clock edge in a
clock cycle.
INVEN=0 INVEN=1
XCK XCK
(IDLE) St 0 1 2 3 4 [5] [6] [7] [8] [P] Sp1 [Sp2] (St / IDLE)
240
8077H–AVR–12/09
XMEGA A
Table 1.
St Start bit, always low.
(n) Data bits (0 to 8).
P Parity bit. Can be odd or even.
Sp Stop bit, always high.
IDLE No transfers on the communication line (RxD or TxD). The IDLE state is always high.
241
8077H–AVR–12/09
XMEGA A
transmission) or immediately after the last stop bit of the previous frame is transmitted. When the
Shift Register is loaded with data, it will transfer one complete frame.
The Transmit Complete Interrupt Flag (TXCIF) is set and the optional interrupt is generated
when the entire frame in the Shift Register has been shifted out and there are no new data pres-
ent in the transmit buffer.
The Transmit Data Register (DATA) can only be written when the Data Register Empty Flag
(DREIF) is set, indicating that the register is empty and ready for new data.
When using frames with less than eight bits, the most significant bits written to the DATA are
ignored. If 9-bit characters are used the ninth bit must be written to the TXB8 bit before the low
byte of the character is written to DATA.
242
8077H–AVR–12/09
XMEGA A
Sample
(U2X = 0) 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3
Sample
(U2X = 1) 0 1 2 3 4 5 6 7 8 1 2
When the clock recovery logic detects a high (idle) to low (start) transition on the RxD line, the
start bit detection sequence is initiated. Sample 1 denotes the first zero-sample as shown in the
figure. The clock recovery logic then uses samples 8, 9, and 10 for Normal mode, and samples
4, 5, and 6 for Double Speed mode (indicated with sample numbers inside boxes on the figure)
to decide if a valid start bit is received. If two or more of these three samples have a low level
(the majority wins), the start bit is accepted. The clock recovery logic is synchronized and the
data recovery can begin. If two or more of the three samples have a high level the start bit is
rejected as a noise spike and the Receiver starts looking for the next high to low-transition. The
synchronization process is repeated for each start bit.
243
8077H–AVR–12/09
XMEGA A
RxD BIT n
Sample
(CLK2X = 0) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1
Sample
(CLK2X = 1) 1 2 3 4 5 6 7 8 1
As for start bit detection, identical majority voting technique is used on the three center samples
(indicated with sample numbers inside boxes) for deciding of the logic level of the received bit.
This majority voting process acts as a low pass filter for the received signal on the RxD pin. The
process is repeated for each bit until a complete frame is received. Including the first, but exclud-
ing additional stop bits. If the stop bit sampled has a logic 0 value, the Frame Error (FERR) Flag
will be set.
Figure 21-8 on page 244 shows the sampling of the stop bit in relation to the earliest possible
beginning of the next frame's start bit.
Figure 21-8. Stop Bit Sampling and Next Start Bit Sampling
Sample
(CLK2X = 0) 1 2 3 4 5 6 7 8 9 10 0/1 0/1 0/1
Sample
(CLK2X = 1) 1 2 3 4 5 6 0/1
A new high to low transition indicating the start bit of a new frame can come right after the last of
the bits used for majority voting. For Normal Speed mode, the first low level sample can be at
point marked (A) in Stop Bit Sampling and Next Start Bit Sampling. For Double Speed mode the
first low level must be delayed to (B). (C) marks a stop bit of full length at nominal baud rate. The
early start bit detection influences the operational range of the Receiver.
244
8077H–AVR–12/09
XMEGA A
The following equations can be used to calculate the ratio of the incoming data rate and internal
receiver baud rate.
Table 1.
( D + 1 )S ( D + 2 )S
R slow = ------------------------------------------- R fast = -----------------------------------
S – 1 + D ⋅ S + SF ( D + 1 )S + S M
Table 1.
D Sum of character size and parity size (D = 5 to 10 bit).
S Samples per bit. S = 16 for Normal Speed mode and S = 8 for Double Speed mode.
SF First sample number used for majority voting. SF = 8 for normal speed and SF = 4 for
Double Speed mode.
SM Middle sample number used for majority voting. SM = 9 for normal speed and SM = 5
for Double Speed mode.
Rslow Is the ratio of the slowest incoming data rate that can be accepted in relation to the
receiver baud rate.
Rfast Is the ratio of the fastest incoming data rate that can be accepted in relation to the
receiver baud rate.
Table 21-3 and Table 21-4 on page 245 list the maximum receiver baud rate error that can be
tolerated. Normal Speed mode has higher toleration of baud rate variations.
Table 21-3. Recommended Maximum Receiver Baud Rate Error for Normal Speed Mode
(CLK2X = 0)
D Recommended Max
#(Data + Parity Bit) Rslow (%) Rfast (%) Max Total Error (%) Receiver Error (%)
5 93.20 106.67 +6.67/-6.80 ± 3.0
6 94.12 105.79 +5.79/-5.88 ± 2.5
7 94.81 105.11 +5.11/-5.19 ± 2.0
8 95.36 104.58 +4.58/-4.54 ± 2.0
9 95.81 104.14 +4.14/-4.19 ± 1.5
10 96.17 103.78 +3.78/-3.83 ± 1.5
Table 21-4. Recommended Maximum Receiver Baud Rate Error for Double Speed Mode
(CLK2X = 1)
D Recommended Max
#(Data + Parity Bit) Rslow (%) Rfast (%) Max Total Error (%) Receiver Error (%)
5 94.12 105.66 +5.66/-5.88 ± 2.5
6 94.92 104.92 +4.92/-5.08 ± 2.0
7 95.52 104.35 +4.35/-4.48 ± 1.5
245
8077H–AVR–12/09
XMEGA A
Table 21-4. Recommended Maximum Receiver Baud Rate Error for Double Speed Mode
(CLK2X = 1) (Continued)
D Recommended Max
#(Data + Parity Bit) Rslow (%) Rfast (%) Max Total Error (%) Receiver Error (%)
8 96.00 103.90 +3.90/-4.00 ± 1.5
9 96.39 103.53 +3.53/-3.61 ± 1.5
10 96.70 103.23 +3.23/-3.30 ± 1.0
The recommendations of the maximum receiver baud rate error was made under the assump-
tion that the Receiver and Transmitter equally divides the maximum total error.
There are two possible sources for the receivers baud rate error. The Receiver's system clock
will always have some minor instability. In addition, the baud rate generator can not always do
an exact division of the peripheral clock frequency to get the baud rate wanted. In this case the
BSEL and BSCALE value should be selected to give the lowest possible error.
246
8077H–AVR–12/09
XMEGA A
samples per 10-bit frame compared to the previous from 160 to 320. Higher negative scale fac-
tor gives even finer granularity. There is a limit to how high the scale factor can be. A rule of
thumb is that the value 2BSCALE must be at least half of the minimum number of clock cycles a
frame takes. For instance for 10-bit frames the minimum number of clock cycles is 160. This
means that the highest applicable scale factor is -6 (2-6 = 64 < 160/2 = 80). For higher BSEL set-
tings the scale factor can be increased.
247
8077H–AVR–12/09
XMEGA A
A comparison of the USART in Master SPI mode and the SPI pins is shown Table 21-5.
Table 21-5. Comparison of USART in Master SPI mode and SPI pins.
USART SPI Comment
TxD MOSI Master Out only
RxD MISO Master In only
XCK SCK Functionally identical
N/A SS Not supported by USART in Master SPI
248
8077H–AVR–12/09
XMEGA A
RXB[[7:0]
+0x00
TXB[[7:0]
Initial Value 0 0 0 0 0 0 0 0
The USART Transmit Data Buffer Register and USART Receive Data Buffer Registers share the
same I/O address referred to as USART Data Register (DATA). The Transmit Data Buffer Reg-
ister (TXB) will be the destination for data written to the DATA Register location. Reading the
DATA Register location will return the contents of the Receive Data Buffer Register (RXB).
For 5-, 6-, or 7-bit characters the upper unused bits will be ignored by the Transmitter and set to
zero by the Receiver.
The transmit buffer can only be written when the DREIF Flag in the STATUS Register is set.
Data written to DATA when the DREIF Flag is not set, will be ignored by the USART Transmitter.
When data is written to the transmit buffer, and the Transmitter is enabled, the Transmitter will
load the data into the Transmit Shift Register when the Shift Register is empty. The data is then
transmitted on the TxD pin.
The receive buffer consists of a two level FIFO. The FIFO and the corresponding flags in the
Status Register (STATUS) will change state whenever the receive buffer is accessed (read).
Always read STATUS before DATA in order to get the correct flags.
Initial Value 0 0 1 0 0 0 0 0
249
8077H–AVR–12/09
XMEGA A
When interrupt-driven data reception is used, the receive complete interrupt routine must read
the received data from DATA in order to clear the RXCIF. If not, a new interrupt will occur
directly after the return from the current interrupt. This flag can also be cleared by writing a one
to its bit location.
• Bit 1 - Reserved
This bit is reserved and will always be read as zero. For compatibility with future devices, always
write this bit to zero when this register is written.
250
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
251
8077H–AVR–12/09
XMEGA A
(1)
+0x05 CMODE[1:0] - - - UDORD UCPHA -
Initial Value 0 0 0 0 0 1 1 0
Notes: 1. See Section 22. ”IRCOM - IR Communication Module” on page 256 for full description on
using IRCOM mode.
252
8077H–AVR–12/09
XMEGA A
2. See ”USART” on page 235 for full description of the Master SPI Mode (MSPIM) operation.
253
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
254
8077H–AVR–12/09
XMEGA A
255
8077H–AVR–12/09
XMEGA A
22.1 Features
• Pulse modulation/demodulation for infrared communication
• IrDA 1.4 Compatible for baud rates up to 115.2 kbps
• Selectable pulse modulation scheme
– 3/16 of baud rate period
– Fixed pulse period, 8-bit programmable
– Pulse modulation disabled
• Built in filtering
• Can be connected to and used by any USART
22.2 Overview
XMEGA contains an Infrared Communication Module (IRCOM) IrDA 1.4 compatible module for
baud rates up to 115.2 kbps. This supports three modulation schemes: 3/16 of baud rate period,
fixed programmable pulse time based on the Peripheral Clock speed, or pulse modulation dis-
abled. There is one IRCOM available, and this can be connected to any USART to enable
infrared pulse coding/decoding for that USART.
RXDnx
USARTxn
TXDnx
IRCOM
.... RXD...
TXD...
encoded RXD USARTD0 RXDD0
Pulse
TXDD0
Decoding
USARTC0 RXDC0
decoded RXD TXDC0
decoded TXD
Pulse
Encoding encoded TXD
The IRCOM is automatically enabled when a USART is set in IRCOM mode. When this is done
signals between the USART and the RX/TX pins are routed through the module as shown in Fig-
ure 22-1 on page 256. It is also possible to select an Event Channel from the Event System as
input for the IRCOM receiver. This will disable the RX input from the USART pin.
256
8077H–AVR–12/09
XMEGA A
257
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
258
8077H–AVR–12/09
XMEGA A
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRL - - - - EVSEL[3:0] 258
+0x01 TXPLCTRL TXPLCTRL[7:0] 258
+0x02 RXPLCTRL RXPLCTRL[7:0] 258
259
8077H–AVR–12/09
XMEGA A
23.1 Features
• Data Encryption Standard (DES) core instruction
• Advanced Encryption Standard (AES) crypto module
• DES Instruction
– Encryption and Decryption
– DES supported
– Single-cycle DES instruction
– Encryption/Decryption in 16 clock cycles per 8-byte block
• AES Crypto Module
– Encryption and Decryption
– Support 128-bit keys
– Support XOR data load mode to the State memory
– Encryption/Decryption in 375 clock cycles per 16-byte block
23.2 Overview
The Advanced Encryption Standard (AES) and Data Encryption Standard (DES) are two com-
monly used standards for encryption. These are supported through an AES peripheral module
and a DES core instruction.
DES is supported by a DES instruction in the AVR XMEGA core. The 8-byte key and 8-byte data
blocks must be loaded into the Register file, and then DES must be executed 16 times to
encrypt/decrypt the data block.
The AES Crypto Module encrypts and decrypts 128-bit data blocks with the use of a 128-bit key.
The key and data must be loaded into the module before encryption/decryption is started. It
takes 375 peripheral clock cycles before encrypted/decrypted data can be read out.
260
8077H–AVR–12/09
XMEGA A
data
R4 data4
R5 data5
R6 data6
R7 data7
R8 key0
R9 key1
R10 key2
R11 key3
key
R12 key4
R13 key5
R14 key6
R15 key7
R16
...
R31
Executing one DES instruction performs one round in the DES algorithm. Sixteen rounds must
be executed in increasing order to form the correct DES ciphertext or plaintext. Intermediate
results are stored in the register file (R0-R15) after each DES instruction. After sixteen rounds
the key is located in R8-R16 and the encrypted/decrypted ciphertext/plaintext is located in R0-
R7. The instruction's operand (K) determines which round is executed, and the half carry flag (H)
in the CPU Status Register determines whether encryption or decryption is performed. If the half
carry flag is set, decryption is performed and if the flag is cleared, encryption is performed.
For more details on the DES instruction refer to the AVR instruction set manual.
261
8077H–AVR–12/09
XMEGA A
Reset pointer
-
Reset pointer
reset or access
to AES Control STATE
XOR
STATE[read pointer]
262
8077H–AVR–12/09
XMEGA A
The State memory contains the AES State throughout the encryption/decryption process. The
initial value of the State is the initial data (i.e. plain text in the encryption mode, and cipher text in
the decryption mode). The last value of the State is the encrypted/decrypted data.
Reset pointer
-
Reset pointer
reset or
access to CTRL KEY
In the AES Crypto Module the following definition of the Key is used:
• In encryption mode, the Key is the one defined in the AES standard.
• In decryption mode, the Key is the last subkey of the Expanded Key defined in the AES
standard.
In decryption mode the Key Expansion procedure must be executed by software before opera-
tion with the AES Crypto Module, so that the last subkey is ready to be loaded through the Key
register. Alternatively this procedure can be run by hardware by using the AES Crypto Module
and process a dummy data block in encryption mode, using the same Key. After the end of the
encryption, reading from the Key memory allows to obtain the last subkey, i.e. get the result of
the Key Expansion procedure. Table 23-1 on page 263 shows the results of reading the key,
depending on the mode (encryption or decryption) and status of the AES Crypto Module.
Table 23-1. The result of reading the Key memory at different stages.
Encryption Decryption
263
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
• Bit 3 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
264
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
The State Register is used to access the State memory. Before encryption/decryption can take
place the State memory must be written sequentially byte by byte through the State Register.
After encryption/decryption is done the ciphertext/plaintext can be read sequentially byte by byte
through the State Register.
Loading the initial data to the State Register should be made after setting the appropriate AES-
mode and direction. During encryption/ decryption this register can not be accessed.
265
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
The Key Register is used to access the Key memory. Before encryption/decryption can take
place the Key memory must be written sequentially byte by byte through the Key Register. After
encryption/decryption is done the last subkey can be read sequentially byte by byte through the
Key Register.
Loading the initial data to the Key Register should be made after setting the appropriate AES-
mode and direction.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
266
8077H–AVR–12/09
XMEGA A
267
8077H–AVR–12/09
XMEGA A
The base address is the lowest address in the address space for a chip select. This decides the
first location in data memory space where the connected memory hardware can be accessed.
268
8077H–AVR–12/09
XMEGA A
The base address associated with each chip select must be on a 4 Kbyte boundary, i.e to
address 0, 4096, 8192 etc.
24.3.2 Address Size
The address size selects how many bits of the address that should be compared when generat-
ing a chip select. The address size can be anything from 256 bytes to 16M bytes. If the address
space is set to anything larger than 4K bytes, the base address must be on a boundary equal to
the address space. With 1M byte address space for a chip select, the base address must be on
a 0, 1M byte, 2M byte etc. boundary.
If the EBI is configured so that if the address spaces overlap, the internal memory space have
priority, followed by Chip Select 0 (CS0), CS1, CS2 and CS3.
24.3.3 Chip Select as Address Lines
If one or more Chip Select lines are unused, they can in some combinations be used as address
lines instead. This can enable larger external memory or external CS generation. Each column
in Figure 24-1 on page 269 shows enabled chip select lines (CSn), and the address lines avail-
able on unused chip select lines (Ann). Column four shows that all four CS lines are used as
address lines when only CS3 is enabled, and this is for SDRAM configuring.
269
8077H–AVR–12/09
XMEGA A
24.6.1 No Multiplexing
When no multiplexing is used, there is a one-to-one connection between the EBI and the SRAM.
No external address latches are used.
D[7:0] D[7:0]
A[7:0] A[7:0]
EBI SRAM
A[15:8] A[15:8]
A[21:16] A[21:16]
When address byte 0 (A[7:0]) and address byte 1 (A[15:8]) are multiplexed, they are output from
the same port, and the ALE1 signal from the device control the address latch.
270
8077H–AVR–12/09
XMEGA A
D[7:0] D[7:0]
A[15:8]/
A[7:0]
A[7:0]
EBI D Q A[15:8]
SRAM
ALE1 G
A[19:16] A[19:16]
When address byte 0 (A[7:0]) and address byte 2 (A[23:16) are multiplexed, they are output
from the same port, and the ALE2 signal from the device control the address latch.
D[7:0] D[7:0]
A[23:16]/
A[7:0]
A[7:0]
EBI A[15:8] A[15:8]
SRAM
D Q A[23:16]
ALE2 G
When address byte 0 (A[7:0]), address byte 1 (A[15:8]) and address byte 2 (A[23:16] are multi-
plexed, they are output from the same port, and the ALE1 and ALE2 signal from the device
control the external address latches.
271
8077H–AVR–12/09
XMEGA A
D[7:0] D[7:0]
A[23:16]/
A[15:8]/ A[7:0]
A[7:0]
EBI D Q A[15:8]
SRAM
ALE1 G
D Q A[23:16]
ALE2 G
The Address Latch timing and parameter requirements are described in ”EBI Timing” on page
277.
24.6.6 Timing
SRAM or external memory devices may have different timing requirements. To meet these vary-
ing requirements, each Chip Select can be configured with different wait-states. Timing details is
described in ”EBI Timing” on page 277.
When the data byte and address byte 0 (AD[7:0]) are multiplexed, they are output from the same
port, and the ALE1 signal from the device controls the address latch.
AD[7:0] D[7:0]
D Q A[7:0]
EBI ALE1 G SRAM
A[15:8] A[15:8]
A[19:16] A[19:16]
272
8077H–AVR–12/09
XMEGA A
When the data byte and address byte 0 (AD[7:0]), and address byte 1 (A[15:8]) are multiplexed,
they are output from the same port, and the ALE1 and ALE2 signal from the device control the
external address latches.
Figure 24-7. Multiplexed SRAM LPC connection using ALE1 and ALE2
A[15:8]/
D[7:0]
AD[7:0]
D Q A[7:0]
EBI ALE1 G SRAM
D Q A[15:8]
ALE2 G
A[19:16] A[19:16]
273
8077H–AVR–12/09
XMEGA A
The SDRAM commands that are supported by the EBI is listed in Table 24-3 on page 274.
When 3 EBI ports are available, SDRAM can be connected with 3-Port EBI configuration. When
this is done only 4-bit data bus is available, and any chip select must be controlled from software
using a general purpose I/O pin (Pxn).
CLK CLK
CKE CKE
BA[1:0] BA[1:0]
DQM DQM
WE WE
RAS RAS
EBI CAS/RE CAS SDRAM
D[3:0] D[3:0]
A[7:0]] A[7:0]
A[11:8] A[11:8]
Pxn CS
When 4 EBI ports are available, SDRAM can be connected with 3-Port or 4-Port EBI configura-
tion. When 4-Port configuration is used, 8-bit data bus is available and all four chip selects will
be available.
274
8077H–AVR–12/09
XMEGA A
CLK CLK
CKE CKE
BA[1:0] BA[1:0]
DQM DQM
WE WE
RAS RAS
EBI CAS/RE CAS SDRAM
D[7:0] D[7:0]
A[7:0]] A[7:0]
A[11:8] A[11:8]
CS[3:0] CS
24.8.4 Timing
The Clock Enable (CKE) signal is required for SDRAM when the EBI is clocked at 2x the CPU
clock speed.
24.8.5 Initialization
Configuring Chip Select 3 to SDRAM will enable the initialization of the SDRAM. The “Load
Mode Register” command is automatically issued at the end of the initialization. For the correct
information to be loaded to the SDRAM, one must do one of the following:
1. Configure SDRAM control registers before enabling Chip Select 3 to SDRAM.
2. Issue a “Load Mode Register” command and perform a dummy-access after SDRAM is
initialized.
The SDRAM initialization is non-interruptible by other EBI accesses.
24.8.6 Refresh
The EBI will automatically handle the refresh of the SDRAM as long as the refresh period is con-
figured. Refresh will be done as soon as available after the refresh counter reaches the period.
The EBI can collect up to 4 refresh commands in case the interface is busy on another chip
select or in the middle of a read/write at a time a refresh should have been performed.
275
8077H–AVR–12/09
XMEGA A
CLK CLK
CKE CKE
BA[1:0] BA[1:0]
DQM DQM
WE WE
RAS/ALE1 RAS
EBI CAS/RE CAS SDRAM
D[7:0] D[7:0]
A[7:0]/A[15:8] A[7:0]
A[11:8]/A[19:16] A[11:8]
CS[3:0] CS
CS
WE
RE
D[7:0]
A[7:0] SRAM
D Q A[15:8]
G
A[19:16]
276
8077H–AVR–12/09
XMEGA A
Note: 1. For characterization of ClkSYS and tDRS refer to device data sheet
277
8077H–AVR–12/09
XMEGA A
24.10.2 SDRAM
Note: 1. For characterization of ClkSYS and tDRS refer to device data sheet
278
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
+0x00 SDDATAW[1:0] LPCMODE[1:0] SRMODE[1:0] IFMODE[1:0] CTRL
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Note: 1. 8-bit data bus only available for 4-port EBI interface
Note: 1. ALE2 and NOALE only available with 4-port EBI interface
279
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
+0x01 - - - - SDCAS SDROW SDCOL[1:0] SDRAMCTRLA
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
280
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
+0x04 REFRESH[7:0] REFRESHL
+0x05 - - - - - - REFRESH[9:8] REFRESHH
15 14 13 12 11 10 9 8
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x06 INITDLY[7:0] INITDLYL
+0x07 - - INITDLY[9:8] INITDLYH
15 14 13 12 11 10 9 8
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x08 MRDLY[1:0] ROWCYCDLY[2:0] RPDLY[2:0] SDRAMCTRLB
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
281
8077H–AVR–12/09
XMEGA A
282
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
+0x09 WRDLY[1:0] ESRDLY[1:0] ROWCOLDLY[1:0] SDRAMCTRLC
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
283
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
+0x00 - ASIZE[4:0] MODE[1:0] CTRLA
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
• Bit 7 - Reserved
This bit is reserved and will always be read as zero.
284
8077H–AVR–12/09
XMEGA A
This configuration options in this register depend on the Chip Select Mode configuration. The
register description below is valid when the Chip Select Mode is configured for SRAM or SRAM
LPC.
Bit 7 6 5 4 3 2 1 0
+0x01 - - - - - SRWS[2:0] CTRLB
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
285
8077H–AVR–12/09
XMEGA A
This configuration options in this register depend on the Chip Select Mode configuration. The
register description below is valid when the Chip Select Mode is configured for SDRAM.
Bit 7 6 5 4 3 2 1 0
+0x01 SDINITDONE - - - - SDREN SDMODE[1:0] CTRLB
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 BASEADDR[15:12] - - - - BASEADDRL
+0x03 BASEADDR[23:16] BASEADDRH
15 14 13 12 11 10 9 8
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
286
8077H–AVR–12/09
XMEGA A
287
8077H–AVR–12/09
XMEGA A
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRL SDDATAW[1:0] LPCMODE[1:0] SRMODE[1:0] IFMODE[1:0] 279
+0x01 SDRAMCTRLA - - - - SDCAS SDROW SDCOL[1:0] 280
+0x02 Reserved - - - - - - - -
+0x03 Reserved - - - - - - - -
+0x04 REFRESHL SDRAM Refresh Period Low Byte 281
+0x05 REFRESHH - - - - - - SDRAM Refresh Period High 281
+0x06 INITDLYL SDRAM Initialization Time Low Byte 281
+0x07 INITDLYH - - SDRAM Initialization Time High Byte 281
+0x08 SDRAMCTRLB MRDLY[1:0] ROWCYCDLY[[2:0] RPDLY[2:0] 281
+0x09 SDRAMCTRLC RWDLY[1:0] ESRDLY[2:0] ROWCOLDLY[2:0] 283
+0x0A Reserved - - - - - - - -
+0x0B Reserved - - - - - - - -
+0x0C Reserved - - - - - - - -
+0x0D Reserved - - - - - - - -
+0x0E Reserved - - - - - - - -
+0x0F Reserved - - - - - - - -
+0x10 CS0 Chip Select 0 Offset Address
+0x14 CS1 Chip Select 1 Offset Address
+0x18 CS2 Chip Select 2 Offset Address
+0x1C CS3 Chip Select 3 Offset Address
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRLA - ASIZE[4:0] MODE[1:0] 284
+0x01 CTRLB (SRAM) - - - - - SRWS[2:0] 285
(SDRAM) SDINITDONE - - - - SDSREN SDMODE[1:0] 286
+0x02 BASEADDRL Chip Select Base Address Low Byte - - - - 286
+0x03 BASEADDRH Chip Select Base Address High Byte 286
288
8077H–AVR–12/09
XMEGA A
25.1 Features
• 12-bit resolution
• Up to 2 Msps sample and conversion rate
• Single-ended or Differential measurements
• Signed and Unsigned mode
• 4 result registers with individual input control
• 8 - 16 single-ended inputs
• 8x4 differential inputs without gain
• 8x4 differential input with gain
• 4 internal inputs
– Temperature Sensor
– DAC Output
– VCC voltage divided by 10
– Bandgap voltage
• 1x, 2x, 4x, 8x, 16x, 32x or 64x software selectable gain
• 4 inputs can be sampled within 1.5 µs
• 8-, or 12-bit selectable resolution
• Minimum single result propagation delay of 2.5 µs (8-bit resolution)
• Minimum single result propagation delay of 3.5 µs (12-bit resolution)
• Built-in reference
• Optional external reference
• Optional event triggered conversion for accurate timing
• Optional DMA transfer of conversion results
• Optional interrupt/event on compare result
25.2 Overview
The ADC converts analog voltages to digital values. The ADC has 12-bit resolution and is capa-
ble of converting up to 2 million samples per second. The input selection is flexible, and both
single-ended and differential measurements can be done. For differential measurements an
optional gain stage is available to increase the dynamic range. In addition several internal signal
inputs are available. The ADC can provide both signed and unsigned results.
This is a pipeline ADC. A pipeline ADC consists of several consecutive stages, where each
stage convert one part of the result. The pipeline design enables high sample rate at low clock
speeds, and remove dependencies between sample speed and propagation delay. This also
means that a new analog voltage can be sampled and a new ADC measurement started while
other ADC measurements are ongoing.
ADC measurements can either be started by application software or an incoming event from
another peripheral in the device. Four different result registers with individual input selection
(MUX selection) are provided to make it easier for the application to keep track of the data. Each
result register and MUX selection pair is referred to as an ADC Channel. It is possible to use
DMA to move ADC results directly to memory or peripherals when conversions are done.
Both internal and external analog reference voltages can be used. A very accurate internal
1.00V reference is available.
289
8077H–AVR–12/09
XMEGA A
An integrated temperature sensor is available and the output from this can be measured with the
ADC. The output from the DAC, VCC/10 and the Bandgap voltage can also be measured by the
ADC.
Internal inputs
Configuration Channel 0 Result
Reference selection Register
Channel 1 Result
Pin inputs
Register
ADC
Channel 2 Result
Register
Differential
Pin inputs
Channel 3 Result
Event Register
1-64 X
triggers
290
8077H–AVR–12/09
XMEGA A
ADC0
ADC1
ADC2
ADC3
ADC4
ADC5
ADC6
ADC7
+
ADC
-
ADC0
ADC1
ADC2
ADC3
ADC0
ADC1
ADC2
ADC3
ADC4
ADC5
ADC6
ADC7 +
1-64 X ADC
-
ADC4
ADC5
ADC6
ADC7
291
8077H–AVR–12/09
XMEGA A
ADC0
ADC1
ADC2
ADC3
+
ADC4
ADC5 ADC
ADC6
-
ADC7
In unsigned mode the negative input is connected to half of the voltage reference (VREF) volt-
age minus a fixed offset. The nominal value for the offset is:
ΔV = VREF × 0.05
Since the ADC is differential, unsigned mode is achieved by dividing the reference by two inter-
nally, resulting in an input range from VREF to zero for the positive single ended input. The
offset enables the ADC to measure zero cross detection in unsigned mode, and to calibrate any
positive offset where the internal ground in the device is higher than the external ground. See
Figure 25-11 on page 296 for details.
ADC0
ADC1
ADC2
ADC3
+
ADC4
ADC5 ADC
ADC6 VREF
− ΔV -
ADC7 2
292
8077H–AVR–12/09
XMEGA A
temperature sensor, and the value is store in the production calibration row and can be used for
temperature sensor calibration.
The bandgap voltage is an accurate voltage reference inside the microcontroller that is the
source for other internal voltage references.
VCC can be measured directly by scaling it down and dividing it by 10 before the ADC input.
Thus, VCC of 1.8 V will be measured as 0.18 V and VCC of 3.6 V will be measured as 0.36 V.
The output from the DAC module can also be measured by the ADC. It is the output directly from
the DAC, and not the Sample and Hold (S/H) outputs, that is available for the ADC.
Some of the internal signals need to be turned on specifically before they can be used mea-
sured. Refer to the manual for these modules for details of how to turn them on. The sample rate
for the internal signals is lower than the maximum speed for the ADC, refer to the ADC charac-
teristics in the device data sheets for details on sample rate of the internal signals.
When measuring the internal signals, the negative input is connected to internal ground in
signed mode.
TEMP REF
DAC
+
VCC SCALED
BANDGAP REF ADC
-
In unsigned mode the negative input is connected to a fixed value which is half of the voltage ref-
erence (VREF) minus a fixed offset as it is for single ended unsigned input. Refer to Figure 25-
11 on page 296 for details.
TEMP REF
BANDGAP REF
+
VCC SCALED
DAC ADC
VREF
− ΔV -
2
293
8077H–AVR–12/09
XMEGA A
As an example of the ADC channel scheme, one of the MUX/result register pairs can be setup to
do single-ended measurements triggered by event signal input, the second MUX/result pair can
measure a differential input on another event signal input, and the two last MUX/result pairs can
measure two other input sources started by the application software.
All the ADC channels use the same ADC for the conversions, but due to the pipelined design a
new conversion can be started on each ADC clock cycle. This means that multiple ADC conver-
sions can be progressing simultaneously and independently without changing the MUX settings.
A conversion result can be kept in one result register, independently of other result registers that
are continuously updated with new conversion results. This can help reduce software complex-
ity, and different software modules can start conversions and read conversion results fully
independent of each other.
Internal 1.00V
Internal VCC/1.6V
VREF
AREFA
AREFB
VINP - VINN
RES = --------------------------------- ⋅ GAIN ⋅ TOP
VREF
VINP and VINN are the positive and negative inputs to the ADC. GAIN is 1 unless differential
channels with gain is used.
In unsigned mode the ADC transfer functions can be written as:
294
8077H–AVR–12/09
XMEGA A
VINP - (-ΔV )
RES = ---------------------------------- ⋅ TOP
VREF
Figure 25-9. Signed differential input (with gain), input range, and result representation
VREF Dec Hex Binary 16-bit result register
GAIN 2047 7FF 0111 1111 1111 0000 0111 1111 1111
VINN 2046 7FE 0111 1111 1110 0000 0111 1111 1110
2045 7FD 0111 1111 1101 0000 0111 1111 1101
... ... ... ...
3 3 0000 0000 0011 0000 0000 0000 0011
VINP 2 2 0000 0000 0010 0000 0000 0000 0010
1 1 0000 0000 0001 0000 0000 0000 0001
0V 0 0 0000 0000 0000 0000 0000 0000 0000
-1 FFF 1111 1111 1111 1111 1111 1111 1111
-2 FFE 1111 1111 1110 1111 1111 1111 1110
... ... ... ...
RES -2045 803 1000 0000 0011 1111 1000 0000 0011
-2046 802 1000 0000 0010 1111 1000 0000 0010
-2047 801 1000 0000 0001 1111 1000 0000 0001
-VREF -2048 800 1000 0000 0000 1111 1000 0000 0000
GAIN
Figure 25-10. Signed single ended and internal input, input range, and result representation
295
8077H–AVR–12/09
XMEGA A
Figure 25-11. Unsigned single ended and internal input, input range, and result representation
Dec Hex Binary 16-bit result register
VREF − ΔV
4095 FFF 1111 1111 1111 0000 1111 1111 1111
VINP 4094 FFE 1111 1111 1110 0000 1111 1111 1110
4093 FFD 1111 1111 1101 0000 1111 1111 1101
... ... ... ...
203 0CB 0000 1100 1011 0000 0000 1100 1011
202 0CA 0000 1100 1010 0000 0000 1100 1010
VREF 201 0C9 0000 1100 1001 0000 0000 1100 1001
VINN = − ΔV
2 200 0C8 0000 1100 1000 0000 0000 1100 1000
GND
...
0 0 0000 0000 0000 0000 0000 0000 0000
PRESCALER[2:0]
ClkADC
The maximum ADC sample rate is given by the he ADC clock frequency (fADC). The ADC can
sample a new measurement on every ADC clock cycle.
Sample Rate = f ADC
296
8077H–AVR–12/09
XMEGA A
RES is the resolution, 8- or 12-bit. The propagation delay will increase by one extra ADC clock
cycle if the Gain Stage (GAIN) is used.
Even though the propagation delay is longer than one ADC clock cycle, the pipelined design
removes any limitations on sample speed versus propagation delay.
Figure 25-13. ADC timing for one single conversion without gain
1 2 3 4 5 6 7 8
CLK ADC
START
ADC SAMPLE
IF
297
8077H–AVR–12/09
XMEGA A
Figure 25-14. ADC timing for one single conversion with gain
1 2 3 4 5 6 7 8 9
CLKADC
START
GAINSTAGE SAMPLE
GAINSTAGE AMPLIFY
ADC SAMPLE
IF
Figure 25-15. ADC timing for single conversions on two ADC channels
1 2 3 4 5 6 7 8 9
CLKADC
START CH0
START CH1
ADC SAMPLE
IF CH0
IF CH1
298
8077H–AVR–12/09
XMEGA A
Figure 25-16. ADC timing for single conversion on two ADC channels, CH0 with gain
1 2 3 4 5 6 7 8 9 10
CLKADC
GAINSTAGE SAMPLE
GAINSTAGE AMPLIFY
ADC SAMPLE
IF CH0
IF CH1
Figure 25-17. ADC timing for single conversion on two ADC channels, CH1 with gain
1 2 3 4 5 6 7 8 9 10
CLK ADC
GAINSTAGE SAMPLE
GAINSTAGE AMPLIFY
ADC SAMPLE
IF CH0
IF CH1
299
8077H–AVR–12/09
XMEGA A
CLKADC
GAINSTAGE SAMPLE 2 3 2 3
GAINSTAGE AMPLIFY 2 3 2 3
ADC SAMPLE 0 1 2 3 0 1 2 3 0
CONV COMPLETE 0 1
Positive
input
Rchannel Rswitch
CSample
VCC/2
Figure 25-20. ADC input for differential measurements and differential measurements with gain
Positive
input
Rchannel Rswitch
CSample
VCC/2
CSample
Negative
input
Rchannel Rswitch
In order to achieve n bit accuracy, the source output resistance, Rsource, must be less than the
ADC input resistance on a pin:
300
8077H–AVR–12/09
XMEGA A
Ts
R source ≤ ----------------------------------------------
- – R channel – R switch
n+1
C sample ⋅ ln ( 2 )
where the ADC sample time, TS is one half ADC clock cycle given by:
1
T s ≤ -------------------
2 ⋅ f ADC
For details on Rchannel, Rswitch and Csample refer to the ADC and ADC gain stage electrical charac-
teristic in the device data sheet.
25.13 Calibration
The ADC has a built-in calibration mechanism that calibrated the internal pipeline in the ADC.
The calibration value from the production test must be loaded from the signature row and into
the ADC calibration register from software to obtain 12 bit accuracy.
301
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
302
8077H–AVR–12/09
XMEGA A
• Bit 0 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
Initial Value 0 0 0 0 0 0 0 0
303
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
304
8077H–AVR–12/09
XMEGA A
305
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
306
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
8-bit - - - - - - - -
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
307
8077H–AVR–12/09
XMEGA A
12-/8- CHRES[7:0]
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
308
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
309
8077H–AVR–12/09
XMEGA A
See Table 25-6 on page 305 for different gain factor settings. Gain is only valid with certain MUX
settings, see ”MUXCTRL - ADC Channel MUX Control registers” on page 310.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
310
8077H–AVR–12/09
XMEGA A
• Bit 7 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
For devices with more then 8 inputs into an ADC multiplexer, the MUXPOS3 bit is used to select
ADC channels 8 (ADC8) and above.
• Bits 2 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
311
8077H–AVR–12/09
XMEGA A
Table 25-13. ADC MUXNEG Configuration, INPUTMODE[1:0] = 10, Differential without gain
MUXNEG[1:0] Group Configuration Analog input
00 PIN0 ADC0 pin
01 PIN1 ADC1 pin
10 PIN2 ADC2 pin
11 PIN3 ADC3 pin
Table 25-14. ADC MUXNEG Configuration, INPUTMODE[1:0] = 11, Differential with gain
MUXNEG[1:0] Group Configuration Analog input
00 PIN4 ADC4 pin
01 PIN5 ADC5 pin
10 PIN6 ADC6 pin
11 PIN7 ADC7 pin
• Bit 0 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
Bit 7 6 5 4 3 2 1 0
Initial Value 0 0 0 0 0 0 0 0
312
8077H–AVR–12/09
XMEGA A
+0x03 - - - - - - - IF INTFLAGS
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
8-bit - - - - - - - -
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
313
8077H–AVR–12/09
XMEGA A
12-/8- RES[7:0]
+0x04
12-bit, left. RES[3:0] - - - -
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
314
8077H–AVR–12/09
XMEGA A
315
8077H–AVR–12/09
XMEGA A
316
8077H–AVR–12/09
XMEGA A
26.1 Features
• 12-bit resolution
• Up to 1 Msps conversion rate
• Flexible conversion range
• Multiple trigger sources
• 1 continuous time or 2 Sample/Hold (S/H) outputs
• Built-in offset and gain calibration
• High drive capabilities
• Internal/External reference
• Possibility to use as input to analog comparator or ADC
• Power reduction mode
26.2 Overview
The DAC converts digital values to analog voltages. The DAC has 12-bit resolution and is capa-
ble of converting 1 million samples per second. The output from the DAC can either be
continuous to one pin, or fed to two different pins using a sample and hold (S/H) circuitry. A sep-
arate low power mode is available, and the DAC can be gain and offset calibrated.
The output signal swing is defined by the reference voltage (VREF). The following sources are
available as VREF in the DAC:
• AVCC
• Internal 1.00V
• External reference applied to the AREF pin on PORTA or PORTB
CHnDATA
V DACx = ---------------------------- ⋅ VREF
0xFFF
Figure 26-1 on page 318 illustrates the basic functionality related to the DAC. Not all functional-
ity is shown.
317
8077H–AVR–12/09
XMEGA A
AVCC
Int. 1.00 V
AREFA
AREFB
12
CH0DATA DAC CH0
12 Output
DAC
12 Control and Driver
CH1DATA DAC CH1
TRIG ENABLE
ADC
AC
DAC
CTRL
318
8077H–AVR–12/09
XMEGA A
R feedback
26.9 Calibration
To achieve optimal accuracy, it is possible to calibrate both gain and offset error in the DAC.
There is a 7-bit calibration value for gain adjustment and a 7-bit calibration value for offset
adjustment.
To get the best calibration result it is recommended to use the same VREF, output channel
selection, sampling time, and refresh interval when calibrating as will be used in normal DAC
operation. The theoretical transfer function for the DAC was shown in ”Overview” on page 317.
Including errors, the DAC output value can be expressed as:
CHnDATA- + offset
V DACxX = gain ⋅ ---------------------------
0xFFF
In an ideal DAC, gain is 1 and offset is 0.
319
8077H–AVR–12/09
XMEGA A
The calibration of the DAC adjust the offset and gain. To calibrate offset you can output mid
code and adjust the offset calibration until you get ~0 LSB offset The gain is adjusted around mid
code so it should not affect the offset calibration if you read the output at mid code and max (or
min code) and adjust the calibration values until you get ~0 LSB gain.
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
• Bit 7 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
320
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
321
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 1 1 0 0 0 0 1
• Bit 7 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
322
8077H–AVR–12/09
XMEGA A
Table 26-4 shows the available control settings as a number of peripheral clock cycles. To allow
for longer conversion intervals during dual channel operation, a 50% increase in the number
peripheral clock cycles is automatically added.
The number of clock cycles selected multiplied with the period of the Peripheral clock gives the
minimum DAC conversion internal.
323
8077H–AVR–12/09
XMEGA A
The number of clock cycles selected multiplied with the period of the Peripheral clock gives the
DAC refresh time.
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Right-adjust - - - - CHDATA[11:8]
+0x19
Left-adjust CHDATA[11:4]
Left-adjust Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
324
8077H–AVR–12/09
XMEGA A
26.10.7.1 Right-adjusted
26.10.7.2 Left-adjusted
Right-adjust CHDATA[7:0]
+0x18
Left-adjust CHDATA[3:0] - - - -
Right-adjust Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
26.10.8.1 Right-adjusted
26.10.8.2 Left-adjusted
Right-adjust - - - - CHDATA[11:8]
+0x1B
Left-adjust CHDATA[11:4]
Left-adjust Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
325
8077H–AVR–12/09
XMEGA A
26.10.9.1 Right-adjusted
26.10.9.2 Left-adjusted
Right-adjust CHDATA[7:0]
+0x1A
Left-adjust CHDATA[3:0] - - - -
Right-adjust Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
26.10.10.1 Right-adjusted
26.10.10.2 Left-adjusted
Initial Value 0 0 0 0 0 0 0 0
• Bit 7 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
326
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
• Bit 7 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRLA - - - - CH1EN CH0EN LPMODE ENABLE 320
+0x01 CTRLB - CHSEL[1:0] - - - CH1TRIG CH0TRIG 320
+0x02 CTRLC - - - REFSEL[1:0] - - LEFTADJ 321
+0x03 EVCTRL - - - - - EVSEL[2:0] 322
+0x04 TIMCTRL - CONINTVAL[2:0] REFRESH[3:0] 322
+0x05 STATUS - - - - - - CH1DRE CH0DRE 324
+0x06 Reserved - - - - - - - -
+0x07 Reserved - - - - - - - -
+0x08 GAINCAL - GAINCAL[6:0] 326
+0x09 OFFSETCAL - OFFSETCAL[6:0] 327
+0x10 Reserved - - - - - - - -
+0x11 Reserved - - - - - - - -
+0x12 Reserved - - - - - - - -
+0x13 Reserved - - - - - - - -
+0x14 Reserved - - - - - - - -
+0x15 Reserved - - - - - - - -
+0x16 Reserved - - - - - - - -
+0x17 Reserved - - - - - - - -
+0x18 CH0DATAL CHDATA[7:0] 325
+0x19 CH0DATAH - - - - CHDATA[11:8] 324
+0x1A CH1DATAL CHDATA[7:0] 326
+0x1B CH1DATAH - - - - CHDATA[11:8] 325
327
8077H–AVR–12/09
XMEGA A
27.1 Features
• Flexible input selection
• High speed option
• Low power option
• Selectable input hysteresis
• Analog comparator output available on pin
• Window mode
27.2 Overview
The Analog Comparator (AC) compares the voltage level on two inputs and gives a digital output
based on this comparison. The Analog Comparator may be configured to give interrupt requests
and/or events upon several different combinations of input change.
Two important properties of the Analog Comparator when it comes to the dynamic behavior, are
hysteresis and propagation delay. Both these parameters may be adjusted in order to find the
optimal operation for each application.
The Analog Comparators are always grouped in pairs (AC0 and AC1) on each analog port. They
have identical behavior but separate control registers.
328
8077H–AVR–12/09
XMEGA A
Pin inputs
Internal inputs
+
Pin 0 output
AC0
Pin inputs -
Internal inputs
VCC scaled
Interrupts
Interrupt
sensitivity
Events
Pin inputs control
Internal inputs
+
AC1
Pin inputs
-
Internal inputs
VCC scaled
329
8077H–AVR–12/09
XMEGA A
330
8077H–AVR–12/09
XMEGA A
+
AC0
U p p e r lim it o f w in d o w -
In te rru p ts
In te rru p t
In p u t s ig n a l s e n s itiv ity
E v e n ts
c o n tro l
+
AC1
L o w e r lim it o f w in d o w
-
Initial Value 0 0 0 0 0 0 0 0
331
8077H–AVR–12/09
XMEGA A
Initial Value 0 0 0 0 0 0 0 0
332
8077H–AVR–12/09
XMEGA A
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
333
8077H–AVR–12/09
XMEGA A
V CC ⋅ ( SCALEFAC + 1 )
V SCALE = ------------------------------------------------------------
-
64
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
334
8077H–AVR–12/09
XMEGA A
• Bit 3 - Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write
this bit to zero when this register is written.
335
8077H–AVR–12/09
XMEGA A
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 AC0CTRL INTMODE[1:0] INTLVL[1:0] HSMODE HYSMODE[1:0] ENABLE 331
+0x01 AC1CTRL INTMODE[1:0] INTLVL[1:0] HSMODE HYSMODE[1:0] ENABLE 331
+0x02 AC0MUXCTRL - - MUXPOS[2:0] MUXNEG[2:0] 332
+0x03 AC1MUXCTRL - - MUXPOS[2:0] MUXNEG[2:0] 332
+0x04 CTRLA - - - - - - - ACOOUT 333
+0x05 CTRLB - - SCALEFAC5:0] 333
+0x06 WINCTRL - - - WEN WINTMODE[1:0] WINTLVL[1:0] 334
+0x07 STATUS WSTATE[1:0] AC1STATE AC0STATE - WIF AC1IF AC0IF 334
336
8077H–AVR–12/09
XMEGA A
28.1 Features
• JTAG (IEEE std. 1149.1-2001 compliant) interface.
• Boundary-scan capabilities according to the JTAG standard.
• Full scan of all I/O pins.
• Supports the mandatory SAMPLE, PRELOAD, EXTEST, and BYPASS instructions.
• Supports the optional IDCODE, HIGHZ, and CLAMP instructions.
• Supports the AVR specific PDICOM instruction for accessing the PDI for debugging and
programming in its optional JTAG mode.
28.2 Overview
The JTAG Boundary-scan interface is mainly intended for testing PCBs by using the JTAG
Boundary-scan capability. Secondary, the JTAG interface is reused to access the Program and
Debug Interface (PDI) in its optional JTAG mode.
The Boundary-scan chain has the capability of driving and observing the logic levels on I/O pins.
At system level, all ICs having JTAG capabilities are connected serially by the TDI/TDO signals
to form a long shift register. An external controller sets up the devices to drive values at their out-
put pins, and observe the input values received from other devices. The controller compares the
received data with the expected result. In this way, Boundary-scan provides a mechanism for
testing interconnections and integrity of components on Printed Circuit Boards by using the four
TAP signals only.
The IEEE 1149.1-2001 defined mandatory JTAG instructions IDCODE, BYPASS, SAMPLE/
PRELOAD, and EXTEST together with the optional CLAMP, and HIGHZ instructions can be
used for testing the Printed Circuit Board. Initial scanning of the Data Register path will show the
ID-Code of the device, since IDCODE is the default JTAG instruction. If needed, the BYPASS
instruction can be issued to make the shortest possible scan chain through the device. The
EXTEST instruction is used for sampling external pins and loading output pins with data. The
data from the output latch will be driven out on the pins as soon as the EXTEST instruction is
loaded into the JTAG IR-Register. Therefore to avoid damaging the board when issuing the
EXTEST instruction for the first time, the merged SAMPLE/PRELOAD should be used for setting
initial values to the scan ring. SAMPLE/PRELOAD is also used for taking a non-intrusive snap-
shot of the external pins during normal operation of the part. The CLAMP instruction allows
static pin values to be applied via the Boundary-scan registers while bypassing these registers in
the scan path, efficiently shortening the total length of the serial test path. Alternatively the
HIGHZ instruction can be used to place all I/O pins in an inactive drive state, while bypassing the
Boundary-scan register chain of the chip.
The AVR specific PDICOM instruction makes it possible to use the PDI data register as an inter-
face for accessing the PDI for programming and debugging. Note that the PDICOM instruction
has nothing to do with Boundary-scan testing, but represents an alternative way to access inter-
nal programming and debugging resources by using the JTAG interface. For more details on
PDI, programming and on-chip debug refer to Section 29. ”Program and Debug Interface” on
page 344.
The JTAGEN Fuse must be programmed and the JTAGD bit in the MCUCR Register must be
cleared to enable the JTAG Interface and Test Access Port.
337
8077H–AVR–12/09
XMEGA A
When using the JTAG interface for Boundary-scan, the JTAG TCK clock frequency can be
higher than the internal device frequency. The System Clock in the device is not required for
Boundary-scan.
338
8077H–AVR–12/09
XMEGA A
The TAP controller is a 16-state finite state machine that controls the operation of the Boundary-
scan circuitry. The state transitions depicted in Figure 28-1 depend on the signal present on
TMS (shown adjacent to each state transition) at a time of the rising edge at TCK. The initial
state after a Power-on Reset is Test-Logic-Reset.
Assuming Run-Test/Idle is the present state, a typical scenario for using the JTAG interface is:
• At the TMS input, apply the sequence 1, 1, 0, 0 at the rising edges of TCK to enter the Shift
Instruction Register - Shift-IR state. While in this state, shift the four bits of the JTAG
instructions into the JTAG Instruction Register from the TDI input at the rising edge of TCK.
The TMS input must be held low during input of the 3 LSBs in order to remain in the Shift-IR
state. The MSB of the instruction is shifted in when this state is left by setting TMS high.
While the instruction is shifted in from the TDI pin, the captured IR-state 0x01 is shifted out
on the TDO pin. The JTAG Instruction selects a particular Data Register as path between TDI
and TDO and controls the circuitry surrounding the selected Data Register.
• Apply the TMS sequence 1, 1, 0 to re-enter the Run-Test/Idle state. The instruction is latched
onto the parallel output from the Shift Register path in the Update-IR state. The Exit-IR,
Pause-IR, and Exit2-IR states are only used for navigating the state machine.
• ·At the TMS input, apply the sequence 1, 0, 0 at the rising edges of TCK to enter the Shift
Data Register - Shift-DR state. While in this state, upload the selected Data Register
(selected by the present JTAG instruction in the JTAG Instruction Register) from the TDI input
at the rising edge of TCK. In order to remain in the Shift-DR state, the TMS input must be
held low during input of all bits except the MSB. The MSB of the data is shifted in when this
state is left by setting TMS high. While the Data Register is shifted in from the TDI pin, the
parallel inputs to the Data Register captured in the Capture-DR state is shifted out on the
TDO pin.
• Apply the TMS sequence 1, 1, 0 to re-enter the Run-Test/Idle state. If the selected Data
Register has a latched parallel-output, the latching takes place in the Update-DR state. The
Exit-DR, Pause-DR, and Exit2-DR states are only used for navigating the state machine.
As shown in the state diagram, the Run-Test/Idle state need not be entered between selecting
JTAG instruction and using Data Registers.
Note: Independent of the initial state of the TAP Controller, the Test-Logic-Reset state can
always be entered by holding TMS high for five TCK clock periods.
339
8077H–AVR–12/09
XMEGA A
340
8077H–AVR–12/09
XMEGA A
to a ll T C K
TCK
re g is te rs
PDI JTA G
D
D TAP
TM S
CTRL
JTAG Boundary-scan chain
D TDO
I/O P O R T S In te rn a l re g is te rs
D
A
D
B B B TDI
D
C C C C
D
D D D
341
8077H–AVR–12/09
XMEGA A
MSB LSB
Bit 31 28 27 12 11 1 0
28.5.2.1 Version
Version is a 4-bit number identifying the revision of the component. The JTAG version number
follows the revision of the device. Revision A is 0x0, revision B is 0x1 and so on.
28.5.2.3 Manufacturer ID
The Manufacturer ID is an 11-bit code identifying the manufacturer. For Atmel this code is
11x01F.
342
8077H–AVR–12/09
XMEGA A
Output Control
(DIR)
0
0
D Q D Q
1
0
D Q D Q
1
To next cell
0
D Q
1
Clock DR
From last
Shift DR
cell
343
8077H–AVR–12/09
XMEGA A
29.1 Features
• Program and Debug Interface (PDI)
– 2-pin interface for external programming and on-chip debugging
– Uses Reset pin and dedicated Test pin
• No I/O pins required during programming or debugging
• Programming Features
– Flexible communication protocol
– 8 Flexible instructions.
– Minimal protocol overhead.
– Fast
• 10 MHz programming clock at 1.8V VCC
– Reliable
• Built in error detection and handling
• Debugging Features
– Non-Intrusive Operation
• Uses no hardware or software resource
– Complete Program Flow Control
• Symbolic Debugging Support in Hardware
• Go, Stop, Reset, Step into, Step over, Step out, Run-to-Cursor
– 1 dedicated program address breakpoint or symbolic breakpoint for AVR studio/emulator
– 4 Hardware Breakpoints
– Unlimited Number of User Program Breakpoints
– Uses CPU for Accessing I/O, Data, and Program
– High Speed Operation
• No limitation on system clock frequency
• JTAG Interface
– JTAG (IEEE std. 1149.1 Compliant) Interface
– Boundary-scan Capabilities According to the IEEE std. 1149.1 (JTAG) Standard
– Programming features as for PDI
– On-chip debug features as for PDI
29.2 Overview
The Program and Debug Interface (PDI) is an Atmel proprietary interface for external program-
ming and on-chip debugging of the device.
The PDI supports high-speed programming of all Non-Volatile Memory (NVM) spaces; Flash,
EEPOM, Fuses, Lockbits and the User Signature Row. This is done by accessing the NVM Con-
troller, and executing NVM Controller commands as described in Memory Programming.
The On-Chip Debug (OCD) system supports fully intrusive operation. During debugging no soft-
ware or hardware resources in the device is used (except for four I/O pins required if JTAG
connection is used). The OCD system has full program flow control, supports unlimited number
of program and data breakpoints and has full access (read/write) to all memories.
Both programming and debugging can be done through two physical interfaces. The primary
interface is the PDI Physical. This is a 2-pin interface using the Reset pin for the clock input
344
8077H–AVR–12/09
XMEGA A
(PDI_CLK), and the dedicated Test pin for data input and output (PDI_DATA). A JTAG interface
is also available on most devices, and this can be used for programming and debugging through
the 4-pin JTAG interface. The JTAG interface is IEEE std. 1149.1 compliant, and supports
boundary scan. Unless otherwise stated, all references to the PDI assumes access through the
PDI physical. Any external programmer or on-chip debugger/emulator can be directly connected
to these interfaces, and no external components are required.
Figure 29-1. The PDI with JTAG and PDI physical and closely related modules (grey)
PDIBUS Internal Interfaces
Program and Debug Interface (PDI)
TDI OCD
TMI JTAG Physical
TCK (physical layer)
TDO
PDI NVM
Controller Memories
PDI_CLK (RESET)
PDI_DATA (TEST)
Vcc
Programmer/
Debugger
Gnd
345
8077H–AVR–12/09
XMEGA A
The remainder of this section is only intended for third parties developing programming support
for XMEGA.
29.3.1 Enabling
The PDI Physical must be enabled before it can be used. This is done by first forcing the
PDI_DATA line high for a period longer than the equivalent external reset minimum pulse width
(refer to device data sheet for external reset pulse width data). This will disable the RESET func-
tionality of the Reset pin, if not already disabled by the fuse settings.
In the next step of the enabling procedure the PDI_DATA line must be kept high for 16 PDI_CLK
cycles (16 positive edges detected). The first PDI_CLK cycle must start no later than 100uS
after the RESET functionality of the Reset pin was disabled. If this does not occur in time the
RESET functionality of the Reset pin is automatically enabled again and the enabling procedure
must start over again.
After this the PDI is enabled and ready to receive instructions. The enable sequence is shown in
Figure 29-3 on page 346.
The RESET pin is sampled when the PDI interface is enabled. The RESET register is then set
according to the state of the RESET pin, preventing the device from running code after the reset-
functionality of this pin is disabled.
The PDI_DATA pin has an internal pull-down resistor.
PDI_DATA
PDI_CLK
29.3.2 Disabling
If the clock frequency on the PDI_CLK is lower than approximately 10 kHz, this is regarding as
inactivity on the clock line. This will then automatically disable the PDI. If not disabled by fuse,
the RESET function on the Reset (PDI_CLK) pin is automatically enabled again. If the time-out
occurs during the PDI enabling sequence, the whole sequence must be started from the
beginning.
This also means that the minimum programming frequency is approximately 10 kHz.
FRAME
346
8077H–AVR–12/09
XMEGA A
Table 29-1.
St Start bit, always low.
(0-7) Data bits (0 to 7)
P Parity bit, even parity is used
Sp1 Stop bit 1, always high.
Sp2 Stop bit 2, always high.
29.3.3.1 Characters
Three different characters, DATA, BREAK and IDLE, are used. The BREAK character is equal
to 12 bit-length of low level. The IDLE character is equal to 12 bit-length of high level. Both the
BREAK and the IDLE character can be extended beyond the bit-length of 12.
START 0 1 2 3 4 5 6 7 P STOP
1 BREAK character
BREAK
1 IDLE character
IDLE
PDI_CLK
PD I_DATA
347
8077H–AVR–12/09
XMEGA A
PDI_CLK
Output enable
Driven output
PDI_DATA
1 0 1 1 0 0 1
If the programmer and the PDI both drives the PDI_DATA line at the same time, the situation of
drive contention will occur as illustrated in Figure 29-8 on page 349. Every time a bit value is
kept for two or more clock cycles, the PDI is able to verify that the correct bit value is driven on
the PDI_DATA line. If the programmer is driving the PDI_DATA line to the opposite bit value
than what the PDI expects, a collision is detected.
348
8077H–AVR–12/09
XMEGA A
Figure 29-8. Drive contention and collision detection on the PDI_DATA line
PDI_CLK
PDI output
Programmer
output
PDI_DATA
1 0 X 1 X 1 1
Collision
detect
= Collision
As long as the PDI transmits alternating ones and zeros, collisions cannot be detected because
the output driver will be active all the time preventing polling of the PDI_DATA line. However,
within a single frame the two stop bits should always be transmitted as ones, enabling collision
detection at least once per frame.
349
8077H–AVR–12/09
XMEGA A
St d2W DATA Receive (RX) P Sp1 Sp2 IDLE bits St d2W DATA Transmit (TX) V Sp1 Sp2
The programmer will loose control of the PDI_DATA line at the point where the PDI target
changes from RX- to TX-mode. The Guard Time relaxes this critical phase of the communica-
tion. When the programmer changes from RX-mode to TX-mode, minimum a single IDLE bit
should be inserted before the start bit is transmitted.
29.4.1 Enabling
The JTAGEN Fuse must be programmed and the JTAG Disable bit in the MCU Control Register
must be cleared to enable the JTAG Interface. By default the JTAGEN fuse is programmed, and
the JTAG interface is enabled. When the JTAG instruction PDICOM is shifted into the JTAG
instruction register, the PDI communication register is chosen as the data register connected
between TDI and TDO. In this mode, the JTAG interface can be used to access the PDI for
external programming and on-chip debug.
29.4.2 Disabling
The JTAG interface can be disabled by either unprogramming the JTAGEN fuse or by setting
the JTAG Disable bit in the MCU Control Register from the application code
350
8077H–AVR–12/09
XMEGA A
FRAME
0 1 2 3 4 5 6 7 P
Table 29-2.
(0-7) Data/command bits, least significant bit sent first (0 to 7)
P Parity bit, even parity is used
1 1 0 1 1 1 0 1 P1
1 1 0 1 1 0 1 1 P1
1 1 0 1 0 1 1 1 P1
351
8077H–AVR–12/09
XMEGA A
TC K
TD I/TDO
352
8077H–AVR–12/09
XMEGA A
353
8077H–AVR–12/09
XMEGA A
29.5.6.1 LDS - Load data from PDIBUS Data Space using direct addressing
The LDS instruction is used to load data from the PDIBUS Data Space for serial read-out. The
LDS instruction is based on direct addressing, which means that the address must be given as
an argument to the instruction. Even though the protocol is based on byte-wise communication,
the LDS instruction supports multiple-bytes address - and data access. Four different
354
8077H–AVR–12/09
XMEGA A
address/data sizes are supported; byte, word, 3 bytes, and long (4 bytes). It should be noted that
multiple-bytes access is internally broken down to repeated single-byte accesses. The main
advantage with the multiple-bytes access is that it gives a way to reduce the protocol overhead.
When using the LDS, the address byte(s) must be transmitted before the data transfer.
29.5.6.2 STS - Store data to PDIBUS Data Space using direct addressing
The ST instruction is used to store data that is serially shifted into the physical layer shift-register
to locations within the PDIBUS Data Space. The STS instruction is based on direct addressing,
which means that the address must be given as an argument to the instruction. Even though the
protocol is based on byte-wise communication, the ST instruction supports multiple-bytes
address - and data access. Four different address/data sizes are supported; byte, word, 3 bytes,
and long (4 bytes). It should be noted that multiple-bytes access is internally broken down to
repeated single-byte accesses. The main advantage with the multiple-bytes access is that it
gives a way to reduce the protocol overhead. When using the STS, the address byte(s) must be
transmitted before the data transfer.
29.5.6.3 LD - Load data from PDIBUS Data Space using indirect addressing
The LD instruction is used to load data from the PDIBUS Data Space to the physical layer shift-
register for serial read-out. The LD instruction is based on indirect addressing (pointer access),
which means that the address must be stored into the Pointer register prior to the data access.
Indirect addressing can be combined with pointer increment. In addition to read data from the
PDIBUS Data Space, the Pointer register can be read by the LD instruction. Even though the
protocol is based on byte-wise communication, the LD instruction supports multiple-bytes
address - and data access. Four different address/data sizes are supported; byte, word, 3 bytes,
and long (4 bytes). It should be noted that multiple-bytes access is internally broken down to
repeated single-byte accesses. The main advantage with the multiple-bytes access is that it
gives a way to reduce the protocol overhead.
29.5.6.5 LDCS - Load data from PDI Control and Status Register Space
The LDCS instruction is used to load data from the PDI Control and Status Registers to the
physical layer shift-register for serial read-out. The LDCS instruction supports only direct
addressing and single-byte access.
29.5.6.6 STCS - Store data to PDI Control and Status Register Space
The STCS instruction is used to store data that is serially shifted into the physical layer shift-reg-
ister to locations within the PDI Control and Status Registers. The STCS instruction supports
only direct addressing and single-byte access.
355
8077H–AVR–12/09
XMEGA A
356
8077H–AVR–12/09
XMEGA A
LD 0 0 1 0
Size A - Address size (direct access)
0 0 Byte
0 1 Word (2 Bytes)
ST 0 1 1 0
1 0 3 Bytes
1 1 Long (4 Bytes)
CS Address
Ptr - Pointer access (indirect access)
0 0 *(ptr)
LDCS 1 0 0 0
0 1 *(ptr++)
1 0 ptr
STCS
1 1 ptr++ - Reserved
1 1 0 0
357
8077H–AVR–12/09
XMEGA A
itself. Indirect data access can be optionally combined with pointer register post-increment. The
indirect access mode has an option that makes it possible to load or read the pointer register
without accessing any other registers. Any register update is performed in a little-endian fashion.
Hence, loading a single byte of the address register will always update the LSB byte while the
MSB bytes are left unchanged.
The Pointer Register is not involved in addressing registers in the PDI Control and Status Regis-
ter Space (CSRS space).
358
8077H–AVR–12/09
XMEGA A
Bit 7 6 5 4 3 2 1 0
+0x00 - - - - - - NVMEN - STATUS
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 RESET[7:0] CTRLB
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
359
8077H–AVR–12/09
XMEGA A
360
8077H–AVR–12/09
XMEGA A
Address Name Address Name Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 STATUS - - - - - - NVMEN - 359
+0x01 RESET RESET[7:] 359
+0x02 CTRL - - - - - GUARDTIME[2:0] 359
+0x03 Reserved
+0x04 Reserved
+0x05 Reserved
+0x06 Reserved
+0x07 Reserved
+0x08 Reserved
+0x09 Reserved
+0x0A Reserved
+0x0B Reserved
+0x0C Reserved
+0x0D Reserved
+0x0E Reserved
+0x0F Reserved
+0x10 Reserved
361
8077H–AVR–12/09
XMEGA A
30.1 Features
• Read and Write access to all memory spaces from
– External programmers
– Application Software
• Self-Programming and Boot Loader Support
– Real Read-While-Write Self-Programming
– The CPU can run and execute code while Flash is being programmed
– Any communication interface can be used for program upload/download
• External Programming
– Support for in-system and production programming
– Programming through serial PDI or JTAG interface
– Fast and reliable interfaces.
• High Security with Separate Boot Lock Bits for
– External programming access
– Boot Loader Section access
– Application Section access
– Application Table access
• Reset Fuse to Select Reset Vector address to the start of the
– Application Section, or
– Boot Loader Section
• Code Efficient Algorithm
• Efficient Read-Modify-Write Support
30.2 Overview
This section describes how to program the Non Volatile Memory (NVM) in XMEGA, and covers
both self-programming and external programming. The NVM consist of the Flash Program Mem-
ory, User Signature and Calibration rows, Fuses and Lock Bits, and EEPROM data memory. For
details on the actual memories, how they are organized and the register description for the NVM
Controller used to access the memories, refer to ”Memories” on page 18.
The NVM can be accessed for read and write both from application software through self-pro-
gramming and from an external programmer. For both external programming and self-
programming access to the NVM is done through the common NVM Controller, and the two
methods of programming are very similar. Memory access is done by loading address and/or
data into the NVM, and a set of commands and triggers that make the NVM Controller perform
specific tasks on the NVM.
From external programming all memory spaces can be read and written, expect for the Calibra-
tion Row which can only be read. The device can be programmed in-system and is accessed
through the PDI using the PDI or JTAG physical interfaces, ”External Programming” on page
379 describes PDI and JTAG in detail.
Self-programming and Boot Loader support allows application software in the device to read and
write the Flash, User Signature Row and EEPROM, write the Lock Bits to a more secure setting,
and read the Calibration Row and Fuses. The Flash allows Read-While-Write self-programming
meaning that the CPU can continue to operate and execute code while the Flash is being pro-
grammed. ”Self-Programming and Boot Loader Support” on page 367 describes this in detail.
362
8077H–AVR–12/09
XMEGA A
For both self-programming and external programming it is possible to run an automatic CRC
check on the Flash or a section of the Flash to verify its content.
The device can be locked to prevent read and/or write of the NVM. There are separate lock bits
for external programming access, and self-programming access to the Boot Loader Section,
Application Section and Application Table Section.
363
8077H–AVR–12/09
XMEGA A
364
8077H–AVR–12/09
XMEGA A
365
8077H–AVR–12/09
XMEGA A
366
8077H–AVR–12/09
XMEGA A
367
8077H–AVR–12/09
XMEGA A
Application Section -
Read-While-Write
(RWW)
Z-pointer Z-pointer
Adresses RWW Adresses NRWW
Section Section
Boot Loader Section -
No Read-While-Write
Code Located in (NRWW) CPU is Halted
NRWW Section Can During the Operation
be Read During the
Operation
368
8077H–AVR–12/09
XMEGA A
PAGEEND
FLASHEND
369
8077H–AVR–12/09
XMEGA A
0x00 NO_OPERATION No Operation / Read Flash -/(E)LPM -/N N -/N -/ Z-pointer -/Rd
Flash
Application Section
0x25 ERASE_WRITE_APP_PAGE Erase & Write Application Section Page SPM N Y Y Z-pointer -
0x2D ERASE_WRITE_BOOT_PAGE Erase & Write Boot Loader Section Page SPM Y Y Y Z-pointer -
Calibration Row
Notes: 1. The Flash Range CRC command used byte addressing of the Flash.
2. Will depend on the flash section (Application or Boot Loader) that is actually addressed.
3. This command is qualified with the Lock BIts, and requires that the Boot Lock Bits are unprogrammed.
370
8077H–AVR–12/09
XMEGA A
371
8077H–AVR–12/09
XMEGA A
3. Load the end byte address in NVM Data Register (NVM DATA).
4. Set the CMDEX bit in the NVM CTRLA register. This requires the timed CCP sequence
during self-programming.
The BUSY flag in the NVM STATUS register will be set, and the CPU is halted during the execu-
tion of the command.
The CRC checksum will be available in the NVM DATA register.
In order to use the Flash Range CRC all the Boot Lock Bits must be unprogrammed (no locks).
The command execution will be aborted if the Boot Lock Bits for an accessed location are set.
372
8077H–AVR–12/09
XMEGA A
30.11.2.10 Erase & Write Application Section / Boot Loader Section Page
The Erase & Write Application Section Page and Erase & Write Boot Loader Section Page com-
mands are used to erase one flash page and then write the Flash Page Buffer into that flash
page in the Application Section or Boot Loader Section, in one atomic operation.
1. Load the Z-pointer with the flash page to write. The page address must be written to
PCPAGE. Other bits in the Z-pointer will be ignored during this operation.
2. Load the NVM CMD register with the Erase & Write Application Section/Boot Loader
Section Page command.
3. Execute the SPM instruction. This requires the timed CCP sequence during self-
programming.
The BUSY flag in the NVM STATUS register will be set until the operation is finished. The
FBUSY flag is set as long the Flash is Busy, and the Application section cannot be accessed.
An invalid page address in the Z-pointer will abort the NVM command. The Erase & Write Appli-
cation Section command requires that the Z-pointer addresses the Application section, and the
Erase & Write Boot Section Page command requires that the Z-pointer addresses the Boot
Loader Section.
373
8077H–AVR–12/09
XMEGA A
374
8077H–AVR–12/09
XMEGA A
1. Load the NVM ADDR registers with the address to the fuse byte to read.
2. Load the NVM CMD register with the Read Fuses command.
3. Set the CMDEX bit in the NVM CTRLA register. This requires the timed CCP sequence
during self-programming.
The result will be available in the NVM DATA0 register. The CPU is halted during the complete
execution of the command.
375
8077H–AVR–12/09
XMEGA A
01 01
02 02
E2END E2PAGEEND
When EEPROM memory mapping is enabled, loading a data byte into the EEPROM page buffer
can be performed through direct or indirect store instructions. Only the least significant bits of
the EEPROM address are used to determine locations within the page buffer, but the complete
memory mapped EEPROM address is always required to ensure correct address mapping.
Reading from the EEPROM can be done directly using direct or indirect load instructions. When
a memory mapped EEPROM page buffer load operation is performed, the CPU is halted for 3
cycles before the next instruction is executed.
When the EEPROM is memory mapped, the EEPROM page buffer load and EEPROM read
functionality from the NVM controller is disabled.
376
8077H–AVR–12/09
XMEGA A
Section 30.11.5.1 on page 377 through Section 30.11.5.7 on page 378 explains in details the
algorithm for each EEPROM operation.
EEPROM Y
377
8077H–AVR–12/09
XMEGA A
378
8077H–AVR–12/09
XMEGA A
379
8077H–AVR–12/09
XMEGA A
Figure 30-4. Memory map for PDI accessing the data and program memories.
TOP=0x1FFFFFF
DATAMEM
16 MB
(mapped IO/SRAM)
FLASH_BASE = 0x0800000
EPPROM_BASE = 0x08C0000
FUSE_BASE = 0x08F0020
DATAMEM_BASE = 0x1000000
APP_BASE = FLASH_BASE
BOOT_BASE = FLASH_BASE + SIZE_APPL
PROD_SIGNATURE_BASE = 0x008E0200
USER_SIGNATURE_BASE = 0x008E0400
0x1000000
FUSES
0x08F0020
SROW
0x08E0200
0x08C1000
EEPROM
0x08C0000
BOOT SECTION
APPLICATION
SECTION
0x0800000 16 MB
0x0000000
1 BYTE
380
8077H–AVR–12/09
XMEGA A
Change
CMD[6:0] Commands / Operation Trigger Protected NVM Busy
0x00 No Operation - - -
(1)
0x40 Chip Erase CMDEX Y Y
381
8077H–AVR–12/09
XMEGA A
Change
CMD[6:0] Commands / Operation Trigger Protected NVM Busy
Flash
Application Section
0x2D Erase & Write Boot Loader Section Page PDI Write N Y
EEPROM
Notes: 1. If the EESAVE fuse is programmed the EEPROM is preserved during chip erase.
382
8077H–AVR–12/09
XMEGA A
383
8077H–AVR–12/09
XMEGA A
1. Load the NVM CMD register with Erase Application Section/Boot Loader Section/User
Signature Row/EEPROM Page command.
2. Write the selected page by doing a PDI Write. The page is written by addressing any
byte location within the page.
The BUSY flag in the NVM STATUS register will be set until the operation is finished.
384
8077H–AVR–12/09
XMEGA A
385
8077H–AVR–12/09
XMEGA A
386
8077H–AVR–12/09
XMEGA A
387
8077H–AVR–12/09
XMEGA A
FMULSU Rd,Rr Fractional Multiply Signed with Unsigned R1:R0 ← Rd x Rr<<1 (SU) Z,C 2
Branch Instructions
388
8077H–AVR–12/09
XMEGA A
SBIS A, b Skip if Bit in I/O Register Set If (I/O(A,b) =1) PC ← PC + 2 or 3 None 2/3/4
LDS Rd, k Load Direct from data space Rd ← (k) None 2(1)(2)
389
8077H–AVR–12/09
XMEGA A
ELPM Rd, Z+ Extended Load Program Memory and Post- Rd ← (RAMPZ:Z), None 3
Increment Z ← Z+1
390
8077H–AVR–12/09
XMEGA A
Notes: 1. Cycle times for Data memory accesses assume internal memory accesses, and are not valid
for accesses via the external RAM interface.
2. One extra cycle must be added when accessing Internal SRAM.
391
8077H–AVR–12/09
XMEGA A
Write, no ALE
ClkPER2
CS
WE
RE
ALE1
D[7:0] D[7:0]
A[7:0]/A[15:8] A[7:0]
Write, ALE
ClkPER2
CS
WE
RE
ALE1
D[7:0] D[7:0]
392
8077H–AVR–12/09
XMEGA A
Read, no ALE
Clk PER2
CS
WE
RE
ALE1
D[7:0] D[7:0]
A[7:0]/A[15:8] A[7:0]
Read, ALE
Clk PER2
CS
WE
RE
ALE1
D[7:0] D[7:0]
393
8077H–AVR–12/09
XMEGA A
Write, no ALE
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0] D[7:0]
A[7:0]/A[15:8]/A[23:16] A[7:0]
Write, ALE1
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0] D[7:0]
394
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0] D[7:0]
Read, no ALE
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0] D[7:0]
A[7:0]/A[15:8]/A[23:16] A[7:0]
395
8077H–AVR–12/09
XMEGA A
Read, ALE1
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0] D[7:0]
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0] D[7:0]
396
8077H–AVR–12/09
XMEGA A
Write, no ALE
ClkPER2
CS
WE
RE
ALE2
D[7:0] D[7:0]
A[7:0]/A[23:16] A[7:0]
A[15:8] A[15:8]
Write, ALE
ClkPER2
CS
WE
RE
ALE2
D[7:0] D[7:0]
A[15:8] A[15:8]
397
8077H–AVR–12/09
XMEGA A
Read, no ALE
ClkPER2
CS
WE
RE
ALE2
D[7:0] D[7:0]
A[7:0]/A[23:16] A[7:0]
A[15:8] A[15:8]
Read, ALE
ClkPER2
CS
WE
RE
ALE2
D[7:0] D[7:0]
A[15:8] A[15:8]
398
8077H–AVR–12/09
XMEGA A
Write
ClkPER2
CS
WE
RE
D[7:0] D[7:0]
A[7:0] A[7:0]
A[15:8] A[15:8]
A[17:16] A[17:16]
Read
ClkPER2
CS
WE
RE
D[7:0] D[7:0]
A[7:0] A[7:0]
A[15:8] A[15:8]
A[17:16] A[17:16]
399
8077H–AVR–12/09
XMEGA A
Write, ALE1
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0]/A[7:0]/A[15:8] A[7:0] D[7:0]
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0]/A[7:0]/A[15:8] A[15:8] A[7:0] D[7:0]
400
8077H–AVR–12/09
XMEGA A
Read, ALE1
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0]/A[7:0]/A[15:8] A[7:0] D[7:0]
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0]/A[7:0]/A[15:8] A[15:8] A[7:0] D[7:0]
401
8077H–AVR–12/09
XMEGA A
Write
ClkPER2
CS
WE
RE
ALE1
D[7:0]/A[7:0] A[7:0] D[7:0]
A[15:8] A[15:8]
Read
ClkPER2
CS
WE
RE
ALE1
D[7:0]/A[7:0] A[7:0] D[7:0]
A[15:8] A[15:8]
402
8077H–AVR–12/09
XMEGA A
Write
ClkPER2
CS
WE
RE
ALE1
D[7:0]/A[7:0] A[7:0] D[7:0]
Read
ClkPER2
CS
WE
RE
ALE1
D[7:0]/A[7:0] A[7:0] D[7:0]
403
8077H–AVR–12/09
XMEGA A
Write, no ALE
ClkPER2
WE
RE
ALE1
D[7:0] D[7:0]
A[7:0]/A[15:8] A[7:0]
A[19:16] A[19:16]
Write, ALE
ClkPER2
WE
RE
ALE1
D[7:0] D[7:0]
A[19:16] A[19:16]
404
8077H–AVR–12/09
XMEGA A
Read, no ALE
ClkPER2
WE
RE
ALE1
D[7:0] D[7:0]
A[7:0]/A[15:8] A[7:0]
A[19:16] A[19:16]
Read, ALE
ClkPER2
WE
RE
ALE1
D[7:0] D[7:0]
A[19:16] A[19:16]
405
8077H–AVR–12/09
XMEGA A
Write
ClkPER2
WE
RE
D[7:0] D[7:0]
A[7:0] A[7:0]
A[15:8] A[15:8]
A[17:16] A[17:16]
A[21:18] A[21:18]
Read
ClkPER2
WE
RE
D[7:0] D[7:0]
A[7:0] A[7:0]
A[15:8] A[15:8]
A[17:16] A[17:16]
A[21:18] A[21:18]
406
8077H–AVR–12/09
XMEGA A
Write, ALE1
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0]/A[7:0]/A[15:8] A[7:0] D[7:0]
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0]/A[7:0]/A[15:8] A[15:8] A[7:0] D[7:0]
407
8077H–AVR–12/09
XMEGA A
Read, ALE1
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0]/A[7:0]/A[15:8] A[7:0] D[7:0]
ClkPER2
CS
WE
RE
ALE1
ALE2
D[7:0]/A[7:0]/A[15:8] A[15:8] A[7:0] D[7:0]
408
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0]
A[11:0] 0x400 Mode Register
D
Precharge All Banks
NOP*
Auto Refresh**
NOP**
409
8077H–AVR–12/09
XMEGA A
Single write
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0
D D[7:0]
Active
NOP*
NOP**
Write
410
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0 Bank Adr 0x0
A[11:0] Row Adr Col Adr 0x400 Row Adr Col Adr 0x400
D D[7:0] D[7:0]
Active
NOP*
Write
NOP**
Active
NOP*
Write
NOP**
411
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0
A[11:0] Row Adr Col Adr Col Adr Col Adr 0x400
NOP*
Write
Write
Write
NOP**
* The number of NOPs is equal to ROWCOLDLY[2:0] (ROWCOLDLY = 1 is shown) Precharge All Banks
412
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0 Bank Adr 0x0
A[11:0] Row Adr Col Adr 0x400 Row Adr Col Adr Col Adr 0x400
NOP*
Write
NOP***
Active
NOP*
Write
Write
NOP**
413
8077H–AVR–12/09
XMEGA A
Single read
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0
D D[7:0]
Active
NOP*
Read
NOP**
suspend***
Clock
NOP****
414
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0 Bank Adr 0x0
A[11:0] Row Adr Col Adr 0x400 Row Adr Col Adr 0x400
D D[7:0] D[7:0]
Active
NOP*
Read
NOP**
suspend***
Clock
NOP****
Active
NOP*
Read
NOP**
suspend***
Clock
NOP****
Data sampled
* The number of NOPs is equal to ROWCOLDLY[2:0] (ROWCOLDLY = 1 is shown)
** NOP is only inserted for CAS3
*** Clock suspended for 1 cycle when EBI is running at 1x and 1 or 2 cycles when EBI
is running at 2x, to enable sampling of data on the positive edge of the 1x clock.
**** The number of NOPs is equal to WRDLY[1:0] + 1 (WRDLY = 0 is shown)
***** The number of NOPs is equal to RPDLY[1:0] (RPDLY = 1 is shown)
415
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0
A[11:0] Row Adr Col Adr Col Adr Col Adr 0x400
NOP*
Read
NOP**
suspend***
Clock
Read
NOP**
suspend***
Clock
Read
NOP**
suspend***
Clock
NOP****
Data sampled
Data sampled
* The number of NOPs is equal to ROWCOLDLY[2:0] (ROWCOLDLY = 1 is shown)
** NOP is only inserted for CAS3
*** Clock suspended for 1 cycle when EBI is running at 1x and 1 or 2 cycles when EBI
is running at 2x, to enable sampling of data on the positive edge of the 1x clock.
**** The number of NOPs is equal to WRDLY[1:0] + 1 (WRDLY = 0 is shown)
***** The number of NOPs is equal to RPDLY[1:0] (RPDLY = 1 is shown)
416
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0 Bank Adr 0x0
A[11:0] Row Adr Col Adr Col Adr 0x400 Col Adr 0x400
NOP*
Read
NOP**
suspend***
Clock
Read
NOP**
suspend***
Clock
NOP*****
Active
NOP*
Read
NOP**
suspend***
Clock
NOP****
Data sampled
Data sampled
* The number of NOPs is equal to ROWCOLDLY[2:0] (ROWCOLDLY = 1 is shown)
** NOP is only inserted for CAS3
*** Clock suspended for 1 cycle when EBI is running at 1x and 1 or 2 cycles when EBI
is running at 2x, to enable sampling of data on the positive edge of the 1x clock.
**** The number of NOPs is equal to WRDLY[1:0] + 1 (WRDLY = 0 is shown)
***** The number of NOPs is equal to RPDLY[1:0] (RPDLY = 1 is shown)
417
8077H–AVR–12/09
XMEGA A
Single write
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0
D D[3:0] D[7:4]
Active
NOP*
Write
NOP**
418
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0 Bank Adr 0x0
A[11:0] Row Adr Col Adr 0x400 Row Adr Col Adr 0x400
NOP*
Write
NOP**
Active
NOP*
Write
NOP**
419
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0
A[11:0] Row Adr Col Adr Col Adr Col Adr 0x400
NOP*
Write
Write
Write
NOP**
420
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0 Bank Adr 0x0
A[11:0] Row Adr Col Adr 0x400 Row Adr Col Adr Col Adr 0x400
NOP*
Write
NOP***
Active
NOP*
Write
Write
NOP**
421
8077H–AVR–12/09
XMEGA A
Single read
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0
D D[3:0] D[7:4]
NOP*
Read
NOP**
suspend***
Clock
Clock suspend
NOP****
Data sampled
Data sampled
422
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0 Bank Adr 0x0
A[11:0] Row Adr Col Adr 0x400 Row Adr Col Adr 0x400
NOP*
Read
NOP**
suspend***
Clock
Clock suspend
NOP****
Active
NOP*
Read
NOP**
suspend***
Clock
Clock suspend
NOP****
Data sampled
Data sampled
Data sampled
* The number of NOPs is equal to ROWCOLDLY[2:0] (ROWCOLDLY = 1 is shown)
** NOP is only inserted for CAS3
*** Clock suspended for 1 cycle when EBI is running at 1x and 1 or 2 cycles when EBI
is running at 2x, to enable sampling of data on the positive edge of the 1x clock.
**** The number of NOPs is equal to WRDLY[1:0] + 1 (WRDLY = 0 is shown)
***** The number of NOPs is equal to RPDLY[1:0] (RPDLY = 1 is shown)
423
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0
A[11:0] Row Adr Col Adr Col Adr Col Adr 0x400
NOP*
Read
NOP**
suspend***
Clock
Clock suspend
Read
NOP**
suspend***
Clock
Clock suspend
Read
NOP**
suspend***
Clock
Clock suspend
NOP****
Data sampled
Data sampled
Data sampled
Data sampled
Data sampled
* The number of NOPs is equal to ROWCOLDLY[2:0] (ROWCOLDLY = 1 is shown)
** NOP is only inserted for CAS3
*** Clock suspended for 1 cycle when EBI is running at 1x and 1 or 2 cycles when EBI
is running at 2x, to enable sampling of data on the positive edge of the 1x clock.
**** The number of NOPs is equal to WRDLY[1:0] + 1 (WRDLY = 0 is shown)
***** The number of NOPs is equal to RPDLY[1:0] (RPDLY = 1 is shown)
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0] Bank Adr 0x0 Bank Adr 0x0
A[11:0] Row Adr Col Adr Col Adr 0x400 Col Adr 0x400
NOP*
Read
NOP**
suspend***
Clock
Clock suspend
Read
NOP**
suspend***
Clock
Clock suspend
NOP*****
Active
NOP*
Read
NOP**
suspend***
Clock
Clock suspend
NOP****
Data sampled
Data sampled
Data sampled
Data sampled
Data sampled
424
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0]
A[11:0]
D
Auto Refresh
425
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0]
A[11:0]
D
Precharge All
NOP*
Auto Refresh
Active
* The number of NOPs is equal to RPDLY[1:0] (RPDLY = 1 is shown)
** The number of NOPs is equal to ESRDLY[2:0] (ESRDLY = 1 is shown)
426
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0]
A[11:0]
D
Enter Self Refresh
427
8077H–AVR–12/09
XMEGA A
ClkPER2
CS
CLK
CKE
WE
CAS
RAS
DQM
BA[1:0]
A[11:0]
D
NOP**
428
8077H–AVR–12/09
XMEGA A
429
8077H–AVR–12/09
XMEGA A
1. Updated Figure 9-5 External reset characteristics in Section 9.4.3 ”External reset” on page 107.
2. Updated ”Capture Channel” on page 156.
3. Added ADC section ”ADC Input Model” on page 300.
4. Added DAC section ”DAC Output model” on page 318.
430
8077H–AVR–12/09
XMEGA A
431
8077H–AVR–12/09
XMEGA A
1. Updated “Overview” , “AVR CPU” , “DMAC - Direct Memory Access Controller” and “Memories” layout.
2. Updated bit names and register names in Section 5.14 ”Register Description – DMA Channel” on page
55.
3. Updated bit names and register names in Section 4.20 ”Register Description – MCU Control” on page
43.
4. Updated address register in Section 4.21 ”Register Summary - NVM Controller” on page 46.
5. Updated features in Section 6.1 ”Features” on page 65.
6. Updated bit name in Section 6.8.2 ”CHnCTRL – Event Channel n Control Register” on page 73.
7. Updated register format in Section 23.5 ”Register Description - AES” on page 263.
8. Updated register format, bit register and register names in Section 7. ”System Clock and Clock options”
on page 76.
9. Updated the table layout in Table 8-1 on page 96.
10. Updated register description in Section 8.6 ”Register Description – Power Reduction” on page 98.
11. Updated register description, register names and bit register in Section 14. ”TC - 16-bit Timer/Counter”
on page 149, in Section 15. ”AWeX – Advanced Waveform Extension” on page 175 and in Section 16.
”Hi-Res - High Resolution Extension” on page 187.
12. Updated register description, register names and bit register in Section 13. ”I/O Ports” on page 129, in
Section 19. ”TWI – Two Wire Interface” on page 204, in Section 17. ”RTC - Real Time Counter” on page
189, in Section 20. ”SPI – Serial Peripheral Interface” on page 228, in Section 21. ”USART” on page
234, in Section 22. ”IRCOM - IR Communication Module” on page 255 and in Section 25. ”ADC - Analog
to Digital Converter” on page 288.
13. Updated register description, register names and bit register in Section 26. ”DAC - Digital to Analog
Converter” on page 316, in Section 27. ”AC - Analog Comparator” on page 328, in Section 28. ”IEEE
1149.1 JTAG Boundary Scan interface” on page 337, and in Section 29. ”Program and Debug Interface”
on page 344.
14. Removed “Possibility to drive output to ground” from Section 26.1 ”Features” on page 316.
15. Added “Internal/External reference” in Section 26.1 ”Features” on page 316.
16. Updated “Bit utilization” in Section 26.9.6 ”STATUS – DAC Status Register” on page 322.
17. Removed parentheses from the section’s title Section 26.9.10 ”CH1DATAL – DAC Channel 1 Data
Register Low byte” on page 325.
18. Added information text before the table in Section 26.10 ”Register Summary” on page 327.
19. Corrected the VSCALE formula in Section 27.9.4 ”CTRLB – Control Register B” on page 333.
20. Merged Section 23.3.2 and Section 23.3.3 in one Section 27.3.2 ”Internal Inputs” on page 330.
21. Changed “singed” to signed in Section 25.1 ”Features” on page 288.
22. Changed AWEXELOCK bit from position 4 to position 2 in Section 4.20.8 ”AWEXLOCK – Advanced
Waveform Extension Lock Register” on page 45, and updated the entire section and Section 4.25
”Register Summary - MCU Control” on page 48.
23. Added the last paragraph on Section 3.8 ”Stack and Stack Pointer” on page 9.
24. Inserted the correct Figure 14-1 on page 150.
25. Updated the Figure 14-2 on page 152.
26. Updated the Figure 13-10 on page 137.
27. Updated the Figure 25-18 on page 300 by removing the color.
432
8077H–AVR–12/09
XMEGA A
28. Removed section 21.14.6. The removed section was only for the test.
29. Updated the Table 6-3 on page 71 with a footnote and cross-references to the footnote for PORTA_PINn
to PORTF_PINn.
30. Changed connection description of CTRLA in Section 27.9.3 ”CTRLA – Control Register A” on page
333. AC0OUT is connected to pin 7, not on pin 0.
31. Updated the Section 4.1 ”Features” on page 18 with “Flexible Software CRC” in the feature list for the
flash.
32. Updated Figure 7-1 on page 77.
33. Removed Figure 28-4 on page 343 and Figure 28-5 on page 343 and replaced by ones drawn in visio.
34. Updated Figure 4-1 on page 19, Figure 4-2 on page 22 and Figure 4-3 on page 24.
35. Updated Figure 19-11 on page 211.
36. Corrected the bit 0 in Section 8.6.1 ”PR - General Power Reduction Register” on page 98 and in Section
8.7 ”Register Summary - Sleep” on page 101.
37. Updated the text in Section 9.4.6 ”Software reset” on page 109.
38. Updated the table notes in the Table 7-6 on page 89.
39. Updated the Figure 6-1 on page 66 with IRCOM.
40. Updated the Figure 29-1 on page 345.
41. Changed the initial value to FF on the RTC PERH and PERL registers in Section 17.3.8 ”PERH - Real
Time Counter Period Register High” on page 193 and in Section 17.3.9 ”PERL - Real Time Counter
Period Register L” on page 193.
42. Added a footnote in Table 13-5 on page 143 that explains the low level.
43. Updated the high byte and low byte in Section 4.26 ”Interrupt Vector Summary - NVM Controller” on
page 48.
44. Inserted a new Section 30. ”Memory Programming” on page 361.
45. Inserted a new figure Figure 2-1 on page 4.
46. Inserted a new figure Figure 3-1 on page 6.
47. Inserted new sections: ”EBI - External Bus Interface” on page 267, ”Memory Programming” on page
361, and ”Instruction Set Summary” on page 386.
48. Updated ”Virtual Registers” on page 138.
49. Deleted 2 Chapters: “Bootloader - Self-Programming” and Extern Programming.
50. Removed “TRUEGND” bit from ”Register Summary” on page 327.
1. Initial revision
433
8077H–AVR–12/09
XMEGA A
Table of Contents
1 About the Manual ..................................................................................... 2
1.1 Reading the Manual ..........................................................................................2
1.2 Resources .........................................................................................................2
1.3 Recommended Reading ....................................................................................2
2 Overview ................................................................................................... 3
2.1 Block Diagram ...................................................................................................4
4 Memories ................................................................................................ 18
4.1 Features ..........................................................................................................18
4.2 Overview ..........................................................................................................18
4.3 Flash Program Memory ...................................................................................19
4.4 Fuses and Lockbits ..........................................................................................20
4.5 Data Memory ...................................................................................................22
4.6 Internal SRAM .................................................................................................22
4.7 EEPROM .........................................................................................................23
4.8 I/O Memory ......................................................................................................23
4.9 External Memory .............................................................................................23
4.10 Data Memory and Bus Arbitration ...................................................................23
i
8077H–AVR–12/09
XMEGA A
ii
8077H–AVR–12/09
XMEGA A
iii
8077H–AVR–12/09
XMEGA A
iv
8077H–AVR–12/09
XMEGA A
v
8077H–AVR–12/09
XMEGA A
vi
8077H–AVR–12/09
XMEGA A
vii
8077H–AVR–12/09
XMEGA A
viii
8077H–AVR–12/09
XMEGA A
ix
8077H–AVR–12/09
XMEGA A
x
8077H–AVR–12/09
XMEGA A
Table of Contents....................................................................................... i
xi
8077H–AVR–12/09
Headquarters International
Product Contact
Literature Requests
www.atmel.com/literature
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any
intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDI-
TIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY
WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDEN-
TAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF
THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no
representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications
and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided
otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel’s products are not intended, authorized, or warranted for use
as components in applications intended to support or sustain life.
© 2009 Atmel Corporation. All rights reserved. Atmel®, logo and combinations thereof, AVR ® and others are registered trademarks, XMEGATM
and others are trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.
8077H–AVR–12/09