8-bit AVR Microcontroller
ATmega128A
DATASHEET COMPLETE
Introduction
The Atmel ATmega128A 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 ATmega128A achieves throughputs close to
1MIPS per MHz. This empowers system designer to optimize the device for
power consumption versus processing speed.
®
Features
•
•
High-performance, Low-power Atmel AVR 8-bit Microcontroller
Advanced RISC Architecture
–
133 Powerful Instructions - Most Single-clock Cycle Execution
–
32 × 8 General Purpose Working Registers + Peripheral Control
Registers
–
Fully Static Operation
–
Up to 16MIPS Throughput at 16MHz
–
On-chip 2-cycle Multiplier
High Endurance Non-volatile Memory segments
–
128Kbytes of In-System Self-programmable Flash program
memory
–
4Kbytes EEPROM
–
–
–
–
4Kbytes 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
Up to 64 Kbytes Optional External Memory Space
Programming Lock for Software Security
SPI Interface for In-System Programming
•
–
–
–
•
JTAG (IEEE std. 1149.1 Compliant) Interface
–
Boundary-scan Capabilities According to the JTAG Standard
–
Extensive On-chip Debug Support
Atmel-8151J-8-bit AVR Microcontroller_Datasheet_Complete-09/2015
•
•
–
Programming of Flash, EEPROM, Fuses and Lock Bits through the JTAG Interface
Atmel QTouch
®
library support
–
Capacitive touch buttons, sliders and wheels
–
Atmel QTouch and QMatrix acquisition
–
Up to 64 sense channels
Peripheral Features
–
Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
–
Two Expanded 16-bit Timer/Counters with Separate Prescaler, Compare Mode and Capture
Mode
–
Real Time Counter with Separate Oscillator
–
–
–
–
Two 8-bit PWM Channels
6 PWM Channels with Programmable Resolution from 2 to 16 Bits
Output Compare Modulator
8-channel, 10-bit ADC
• 8 Single-ended Channels
•
–
–
–
7 Differential Channels
• 2 Differential Channels with Programmable Gain at 1x, 10x, or 200x
Byte-oriented Two-wire Serial Interface
Dual Programmable Serial USARTs
Master/Slave SPI Serial Interface
•
•
•
•
–
Programmable Watchdog Timer with On-chip Oscillator
–
On-chip Analog Comparator
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
–
Software Selectable Clock Frequency
–
ATmega103 Compatibility Mode Selected by a Fuse
–
Global Pull-up Disable
I/O and Packages
–
53 Programmable I/O Lines
–
64-lead TQFP and 64-pad QFN/MLF
Operating Voltages
–
2.7 - 5.5V
Speed Grades
–
0 - 16MHz
Atmel ATmega128A [DATASHEET]
Atmel-8151J-8-bit AVR Microcontroller_Datasheet_Complete-09/2015
2
Table of Contents
Introduction......................................................................................................................1
Features.......................................................................................................................... 1
1. Description.................................................................................................................9
2. Configuration Summary........................................................................................... 10
3. Ordering Information................................................................................................ 11
4. Block Diagram......................................................................................................... 12
5. ATmega103 and ATmega128A Compatibility.......................................................... 13
5.1.
ATmega103 Compatibility Mode.................................................................................................13
6. Pin Configurations................................................................................................... 14
6.1.
Pin Descriptions..........................................................................................................................14
7. Resources................................................................................................................18
8. Data Retention.........................................................................................................19
9. About Code Examples............................................................................................. 20
10. Capacitive Touch Sensing....................................................................................... 21
11. AVR CPU Core........................................................................................................ 22
11.1.
11.2.
11.3.
11.4.
11.5.
11.6.
11.7.
Overview.....................................................................................................................................22
ALU – Arithmetic Logic Unit........................................................................................................23
Status Register...........................................................................................................................23
General Purpose Register File................................................................................................... 25
Stack Pointer.............................................................................................................................. 26
Instruction Execution Timing...................................................................................................... 28
Reset and Interrupt Handling..................................................................................................... 29
12. AVR Memories.........................................................................................................32
12.1. Overview.....................................................................................................................................32
12.2.
12.3.
12.4.
12.5.
12.6.
12.7.
In-System Reprogrammable Flash Program Memory................................................................ 32
SRAM Data Memory...................................................................................................................33
EEPROM Data Memory............................................................................................................. 35
I/O Memory.................................................................................................................................36
External Memory Interface......................................................................................................... 36
Register Description................................................................................................................... 43
13. System Clock and Clock Options............................................................................ 54
13.1. Clock Systems and their Distribution..........................................................................................54
13.2. Clock Sources............................................................................................................................ 55
13.3. Default Clock Source..................................................................................................................56
13.4. Crystal Oscillator........................................................................................................................ 56
13.5. Low-frequency Crystal Oscillator................................................................................................57
13.6. External RC Oscillator................................................................................................................ 58
13.7. Calibrated Internal RC Oscillator................................................................................................58
13.8. External Clock............................................................................................................................ 59
13.9. Timer/Counter Oscillator.............................................................................................................60
13.10. Register Description...................................................................................................................60
14. Power Management and Sleep Modes................................................................... 63
14.1.
14.2.
14.3.
14.4.
14.5.
14.6.
14.7.
14.8.
14.9.
Sleep Modes...............................................................................................................................63
Idle Mode....................................................................................................................................64
ADC Noise Reduction Mode.......................................................................................................64
Power-down Mode......................................................................................................................64
Power-save Mode.......................................................................................................................64
Standby Mode............................................................................................................................ 65
Extended Standby Mode............................................................................................................ 65
Minimizing Power Consumption................................................................................................. 65
Register Description................................................................................................................... 67
15. System Control and Reset.......................................................................................69
15.1.
15.2.
15.3.
15.4.
15.5.
15.6.
Resetting the AVR...................................................................................................................... 69
Reset Sources............................................................................................................................69
Internal Voltage Reference.........................................................................................................73
Watchdog Timer......................................................................................................................... 73
Timed Sequences for Changing the Configuration of the Watchdog Timer............................... 74
Register Description................................................................................................................... 75
16. Interrupts................................................................................................................. 79
16.1. Interrupt Vectors in ATmega128A...............................................................................................79
16.2. Register Description................................................................................................................... 84
17. External Interrupts................................................................................................... 87
17.1. Register Description................................................................................................................... 87
18. I/O Ports.................................................................................................................. 94
18.1.
18.2.
18.3.
18.4.
Overview.....................................................................................................................................94
Ports as General Digital I/O........................................................................................................95
Alternate Port Functions.............................................................................................................99
Register Description................................................................................................................. 113
19. Timer/Counter3, Timer/Counter2, and Timer/Counter1 Prescalers....................... 136
19.1.
19.2.
19.3.
19.4.
19.5.
Overview...................................................................................................................................136
Internal Clock Source............................................................................................................... 136
Prescaler Reset........................................................................................................................136
External Clock Source..............................................................................................................136
Register Description................................................................................................................. 137
20. 16-bit Timer/Counter (Timer/Counter1 and Timer/Counter3).................................139
Atmel ATmega128A [DATASHEET]
Atmel-8151J-8-bit AVR Microcontroller_Datasheet_Complete-09/2015
4
20.1. Features................................................................................................................................... 139
20.2. Overview...................................................................................................................................139
20.3. Accessing 16-bit Registers.......................................................................................................142
20.4. Timer/Counter Clock Sources.................................................................................................. 144
20.5. Counter Unit............................................................................................................................. 144
20.6. Input Capture Unit.................................................................................................................... 145
20.7. Output Compare Units..............................................................................................................148
20.8. Compare Match Output Unit.....................................................................................................149
20.9. Modes of Operation..................................................................................................................150
20.10. Timer/Counter Timing Diagrams.............................................................................................. 158
20.11. Register Description................................................................................................................. 159
21. 8-bit Timer/Counter0 with PWM and Asynchronous Operation............................. 194
21.1. Features................................................................................................................................... 194
21.2. Overview...................................................................................................................................194
21.3. Timer/Counter Clock Sources.................................................................................................. 195
21.4. Counter Unit............................................................................................................................. 195
21.5. Output Compare Unit................................................................................................................196
21.6. Compare Match Output Unit.....................................................................................................198
21.7. Modes of Operation..................................................................................................................199
21.8. Timer/Counter Timing Diagrams...............................................................................................203
21.9. Asynchronous Operation of the Timer/Counter........................................................................ 205
21.10. Timer/Counter Prescaler.......................................................................................................... 206
21.11. Register Description................................................................................................................. 207
22. 8-bit Timer/Counter2 with PWM.............................................................................217
22.1.
22.2.
22.3.
22.4.
22.5.
22.6.
22.7.
22.8.
22.9.
Features................................................................................................................................... 217
Overview...................................................................................................................................217
Timer/Counter Clock Sources.................................................................................................. 218
Counter Unit............................................................................................................................. 218
Output Compare Unit................................................................................................................219
Compare Match Output Unit.....................................................................................................221
Modes of Operation..................................................................................................................222
Timer/Counter Timing Diagrams...............................................................................................226
Register Description................................................................................................................. 227
23. Output Compare Modulator (OCM1C2).................................................................235
23.1. Overview...................................................................................................................................235
23.2. Description................................................................................................................................235
24. SPI – Serial Peripheral Interface........................................................................... 237
24.1.
24.2.
24.3.
24.4.
24.5.
Features................................................................................................................................... 237
Overview...................................................................................................................................237
SS Pin Functionality................................................................................................................. 240
Data Modes.............................................................................................................................. 241
Register Description................................................................................................................. 242
25. USART...................................................................................................................247
25.1. Features................................................................................................................................... 247
Atmel ATmega128A [DATASHEET]
Atmel-8151J-8-bit AVR Microcontroller_Datasheet_Complete-09/2015
5