- •Features
- •Overview
- •Block Diagram
- •Pin Descriptions
- •Port A (PA7..PA0)
- •Port B (PB7..PB0)
- •Port C (PC7..PC0)
- •Port D (PD7..PD0)
- •Port E (PE7..PE0)
- •Port F (PF7..PF0)
- •Port G (PG4..PG0)
- •RESET
- •XTAL1
- •XTAL2
- •AVCC
- •AREF
- •Resources
- •Data Retention
- •Capacitive touch sensing
- •AVR CPU Core
- •Introduction
- •Status Register
- •Stack Pointer
- •I/O Memory
- •Overview
- •Timing
- •Using all Locations of External Memory Smaller than 64 Kbyte
- •Clock Systems and their Distribution
- •CPU Clock – clkCPU
- •I/O Clock – clkI/O
- •Flash Clock – clkFLASH
- •ADC Clock – clkADC
- •Clock Sources
- •Crystal Oscillator
- •External Clock
- •Idle Mode
- •Power-down Mode
- •Power-save Mode
- •Standby Mode
- •Analog Comparator
- •Brown-out Detector
- •Watchdog Timer
- •Port Pins
- •Resetting the AVR
- •Reset Sources
- •Power-on Reset
- •External Reset
- •Watchdog Reset
- •Watchdog Timer
- •Timed Sequences for Changing the Configuration of the Watchdog Timer
- •Safety Level 0
- •Safety Level 1
- •Safety Level 2
- •Interrupts
- •I/O Ports
- •Introduction
- •Configuring the Pin
- •Reading the Pin Value
- •Unconnected pins
- •Alternate Port Functions
- •Register Description for I/O Ports
- •8-bit Timer/Counter0 with PWM and Asynchronous Operation
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Normal Mode
- •Fast PWM Mode
- •8-bit Timer/Counter Register Description
- •Overview
- •Registers
- •Definitions
- •Compatibility
- •Counter Unit
- •Input Capture Unit
- •Noise Canceler
- •Force Output Compare
- •Normal Mode
- •Fast PWM Mode
- •16-bit Timer/Counter Register Description
- •Internal Clock Source
- •Prescaler Reset
- •External Clock Source
- •8-bit Timer/Counter2 with PWM
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Normal Mode
- •Fast PWM Mode
- •8-bit Timer/Counter Register Description
- •Output Compare Modulator (OCM1C2)
- •Overview
- •Description
- •Timing Example
- •Slave Mode
- •Master Mode
- •Data Modes
- •USART
- •Dual USART
- •Overview
- •AVR USART vs. AVR UART – Compatibility
- •Clock Generation
- •External Clock
- •Frame Formats
- •Parity Bit Calculation
- •Parity Generator
- •Receiver Error Flags
- •Parity Checker
- •Disabling the Receiver
- •Using MPCM
- •Features
- •TWI Terminology
- •Transferring Bits
- •Address Packet Format
- •Data Packet Format
- •Overview of the TWI Module
- •Scl and SDA Pins
- •Bus Interface Unit
- •Address Match Unit
- •Control Unit
- •Using the TWI
- •Master Receiver Mode
- •Slave Receiver Mode
- •Miscellaneous States
- •Analog Comparator
- •Analog to Digital Converter
- •Features
- •Operation
- •Changing Channel or Reference Selection
- •ADC Input Channels
- •Analog Input Circuitry
- •Features
- •Overview
- •TAP Controller
- •PRIVATE0; $8
- •PRIVATE1; $9
- •PRIVATE2; $A
- •PRIVATE3; $B
- •Bibliography
- •Features
- •System Overview
- •Data Registers
- •Bypass Register
- •Reset Register
- •EXTEST; $0
- •IDCODE; $1
- •AVR_RESET; $C
- •BYPASS; $F
- •Scanning the ADC
- •ATmega128 Boundary-scan Order
- •Application Section
- •Programming Time for Flash when Using SPM
- •Simple Assembly Code Example for a Boot Loader
- •Fuse Bits
- •Latching of Fuses
- •Signature Bytes
- •Calibration Byte
- •Signal Names
- •Chip Erase
- •Reading the Flash
- •Reading the EEPROM
- •Data Polling Flash
- •Data Polling EEPROM
- •AVR_RESET ($C)
- •PROG_ENABLE ($4)
- •Data Registers
- •Reset Register
- •Programming Enable Register
- •Programming Command Register
- •Virtual Flash Page Read Register
- •Performing Chip Erase
- •Reading the Flash
- •Reading the EEPROM
- •Electrical Characteristics
- •Absolute Maximum Ratings*
- •DC Characteristics
- •Speed Grades
- •External Clock Drive Waveforms
- •External Clock Drive
- •Two-wire Serial Interface Characteristics
- •ADC Characteristics
- •External Data Memory Timing
- •Idle Supply Current
- •Pin Pull-up
- •Pin Driver Strength
- •Register Summary
- •Instruction Set Summary
- •Ordering Information
- •Packaging Information
- •Errata
- •ATmega128 Rev. F to M
ATmega128
Table 103. Boundary-scan Signals for the Analog Comparator
|
Direction as |
|
Recommended |
Output values when |
Signal |
Seen from the |
|
Input when not |
Recommended |
Name |
Comparator |
Description |
in Use |
Inputs are Used |
|
|
|
|
|
AC_IDLE |
Input |
Turns off Analog |
1 |
Depends upon µC |
|
|
comparator when |
|
code being executed |
|
|
true |
|
|
|
|
|
|
|
ACO |
Output |
Analog |
Will become |
0 |
|
|
Comparator |
input to µC code |
|
|
|
Output |
being executed |
|
|
|
|
|
|
ACME |
Input |
Uses output |
0 |
Depends upon µC |
|
|
signal from ADC |
|
code being executed |
|
|
mux when true |
|
|
|
|
|
|
|
ACBG |
Input |
Bandgap |
0 |
Depends upon µC |
|
|
Reference enable |
|
code being executed |
|
|
|
|
|
Scanning the ADC Figure 131 shows a block diagram of the ADC with all relevant control and observe signals. The Boundary-scan cell from Figure 127 is attached to each of these signals. The ADC need not be used for pure connectivity testing, since all analog inputs are shared with a digital port pin as well.
Figure 131. Analog to Digital Converter
|
|
VCCREN |
|
|
|
|
|
|
AREF |
|
|
|
|
|
|
IREFEN |
|
|
|
|
|
To Comparator |
2.56V |
|
|
|
|
|
ref |
|
|
|
|
|
MUXEN_7 |
|
PASSEN |
|
|
|
|
|
|
|
|
|
|
|
ADC_7 |
|
|
|
|
|
|
MUXEN_6 |
|
|
|
|
|
|
ADC_6 |
|
|
|
|
|
|
MUXEN_5 |
|
|
|
|
|
|
ADC_5 |
|
|
|
|
|
|
MUXEN_4 |
SCTEST |
ADCBGEN |
|
|
|
|
ADC_4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
EXTCH |
|
1.22V |
PRECH |
PRECH |
|
|
|
|
ref |
|
AREF |
|
|
MUXEN_3 |
|
|
|
|
||
|
|
|
AREF |
|
|
|
|
|
|
|
|
|
|
ADC_3 |
|
|
|
|
DACOUT |
|
MUXEN_2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
ADC_2 |
|
|
DAC_9..0 |
10-bit DAC |
+ |
|
MUXEN_1 |
|
|
|
COMP |
||
|
G20 |
|
|
COMP |
||
ADC_1 |
G10 |
|
|
- |
|
|
|
ADCEN |
|
|
|||
MUXEN_0 |
|
|
|
|
|
|
|
ACTEN |
|
|
|
|
|
ADC_0 |
+ |
|
|
|
|
|
+ |
|
|
|
|
||
|
|
|
|
|
||
NEGSEL_2 |
10x |
20x |
HOLD |
|
|
|
ADC_2 |
- |
- |
|
|
|
|
NEGSEL_1 |
|
GNDEN |
|
|
|
|
ADC_1 |
|
|
|
|
|
|
ST |
|
|
|
|
|
|
NEGSEL_0 |
|
|
|
|
|
|
ACLK |
|
|
|
|
|
|
ADC_0 |
|
|
|
|
|
|
AMPEN |
|
|
|
|
|
|
|
|
|
|
|
|
The signals are described briefly in Table 104.
261
2467X–AVR–06/11
ATmega128
Table 104. Boundary-scan Signals for the ADC
|
|
Direction |
|
Recommended |
Output Values when |
|
|
|
as Seen |
|
Input |
Recommended Inputs |
|
|
Signal |
from the |
|
when not |
are Used, and CPU is |
|
|
Name |
ADC |
Description |
in Use |
not Using the ADC |
|
|
|
|
|
|
|
|
|
COMP |
Output |
Comparator Output |
0 |
0 |
|
|
|
|
|
|
|
|
|
ACLK |
Input |
Clock signal to gain stages |
0 |
0 |
|
|
|
|
|
implemented as Switch- |
|
|
|
|
|
|
cap filters |
|
|
|
|
|
|
|
|
|
|
ACTEN |
Input |
Enable path from gain |
0 |
0 |
|
|
|
|
|
stages to the comparator |
|
|
|
|
|
|
|
|
|
|
ADCBGEN |
Input |
Enable Band-gap |
0 |
0 |
|
|
|
|
|
reference as negative |
|
|
|
|
|
|
input to comparator |
|
|
|
|
|
|
|
|
|
|
ADCEN |
Input |
Power-on signal to the |
0 |
0 |
|
|
|
|
|
ADC |
|
|
|
|
|
|
|
|
|
|
AMPEN |
Input |
Power-on signal to the |
0 |
0 |
|
|
|
|
|
gain stages |
|
|
|
|
|
|
|
|
|
|
DAC_9 |
Input |
Bit 9 of digital value to DAC |
1 |
1 |
|
|
|
|
|
|
|
|
|
DAC_8 |
Input |
Bit 8 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
DAC_7 |
Input |
Bit 7 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
DAC_6 |
Input |
Bit 6 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
DAC_5 |
Input |
Bit 5 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
DAC_4 |
Input |
Bit 4 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
DAC_3 |
Input |
Bit 3 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
DAC_2 |
Input |
Bit 2 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
DAC_1 |
Input |
Bit 1 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
DAC_0 |
Input |
Bit 0 of digital value to DAC |
0 |
0 |
|
|
|
|
|
|
|
|
|
EXTCH |
Input |
Connect ADC channels 0 - |
1 |
1 |
|
|
|
|
|
3 to by-pass path around |
|
|
|
|
|
|
gain stages |
|
|
|
|
|
|
|
|
|
|
G10 |
Input |
Enable 10x gain |
0 |
0 |
|
|
|
|
|
|
|
|
|
G20 |
Input |
Enable 20x gain |
0 |
0 |
|
|
|
|
|
|
|
|
|
GNDEN |
Input |
Ground the negative input |
0 |
0 |
|
|
|
|
|
to comparator when true |
|
|
|
|
|
|
|
|
|
|
HOLD |
Input |
Sample & Hold signal. |
1 |
1 |
|
|
|
|
|
Sample analog signal |
|
|
|
|
|
|
when low. Hold signal |
|
|
|
|
|
|
when high. If gain stages |
|
|
|
|
|
|
are used, this signal must |
|
|
|
|
|
|
go active when ACLK is |
|
|
|
|
|
|
high. |
|
|
|
|
|
|
|
|
|
|
IREFEN |
Input |
Enables Band-gap |
0 |
0 |
|
|
|
|
|
reference as AREF signal |
|
|
|
|
|
|
to DAC |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
2467X–AVR–06/11
|
|
|
|
|
|
|
|
ATmega128 |
|
|
|
|
|
|
|
|
|
|
|
Table 104. |
Boundary-scan Signals for the ADC (Continued) |
|
||||
|
|
|
|
|||||
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
Direction |
|
Recommended |
Output Values when |
|
|
|
|
|
as Seen |
|
Input |
Recommended Inputs |
|
|
|
Signal |
|
from the |
|
when not |
are Used, and CPU is |
|
|
|
Name |
|
ADC |
Description |
in Use |
not Using the ADC |
|
|
|
|
|
|
|
|
|
|
|
|
MUXEN_7 |
|
Input |
Input Mux bit 7 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
MUXEN_6 |
|
Input |
Input Mux bit 6 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
MUXEN_5 |
|
Input |
Input Mux bit 5 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
MUXEN_4 |
|
Input |
Input Mux bit 4 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
MUXEN_3 |
|
Input |
Input Mux bit 3 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
MUXEN_2 |
|
Input |
Input Mux bit 2 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
MUXEN_1 |
|
Input |
Input Mux bit 1 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
MUXEN_0 |
|
Input |
Input Mux bit 0 |
1 |
1 |
|
|
|
|
|
|
|
|
|
|
|
|
NEGSEL_2 |
|
Input |
Input Mux for negative |
0 |
0 |
|
|
|
|
|
|
input for differential signal, |
|
|
|
|
|
|
|
|
bit 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NEGSEL_1 |
|
Input |
Input Mux for negative |
0 |
0 |
|
|
|
|
|
|
input for differential signal, |
|
|
|
|
|
|
|
|
bit 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NEGSEL_0 |
|
Input |
Input Mux for negative |
0 |
0 |
|
|
|
|
|
|
input for differential signal, |
|
|
|
|
|
|
|
|
bit 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PASSEN |
|
Input |
Enable pass-gate of gain |
1 |
1 |
|
|
|
|
|
|
stages. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRECH |
|
Input |
Precharge output latch of |
1 |
1 |
|
|
|
|
|
|
comparator. (Active low) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SCTEST |
|
Input |
Switch-cap TEST enable. |
0 |
0 |
|
|
|
|
|
|
Output from x10 gain |
|
|
|
|
|
|
|
|
stage send out to Port Pin |
|
|
|
|
|
|
|
|
having ADC_4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST |
|
Input |
Output of gain stages will |
0 |
0 |
|
|
|
|
|
|
settle faster if this signal is |
|
|
|
|
|
|
|
|
high first two ACLK |
|
|
|
|
|
|
|
|
periods after AMPEN goes |
|
|
|
|
|
|
|
|
high. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VCCREN |
|
Input |
Selects Vcc as the ACC |
0 |
0 |
|
|
|
|
|
|
reference voltage. |
|
|
|
|
|
|
|
|
|
|
|
|
Note: Incorrect setting of the switches in Figure 131 will make signal contention and may damage the part. There are several input choices to the S&H circuitry on the negative input of the output comparator in Figure 131. Make sure only one path is selected from either one ADC pin, Bandgap reference source, or Ground.
If the ADC is not to be used during scan, the recommended input values from Table 104 should be used. The user is recommended not to use the Differential Gain stages during scan. SwitchCap based gain stages require fast operation and accurate timing which is difficult to obtain when used in a scan chain. Details concerning operations of the differential gain stage is therefore not provided.
263
2467X–AVR–06/11
ATmega128
The Atmel® AVR® ADC is based on the analog circuitry shown in Figure 131 with a successive approximation algorithm implemented in the digital logic. When used in Boundary-scan, the problem is usually to ensure that an applied analog voltage is measured within some limits. This can easily be done without running a successive approximation algorithm: apply the lower limit on the digital DAC[9:0] lines, make sure the output from the comparator is low, then apply the upper limit on the digital DAC[9:0] lines, and verify the output from the comparator to be high.
The ADC need not be used for pure connectivity testing, since all analog inputs are shared with a digital port pin as well.
When using the ADC, remember the following
•The Port Pin for the ADC channel in use must be configured to be an input with pull-up disabled to avoid signal contention.
•In normal mode, a dummy conversion (consisting of 10 comparisons) is performed when enabling the ADC. The user is advised to wait at least 200ns after enabling the ADC before controlling/observing any ADC signal, or perform a dummy conversion before using the first result.
•The DAC values must be stable at the midpoint value 0x200 when having the HOLD signal low (Sample mode).
As an example, consider the task of verifying a 1.5V ±5% input signal at ADC channel 3 when the power supply is 5.0V and AREF is externally connected to VCC.
The lower limit is: |
|
|
1024 1.5V 0,95 ⁄ 5V |
|
|
= 291 = 0x123 |
|
|
|
|
|
||||
The upper limit is: |
|
|
|
1024 1.5V 1.05 ⁄ 5V |
|
= 323 = 0x143 |
The recommended values from Table 104 are used unless other values are given in the algorithm in Table 105. Only the DAC and Port Pin values of the Scan Chain are shown. The column “Actions” describes what JTAG instruction to be used before filling the Boundary-scan Register with the succeeding columns. The verification should be done on the data scanned out when scanning in the data on the same row in the table.
Table 105. Algorithm for Using the ADC
|
|
|
|
|
|
|
|
|
PA3. |
|
|
|
|
|
|
|
|
PA3. |
PA3. |
Pullup_ |
|
Step |
Actions |
ADCEN |
DAC |
MUXEN |
HOLD |
PRECH |
Data |
Control |
Enable |
|
|
|
|
|
|
|
|
|
|
|
|
1 |
SAMPLE_ |
1 |
0x200 |
0x08 |
1 |
1 |
0 |
0 |
0 |
|
PRELOAD |
||||||||||
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
2 |
EXTEST |
1 |
0x200 |
0x08 |
0 |
1 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
1 |
0x200 |
0x08 |
1 |
1 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
1 |
0x123 |
0x08 |
1 |
1 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
1 |
0x123 |
0x08 |
1 |
0 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
Verify the |
|
|
|
|
|
|
|
|
|
6 |
COMP bit |
1 |
0x200 |
0x08 |
1 |
1 |
0 |
0 |
0 |
|
scanned |
||||||||||
|
|
|
|
|
|
|
|
|
||
|
out to be 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
1 |
0x200 |
0x08 |
0 |
1 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
1 |
0x200 |
0x08 |
1 |
1 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
264
2467X–AVR–06/11
ATmega128
Table 105. Algorithm for Using the ADC
|
|
|
|
|
|
|
|
|
PA3. |
|
|
|
|
|
|
|
|
PA3. |
PA3. |
Pullup_ |
|
Step |
Actions |
ADCEN |
DAC |
MUXEN |
HOLD |
PRECH |
Data |
Control |
Enable |
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
1 |
0x143 |
0x08 |
1 |
1 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
1 |
0x143 |
0x08 |
1 |
0 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
Verify the |
|
|
|
|
|
|
|
|
|
11 |
COMP bit |
1 |
0x200 |
0x08 |
1 |
1 |
0 |
0 |
0 |
|
scanned |
||||||||||
|
|
|
|
|
|
|
|
|
||
|
out to be 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Using this algorithm, the timing constraint on the HOLD signal constrains the TCK clock frequency. As the algorithm keeps HOLD high for five steps, the TCK clock frequency has to be at least five times the number of scan bits divided by the maximum hold time, thold,max
265
2467X–AVR–06/11