ATmega48A/PA/88A/PA/168A/PA/328/P
megaAVR
®
Data Sheet
Introduction
The ATmega48A/PA/88A/PA/168A/PA/328/P is a low power, CMOS 8-bit microcontrollers based on the
AVR
®
enhanced RISC architecture. By executing instructions in a single clock cycle, the devices achieve
CPU throughput approaching one million instructions per second (MIPS) per megahertz, allowing the sys-
tem designer to optimize power consumption versus processing speed.
Features
High Performance, Low Power AVR
®
8-Bit Microcontroller Family
Advanced RISC Architecture
̶
̶
̶
̶
̶
131 Powerful Instructions – Most Single Clock Cycle Execution
32 x 8 General Purpose Working Registers
Fully Static Operation
Up to 20 MIPS Throughput at 20MHz
On-chip 2-cycle Multiplier
High Endurance Non-volatile Memory Segments
̶
̶
̶
̶
̶
̶
4/8/16/32KBytes of In-System Self-Programmable Flash program memory
256/512/512/1KBytes EEPROM
512/1K/1K/2KBytes 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
Peripheral Features
̶
̶
Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002061B-page 1
ATmega48A/PA/88A/PA/168A/PA/328/P
̶
̶
̶
̶
̶
̶
̶
̶
̶
̶
Real Time Counter with Separate Oscillator
Six PWM Channels
8-channel 10-bit ADC in TQFP and VQFN package
Temperature Measurement
Temperature Measurement
6-channel 10-bit ADC in SPDIP Package
Programmable Serial USART
Master/Slave SPI Serial Interface
Byte-oriented 2-wire Serial Interface (Philips I
2
C compatible)
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 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
̶
̶
23 Programmable I/O Lines
28-pin SPDIP, 32-lead TQFP, 28-pad VQFN and 32-pad VQFN
Operating Voltage:
̶
1.8 - 5.5V
Temperature Range:
̶
-40°C to 85°C
Speed Grade:
̶
0 - 4MHz@1.8 - 5.5V, 0 - 10MHz@2.7 - 5.5.V, 0 - 20MHz @ 4.5 - 5.5V
Power Consumption at 1MHz, 1.8V, 25°C
̶
̶
Active Mode: 0.2mA
Power-down Mode: 0.1µA
• Power-save Mode: 0.75µA (Including 32kHz RTC)
Note:
1. See
“Data Retention” on page 17
for details.
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002061B-page 2
ATmega48A/PA/88A/PA/168A/PA/328/P
Table of Contents
1
2
Pin Configurations
1.1
.............................................................................................................. 12
Pin Descriptions...............................................................................................
13
Overview
.................................................................................................................................... 15
2.1
2.2
Block Diagram .................................................................................................
15
Comparison Between Processors ...................................................................
16
................................................................................................................................ 17
....................................................................................................................... 17
...................................................................................................... 17
............................................................................................. 17
3
4
5
6
7
Resources
Data Retention
About Code Examples
Capacitive Touch Sensing
AVR CPU Core
7.1
7.2
7.3
7.4
7.5
7.6
7.7
....................................................................................................................... 18
Overview..........................................................................................................
18
ALU – Arithmetic Logic Unit.............................................................................
19
Status Register ................................................................................................
19
General Purpose Register File ........................................................................
20
Stack Pointer ...................................................................................................
22
Instruction Execution Timing ...........................................................................
23
Reset and Interrupt Handling...........................................................................
23
....................................................................................................................... 26
8
AVR Memories
8.1
8.2
8.3
8.4
8.5
8.6
Overview..........................................................................................................
26
In-System Reprogrammable Flash Program Memory .....................................
26
SRAM Data Memory........................................................................................
28
EEPROM Data Memory ..................................................................................
29
I/O Memory......................................................................................................
30
Register Description ........................................................................................
31
9
System Clock and Clock Options
.............................................................................. 36
9.1
9.2
9.3
9.4
9.5
9.6
9.7
Clock Systems and their Distribution ...............................................................
36
Clock Sources .................................................................................................
37
Low Power Crystal Oscillator...........................................................................
38
Full Swing Crystal Oscillator ............................................................................
39
Low Frequency Crystal Oscillator ....................................................................
42
Calibrated Internal RC Oscillator .....................................................................
43
128kHz Internal Oscillator ...............................................................................
43
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002061B-page 3
ATmega48A/PA/88A/PA/168A/PA/328/P
9.8
9.9
9.10
9.11
9.12
External Clock .................................................................................................
44
Clock Output Buffer .........................................................................................
45
Timer/Counter Oscillator..................................................................................
45
System Clock Prescaler ..................................................................................
45
Register Description ........................................................................................
46
................................................................... 48
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
Sleep Modes....................................................................................................
48
BOD Disable
(1)
................................................................................................
49
Idle Mode.........................................................................................................
49
ADC Noise Reduction Mode............................................................................
49
Power-down Mode...........................................................................................
49
Power-save Mode............................................................................................
50
Standby Mode .................................................................................................
50
Extended Standby Mode .................................................................................
51
Power Reduction Register ...............................................................................
51
Minimizing Power Consumption ......................................................................
51
Register Description ........................................................................................
53
............................................................................................. 56
11 System Control and Reset
11.1
11.2
11.3
11.4
11.5
11.6
11.7
11.8
11.9
Resetting the AVR ...........................................................................................
56
Reset Sources .................................................................................................
56
Power-on Reset...............................................................................................
57
External Reset .................................................................................................
58
Brown-out Detection ........................................................................................
58
Watchdog System Reset .................................................................................
59
Internal Voltage Reference ..............................................................................
59
Watchdog Timer ..............................................................................................
60
Register Description ........................................................................................
63
12 Interrupts
................................................................................................................................... 66
12.1
12.2
12.3
12.4
12.5
Interrupt Vectors in ATmega48A and ATmega48PA .......................................
66
Interrupt Vectors in ATmega88A and ATmega88PA .......................................
68
Interrupt Vectors in ATmega168A and ATmega168PA ...................................
71
Interrupt Vectors in ATmega328 and ATmega328P........................................
74
Register Description ........................................................................................
77
.............................................................................................................. 79
13 External Interrupts
13.1
Pin Change Interrupt Timing............................................................................
79
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002061B-page 4
ATmega48A/PA/88A/PA/168A/PA/328/P
13.2
Register Description ........................................................................................
80
14 I/O-Ports
..................................................................................................................................... 84
14.1
14.2
14.3
14.4
Overview..........................................................................................................
84
Ports as General Digital I/O .............................................................................
85
Alternate Port Functions ..................................................................................
89
Register Description ......................................................................................
100
................................................................................ 102
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 ........................................................................................................
102
Overview........................................................................................................
102
Timer/Counter Clock Sources .......................................................................
103
Counter Unit ..................................................................................................
103
Output Compare Unit.....................................................................................
104
Compare Match Output Unit ..........................................................................
106
Modes of Operation .......................................................................................
107
Timer/Counter Timing Diagrams ...................................................................
111
Register Description ......................................................................................
113
............................................................................. 120
16 16-bit Timer/Counter1 with PWM
16.1
16.2
16.3
16.4
16.5
16.6
16.7
16.8
16.9
16.10
16.11
Features ........................................................................................................
120
Overview........................................................................................................
120
Accessing 16-bit Registers ............................................................................
122
Timer/Counter Clock Sources .......................................................................
125
Counter Unit ..................................................................................................
125
Input Capture Unit .........................................................................................
126
Output Compare Units ...................................................................................
128
Compare Match Output Unit ..........................................................................
130
Modes of Operation .......................................................................................
131
Timer/Counter Timing Diagrams ...................................................................
138
Register Description ......................................................................................
140
........................................... 147
17 Timer/Counter0 and Timer/Counter1 Prescalers
17.1
17.2
17.3
17.4
Internal Clock Source ....................................................................................
147
Prescaler Reset .............................................................................................
147
External Clock Source ...................................................................................
147
Register Description ......................................................................................
149
........... 150
18 8-bit Timer/Counter2 with PWM and Asynchronous Operation
18.1
Features ........................................................................................................
150
2020 Microchip Technology Inc.
Data Sheet Complete
DS40002061B-page 5