ATmega164A/PA/324A/PA/644A/PA/1284/P
megaAVR
®
Data Sheet
Introduction
The ATmega164A/PA/324A/PA/644A/PA/1284/P is a low power, CMOS 8-bit microcontrollers based on the
AVR
®
enhanced RISC architecture. The ATmega164A/PA/324A/PA/644A/PA/1284/P is a 40/49-pins device
ranging from 16 KB to 128 KB Flash, with 1 KB to 16 KB SRAM, 512 Bytes to 4 KB EEPROM. By executing
instructions in a single clock cycle, the devices achieve CPU throughput approaching one million instruc-
tions per second (MIPS) per megahertz, allowing the system designer to optimize power consumption ver-
sus processing speed.
Features
High-performance, low-power 8-bit AVR
®
Microcontroller
Advanced RISC architecture
131 powerful Instructions – most single-clock cycle execution
32 × 8 general purpose working registers
Fully static operation
Up to 20MIPS throughput at 20MHz
On-chip 2-cycle multiplier
High endurance non-volatile memory segments
16/32/64/128KBytes of In-System Self-programmable Flash program memory
512/1K/2K/4KBytes EEPROM
1/2/4/16KBytes Internal SRAM
Write/Erase Cycles: 10,000 Flash/ 100,000 EEPROM
Data retention: 20 years at 85°C/ 100 years at 25°C
(1)
Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
Programming Lock for Software Security
QTouch
®
Library Support
Capacitive touch buttons, sliders and wheels
QTouch and QMatrix™ acquisition
Up to 64 sense channels
JTAG (IEEE std. 1149.1 Compliant) Interface
Boundary-scan Capabilities According to the JTAG Standard
Extensive On-chip Debug Support
Programming of Flash, EEPROM, Fuses, and Lock Bits through the JTAG Interface
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002070B-page 1
ATmega164A/PA/324A/PA/644A/PA/1284/P
Peripheral Features
Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
One/two 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
Real Time Counter with Separate Oscillator
Six PWM Channels
8-channel, 10-bit ADC
Differential mode with selectable gain at 1×, 10× or 200×
Byte-oriented Two-wire Serial Interface
Two Programmable Serial USART
Master/Slave SPI Serial Interface
Programmable Watchdog Timer with Separate On-chip Oscillator
On-chip Analog Comparator
Interrupt and Wake-up on Pin Change
Special Microcontroller Features
Power-on Reset and Programmable Brown-out Detection
Internal Calibrated RC Oscillator
External and Internal Interrupt Sources
Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby and Extended Standby
I/O and Packages
32 Programmable I/O Lines
40-pin PDIP, 44-lead TQFP, 44-pad VQFN/QFN/MLF
44-pad DRQFN
49-ball VFBGA
Operating Voltages
1.8 - 5.5V
Speed Grades
0 - 4MHz @ 1.8 - 5.5V
0 - 10MHz @ 2.7 - 5.5V
0 - 20MHz @ 4.5 - 5.5V
Power Consumption at 1MHz, 1.8V, 25C
Active: 0.4mA
Power-down Mode: 0.1µA
Power-save Mode: 0.6µA (Including 32kHz RTC)
Note:
1. See
“Data retention” on page 17
for details.
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002070B-page 2
ATmega164A/PA/324A/PA/644A/PA/1284/P
Table of Contents
1
Pin configurations
............................................................................................................... 11
1.1
1.2
1.3
Pinout - PDIP/TQFP/VQFN/QFN/MLF for ATmega164A/164PA/324A/324PA/644A/644PA/1284/1284P
11
Pinout - DRQFN for ATmega164A/164PA/324A/324PA .................................
12
Pinout - VFBGA for ATmega164A/164PA/324A/324PA ..................................
13
2
Overview
.................................................................................................................................... 13
2.1
2.2
Block diagram ..................................................................................................
14
Comparison between ATmega164A, ATmega164PA, ATmega324A, ATmega324PA, ATmega644A, AT-
mega644PA, ATmega1284 and ATmega1284P
...................................................................................................................................... 15
2.3
Pin Descriptions...............................................................................................
15
................................................................................................................................ 17
....................................................................................................... 17
3
4
5
6
7
Resources
About code examples
Data retention
......................................................................................................................... 17
Capacitive touch sensing
AVR CPU Core
7.1
7.2
7.3
7.4
7.5
7.6
7.7
............................................................................................... 17
....................................................................................................................... 18
Overview..........................................................................................................
18
ALU – Arithmetic Logic Unit.............................................................................
19
Status Register ................................................................................................
19
General Purpose Register File ........................................................................
21
Stack Pointer ...................................................................................................
22
Instruction Execution Timing ...........................................................................
23
Reset and interrupt handling ...........................................................................
24
8
AVR memories
....................................................................................................................... 27
8.1
8.2
8.3
8.4
8.5
8.6
Overview..........................................................................................................
27
In-System Reprogrammable Flash Program Memory .....................................
27
SRAM data memory ........................................................................................
28
EEPROM data memory ...................................................................................
30
I/O memory......................................................................................................
31
Register Description ........................................................................................
32
................................................................................ 38
9
System clock and clock options
9.1
9.2
Clock systems and their distribution ................................................................
38
Clock Sources .................................................................................................
39
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002070B-page 3
ATmega164A/PA/324A/PA/644A/PA/1284/P
9.3
9.4
9.5
9.6
9.7
9.8
9.9
9.10
9.11
9.12
Low Power Crystal Oscillator...........................................................................
41
Full swing Crystal Oscillator ............................................................................
42
Low Frequency Crystal Oscillator ....................................................................
43
Calibrated Internal RC Oscillator .....................................................................
44
128kHz internal oscillator ................................................................................
45
External clock ..................................................................................................
46
Timer/Counter Oscillator..................................................................................
46
Clock Output Buffer .........................................................................................
47
System Clock Prescaler ..................................................................................
47
Register description .........................................................................................
48
................................................................... 50
10 Power management and sleep modes
10.1
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
10.10
10.11
10.12
Overview..........................................................................................................
50
Sleep Modes....................................................................................................
50
BOD disable
(1)
.................................................................................................
51
Idle mode.........................................................................................................
51
ADC Noise Reduction mode............................................................................
51
Power-down mode...........................................................................................
52
Power-save mode............................................................................................
52
Standby mode .................................................................................................
52
Extended Standby mode .................................................................................
52
Power Reduction Register ...............................................................................
53
Minimizing Power Consumption ......................................................................
53
Register description .........................................................................................
55
............................................................................................. 58
11 System Control and Reset
11.1
11.2
11.3
11.4
Resetting the AVR ...........................................................................................
58
Internal Voltage Reference..............................................................................
62
Watchdog Timer ..............................................................................................
63
Register description .........................................................................................
66
12 Interrupts
................................................................................................................................... 69
12.1
12.2
12.3
Overview..........................................................................................................
69
Interrupt Vectors in ATmega164A/164PA/324A/324PA/644A/644PA/1284/1284P
69
Register description .........................................................................................
73
.............................................................................................................. 75
13 External Interrupts
13.1
13.2
Overview..........................................................................................................
75
Register description .........................................................................................
75
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002070B-page 4
ATmega164A/PA/324A/PA/644A/PA/1284/P
14 I/O-Ports
..................................................................................................................................... 80
14.1
14.2
14.3
14.4
Overview..........................................................................................................
80
Ports as General Digital I/O .............................................................................
81
Alternate Port Functions ..................................................................................
85
Register description .........................................................................................
97
.................................................................................. 99
15 8-bit Timer/Counter0 with PWM
15.1
15.2
15.3
15.4
15.5
15.6
15.7
15.8
15.9
Features ..........................................................................................................
99
Overview..........................................................................................................
99
Timer/Counter Clock Sources .......................................................................
100
Counter Unit ..................................................................................................
100
Output Compare unit .....................................................................................
101
Compare Match Output unit ..........................................................................
102
Modes of operation........................................................................................
103
Timer/Counter Timing diagrams ....................................................................
107
Register description .......................................................................................
109
.......................... 115
16 16-bit Timer/Counter1 and Timer/Counter3
(1)
with PWM
16.1
16.2
16.3
16.4
16.5
16.6
16.7
16.8
16.9
16.10
16.11
16.12
Features ........................................................................................................
115
Overview........................................................................................................
115
Accessing 16-bit Registers ............................................................................
117
Timer/Counter Clock Sources .......................................................................
120
Prescaler Reset .............................................................................................
120
Counter Unit ..................................................................................................
121
Input Capture Unit .........................................................................................
122
Output Compare units ...................................................................................
123
Compare Match Output unit ..........................................................................
126
Modes of Operation .......................................................................................
127
Timer/Counter Timing diagrams ....................................................................
134
Register description .......................................................................................
136
17 8-bit Timer/Counter2 with PWM and asynchronous operation
............. 146
17.1
17.2
17.3
17.4
17.5
17.6
Features ........................................................................................................
146
Overview........................................................................................................
146
Timer/Counter clock sources .........................................................................
147
Counter unit ...................................................................................................
148
Output Compare unit .....................................................................................
148
Compare Match Output unit ..........................................................................
150
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002070B-page 5