- •Features
- •Pin Configurations
- •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
- •AVR CPU Core
- •Introduction
- •Architectural Overview
- •Status Register
- •Stack Pointer
- •Interrupt Response Time
- •SRAM Data Memory
- •Data Memory Access Times
- •EEPROM Data Memory
- •EEPROM Read/Write Access
- •I/O Memory
- •Overview
- •ATmega103 Compatibility
- •Address Latch Requirements
- •Pull-up and Bus-keeper
- •Timing
- •XMEM Register Description
- •Using all 64KB Locations of External Memory
- •Clock Systems and their Distribution
- •CPU Clock – clkCPU
- •I/O Clock – clkI/O
- •Flash Clock – clkFLASH
- •ADC Clock – clkADC
- •Clock Sources
- •Crystal Oscillator
- •External RC Oscillator
- •External Clock
- •Timer/Counter Oscillator
- •Idle Mode
- •Power-down Mode
- •Power-save Mode
- •Standby Mode
- •Extended Standby Mode
- •Analog to Digital Converter
- •Analog Comparator
- •Brown-out Detector
- •Internal Voltage Reference
- •Watchdog Timer
- •Port Pins
- •System Control and Reset
- •Resetting the AVR
- •Reset Sources
- •Power-on Reset
- •External Reset
- •Brown-out Detection
- •Watchdog Reset
- •Watchdog Timer
- •Timed Sequences for Changing the Configuration of the Watch Dog Timer
- •Safety Level 0
- •Safety Level 1
- •Safety Level 2
- •Interrupts
- •I/O-Ports
- •Introduction
- •Configuring the Pin
- •Reading the Pin Value
- •Alternate Port Functions
- •Alternate Functions of Port A
- •Alternate Functions of Port B
- •Alternate Functions of Port C
- •Alternate Functions of Port D
- •Alternate Functions of Port E
- •Alternate Functions of Port F
- •Alternate Functions of Port G
- •Port A Data Register – PORTA
- •Port B Data Register – PORTB
- •Port C Data Register – PORTC
- •Port D Data Register – PORTD
- •Port E Data Register – PORTE
- •Port F Data Register – PORTF
- •Port G Data Register – PORTG
- •External Interrupts
- •8-bit Timer/Counter0 with PWM and Asynchronous Operation
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Output Compare Unit
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •Timer/Counter Prescaler
- •16-bit Timer/Counter (Timer/Counter1 and Timer/Counter3)
- •Overview
- •Registers
- •Definitions
- •Compatibility
- •Counter Unit
- •Input Capture Unit
- •Input Capture Trigger Source
- •Noise Canceler
- •Using the Input Capture Unit
- •Output Compare Units
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct 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
- •Output Compare Unit
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •Overview
- •Description
- •Timing Example
- •Slave Mode
- •Master Mode
- •SPI Control Register – SPCR
- •SPI Status Register – SPSR
- •SPI Data Register – SPDR
- •Data Modes
- •USART
- •Dual USART
- •Overview
- •AVR USART vs. AVR UART – Compatibility
- •Clock Generation
- •External Clock
- •Synchronous Clock Operation
- •Frame Formats
- •Parity Bit Calculation
- •USART Initialization
- •Sending Frames with 5 to 8 Data Bit
- •Sending Frames with 9 Data Bit
- •Parity Generator
- •Disabling the Transmitter
- •Receiving Frames with 5 to 8 Data Bits
- •Receiving Frames with 9 Data Bits
- •Receiver Error Flags
- •Parity Checker
- •Disabling the Receiver
- •Flushing the Receive Buffer
- •Asynchronous Data Recovery
- •Using MPCM
- •Two-wire Serial Interface
- •Features
- •TWI Terminology
- •Electrical Interconnection
- •Transferring Bits
- •START and STOP Conditions
- •Address Packet Format
- •Data Packet Format
- •Multi-master Bus Systems, Arbitration and Synchronization
- •Overview of the TWI Module
- •Scl and SDA Pins
- •Bit Rate Generator Unit
- •Bus Interface Unit
- •Address Match Unit
- •Control Unit
- •TWI Register Description
- •TWI Bit Rate Register – TWBR
- •TWI Control Register – TWCR
- •TWI Status Register – TWSR
- •TWI Data Register – TWDR
- •Using the TWI
- •Transmission Modes
- •Master Transmitter Mode
- •Master Receiver Mode
- •Slave Receiver Mode
- •Slave Transmitter Mode
- •Miscellaneous States
- •Analog Comparator
- •Analog Comparator Multiplexed Input
- •Analog to Digital Converter
- •Features
- •Operation
- •Starting a Conversion
- •Differential Gain Channels
- •ADC Input Channels
- •ADC Voltage Reference
- •ADC Noise Canceler
- •Analog Input Circuitry
- •ADC Accuracy Definitions
- •ADC Conversion Result
- •ADLAR = 0:
- •ADLAR = 1:
- •Features
- •Overview
- •Test Access Port – TAP
- •TAP Controller
- •PRIVATE0; $8
- •PRIVATE1; $9
- •PRIVATE2; $A
- •PRIVATE3; $B
- •Bibliography
- •Features
- •System Overview
- •Data Registers
- •Bypass Register
- •Device Identification Register
- •Reset Register
- •Boundary-scan Chain
- •EXTEST; $0
- •IDCODE; $1
- •SAMPLE_PRELOAD; $2
- •AVR_RESET; $C
- •BYPASS; $F
- •Boundary-scan Chain
- •Scanning the Digital Port Pins
- •Scanning the RESET Pin
- •Scanning the Clock Pins
- •Scanning the ADC
- •Boot Loader Features
- •Application Section
- •Boot Loader Section – BLS
- •Boot Loader Lock Bits
- •Performing a Page Write
- •Using the SPM Interrupt
- •Setting the Boot Loader Lock Bits by SPM
- •Reading the Fuse and Lock Bits from Software
- •Preventing Flash Corruption
- •Simple Assembly Code Example for a Boot Loader
- •Fuse Bits
- •Latching of Fuses
- •Signature Bytes
- •Calibration Byte
- •Signal Names
- •Parallel Programming
- •Enter Programming Mode
- •Chip Erase
- •Programming the Flash
- •Programming the EEPROM
- •Reading the Flash
- •Reading the EEPROM
- •Programming the Lock Bits
- •Reading the Signature Bytes
- •Reading the Calibration Byte
- •Serial Downloading
- •Data Polling Flash
- •Data Polling EEPROM
- •AVR_RESET ($C)
- •PROG_ENABLE ($4)
- •PROG_COMMANDS ($5)
- •PROG_PAGELOAD ($6)
- •PROG_PAGEREAD ($7)
- •Data Registers
- •Reset Register
- •Programming Enable Register
- •Virtual Flash Page Read Register
- •Programming Algorithm
- •Entering Programming Mode
- •Leaving Programming Mode
- •Performing Chip Erase
- •Programming the Flash
- •Reading the Flash
- •Programming the EEPROM
- •Reading the EEPROM
- •Programming the Fuses
- •Programming the Lock Bits
- •Reading the Signature Bytes
- •Reading the Calibration Byte
- •Electrical Characteristics
- •Absolute Maximum Ratings*
- •DC Characteristics
- •External Clock Drive Waveforms
- •External Clock Drive
- •2-wire Serial Interface Characteristics
- •ADC Characteristics - Preliminary Data
- •External Data Memory Timing
- •Ordering Information
- •Packaging Information
ATmega128(L)
In Single Conversion mode, always select the channel before starting the conversion.
The channel selection may be changed one ADC clock cycle after writing one to ADSC.
However, the simplest method is to wait for the conversion to complete before changing
|
the channel selection. |
|
In Free Running mode, always select the channel before starting the first conversion. |
|
The channel selection may be changed one ADC clock cycle after writing one to ADSC. |
|
However, the simplest method is to wait for the first conversion to complete, and then |
|
change the channel selection. Since the next conversion has already started automati- |
|
cally, the next result will reflect the previous channel selection. Subsequent conversions |
|
will reflect the new channel selection. |
|
When switching to a differential gain channel, the first conversion result may have a |
|
poor accuracy due to the required settling time for the automatic offset cancellation cir- |
|
cuitry. The user should preferably disregard the first conversion result. |
ADC Voltage Reference |
The reference voltage for the ADC (VREF) indicates the conversion range for the ADC. |
|
Single ended channels that exceed VREF will result in codes close to 0x3FF. VREF can be |
|
selected as either AVCC, internal 2.56V reference, or external AREF pin. |
|
AVCC is connected to the ADC through a passive switch. The internal 2.56V reference is |
|
generated from the internal bandgap reference (VBG) through an internal amplifier. In |
|
either case, the external AREF pin is directly connected to the ADC, and the reference |
|
voltage can be made more immune to noise by connecting a capacitor between the |
|
AREF pin and ground. VREF can also be measured at the AREF pin with a high impedant |
|
voltmeter. Note that VREF is a high impedant source, and only a capacitive load should |
|
be connected in a system. |
|
If the user has a fixed voltage source connected to the AREF pin, the user may not use |
|
the other reference voltage options in the application, as they will be shorted to the |
|
external voltage. If no external voltage is applied to the AREF pin, the user may switch |
|
between AVCC and 2.56 V as reference selection. The first ADC conversion result after |
|
switching reference voltage source may be inaccurate, and the user is advised to dis- |
|
card this result. |
|
If differential channels are used, the selected reference should not be closer to AVCC |
|
than indicated in Table 137 on page 316. |
ADC Noise Canceler The ADC features a noise canceler that enables conversion during sleep mode to reduce noise induced from the CPU core and other I/O peripherals. The noise canceler can be used with ADC Noise Reduction and Idle mode. To make use of this feature, the following procedure should be used:
1.Make sure that the ADC is enabled and is not busy converting. Single Conversion Mode must be selected and the ADC conversion complete interrupt must be enabled.
2.Enter ADC Noise Reduction mode (or Idle mode). The ADC will start a conversion once the CPU has been halted.
3.If no other interrupts occur before the ADC conversion completes, the ADC interrupt will wake up the CPU and execute the ADC Conversion Complete interrupt routine. If another interrupt wakes up the CPU before the ADC conversion is complete, that interrupt will be executed, and an ADC Conversion Complete interrupt request will be generated when the ADC conversion completes. The CPU will remain in active mode until a new sleep command is executed.
227
2467B–09/01
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note that the ADC will not be automatically turned off when entering other sleep modes |
||||||
|
than idle mode and ADC noise reduction mode. The user is advised to write zero to |
||||||
|
ADEN before entering such sleep modes to avoid excessive power consumption. If the |
||||||
|
ADC is enabled in such sleep modes and the user wants to perform differential conver- |
||||||
|
sions, the user is advised to switch the ADC off and on after waking up from sleep to |
||||||
|
prompt an extended conversion to get a valid result. |
||||||
Analog Input Circuitry |
The analog input circuitry for single ended channels is illustrated in Figure 112. An ana- |
||||||
|
log source applied to ADCn is subjected to the pin capacitance and input leakage of that |
||||||
|
pin, regardless of whether that channel is selected as input for the ADC. When the chan- |
||||||
|
nel is selected, the source must drive the S/H capacitor through the series resistance |
||||||
|
(combined resistance in the input path). |
||||||
|
The ADC is optimized for analog signals with an output impedance of approximately |
||||||
|
10 kΩ or less. If such a source is used, the sampling time will be negligible. If a source |
||||||
|
with higher impedance is used, the sampling time will depend on how long time the |
||||||
|
source needs to charge the S/H capacitor, with can vary widely. The user is recom- |
||||||
|
mended to only use high impedant sources with slowly varying signals, since this |
||||||
|
minimizes the required charge transfer to the S/H capacitor. |
||||||
|
If differential gain channels are used, the input circuitry looks somewhat different, |
||||||
|
although source impedances of a few hundred kΩ or less is recommended. |
||||||
|
Signal components higher than the Nyquist frequency (fADC / 2) should not be present |
||||||
|
for either kind of channels, to avoid distortion from unpredictable signal convolution. The |
||||||
|
user is advised to remove high frequency components with a low-pass filter before |
||||||
|
applying the signals as inputs to the ADC. |
||||||
|
Figure 112. Analog Input Circuitry |
||||||
|
|
|
|
|
|
|
|
|
|
|
|
IIH |
|||
|
|
|
|
||||
|
ADCn |
|
|
|
1..100 kΩ |
||
|
|
|
|
||||
|
|
|
|
|
|||
|
|
|
|||||
|
|
|
|
|
CS/H= 14 pF |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
IIL |
||
|
|
|
|
|
VCC/2 |
||
Analog Noise Canceling |
Digital circuitry inside and outside the device generates EMI which might affect the |
||||||
Techniques |
accuracy of analog measurements. If conversion accuracy is critical, the noise level can |
||||||
|
be reduced by applying the following techniques: |
1.Keep analog signal paths as short as possible. Make sure analog tracks run over the analog ground plane, and keep them well away from high-speed switching digital tracks.
2.The AVCC pin on the device should be connected to the digital VCC supply voltage via an LC network as shown in Figure 113.
3.Use the ADC noise canceler function to reduce induced noise from the CPU.
4.If any ADC port pins are used as digital outputs, it is essential that these do not switch while a conversion is in progress.
228 ATmega128(L)
2467B–09/01
ATmega128(L)
Figure 113. ADC Power Connections
(AD0) PA0 51
VCC
52 GND 53 (ADC7) PF7 54 (ADC6) PF6 55 (ADC5) PF5 56 (ADC4) PF4 57 (ADC3) PF3 58 (ADC2) PF2 59 (ADC1) PF1 60 (ADC0) PF0 61
10µΗ |
|
AREF 62 |
|
GND |
63 |
|
|
AVCC |
64 |
|
|
100nF |
|
Analog Ground Plane |
|
1
PEN
Offset Compensation |
The gain stage has a built-in offset cancellation circuitry that nulls the offset of differen- |
Schemes |
tial measurements as much as possible. The remaining offset in the analog path can be |
|
measured directly by selecting the same channel for both differential inputs. This offset |
|
residue can be then subtracted in software from the measurement results. Using this |
|
kind of software based offset correction, offset on any channel can be reduced below |
|
one LSB. |
ADC Accuracy Definitions |
An n-bit single-ended ADC converts a voltage linearly between GND and VREF in 2n |
|
steps (LSBs). The lowest code is read as 0, and the highest code is read as 2n-1. |
Several parameters describe the deviation from the ideal behavior:
•Offset: The deviation of the first transition (0x000 to 0x001) compared to the ideal transition (at 0.5 LSB). Ideal value: 0 LSB.
229
2467B–09/01
Figure 114. Offset Error
Output code
Ideal ADC
Actual ADC
Offset
Error
VREF Input voltage
•Gain error: After adjusting for offset, the gain error is found as the deviation of the last transition (0x3FE to 0x3FF) compared to the ideal transition (at 1.5 LSB below maximum). Ideal value: 0 LSB
Figure 115. Gain Error
Output code |
Gain |
|
|
Error |
|
|
|
Ideal ADC |
|
|
Actual ADC |
|
VREF |
Input voltage |
•Integral Non-Linearity (INL): After adjusting for offset and gain error, the INL is the maximum deviation of an actual transition compared to an ideal transition for any code. Ideal value: 0 LSB.
230 ATmega128(L)
2467B–09/01