Rainbow-electronics ATmega128L User Manual

Browse online or download User Manual for Sensors Rainbow-electronics ATmega128L. Rainbow Electronics ATmega128L User Manual

  • Download
  • Add to my manuals
  • Print
  • Page
    / 331
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 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
Page view 0
1 2 3 4 5 6 ... 330 331

Summary of Contents

Page 1 - Features

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

Page 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

Page 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

Page 4

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

Page 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

Page 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

Page 7

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 13

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

Page 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

Page 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

Page 16

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

Page 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

Page 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

Page 19

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

Page 20

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

Page 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

Page 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

Page 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

Page 24

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 32

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

Page 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

Page 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”

Page 35

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

Page 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

Page 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

Page 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

Page 39

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

Page 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

Page 41

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

Page 42

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

Page 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

Page 44

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 51

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

Page 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,

Page 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

Page 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

Page 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

Page 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

Page 57

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

Page 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

Page 59

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

Page 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

Page 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

Page 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

Page 63

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

Page 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

Page 65

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

Page 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

Page 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

Page 68

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 74

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

Page 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

Page 76

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

Page 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

Page 78

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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,

Page 90

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

Page 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

Page 92

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 98 - Register Description

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

Page 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%

Page 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

Page 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

Page 102

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

Page 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

Page 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/

Page 105

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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 (

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 129

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

Page 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

Page 131

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

Page 132

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

Page 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

Page 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

Page 135

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

Page 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

Page 137

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

Page 138

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

Page 139

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

Page 140

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

Page 141

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

Page 142

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

Page 143

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

Page 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

Page 145

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

Page 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

Page 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

Page 148

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 155

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

Page 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

Page 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

Page 158

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

Page 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

Page 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

Page 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

Page 162

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

Page 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

Page 164

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

Page 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

Page 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.

Page 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

Page 168

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

Page 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

Page 170

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

Page 171

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

Page 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

Page 173

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

Page 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

Page 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

Page 176

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

Page 177

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

Page 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_

Page 179

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 185

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

Page 186

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

Page 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

Page 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

Page 189

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

Page 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

Page 191

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 198

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

Page 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

Page 200

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

Page 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

Page 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

Page 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

Page 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

Page 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,

Page 206

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

Page 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

Page 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

Page 209

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

Page 210

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

Page 211

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

Page 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

Page 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

Page 214

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

Page 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

Page 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

Page 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

Page 218

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

Page 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

Page 220

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

Page 221

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

Page 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

Page 223

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

Page 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

Page 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

Page 226

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

Page 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,

Page 228

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

Page 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

Page 230

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

Page 231

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

Page 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

Page 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

Page 234

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

Page 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

Page 236

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

Page 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

Page 238

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

Page 239

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

Page 240

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

Page 241

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

Page 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

Page 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

Page 244

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

Page 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

Page 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

Page 247

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

Page 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:

Page 249

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

Page 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

Page 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)

Page 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

Page 253

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

Page 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

Page 255

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

Page 256

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

Page 257

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

Page 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.

Page 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

Page 260

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 268

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

Page 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

Page 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

Page 271

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

Page 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

Page 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

Page 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

Page 275

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

Page 276

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

Page 277

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

Page 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

Page 279

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

Page 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

Page 281

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

Page 282

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

Page 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

Page 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

Page 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

Page 286

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

Page 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

Page 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

Page 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

Page 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

Page 291

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

Page 292

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

Page 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

Page 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

Page 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

Page 296

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

Page 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

Page 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

Page 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

Page 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

Page 301

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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 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

Page 312

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

Page 313

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

Page 314

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

Page 315

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

Page 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

Page 317

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

Page 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

Page 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

Page 320

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

Page 321

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

Page 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

Page 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

Page 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

Page 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

Page 326

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

Page 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

Page 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

Page 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

Page 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

Page 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

Comments to this Manuals

No comments