Rainbow-electronics ATmega128L Uživatelský manuál

Procházejte online nebo si stáhněte Uživatelský manuál pro Senzory Rainbow-electronics ATmega128L. Rainbow Electronics ATmega128L User Manual Uživatelská příručka

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 331
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 0
1
Features
High-performance, Low-power AVR
®
8-bit Microcontroller
Advanced RISC Architecture
133 Powerful Instructions – Most Single Clock Cycle Execution
32 x 8 General Purpose Working Registers + Peripheral Control Registers
Fully Static Operation
Up to 16 MIPS Throughput at 16 MHz
On-chip 2-cycle Multiplier
Nonvolatile Program and Data Memories
128K Bytes of In-System Reprogrammable Flash
Endurance: 1,000 Write/Erase Cycles
Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
4K Bytes EEPROM
Endurance: 100,000 Write/Erase Cycles
4K Bytes Internal SRAM
Up to 64K Bytes 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
Programming of Flash, EEPROM, Fuses and Lock Bits through the JTAG Interface
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 1 to 16 Bits
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 2-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
Operating Voltages
2.7 - 5.5V for ATmega128L
4.5 - 5.5V for ATmega128
Speed Grades
0 - 8 MHz for ATmega128L
0 - 16 MHz for ATmega128
Rev. 2467B-09/01
8-bit
Microcontroller
with 128K Bytes
In-System
Programmable
Flash
ATmega128
ATmega128L
Preliminary
Zobrazit stránku 0
1 2 3 4 5 6 ... 330 331

Shrnutí obsahu

Strany 1 - Features

1Features• High-performance, Low-power AVR® 8-bit Microcontroller• Advanced RISC Architecture– 133 Powerful Instructions – Most Single Clock Cycle Exe

Strany 2

10ATmega128(L)2467B–09/01• Bit 7 - I: Global Interrupt EnableThe global interrupt enable bit must be set for the interrupts to be enabled. The individ

Strany 3

100ATmega128(L)2467B–09/01Note: 1. A special case occurs when OCR0 equals TOP and COM01 is set. In this case, thecompare match is ignored, but the set

Strany 4

101ATmega128(L)2467B–09/01Asynchronous Operation of the Timer/CounterAsynchronous Status Register – ASSR• Bit 3 - AS0: Asynchronous Timer/Counter0When

Strany 5

102ATmega128(L)2467B–09/01• The oscillator is optimized for use with a 32.768 kHz watch crystal. Applying an external clock to the TOSC1 pin may resul

Strany 6

103ATmega128(L)2467B–09/01read as the previous value (before entering sleep) until the next rising TOSC1 edge. The phase of the TOSC clock after wakin

Strany 7

104ATmega128(L)2467B–09/01Timer/Counter Prescaler Figure 44. Prescaler for Timer/Counter0The clock source for Timer/Counter0 is named clkT0S. clkT0S

Strany 8

105ATmega128(L)2467B–09/01• Bit 1 - PSR0: Prescaler Reset Timer/Counter0When this bit is written to one, the Timer/Counter0 prescaler will be reset. T

Strany 9

106ATmega128(L)2467B–09/0116-bit Timer/Counter (Timer/Counter1 and Timer/Counter3)The 16-bit Timer/Counter unit allows accurate program execution timi

Strany 10 - ATmega128(L)

107ATmega128(L)2467B–09/01Figure 45. 16-bit Timer/Counter Block DiagramNote: Refer to Figure 1 on page 2, Table 30 on page 69, and Table 39 on page

Strany 11

108ATmega128(L)2467B–09/01The double buffered Output Compare Registers (OCRnA/B/C) are compared with theTimer/Counter value at all time. The result of

Strany 12

109ATmega128(L)2467B–09/01• WGMn3 is added to TCCRnB.Interrupt flag and mask bits for output compare unit C are added.The 16-bit Timer/Counter has imp

Strany 13

11ATmega128(L)2467B–09/01Figure 4. AVR CPU General Purpose Working RegistersMost of the instructions operating on the Register file have direct acces

Strany 14

110ATmega128(L)2467B–09/01It is important to notice that accessing 16-bit registers are atomic operations. If an inter-rupt occurs between the two ins

Strany 15

111ATmega128(L)2467B–09/01The following code examples show how to do an atomic write of the TCNTn registercontents. Writing any of the OCRnA/B/C or IC

Strany 16

112ATmega128(L)2467B–09/01Figure 46. Counter Unit Block DiagramSignal description (internal signals):Count Increment or decrement TCNTn by 1.Directio

Strany 17

113ATmega128(L)2467B–09/01Input Capture Unit The Timer/Counter incorporates an input capture unit that can capture external eventsand give them a time

Strany 18

114ATmega128(L)2467B–09/01written to the ICRn register. When writing the ICRn register the high byte must be writtento the ICRnH I/O location before t

Strany 19

115ATmega128(L)2467B–09/01Output Compare Units The 16-bit comparator continuously compares TCNTn with the output compare register(OCRnx). If TCNT equa

Strany 20

116ATmega128(L)2467B–09/01sequence. The synchronization prevents the occurrence of odd-length, non-symmetricalPWM pulses, thereby making the output gl

Strany 21

117ATmega128(L)2467B–09/01internal OCnx register, not the OCnx pin. If a system reset occur, the OCnx register isreset to “0”.Figure 49. Compare Matc

Strany 22

118ATmega128(L)2467B–09/01inverted PWM). For non-PWM modes the COMnx1:0 bits control whether the outputshould be set, cleared or toggle at a compare m

Strany 23

119ATmega128(L)2467B–09/01counter is running with none or a low prescaler value must be done with care since theCTC mode does not have the double buff

Strany 24

12ATmega128(L)2467B–09/01Stack Pointer The stack is mainly used for storing temporary data, for storing local variables and forstoring return addresse

Strany 25

120ATmega128(L)2467B–09/01Figure 51. Fast PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOVn) is set each time the counter reaches TOP. In

Strany 26

121ATmega128(L)2467B–09/01setting (or clearing) the OCnx register at the compare match between OCRnx andTCNTn, and clearing (or setting) the OCnx regi

Strany 27

122ATmega128(L)2467B–09/01Figure 52. Phase Correct PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOVn) is set each time the counter reache

Strany 28

123ATmega128(L)2467B–09/01match between OCRnx and TCNTn when the counter decrements. The PWM frequencyfor the output when using phase correct PWM can

Strany 29

124ATmega128(L)2467B–09/01Figure 53. Phase and Frequency Correct PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOVn) is set at the same ti

Strany 30

125ATmega128(L)2467B–09/01decrements. The PWM frequency for the output when using phase and frequencycorrect PWM can be calculated by the following eq

Strany 31

126ATmega128(L)2467B–09/01Figure 55. Timer/Counter Timing Diagram, Setting of OCFnx, with Prescaler (fclk_I/O/8)Figure 56 shows the count sequence cl

Strany 32

127ATmega128(L)2467B–09/01Figure 57. Timer/Counter Timing Diagram, with Prescaler (fclk_I/O/8)16-bit Timer/Counter Register DescriptionTimer/Counter

Strany 33

128ATmega128(L)2467B–09/01Table 59 shows the COMnx1:0 bit functionality when the WGMn3:0 bits are set to thefast PWM modeNote: A special case occurs w

Strany 34

129ATmega128(L)2467B–09/01Note: A special case occurs when OCRnA/OCRnB/OCRnC equals TOP andCOMnA1/COMnB1//COMnC1 is set. See “Phase Correct PWM Mode”

Strany 35

13ATmega128(L)2467B–09/01Instruction Execution TimingThis section describes the general access timing concepts for instruction execution. TheAVR CPU i

Strany 36

