8-bit AVR Microcontroller
ATmega48/V / 88/V / 168/V
DATASHEET COMPLETE
Introduction
The Atmel ATmega48/V/ 88/V /168/V is a low-power CMOS 8-bit
microcontroller based on the AVR
®
enhanced RISC architecture. By
executing powerful instructions in a single clock cycle, the ATmega48/V/
88/V /168/V achieves throughputs close to 1MIPS per MHz. This empowers
system designer to optimize the device for power consumption versus
processing speed.
®
Feature
High Performance, Low Power Atmel
®
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
–
4K/8K/16KBytes of In-System Self-Programmable Flash program
Memory
–
256/512/512Bytes EEPROM
–
512/1K/1KBytes 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
•
Atmel
®
QTouch
®
Library Support
–
Capacitive Touch Buttons, Sliders and Wheels
–
QTouch and QMatrix
®
Acquisition
–
Up to 64 sense channels
Atmel-2545W-ATmega48/V / 88/V / 168/V_Datasheet_Complete-11/2016
•
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
–
Real Time Counter with Separate Oscillator
–
Six PWM Channels
–
8-channel 10-bit ADC in TQFP and QFN/MLF package
• Temperature Measurement
–
6-channel 10-bit ADC in PDIP Package
• Temperature Measurement
–
–
–
–
–
–
Two Master/Slave SPI Serial Interface
One Programmable Serial USART
One Byte-oriented 2-wire Serial Interface (Philips I
2
C compatible)
Programmable Watchdog Timer with Separate On-chip Oscillator
One 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 PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF
Operating Voltage:
–
2.7 - 5.5V for ATmega48/88/168
–
1.8 - 5.5V for ATmega48V/88V/168V
Temperature Range:
–
-40°C to 85°C
Speed Grade:
–
ATmega48/88/168: 0 - 10MHz @ 2.7V - 5.5V, 0 - 20MHz @ 4.5V - 5.5V
–
ATmega48V/88V/168V: 0 - 4MHz @ 1.8V - 5.5V, 0 - 10MHz @ 2.7V - 5.5V
Power Consumption at 1MHz, 1.8V, 25°C
–
Active Mode: 0.3mA
–
Power-down Mode: 0.1μA
–
Power-save Mode: 0.8μA (Including 32kHz RTC)
Atmel ATmega48/V / 88/V / 168/V [DATASHEET]
Atmel-2545W-ATmega48/V / 88/V / 168/V_Datasheet_Complete-11/2016
2
Table of Contents
Introduction......................................................................................................................1
Feature............................................................................................................................ 1
1. Description...............................................................................................................10
2. Configuration Summary........................................................................................... 11
3. Ordering Information ...............................................................................................12
3.1.
3.2.
3.3.
ATmega48/V...............................................................................................................................12
ATmega88/V...............................................................................................................................13
ATmega168/V.............................................................................................................................14
4. Block Diagram......................................................................................................... 15
5. Pin Configurations................................................................................................... 16
5.1.
5.2.
Pin-out........................................................................................................................................ 16
Pin Descriptions..........................................................................................................................19
6. I/O Multiplexing........................................................................................................ 21
7. Resources................................................................................................................23
8. Data Retention.........................................................................................................24
9. About Code Examples............................................................................................. 25
10. Capacitive Touch Sensing....................................................................................... 26
10.1. QTouch Library........................................................................................................................... 26
11. AVR CPU Core........................................................................................................ 27
11.1.
11.2.
11.3.
11.4.
11.5.
Overview.....................................................................................................................................27
ALU – Arithmetic Logic Unit........................................................................................................28
Status Register...........................................................................................................................28
General Purpose Register File................................................................................................... 30
Stack Pointer.............................................................................................................................. 31
11.6. Instruction Execution Timing...................................................................................................... 33
11.7. Reset and Interrupt Handling..................................................................................................... 34
12. AVR Memories.........................................................................................................36
12.1.
12.2.
12.3.
12.4.
12.5.
12.6.
Overview.....................................................................................................................................36
In-System Reprogrammable Flash Program Memory................................................................ 36
SRAM Data Memory...................................................................................................................37
EEPROM Data Memory............................................................................................................. 39
I/O Memory.................................................................................................................................40
Register Description................................................................................................................... 41
13. System Clock and Clock Options............................................................................ 51
13.1. Clock Systems and Their Distribution.........................................................................................51
13.2. Clock Sources............................................................................................................................ 52
13.3. Low Power Crystal Oscillator......................................................................................................54
13.4. Full Swing Crystal Oscillator.......................................................................................................55
13.5. Low Frequency Crystal Oscillator...............................................................................................56
13.6. Calibrated Internal RC Oscillator................................................................................................57
13.7. 128kHz Internal Oscillator.......................................................................................................... 58
13.8. External Clock............................................................................................................................ 59
13.9. Timer/Counter Oscillator.............................................................................................................60
13.10. Clock Output Buffer....................................................................................................................60
13.11. System Clock Prescaler............................................................................................................. 60
13.12. Register Description...................................................................................................................61
14. PM - Power Management and Sleep Modes...........................................................65
14.1. Overview.....................................................................................................................................65
14.2. Sleep Modes...............................................................................................................................65
14.3. Idle Mode....................................................................................................................................65
14.4. ADC Noise Reduction Mode.......................................................................................................66
14.5. Power-Down Mode.....................................................................................................................66
14.6. Power-save Mode.......................................................................................................................67
14.7. Standby Mode............................................................................................................................ 67
14.8. Extended Standby Mode............................................................................................................ 67
14.9. Power Reduction Register..........................................................................................................67
14.10. Minimizing Power Consumption.................................................................................................68
14.11. Register Description................................................................................................................... 69
15. SCRST - System Control and Reset....................................................................... 74
15.1.
15.2.
15.3.
15.4.
15.5.
15.6.
15.7.
15.8.
15.9.
Resetting the AVR...................................................................................................................... 74
Reset Sources............................................................................................................................74
Power-on Reset..........................................................................................................................75
External Reset............................................................................................................................76
Brown-out Detection...................................................................................................................76
Watchdog System Reset............................................................................................................ 77
Internal Voltage Reference.........................................................................................................77
Watchdog Timer......................................................................................................................... 78
Register Description................................................................................................................... 80
16. Interrupts................................................................................................................. 84
16.1.
16.2.
16.3.
16.4.
Interrupt Vectors in ATmega48/V................................................................................................84
Interrupt Vectors in ATmega88/V................................................................................................85
Interrupt Vectors in ATmega168/V..............................................................................................88
Register Description................................................................................................................... 91
17. EXINT - External Interrupts..................................................................................... 94
17.1. Pin Change Interrupt Timing.......................................................................................................94
17.2. Register Description................................................................................................................... 95
18. I/O-Ports................................................................................................................ 104
Atmel ATmega48/V / 88/V / 168/V [DATASHEET]
Atmel-2545W-ATmega48/V / 88/V / 168/V_Datasheet_Complete-11/2016
4
18.1.
18.2.
18.3.
18.4.
Overview...................................................................................................................................104
Ports as General Digital I/O......................................................................................................105
Alternate Port Functions...........................................................................................................108
Register Description................................................................................................................. 120
19. TC0 - 8-bit Timer/Counter0 with PWM...................................................................132
19.1.
19.2.
19.3.
19.4.
19.5.
19.6.
19.7.
19.8.
19.9.
Features................................................................................................................................... 132
Overview...................................................................................................................................132
Timer/Counter Clock Sources.................................................................................................. 134
Counter Unit............................................................................................................................. 134
Output Compare Unit................................................................................................................135
Compare Match Output Unit.....................................................................................................137
Modes of Operation..................................................................................................................138
Timer/Counter Timing Diagrams...............................................................................................142
Register Description................................................................................................................. 144
20. TC1 - 16-bit Timer/Counter1 with PWM.................................................................156
20.1. Overview...................................................................................................................................156
20.2. Features................................................................................................................................... 156
20.3. Block Diagram.......................................................................................................................... 156
20.4. Definitions.................................................................................................................................157
20.5. Registers.................................................................................................................................. 158
20.6. Accessing 16-bit Registers.......................................................................................................158
20.7. Timer/Counter Clock Sources.................................................................................................. 161
20.8. Counter Unit............................................................................................................................. 161
20.9. Input Capture Unit.................................................................................................................... 162
20.10. Output Compare Units............................................................................................................. 164
20.11. Compare Match Output Unit.....................................................................................................166
20.12. Modes of Operation..................................................................................................................167
20.13. Timer/Counter Timing Diagrams.............................................................................................. 175
20.14. Register Description.................................................................................................................176
21. Timer/Counter 0, 1 Prescalers...............................................................................193
21.1.
21.2.
21.3.
21.4.
Internal Clock Source............................................................................................................... 193
Prescaler Reset........................................................................................................................193
External Clock Source..............................................................................................................193
Register Description................................................................................................................. 194
22. TC2 - 8-bit Timer/Counter2 with PWM and Asynchronous Operation................... 196
22.1. Features................................................................................................................................... 196
22.2. Overview...................................................................................................................................196
22.3. Timer/Counter Clock Sources.................................................................................................. 198
22.4. Counter Unit............................................................................................................................. 198
22.5. Output Compare Unit................................................................................................................199
22.6. Compare Match Output Unit.....................................................................................................201
22.7. Modes of Operation..................................................................................................................202
22.8. Timer/Counter Timing Diagrams...............................................................................................206
22.9. Asynchronous Operation of Timer/Counter2............................................................................ 207
22.10. Timer/Counter Prescaler.......................................................................................................... 209
Atmel ATmega48/V / 88/V / 168/V [DATASHEET]
Atmel-2545W-ATmega48/V / 88/V / 168/V_Datasheet_Complete-11/2016
5