130ATmega128(L)2467B–09/01Note: 1. The CTCn and PWMn1:0 bit definition names are obsolete. Use the WGMn2:0 definitions. However, the functionality and

Strany 37

131ATmega128(L)2467B–09/01• Bit 6 - ICESn: Input Capture Edge SelectThis bit selects which edge on the Input Capture Pin (ICPn) that is used to trigge

Strany 38

132ATmega128(L)2467B–09/01Timer/Counter 3 Control Register C – TCCR3C• Bit 7- FOCnA: Force Output Compare for Channel A• Bit 6- FOCnB: Force Output Co

Strany 39

133ATmega128(L)2467B–09/01Output Compare Register 1 A – OCR1AH and OCR1ALOutput Compare Register 1 B – OCR1BH and OCR1BLOutput Compare Register 1 C –

Strany 40

134ATmega128(L)2467B–09/01Input Capture Register 1 – ICR1H and ICR1LInput Capture Register 3 – ICR3H and ICR3LThe input capture is updated with the co

Strany 41

135ATmega128(L)2467B–09/01Extended Timer/Counter Interrupt Mask Register – ETIMSKNote: This register is not available in ATmega103 compatibility mode.

Strany 42

136ATmega128(L)2467B–09/01Timer/Counter Interrupt Flag Register – TIFRNote: This register contains flag bits for several timer/counters, but only time

Strany 43

137ATmega128(L)2467B–09/01ICF3 is automatically cleared when the Input Capture 3 interrupt vector is executed.Alternatively, ICF3 can be cleared by wr

Strany 44

138ATmega128(L)2467B–09/01Timer/Counter3, Timer/Counter2, and Timer/Counter1 PrescalersTimer/Counter3, Timer/Counter1, and Timer/Counter0 share the sa

Strany 45

139ATmega128(L)2467B–09/01Each half period of the external clock applied must be longer than one system clockcycle to ensure correct sampling. The ext

Strany 46

14ATmega128(L)2467B–09/01When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interruptsare disabled. The user software can

Strany 47

140ATmega128(L)2467B–09/018-bit Timer/Counter2 with PWMTimer/Counter2 is a general purpose, single channel, 8-bit Timer/Counter module. Themain featur

Strany 48

141ATmega128(L)2467B–09/01inactive when no clock source is selected. The output from the clock select logic isreferred to as the timer clock (clkT2).T

Strany 49

142ATmega128(L)2467B–09/01clear Clear TCNT2 (set all bits to zero).clkTnTimer/counter clock, referred to as clkT0 in the following.top Signalize that

Strany 50

143ATmega128(L)2467B–09/01Figure 62. Output Compare Unit, Block DiagramThe OCR2 register is double buffered when using any of the pulse width modulat

Strany 51

144ATmega128(L)2467B–09/01compare (FOC2) strobe bits in normal mode. The OC2 register keeps its value evenwhen changing between waveform generation mo

Strany 52

145ATmega128(L)2467B–09/01A change of the COM21:0 bits state will have effect at the first compare match after thebits are written. For non-PWM modes,

Strany 53

146ATmega128(L)2467B–09/01An interrupt can be generated each time the counter value reaches the TOP value byusing the OCF2 flag. If the interrupt is e

Strany 54

147ATmega128(L)2467B–09/01Figure 65. Fast PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOV2) is set each time the counter reaches Max If

Strany 55

148ATmega128(L)2467B–09/01cleared on the compare match between TCNT2 and OCR2 while upcounting, and set onthe compare match while downcounting. In inv

Strany 56

149ATmega128(L)2467B–09/01The N variable represents the prescale factor (1, 8, 64, 256, or 1024).The extreme values for the OCR2 register represent sp

Strany 57

15ATmega128(L)2467B–09/01Interrupt Response Time The interrupt execution response for all the enabled AVR interrupts is 4 clock cyclesminimum. After 4

Strany 58

150ATmega128(L)2467B–09/01Figure 69. Timer/Counter Timing Diagram, Setting of OCF2, with Prescaler (fclk_I/O/8)Figure 70 shows the setting of OCF2 an

Strany 59

151ATmega128(L)2467B–09/018-bit Timer/Counter Register DescriptionTimer/Counter Control Register – TCCR2• Bit 7 - FOC2: Force Output CompareThe FOC2 b

Strany 60

152ATmega128(L)2467B–09/01When OC2 is connected to the pin, the function of the COM21:0 bits depends on theWGM21:0 bit setting. Table 65 shows the COM

Strany 61

153ATmega128(L)2467B–09/01If external pin modes are used for the Timer/Counter2, transitions on the T2 pin willclock the counter even if the pin is co

Strany 62

154ATmega128(L)2467B–09/01• Bit 6- TOIE2: Timer/Counter2 Overflow Interrupt EnableWhen the TOIE2 bit is written to one, and the I-bit in the Status Re

Strany 63

155ATmega128(L)2467B–09/01Output Compare Modulator (OCM1C2)Overview The Output Compare Modulator (OCM) allows generation of waveforms modulated witha

Strany 64

156ATmega128(L)2467B–09/01When the modulator is enabled the type of modulation (logical AND or OR) can beselected by the PORTB7 register. Note that th

Strany 65

157ATmega128(L)2467B–09/01Serial Peripheral Interface – SPIThe Serial Peripheral Interface (SPI) allows high-speed synchronous data transferbetween th

Strany 66

158ATmega128(L)2467B–09/01When configured as a Master, the SPI interface has no automatic control of the SS line.This must be handled by user software

Strany 67

159ATmega128(L)2467B–09/01The following code examples show how to initialize the SPI as a master and how to per-form a simple transmission. DDR_SPI in

Strany 68

16ATmega128(L)2467B–09/01AVR ATmega128 MemoriesThis section describes the different memories in the ATmega128. The AVR architecturehas two main memory

Strany 69

160ATmega128(L)2467B–09/01The following code examples show how to initialize the SPI as a slave and how to per-form a simple reception.Note: 1. The ex

Strany 70

161ATmega128(L)2467B–09/01will immediately reset the send and receive logic, and drop any partially received data inthe shift register.Master Mode Whe

Strany 71

162ATmega128(L)2467B–09/01• Bit 3 - CPOL: Clock PolarityWhen this bit is written to one, SCK is high when idle. When CPOL is written to zero,SCK is lo

Strany 72

163ATmega128(L)2467B–09/01SPIF bit is cleared by first reading the SPI status register with SPIF set, then accessingthe SPI Data Register (SPDR).• Bit

Strany 73

164ATmega128(L)2467B–09/01Figure 76. SPI Transfer Format with CPHA = 0Figure 77. SPI Transfer Format with CPHA = 1Bit 1Bit 6LSBMSBSCK (CPOL = 0)mode

Strany 74

165ATmega128(L)2467B–09/01USART The Universal Synchronous and Asynchronous serial Receiver and Transmitter(USART) is a highly flexible serial communic

Strany 75

166ATmega128(L)2467B–09/01Figure 78. USART Block DiagramNote: Refer to Figure 1 on page 2, Table 36 on page 73, and Table 39 on page 76 for USARTpin

Strany 76

167ATmega128(L)2467B–09/01• Transmit Buffer Functionality• Receiver OperationHowever, the receive buffering has two improvements that will affect the

Strany 77

168ATmega128(L)2467B–09/01xcki Input from XCK pin (internal Signal). Used for synchronous slave operation.xcko Clock output to XCK pin (Internal Signa

Strany 78

169ATmega128(L)2467B–09/01External Clock External clocking is used by the synchronous slave modes of operation. The descriptionin this section refers

Strany 79

17ATmega128(L)2467B–09/01SRAM Data Memory The ATmega128 supports two different configurations for the SRAM data memory aslisted in Table 1.Figure 9 sh

Strany 80

170ATmega128(L)2467B–09/01plete frame is transmitted, it can be directly followed by a new frame, or thecommunication line can be set to an idle (high

Strany 81

171ATmega128(L)2467B–09/01that the TXC flag must be cleared before each transmission (before UDR is written) if itis used for this purpose.The followi

Strany 82

172ATmega128(L)2467B–09/01Sending Frames with 5 to 8 Data BitA data transmission is initiated by loading the transmit buffer with the data to be trans

Strany 83

173ATmega128(L)2467B–09/01Sending Frames with 9 Data BitIf 9 bit characters are used (UCSZ = 7), the ninth bit must be written to the TXB8 bit inUCSRB

Strany 84

174ATmega128(L)2467B–09/01interrupt-driven data transmission is used, the data register empty Interrupt routine musteither write new data to UDR in or

Strany 85

175ATmega128(L)2467B–09/01The following code example shows a simple USART receive function based on pollingof the Receive Complete (RXC) flag. When us

Strany 86

176ATmega128(L)2467B–09/01Receiving Frames with 9 Data BitsIf 9 bit characters are used (UCSZ=7) the ninth bit must be read from the RXB8 bit inUCSRB

Strany 87

177ATmega128(L)2467B–09/01The receive function example reads all the I/O registers into the register file before anycomputation is done. This gives an

Strany 88

178ATmega128(L)2467B–09/01The UPE bit is set if the next character that can be read from the receive buffer had aparity error when received and the pa

Strany 89

179ATmega128(L)2467B–09/01Figure 82. Start Bit SamplingWhen the clock recovery logic detects a high (idle) to low (start) transition on the RxDline,

Strany 90

18ATmega128(L)2467B–09/01The five different addressing modes for the data memory cover: Direct, Indirect with Dis-placement, Indirect, Indirect with P

Strany 91

180ATmega128(L)2467B–09/01Figure 84. Stop Bit Sampling and Next Start Bit SamplingThe same majority voting is done to the stop bit as done for the ot

Strany 92

181ATmega128(L)2467B–09/01The recommendations of the maximum receiver baud rate error was made under theassumption that the receiver and transmitter e

Strany 93

182ATmega128(L)2467B–09/01frames. When the frame type bit (the first stop or the 9th bit) is one, the frame containsan address. When the frame type bi

Strany 94

183ATmega128(L)2467B–09/01location. Reading the UDR register location will return the contents of the receive databuffer register (RXB). For 5-, 6- or

Strany 95 - Table 55 on

184ATmega128(L)2467B–09/01• Bit 2 - UPE: Parity ErrorThis bit is set if the next character in the receive buffer had a Parity Error when receivedand t

Strany 96 - OCnPCPWM

185ATmega128(L)2467B–09/01• Bit 1 - RXB8: Receive Data Bit 8RXB8 is the 9th data bit of the received character when operating with serial frames with9

Strany 97 - MAX - 1 MAX BOTTOM BOTTOM + 1

186ATmega128(L)2467B–09/01• Bit 2:1 - UCSZ1:0: Character SizeThe UCSZ1:0 bits combined with the UCSZ2 bit in UCSRB sets the number of data bits(charac

Strany 98 - Register Description

187ATmega128(L)2467B–09/01Examples of Baud Rate SettingFor standard crystal and resonator frequencies, the most commonly used baud rates forasynchrono

Strany 99

188ATmega128(L)2467B–09/0128.8k 7 0.0% 15 0.0% 8 -3.5% 16 2.1% 15 0.0% 31 0.0%38.4k 5 0.0% 11 0.0% 6 -7.0% 12 0.2% 11 0.0% 23 0.0%57.6k 3 0.0% 7 0.0%

Strany 100

189ATmega128(L)2467B–09/01Table 85. Examples of UBRR Settings for Commonly Used Oscillator Frequencies Baud Rate (bps)fosc = 16.0000 MHz fosc = 18.43

Strany 101

19ATmega128(L)2467B–09/01Figure 10. On-chip Data SRAM Access CyclesEEPROM Data Memory The ATmega128 contains 4K bytes of data EEPROM memory. It is or

Strany 102

190ATmega128(L)2467B–09/01Two-wire Serial InterfaceFeatures • Simple yet Powerful and Flexible Communication Interface, only Two Bus Lines Needed• Bot

Strany 103

191ATmega128(L)2467B–09/01allowing the pull-up resistors to pull the line high. Note that all AVR devices connected tothe TWI bus must be powered in o

Strany 104

192ATmega128(L)2467B–09/01Address Packet Format All address packets transmitted on the TWI bus are 9 bits long, consisting of 7 addressbits, one READ/

Strany 105

193ATmega128(L)2467B–09/01Figure 89. Data Packet FormatCombining Address and Data Packets Into a TransmissionA transmission basically consists of a S

Strany 106

194ATmega128(L)2467B–09/01• Different masters may use different SCL frequencies. A scheme must be devised to synchronize the serial clocks from all ma

Strany 107 - “Access

195ATmega128(L)2467B–09/01Figure 92. Arbitration Between two MastersNote that arbitration is not allowed between:• A REPEATED START condition and a d

Strany 108

196ATmega128(L)2467B–09/01Overview of the TWI ModuleThe TWI module is comprised of several submodules, as shown in Figure 93. All regis-ters drawn in

Strany 109

197ATmega128(L)2467B–09/01TWI Control Register (TWCR). When in transmitter mode, the value of the received(N)ACK bit can be determined by the value in

Strany 110

198ATmega128(L)2467B–09/01• Bits 7..0 - TWI Bit Rate RegisterTWBR selects the division factor for the bit rate generator. The bit rate generator is af

Strany 111

199ATmega128(L)2467B–09/01• Bit 3 - TWWC: TWI Write Collision FlagThe TWWC bit is set when attempting to write to the TWI Data Register – TWDR whenTWI

Strany 112 - DATABUS (8-bit)

2ATmega128(L)2467B–09/01Pin Configurations Figure 1. Pinout ATmega128Overview The ATmega128 is a low-power CMOS 8-bit microcontroller based on the AV

Strany 113

20ATmega128(L)2467B–09/01• Bits 11..0 - EEAR11..0: EEPROM AddressThe EEPROM Address Registers – EEARH and EEARL specify the EEPROM addressin the 4K by

Strany 114

200ATmega128(L)2467B–09/01data is lost in the transition from Master to Slave. Handling of the ACK bit is controlledautomatically by the TWI logic, th

Strany 115

201ATmega128(L)2467B–09/01Figure 94. Interfacing the Application to the TWI in a Typical Transmission1. The first step in a TWI transmission is to tr

Strany 116

202ATmega128(L)2467B–09/01Subsequently, a specific value must be written to TWCR, instructing the TWI hardware to transmit the data packet present in

Strany 117

203ATmega128(L)2467B–09/01Note: For I/O registers located in extended I/O map, “IN”, “OUT”, “SBIS”, “SBIC”, “CBI”, and “SBI” instructions must be repl

Strany 118 - (Toggle)

204ATmega128(L)2467B–09/01Transmission Modes The TWI can operate in one of four major modes. These are named Master Transmitter(MT), Master Receiver (

Strany 119

205ATmega128(L)2467B–09/01Figure 95. Data Transfer in Master Transmitter ModeA START condition is sent by writing the following value to TWCR:TWEN mu

Strany 120

206ATmega128(L)2467B–09/01After a repeated START condition (state $10) the 2-wire Serial Interface can access thesame slave again, or a new slave with

Strany 121

207ATmega128(L)2467B–09/01Figure 96. Formats and States in the Master Transmitter ModeMaster Receiver Mode In the master receiver mode, a number of d

Strany 122

208ATmega128(L)2467B–09/01Figure 97. Data Transfer in Master Receiver ModeA START condition is sent by writing the following value to TWCR:TWEN must

Strany 123

209ATmega128(L)2467B–09/01Figure 98. Formats and States in the Master Receiver ModeTable 88. Status Codes for Master Receiver ModeStatus Code(TWSR)P

Strany 124

21ATmega128(L)2467B–09/01The EEPROM can not be programmed during a CPU write to the Flash memory. Thesoftware must check that the Flash programming is

Strany 125 - OCnxPFCPWM

210ATmega128(L)2467B–09/01Slave Receiver Mode In the slave receiver mode, a number of data bytes are received from a master transmit-ter (see Figure 9

Strany 126 - OCRnx Value

211ATmega128(L)2467B–09/01set up with a long start-up time, the SCL line may be held low for a long time, blockingother data transmissions.Note that t

Strany 127

212ATmega128(L)2467B–09/01Figure 100. Formats and States in the Slave Receiver ModeSlave Transmitter Mode In the slave transmitter mode, a number of

Strany 128

213ATmega128(L)2467B–09/01The upper 7 bits are the address to which the 2-wire Serial Interface will respond whenaddressed by a master. If the LSB is

Strany 129

214ATmega128(L)2467B–09/01Figure 102. Formats and States in the Slave Transmitter ModeTable 90. Status Codes for Slave Transmitter ModeStatus Code(T

Strany 130

215ATmega128(L)2467B–09/01Miscellaneous States There are two status codes that do not correspond to a defined TWI state, see Table 91.Status $F8 indic

Strany 131

216ATmega128(L)2467B–09/01Multi-master Systems and ArbitrationIf multiple masters are connected to the same bus, transmissions may be initiated simul-

Strany 132

217ATmega128(L)2467B–09/01Figure 105. Possible Status Codes Caused by ArbitrationOwnAddress / General CallreceivedArbitration lost in SLATWI bus will

Strany 133

218ATmega128(L)2467B–09/01Analog Comparator The analog comparator compares the input values on the positive pin AIN0 and nega-tive pin AIN1. When the

Strany 134

219ATmega128(L)2467B–09/01• Bit 7 - ACD: Analog Comparator DisableWhen this bit is written logic one, the power to the analog comparator is switched o

Strany 135

22ATmega128(L)2467B–09/01The next code examples show assembly and C functions for reading the EEPROM. Theexamples assume that interrupts are controlle

Strany 136

220ATmega128(L)2467B–09/01Analog Comparator Multiplexed InputIt is possible to select any of the ADC7..0 pins to replace the negative input to the ana

Strany 137

221ATmega128(L)2467B–09/01Analog to Digital ConverterFeatures • 10-bit Resolution• 0.5 LSB Integral Non-linearity• ±2 LSB Absolute Accuracy• TBD - 260

Strany 138

222ATmega128(L)2467B–09/01Figure 107. Analog to Digital Converter Block SchematicADC CONVERSIONCOMPLETE IRQ8-BIT DATA BUS15 0ADC MULTIPLEXERSELECT (A

Strany 139

223ATmega128(L)2467B–09/01Operation The ADC converts an analog input voltage to a 10-bit digital value through successiveapproximation. The minimum va

Strany 140

224ATmega128(L)2467B–09/01Prescaling and Conversion TimingFigure 108. ADC PrescalerBy default, the successive approximation circuitry requires an inp

Strany 141

225ATmega128(L)2467B–09/01Figure 109. ADC Timing Diagram, First Conversion (Single Conversion Mode)Figure 110. ADC Timing Diagram, Single Conversion

Strany 142

226ATmega128(L)2467B–09/01Differential Gain Channels When using differential gain channels, certain aspects of the conversion need to betaken into con

Strany 143

227ATmega128(L)2467B–09/01In Single Conversion mode, always select the channel before starting the conversion.The channel selection may be changed one

Strany 144

228ATmega128(L)2467B–09/01Note that the ADC will not be automatically turned off when entering other sleep modesthan idle mode and ADC noise reduction

Strany 145

229ATmega128(L)2467B–09/01Figure 113. ADC Power ConnectionsOffset Compensation SchemesThe gain stage has a built-in offset cancellation circuitry tha

Strany 146

23ATmega128(L)2467B–09/01Preventing EEPROM CorruptionDuring periods of low VCC, the EEPROM data can be corrupted because the supply volt-age is too lo

Strany 147

230ATmega128(L)2467B–09/01Figure 114. Offset Error• Gain error: After adjusting for offset, the gain error is found as the deviation of the last tran

Strany 148

231ATmega128(L)2467B–09/01Figure 116. Integral Non-Linearity (INL)• Differential Non-Linearity (DNL): The maximum deviation of the actual code width

Strany 149

232ATmega128(L)2467B–09/01where VIN is the voltage on the selected input pin and VREF the selected voltage refer-ence (see Table 96 on page 233 and Ta

Strany 150 - 2467B–09/01

233ATmega128(L)2467B–09/01Example: ADMUX = 0xED (ADC3 - ADC2, 10x gain, 2.56V reference, left adjusted result) Voltage on ADC3 is 300 mV, voltage on A

Strany 151

234ATmega128(L)2467B–09/01regardless of any ongoing conversions. For a complete description of this bit, see “TheADC Data Register – ADCL and ADCH” on

Strany 152

235ATmega128(L)2467B–09/01ADC Control and Status Register A – ADCSRA• Bit 7 - ADEN: ADC EnableWriting this bit to one enables the ADC. By writing it t

Strany 153

236ATmega128(L)2467B–09/01The ADC Data Register – ADCL and ADCHADLAR = 0:ADLAR = 1:When an ADC conversion is complete, the result is found in these tw

Strany 154

237ATmega128(L)2467B–09/01Special Function IO Register – SFIOR• Bit 4 - ADHSM: ADC High Speed ModeWriting this bit to one enables the ADC High Speed M

Strany 155

238ATmega128(L)2467B–09/01JTAG Interface and On-chip Debug SystemFeatures• JTAG (IEEE std. 1149.1 Compliant) Interface• Boundary-scan Capabilities Acc

Strany 156

239ATmega128(L)2467B–09/01• TDO: Test Data Out. Serial output data from Instruction register or Data Register.The IEEE std. 1149.1 also specifies an o

Strany 157

24ATmega128(L)2467B–09/01I/O Memory The I/O space definition of the ATmega128 is shown in “Register Summary” on page323.All ATmega128 I/Os and periphe

Strany 158

240ATmega128(L)2467B–09/01Figure 120. TAP Controller State DiagramTAP Controller The TAP controller is a 16-state finite state machine that controls

Strany 159

241ATmega128(L)2467B–09/01is left by setting TMS high. While the instruction is shifted in from the TDI pin, the captured IR-state 0x01 is shifted out

Strany 160

242ATmega128(L)2467B–09/01• 2 single Program Memory break-points + 1 Data Memory break point with mask “range break point”.A debugger, like the AVR St

Strany 161

243ATmega128(L)2467B–09/01to this location. At the same time, an internal flag; I/O Debug Register Dirty – IDRD – isset to indicate to the debugger th

Strany 162

244ATmega128(L)2467B–09/01IEEE 1149.1 (JTAG) Boundary-scanFeatures • JTAG (IEEE std. 1149.1 Compliant) Interface• Boundary-scan Capabilities According

Strany 163

245ATmega128(L)2467B–09/01Capture-DR controller state. The Bypass register can be used to shorten the scan chainon a system when the other devices are

Strany 164

246ATmega128(L)2467B–09/01Figure 122. Reset RegisterBoundary-scan Chain The Boundary-scan Chain has the capability of driving and observing the logic

Strany 165

247ATmega128(L)2467B–09/01• Shift-DR: The IDCODE scan chain is shifted by the TCK input.SAMPLE_PRELOAD; $2 Mandatory JTAG instruction for pre-loading

Strany 166

248ATmega128(L)2467B–09/01Scanning the Digital Port Pins Figure 123 shows the Boundary-scan Cell for a bidirectional port pin with pull-up func-tion.

Strany 167

249ATmega128(L)2467B–09/01Figure 124. General Port Pin Schematic diagramBoundary-scan and the Two-wire InterfaceThe 2 Two-wire Interface pins SCL and

Strany 168

25ATmega128(L)2467B–09/01Figure 11. External Memory with Sector SelectNote: ATmega128 in non ATmega103 compatibility mode: Memory Configuration A is

Strany 169

250ATmega128(L)2467B–09/01Figure 125. Additional Scan Signal for the Two-wire InterfaceScanning the RESET Pin The RESET pin accepts 5V active low log

Strany 170

251ATmega128(L)2467B–09/01Figure 127. Boundary-scan Cells for Oscillators and Clock OptionsTable 102 summaries the scan registers for the external cl

Strany 171

252ATmega128(L)2467B–09/01Figure 128. Analog comparatorFigure 129. General Boundary-scan Cell used for Signals for Comparator and ADCACBGBANDGAPREFE

Strany 172

253ATmega128(L)2467B–09/01Scanning the ADC Figure 130 shows a block diagram of the ADC with all relevant control and observe sig-nals. The Boundary-sc

Strany 173

254ATmega128(L)2467B–09/01Table 104. Boundary-scan Signals for the ADC Signal NameDirection as Seenfrom theADC DescriptionRecommen-ded Input when not

Strany 174

255ATmega128(L)2467B–09/01G10 Input Enable 10x gain 0 0G20 Input Enable 20x gain 0 0GNDEN Input Ground the negative input to comparator when true00HOL

Strany 175

256ATmega128(L)2467B–09/01Note: Incorrect setting of the switches in Figure 130 will make signal contention and may dam-age the part. There are severa

Strany 176

257ATmega128(L)2467B–09/01sidered since serial scanning of the Boundary-scan register usually takes considerablylonger time.Figure 131. ADC Timing Di

Strany 177

258ATmega128(L)2467B–09/01Using this algorithm, the timing constraint on the HOLD signal constrains the TCK clockfrequency. As the algorithm keeps HOL

Strany 178

259ATmega128(L)2467B–09/01200 COMP ADC199 PRIVATE_SIGNAL1(1)198 ACLK197 ACTEN196 ADHSM195 ADCBGEN194 ADCEN193 AMPEN192 DAC_9191 DAC_8190 DAC_7189 DAC_

Strany 179

26ATmega128(L)2467B–09/01The control bits for the External Memory Interface are located in three registers, theMCU Control Register – MCUCR, the Exter

Strany 180

260ATmega128(L)2467B–09/01186 DAC_3 ADC185 DAC_2184 DAC_1183 DAC_0182 EXTCH181 G10180 G20179 GNDEN178 HOLD177 IREFEN176 MUXEN_7175 MUXEN_6174 MUXEN_51

Strany 181

261ATmega128(L)2467B–09/01159 PE0.Data Port E158 PE0.Control157 PE0.Pullup_Enable156 PE1.Data155 PE1.Control154 PE1.Pullup_Enable153 PE2.Data152 PE2.C

Strany 182

262ATmega128(L)2467B–09/01123 PB4.Data Port B122 PB4.Control121 PB4.Pullup_Enable120 PB5.Data119 PB5.Control118 PB5.Pullup_Enable117 PB6.Data116 PB6.C

Strany 183

263ATmega128(L)2467B–09/0192 PD0.Data Port D91 PD0.Control90 PD0.Pullup_Enable89 PD1.Data88 PD1.Control87 PD1.Pullup_Enable86 PD2.Data85 PD2.Control84

Strany 184

264ATmega128(L)2467B–09/0162 PC0.Data Port C61 PC0.Control60 PC0.Pullup_Enable59 PC1.Data58 PC1.Control57 PC1.Pullup_Enable56 PC2.Data55 PC2.Control54

Strany 185

265ATmega128(L)2467B–09/01Note: 1. PRIVATE_SIGNAL1 should always scanned in as zero.Boundary-scan Description Language FilesBoundary-scan Description

Strany 186

266ATmega128(L)2467B–09/01Boot Loader Support – Read-While-Write Self-ProgrammingThe Boot Loader Support provides a real Read-While-Write self-program

Strany 187

267ATmega128(L)2467B–09/01Note that the user software can never read any code that is located inside the RWWsection during a Boot Loader software oper

Strany 188

268ATmega128(L)2467B–09/01Figure 133. Memory Sections(1)Note: 1. The parameters in the figure above are given in Table on page 277.Boot Loader Lock

Strany 189

269ATmega128(L)2467B–09/01Note: 1. “1” means unprogrammed, “0” means programmedNote: 1. “1” means unprogrammed, “0´means programmedEntering the Boot L

Strany 190

27ATmega128(L)2467B–09/01The XMEM interface also provides a bus-keeper on the AD7:0 lines. The bus-keepercan be disabled and enabled in software as de

Strany 191

270ATmega128(L)2467B–09/01Store Program Memory Control Register – SPMCRThe Store Program Memory Control Register contains the control bits needed to c

Strany 192

271ATmega128(L)2467B–09/01the Z pointer. The data in R1 and R0 are ignored. The PGERS bit will auto-clear uponcompletion of a page erase, or if no SPM

Strany 193

272ATmega128(L)2467B–09/01Figure 134. Addressing the Flash During SPM(1)Note: 1. The different variables used in Figure 134 are listed in Table 114 o

Strany 194

273ATmega128(L)2467B–09/01Performing Page Erase by SPMTo execute page erase, set up the address in the Z pointer, write “X0000011” to SPMCRand execute

Strany 195

274ATmega128(L)2467B–09/01See Table 109 and Table 110 for how the different settings of the Boot Loader Bitsaffect the Flash access.If bits 5..2 in R0

Strany 196

275ATmega128(L)2467B–09/01Fuse and Lock bits that are programmed, will be read as zero. Fuse and Lock bits thatare unprogrammed, will be read as one.P

Strany 197

276ATmega128(L)2467B–09/01ldi spmcrval, (1<<RWWSRE) | (1<<SPMEN)call Do_spm; transfer data from RAM to Flash page bufferldi looplo, low(PA

Strany 198

277ATmega128(L)2467B–09/01spm; restore SREG (to enable interrupts if originally enabled)out SREG, temp2retATmega128 Boot Loader ParametersIn Table 113

Strany 199

278ATmega128(L)2467B–09/01Notes: 1. The Z-register is only 15 bits wide. Bit 16 is located in the RAMPZ register in the I/Omap.2. Z0: should be zero f

Strany 200

279ATmega128(L)2467B–09/01Memory ProgrammingProgram and Data Memory Lock BitsThe ATmega128 provides six Lock bits which can be left unprogrammed (“1”)

Strany 201

28ATmega128(L)2467B–09/01Figure 14. External Data Memory Cycles with SRWn1 = 0 and SRWn0 = 1(1)Note: 1. SRWn1 = SRW11 (upper sector) or SRW01 (lower

Strany 202

280ATmega128(L)2467B–09/01Notes: 1. Program the fuse bits before programming the Lock bits.2. “1” means unprogrammed, “0´means programmedFuse Bits The

Strany 203

281ATmega128(L)2467B–09/01Notes: 1. The SPIEN fuse is not accessible in serial programming mode.2. The CKOPT fuse functionality depends on the setting

Strany 204

282ATmega128(L)2467B–09/01Signature Bytes All Atmel microcontrollers have a three-byte signature code which identifies the device.This code can be rea

Strany 205

283ATmega128(L)2467B–09/01Table 121. Pin Name Mapping Signal Name in Programming Mode Pin Name I/O FunctionRDY/BSYPD1 O0: Device is busy programming,

Strany 206

284ATmega128(L)2467B–09/01Parallel ProgrammingEnter Programming Mode The following algorithm puts the device in parallel programming mode:1. Apply 4.5

Strany 207

285ATmega128(L)2467B–09/013. Set DATA to “1000 0000”. This is the command for Chip Erase.4. Give XTAL1 a positive pulse. This loads the command.5. Giv

Strany 208

286ATmega128(L)2467B–09/01H. Program Page1. Set BS1 = “0”2. Give WR a negative pulse. This starts programming of the entire page of data. RDY/BSYgoes

Strany 209

287ATmega128(L)2467B–09/01Figure 137. Programming the Flash WaveformsNote: “XX” is don’t care. The letters refer to the programming description above

Strany 210

288ATmega128(L)2467B–09/01Figure 138. Programming the EEPROM WaveformsReading the Flash The algorithm for reading the Flash memory is as follows (ref

Strany 211

289ATmega128(L)2467B–09/01Programming the Fuse High BitsThe algorithm for programming the Fuse high bits is as follows (refer to “Programmingthe Flash

Strany 212

29ATmega128(L)2467B–09/01Figure 16. External Data Memory Cycles with SRWn1 = 1 and SRWn0 = 1(1)Note: 1. SRWn1 = SRW11 (upper sector) or SRW01 (lower

Strany 213

290ATmega128(L)2467B–09/01Figure 139. Mapping Between BS1, BS2 and the Fuse- and Lock Bits During ReadReading the Signature Bytes The algorithm for r

Strany 214

291ATmega128(L)2467B–09/01Figure 141. Parallel Programming Timing, Loading Sequence with TimingRequirementsNote: The timing requirements shown in Fig

Strany 215

292ATmega128(L)2467B–09/01Notes: 1. tWLRH is valid for the Write Flash, Write EEPROM, Write Fuse Bits and Write LockBits commands.2. tWLRH_CE is val

Strany 216

293ATmega128(L)2467B–09/01Figure 143. Serial Programming and VerifyNote: If the device is clocked by the internal oscillator, it is no need to connec

Strany 217

294ATmega128(L)2467B–09/01ing the third byte of the Programming Enable instruction. Whether the echo is correct or not, all 4 bytes of the instruction

Strany 218

295ATmega128(L)2467B–09/01least tWD_EEPROM before programming the next byte. See Table 129 for tWD_EEPROMvalue.Figure 144. .Serial Programming Wavefo

Strany 219

296ATmega128(L)2467B–09/01Note: a = address high bitsb = address low bitsH = 0 - Low byte, 1 - High Byteo = data outi = data inx = don’t careWrite Fus

Strany 220

297ATmega128(L)2467B–09/01Serial Programming CharacteristicsFigure 145. Serial Programming TimingNote: 2 tCLCL for fck < 12 MHz, 3 tCLCL for fck &

Strany 221

298ATmega128(L)2467B–09/01Figure 146. State Machine Sequence for Changing the Instruction WordAVR_RESET ($C) The AVR specific public JTAG instruction

Strany 222

299ATmega128(L)2467B–09/01PROG_COMMANDS ($5) The AVR specific public JTAG instruction for entering programming commands via theJTAG port. The 15-bit P

Strany 223

3ATmega128(L)2467B–09/01Block DiagramFigure 2. Block DiagramPROGRAMCOUNTERINTERNALOSCILLATORWATCHDOGTIMERSTACKPOINTERPROGRAMFLASHMCU CONTROLREGISTERS

Strany 224

30ATmega128(L)2467B–09/01• Bit 6..4 - SRL2, SRL1, SRL0: Wait-state Sector LimitIt is possible to configure different wait-states for different externa

Strany 225

300ATmega128(L)2467B–09/01When the contents of the register is equal to the programming enable signature, pro-gramming via the JTAG port is enabled. T

Strany 226

301ATmega128(L)2467B–09/01Figure 148. Programming Command RegisterTDITDOSTROBESADDRESS/DATAFlashEEPROMFusesLock Bits

Strany 227

302ATmega128(L)2467B–09/01Table 132. JTAG Programming Instruction Set a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte,

Strany 228

303ATmega128(L)2467B–09/015c. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx5d. Read Data Byte 0110011_bbbbbbbb0110010_000000000110011_000000

Strany 229

304ATmega128(L)2467B–09/01Notes: 1. This command sequence is not required if the seven MSB are correctly set by the previous command sequence (which i

Strany 230

305ATmega128(L)2467B–09/01Figure 149. State Machine Sequence for Changing/Reading the Data WordVirtual Flash Page Load RegisterThe Virtual Flash Page

Strany 231

306ATmega128(L)2467B–09/01Figure 150. Virtual Flash Page Load RegisterVirtual Flash Page Read RegisterThe Virtual Flash Page Read register is a virtu

Strany 232

307ATmega128(L)2467B–09/01Entering Programming Mode 1. Enter JTAG instruction AVR_RESET and shift 1 in the Reset register.2. Enter instruction PROG_EN

Strany 233

308ATmega128(L)2467B–09/017. Write the page using programming instruction 2g.8. Poll for Flash write complete using programming instruction 2h, or wai

Strany 234

309ATmega128(L)2467B–09/01Programming the Fuses 1. Enter JTAG instruction PROG_COMMANDS.2. Enable Fuse write using programming instruction 6a.3. Load

Strany 235

31ATmega128(L)2467B–09/01• Bit 0 - Res: Reserved BitThis is a reserved bit and will always read as zero. When writing to this address location,write t

Strany 236

310ATmega128(L)2467B–09/01Electrical CharacteristicsAbsolute Maximum Ratings*DC CharacteristicsOperating Temperature...

Strany 237

311ATmega128(L)2467B–09/01Notes: 1. “Max” means the highest value where the pin is guaranteed to be read as low2. “Min” means the lowest value where t

Strany 238

312ATmega128(L)2467B–09/01External Clock Drive WaveformsFigure 152. External Clock Drive WaveformsExternal Clock DriveNote: R should be in the range

Strany 239

313ATmega128(L)2467B–09/012-wire Serial Interface CharacteristicsTable 135 describes the requirements for devices connected to the 2-wire Serial Bus.

Strany 240

314ATmega128(L)2467B–09/015. This requirement applies to all ATmega128 2-wire Serial Interface operation. Otherdevices connected to the 2-wire Serial

Strany 241

315ATmega128(L)2467B–09/01Figure 154. SPI Interface Timing Requirements (Master Mode)Figure 155. SPI Interface Timing Requirements (Slave Mode)MOSI(

Strany 242

316ATmega128(L)2467B–09/01ADC Characteristics - Preliminary DataNote: 1. Values are guidelines only. Actual values are TBD.2. Minimum for AVCC is 2.7

Strany 243

317ATmega128(L)2467B–09/01External Data Memory TimingNotes: 1. This assumes 50% clock duty cycle. The half period is actually the high time of the ext

Strany 244

318ATmega128(L)2467B–09/01Table 140. External Data Memory Characteristics, 4.5 - 5.5 Volts, SRWn1 = 1, SRWn0 = 0Symbol Parameter4 MHz Oscillator Vari

Strany 245

319ATmega128(L)2467B–09/01Notes: 1. This assumes 50% clock duty cycle. The half period is actually the high time of the external clock, XTAL1.2. This

Strany 246

32ATmega128(L)2467B–09/01Using all 64KB Locations of External MemorySince the external memory is mapped after the internal memory as shown in Figure 1

Strany 247

320ATmega128(L)2467B–09/01Figure 156. External Memory Timing (SRWn1 = 0, SRWn0 = 0Figure 157. External Memory Timing (SRWn1 = 0, SRWn0 = 1)ALET1 T2

Strany 248

321ATmega128(L)2467B–09/01Figure 158. External Memory Timing (SRWn1 = 1, SRWn0 = 0)Figure 159. External Memory Timing (SRWn1 = 1, SRWn0 = 1)(1)Note:

Strany 249

322ATmega128(L)2467B–09/01ATmega128 Typical Characteristics – Preliminary DataThe following charts show typical behavior. These figures are not tested

Strany 250

323ATmega128(L)2467B–09/01Register Summary Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page($FF) Reserved - - - - - - - -.. Reserved

Strany 251 - Oscillator

324ATmega128(L)2467B–09/01($61) DDRF DDF7 DDF6 DDF5 DDF4 DDF3 DDF2 DDF1 DDF0 83($60) Reserved - - - - - - - -$3F ($5F) SREG I T H S V N Z C 9$3E ($5E)

Strany 252

325ATmega128(L)2467B–09/01Notes: 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory ad

Strany 253

326ATmega128(L)2467B–09/01Instruction Set Summary Mnemonics Operands Description Operation Flags #ClocksARITHMETIC AND LOGIC INSTRUCTIONSADD Rd, Rr Ad

Strany 254

327ATmega128(L)2467B–09/01Mnemonics Operands Description Operation Flags #ClocksBRIE k Branch if Interrupt Enabled if ( I = 1) then PC ← PC + k + 1 N

Strany 255

328ATmega128(L)2467B–09/01Mnemonics Operands Description Operation Flags #ClocksSEV Set Twos Complement Overflow. V ← 1V1CLV Clear Twos Complement Ove

Strany 256

329ATmega128(L)2467B–09/01Ordering InformationSpeed (MHz) Power Supply Ordering Code Package Operation Range8 2.7 - 5.5V ATmega128-8AC 64A Commercial(

Strany 257

33ATmega128(L)2467B–09/01System Clock and Clock OptionsClock Systems and their DistributionFigure 17 presents the principal clock systems in the AVR a

Strany 258

330ATmega128(L)2467B–09/01Packaging Information64APIN 1 ID0.80(0.0315) BSC16.25(0.640)SQSQ15.75(0.620)0.45(0.018)0.30(0.012)14.10(0.555)13.90(0.547)0.

Strany 259

© Atmel Corporation 2001.Atmel Corporation makes no warranty for the use of its products, other than those expressly contained in the Company’s standa

Strany 260

34ATmega128(L)2467B–09/01Asynchronous Timer Clock – clkASYThe Asynchronous Timer clock allows the Asynchronous Timer/Counter to be clockeddirectly fro

Strany 261

35ATmega128(L)2467B–09/01For resonators, the maximum frequency is 8 MHz with CKOPT unprogrammed and 16MHz with CKOPT programmed. C1 and C2 should alwa

Strany 262

36ATmega128(L)2467B–09/01Notes: 1. These options should only be used when not operating close to the maximum fre-quency of the device, and only if fre

Strany 263

37ATmega128(L)2467B–09/01Note: 1. These options should only be used if frequency stability at start-up is not importantfor the application.External RC

Strany 264

38ATmega128(L)2467B–09/01Calibrated Internal RC OscillatorThe calibrated internal RC oscillator provides a fixed 1.0 MHz, 2.0 MHz, 4.0 MHz, or 8.0MHz

Strany 265

39ATmega128(L)2467B–09/01External Clock To drive the device from an external clock source, XTAL1 should be driven as shown inFigure 20. To run the dev

Strany 266

4ATmega128(L)2467B–09/01The AVR core combines a rich instruction set with 32 general purpose working registers.All the 32 registers are directly conne

Strany 267

40ATmega128(L)2467B–09/01• Bit 7 - XDIVEN: XTAL Divide EnableWhen the XDIVEN bit is written one, the clock frequency of the CPU and all peripherals(cl

Strany 268

41ATmega128(L)2467B–09/01Power Management and Sleep ModesSleep modes enable the application to shut down unused modules in the MCU, therebysaving powe

Strany 269

42ATmega128(L)2467B–09/01Idle Mode When the SM2..0 bits are written to 000, the SLEEP instruction makes the MCU enterIdle Mode, stopping the CPU but a

Strany 270

43ATmega128(L)2467B–09/01asynchronous timer should be considered undefined after wake-up in Power-save Modeif AS0 is 0.This sleep mode basically halts

Strany 271

44ATmega128(L)2467B–09/01Minimizing Power ConsumptionThere are several issues to consider when trying to minimize the power consumption inan AVR contr

Strany 272

45ATmega128(L)2467B–09/01System Control and ResetResetting the AVR During reset, all I/O registers are set to their initial values, and the program st

Strany 273

46ATmega128(L)2467B–09/01Figure 21. Reset LogicNotes: 1. Values are guidelines only. Actual values are TBD.2. The Power-on Reset will not work unless

Strany 274

47ATmega128(L)2467B–09/01Power-on Reset A Power-on Reset (POR) pulse is generated by an on-chip detection circuit. The detec-tion level is defined in

Strany 275

48ATmega128(L)2467B–09/01Figure 24. External Reset During OperationBrown-out Detection ATmega128 has an on-chip brown-out detection (BOD) circuit for

Strany 276

49ATmega128(L)2467B–09/01Figure 26. Watchdog Reset During OperationMCU Control and Status Register – MCUCSRThe MCU Control and Status Register provid

Strany 277

5ATmega128(L)2467B–09/01The ATmega128 is 100% pin compatible with ATmega103, and can replace theATmega103 on current Printed Circuit Boards. The appli

Strany 278

50ATmega128(L)2467B–09/01Voltage Reference Enable Signals and Start-up TimeThe voltage reference has a start-up time that may influence the way it sho

Strany 279

51ATmega128(L)2467B–09/01Figure 27. Watchdog TimerWatchdog Timer Control Register – WDTCR• Bits 7..5 - Res: Reserved BitsThese bits are reserved bits

Strany 280

52ATmega128(L)2467B–09/011. In the same operation, write a logic one to WDCE and WDE. A logic one must be written to WDE even though it is set to one

Strany 281

53ATmega128(L)2467B–09/01Timed Sequences for Changing the Configuration of the Watch Dog TimerThe sequence for changing configuration differs slightly

Strany 282

54ATmega128(L)2467B–09/01Interrupts This chapter describes the specifics of the interrupt handling as performed inATmega128. For a general explanation

Strany 283

55ATmega128(L)2467B–09/01Notes: 1. When the BOOTRST fuse is programmed, the device will jump to the Boot Loaderaddress at reset, see “Boot Loader Supp

Strany 284

56ATmega128(L)2467B–09/01The most typical and general program setup for the Reset and Interrupt VectorAddresses in ATmega128 is:Address Labels Code Co

Strany 285

57ATmega128(L)2467B–09/01When the BOOTRST fuse is unprogrammed, the boot section size set to 8K bytes andthe IVSEL bit in the MCUCR register is set be

Strany 286

58ATmega128(L)2467B–09/01Moving Interrupts Between Application and Boot SpaceThe General Interrupt Control Register controls the placement of the inte

Strany 287

59ATmega128(L)2467B–09/01• Bit 0 - IVCE: Interrupt Vector Change EnableThe IVCE bit must be written to logic one to enable change of the IVSEL bit. IV

Strany 288

6ATmega128(L)2467B–09/01Port C also serves the functions of special features of the ATmega128 as listed on page72. In ATmega103 compatibility mode, Po

Strany 289

60ATmega128(L)2467B–09/01I/O-PortsIntroduction All AVR ports have true Read-Modify-Write functionality when used as general digitalI/O ports. This mea

Strany 290

61ATmega128(L)2467B–09/01Ports as General Digital I/OThe ports are bi-directional I/O ports with optional internal pull-ups. Figure 29 shows afunction

Strany 291

62ATmega128(L)2467B–09/01When switching between tri-state ({DDxn, PORTxn} = 0b00) and output high ({DDxn,PORTxn} = 0b11), an intermediate state with e

Strany 292

63ATmega128(L)2467B–09/01Figure 30. Synchronization when Reading an Externally Applied Pin ValueConsider the clock period starting shortly after the

Strany 293

64ATmega128(L)2467B–09/01Figure 31. Synchronization when Reading a Software Assigned Pin ValueThe following code example shows how to set port B pins

Strany 294

65ATmega128(L)2467B–09/01Note: 1. For the assembly program, two temporary registers are used to minimize the timefrom pull-ups are set on pins 0, 1, 6

Strany 295

66ATmega128(L)2467B–09/01Alternate Port Functions Most port pins have alternate functions in addition to being general digital I/Os. Figure32 shows ho

Strany 296

67ATmega128(L)2467B–09/01The following subsections shortly describes the alternate functions for each port, andrelates the overriding signals to the a

Strany 297

68ATmega128(L)2467B–09/01• Bit 2 - PUD: Pull-up disableWhen this bit is written to one, the pull-ups in the I/O ports are disabled even if the DDxnand

Strany 298

69ATmega128(L)2467B–09/01Alternate Functions of Port B The Port B pins with alternate functions are shown in Table 30.Note: 1. OC1C not applicable in

Strany 299

7ATmega128(L)2467B–09/01XTAL2 Output from the inverting oscillator amplifier.AVCC This is the supply voltage pin for Port F and the A/D Converter. It

Strany 300

70ATmega128(L)2467B–09/01• OC1B, Bit 6OC1B, Output Compare matchB output: The PB6 pin can serve as an external outputfor the Timer/Counter1 output com

Strany 301

71ATmega128(L)2467B–09/01Note: 1. See “Output Compare Modulator (OCM1C2)” on page 155 for details. OC1C doesnot exist in ATmega103 compatibility mode.

Strany 302

72ATmega128(L)2467B–09/01Alternate Functions of Port C In ATmega103 compatibility mode, Port C is output only. The Port C has an alternatefunction as

Strany 303

73ATmega128(L)2467B–09/01Note: 1. XMM = 0 in ATmega103 compatibility mode.Alternate Functions of Port D The Port D pins with alternate functions are s

Strany 304

74ATmega128(L)2467B–09/01• IC1 - Port D, Bit 4IC1 - Input Capture Pin1: The PD4 pin can act as an input capture pin forTimer/Counter1.• INT3/TXD1 - Po

Strany 305

75ATmega128(L)2467B–09/01 Note: 1. When enabled, the Two-wire Serial Interface enables Slew-Rate controls on the out-put pins PD0 and PD1. This is not

Strany 306

76ATmega128(L)2467B–09/01Alternate Functions of Port E The Port E pins with alternate functions are shown in Table 39.Note: 1. IC3, T3, OC3C, OC3B, OC

Strany 307

77ATmega128(L)2467B–09/01OC3A, Output Compare matchA output: The PE3 pin can serve as an external outputfor the Timer/Counter3 output compareA. The pi

Strany 308

78ATmega128(L)2467B–09/01 Alternate Functions of Port F The Port F has an alternate function as analog input for the ADC as shown in Table 42.If some

Strany 309

79ATmega128(L)2467B–09/01• TMS, ADC5 - Port F, Bit 5ADC5, Analog to Digital Converter, Channel 5.TMS, JTAG Test Mode Select: This pin is used for navi

Strany 310

8ATmega128(L)2467B–09/01AVR CPU CoreIntroduction This chapter discusses the AVR core architecture in general. The main function of theCPU core is to e

Strany 311

80ATmega128(L)2467B–09/01Alternate Functions of Port G In ATmega103 compatibility mode, only the alternate functions are the defaults for PortG, and P

Strany 312

81ATmega128(L)2467B–09/01Register Description for I/O PortsPort A Data Register – PORTAPort A Data Direction Register – DDRAPort A Input Pins Address

Strany 313

82ATmega128(L)2467B–09/01Port B Input Pins Address – PINBPort C Data Register – PORTCPort C Data Direction Register – DDRCPort C Input Pins Address –

Strany 314

83ATmega128(L)2467B–09/01Port E Data Direction Register – DDREPort E Input Pins Address – PINEPort F Data Register – PORTFPort F Data Direction Regist

Strany 315

84ATmega128(L)2467B–09/01External Interrupts The external interrupts are triggered by the INT7:0 pins. Observe that, if enabled, theinterrupts will tr

Strany 316

85ATmega128(L)2467B–09/01Note: 1. n = 3, 2, 1or 0.When changing the ISCn1/ISCn0 bits, the interrupt must be disabled by clearing itsInterrupt Enable b

Strany 317

86ATmega128(L)2467B–09/01External Interrupt Mask Register – EIMSK• Bits 7..4 - INT7 - INT0: External Interrupt Request 7 - 0 EnableWhen an INT7- INT4

Strany 318

87ATmega128(L)2467B–09/018-bit Timer/Counter0 with PWM and Asynchronous OperationTimer/Counter0 is a general purpose, single channel, 8-bit Timer/Coun

Strany 319

88ATmega128(L)2467B–09/01The Timer/Counter can be clocked internally, via the prescaler, or asynchronouslyclocked from the TOSC1/2 pins, as detailed l

Strany 320

89ATmega128(L)2467B–09/01Signal description (internal signals):count Increment or decrement TCNT0 by 1.direction Selects between increment and decreme

Strany 321

9ATmega128(L)2467B–09/01an arithmetic operation, the Status Register is updated to reflect information about theresult of the operation.Program flow i

Strany 322

90ATmega128(L)2467B–09/01Figure 35. Output Compare Unit, Block DiagramThe OCR0 register is double buffered when using any of the pulse width modulati

Strany 323

91ATmega128(L)2467B–09/01The setup of the OC0 should be performed before setting the data direction register forthe port pin to output. The easiest wa

Strany 324

92ATmega128(L)2467B–09/01mode, refer to Table 54 on page 99, and for phase correct PWM refer to Table 55 onpage 100.A change of the COM01:0 bits state

Strany 325

93ATmega128(L)2467B–09/01Figure 37. CTC Mode, Timing DiagramAn interrupt can be generated each time the counter value reaches the TOP value byusing t

Strany 326

94ATmega128(L)2467B–09/01non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT0slopes represent compare matches between O

Strany 327

95ATmega128(L)2467B–09/01Phase Correct PWM Mode The phase correct PWM mode (WGM01:0 = 3) provides a high resolution phase correctPWM waveform generati

Strany 328

96ATmega128(L)2467B–09/01and TCNT0 when the counter decrements. The PWM frequency for the output whenusing phase correct PWM can be calculated by the

Strany 329

97ATmega128(L)2467B–09/01Figure 41. Timer/Counter Timing Diagram, with Prescaler (fclk_I/O/8)Figure 42 shows the setting of OCF0 in all modes except

Strany 330

98ATmega128(L)2467B–09/01Figure 43. Timer/Counter Timing Diagram, Clear Timer on Compare Match Mode, withPrescaler (fclk_I/O/8)8-bit Timer/Counter Re

Strany 331

99ATmega128(L)2467B–09/01Note: 1. The CTC0 and PWM0 bit definition names are now obsolete. Use the WGM01:0 def-initions. However, the functionality an

Komentáře k této Příručce

Žádné komentáře