Rainbow-electronics ATmega64L User Manual

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

  • Download
  • Add to my manuals
  • Print
  • Page
    / 298
  • 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
130 Powerful Instructions – Most Single-clock Cycle Execution
32 x 8 General Purpose Working Registers
Fully Static Operation
Up to 16 MIPS Throughput at 16 MHz
On-chip 2-cycle Multiplier
Nonvolatile Program and Data Memories
16K Bytes of In-System Self-Programmable 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
512 Bytes EEPROM
Endurance: 100,000 Write/Erase Cycles
1K Byte Internal SRAM
Programming Lock for Software Security
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
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
Real Time Counter with Separate Oscillator
Four PWM Channels
8-channel, 10-bit ADC
8 Single-ended Channels
7 Differential Channels in TQFP Package Only
2 Differential Channels with Programmable Gain at 1x, 10x, or 200x in TQFP
Package Only
Byte-oriented 2-wire Serial Interface
Programmable Serial USART
Master/Slave SPI Serial Interface
Programmable Watchdog Timer with Separate 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
I/O and Packages
32 Programmable I/O Lines
40-pin PDIP and 44-lead TQFP
Operating Voltages
2.7 - 5.5V for ATmega16L
4.5 - 5.5V for ATmega16
Speed Grades
0 - 8 MHz for ATmega16L
–0 - 16 MHz for ATmega16
8-bit
Microcontroller
with 16K Bytes
In-System
Programmable
Flash
ATmega16
ATmega16L
Preliminary
Rev. 2466B–09/01
Page view 0
1 2 3 4 5 6 ... 297 298

Summary of Contents

Page 1 - Features

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

Page 2

10ATmega16(L)2466B–09/01Stack Pointer The stack is mainly used for storing temporary data, for storing local variables and forstoring return addresses

Page 3

100ATmega16(L)2466B–09/01for the output when using phase correct PWM can be calculated by the followingequation:The N variable represents the prescale

Page 4

101ATmega16(L)2466B–09/01Figure 48. Phase and Frequency Correct PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOV1) is set at the same tim

Page 5

102ATmega16(L)2466B–09/01The extreme values for the OCR1x register represents special cases when generating aPWM waveform output in the phase correct

Page 6

103ATmega16(L)2466B–09/01Figure 51 shows the count sequence close to TOP in various modes. When using phaseand frequency correct PWM mode the OCR1x re

Page 7

104ATmega16(L)2466B–09/0116-bit Timer/Counter Register DescriptionTimer/Counter 1 Control Register A – TCCR1A• Bit 7:6 - COM1A1:0: Compare Output Mode

Page 8

105ATmega16(L)2466B–09/01Table 46 shows the COM1x1:0 bit functionality when the WGM13:0 bits are set to thephase correct or the phase and frequency co

Page 9

106ATmega16(L)2466B–09/01Note: 1. The CTC1 and PWM11:0 bit definition names are obsolete. Use the WGM12:0 definitions. However, the functionality andl

Page 10 - ATmega16(L)

107ATmega16(L)2466B–09/01Timer/Counter 1 Control Register B – TCCR1B• Bit 7 - ICNC1: Input Capture Noise CancelerSetting this bit (to one) activates t

Page 11

108ATmega16(L)2466B–09/01If external pin modes are used for the Timer/Counter1, transitions on the T1 pin willclock the counter even if the pin is con

Page 12

109ATmega16(L)2466B–09/01The input capture is updated with the counter (TCNT1) value each time an event occurson the ICP1 pin (or optionally on the an

Page 13

11ATmega16(L)2466B–09/01Figure 7. Single Cycle ALU OperationReset and Interrupt HandlingThe AVR provides several different interrupt sources. These i

Page 14

110ATmega16(L)2466B–09/01• Bit 5 - ICF1: Timer/Counter1, Input Capture FlagThis flag is set when a capture event occurs on the ICP1 pin. When the Inpu

Page 15

111ATmega16(L)2466B–09/018-bit Timer/Counter2 with PWM and Asynchronous OperationTimer/Counter2 is a general purpose, single channel, 8-bit Timer/Coun

Page 16

112ATmega16(L)2466B–09/01The double buffered Output Compare Register (OCR2) is compared with theTimer/Counter value at all times. The result of the co

Page 17

113ATmega16(L)2466B–09/01top Signalizes that TCNT2 has reached maximum value.bottom Signalizes that TCNT2 has reached minimum value (zero).Depending o

Page 18

114ATmega16(L)2466B–09/01OCR2 compare register to either top or bottom of the counting sequence. The synchro-nization prevents the occurrence of odd-l

Page 19

115ATmega16(L)2466B–09/01Figure 56. Compare Match Output Unit, SchematicThe general I/O port function is overridden by the output compare (OC2) from

Page 20

116ATmega16(L)2466B–09/01restarts from the bottom (0x00). In normal operation the Timer/Counter overflow flag(TOV2) will be set in the same timer cloc

Page 21

117ATmega16(L)2466B–09/01The N variable represents the prescale factor (1, 8, 32, 64, 128, 256, or 1024).As for the normal mode of operation, the TOV2

Page 22

118ATmega16(L)2466B–09/01The PWM frequency for the output can be calculated by the following equation:The N variable represents the prescale factor (1

Page 23

119ATmega16(L)2466B–09/01Figure 59. Phase Correct PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOV2) is set each time the counter reaches

Page 24

12ATmega16(L)2466B–09/01Note that the status register is not automatically stored when entering an interrupt rou-tine, nor restored when returning fro

Page 25

120ATmega16(L)2466B–09/01Figure 60. Timer/Counter Timing Diagram, no PrescalingFigure 61 shows the same timing data, but with the prescaler enabled.F

Page 26

121ATmega16(L)2466B–09/01Figure 63 shows the setting of OCF2 and the clearing of TCNT2 in CTC mode.Figure 63. Timer/Counter Timing Diagram, Clear Tim

Page 27

122ATmega16(L)2466B–09/01Note: 1. The CTC2 and PWM2 bit definition names are now obsolete. Use the WGM21:0 def-initions. However, the functionality an

Page 28

123ATmega16(L)2466B–09/01.Note: 1. A special case occurs when OCR2 equals TOP and COM21 is set. In this case, thecompare match is ignored, but the set

Page 29

124ATmega16(L)2466B–09/01Asynchronous Operation of the Timer/CounterAsynchronous Status Register – ASSR• Bit 3 - AS2: Asynchronous Timer/Counter2When

Page 30

125ATmega16(L)2466B–09/01The CPU main clock frequency must be more than four times the oscillator frequency.• When writing to one of the registers TCN

Page 31

126ATmega16(L)2466B–09/01unpredictable, as it depends on the wake-up time. The recommended procedure for reading TCNT2 is thus as follows: 1. Write an

Page 32

127ATmega16(L)2466B–09/01Timer/Counter Prescaler Figure 64. Prescaler for Timer/Counter2The clock source for Timer/Counter2 is named clkT2S. clkT2S i

Page 33

128ATmega16(L)2466B–09/01Serial Peripheral Interface – SPIThe Serial Peripheral Interface (SPI) allows high-speed synchronous data transferbetween the

Page 34

129ATmega16(L)2466B–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 35

13ATmega16(L)2466B–09/01AVR ATmega16 MemoriesThis section describes the different memories in the ATmega16. The AVR architecturehas two main memory sp

Page 36

130ATmega16(L)2466B–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 37

131ATmega16(L)2466B–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 exa

Page 38

132ATmega16(L)2466B–09/01will immediately reset the send and receive logic, and drop any partially received data inthe shift register.Master Mode When

Page 39

133ATmega16(L)2466B–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 low

Page 40

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

Page 41

135ATmega16(L)2466B–09/01Figure 67. SPI Transfer Format with CPHA = 0Figure 68. SPI Transfer Format with CPHA = 1Bit 1Bit 6LSBMSBSCK (CPOL = 0)mode

Page 42

136ATmega16(L)2466B–09/01USART The Universal Synchronous and Asynchronous serial Receiver and Transmitter(USART) is a highly flexible serial communica

Page 43

137ATmega16(L)2466B–09/01The dashed boxes in the block diagram separate the three main parts of the USART(listed from the top): clock generator, trans

Page 44

138ATmega16(L)2466B–09/01Figure 70. Clock Generation Logic, Block DiagramSignal description:txclk Transmitter clock. (Internal Signal)rxclk Receiver

Page 45

139ATmega16(L)2466B–09/01Note: 1. The baud rate is defined to be the transfer rate in bit per second (bps).BAUD Baud rate (in bits per second, bps)fOS

Page 46

14ATmega16(L)2466B–09/01SRAM Data Memory Figure 9 shows how the ATmega16 SRAM Memory is organized.The lower 1120 Data Memory locations address the Reg

Page 47

140ATmega16(L)2466B–09/01Figure 71. Synchronous Mode XCK Timing.The UCPOL bit UCRSC selects which XCK clock edge is used for data sampling andwhich i

Page 48

141ATmega16(L)2466B–09/01The USART Character SiZe (UCSZ2:0) bits select the number of data bits in the frame.The USART Parity Mode (UPM1:0) bits enabl

Page 49

142ATmega16(L)2466B–09/01USART Initialization The USART has to be initialized before any communication can take place. The initial-ization process nor

Page 50

143ATmega16(L)2466B–09/01Data Transmission – The USART TransmitterThe USART transmitter is enabled by setting the Transmit Enable (TXEN) bit in theUCS

Page 51

144ATmega16(L)2466B–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 52 - DATA BU S

145ATmega16(L)2466B–09/01either write new data to UDR in order to clear UDRE or disable the data register emptyinterrupt, otherwise a new interrupt wi

Page 53

146ATmega16(L)2466B–09/01Data Reception – The USART ReceiverThe USART receiver is enabled by writing the Receive Enable (RXEN) bit in the UCSRBregiste

Page 54

147ATmega16(L)2466B–09/01Receiving Frames with 9 DatabitsIf 9 bit characters are used (UCSZ=7) the ninth bit must be read from the RXB8 bit inUCSRB be

Page 55

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

Page 56

149ATmega16(L)2466B–09/01The PE bit is set if the next character that can be read from the receive buffer had a par-ity error when received and the pa

Page 57

15ATmega16(L)2466B–09/01Data Memory Access Times This section describes the general access timing concepts for internal memory access.The internal dat

Page 58

150ATmega16(L)2466B–09/01Asynchronous Data ReceptionThe USART includes a clock recovery and a data recovery unit for handling asynchro-nous data recep

Page 59

151ATmega16(L)2466B–09/01The decision of the logic level of the received bit is taken by doing a majority voting ofthe logic value to the three sample

Page 60

152ATmega16(L)2466B–09/01SMMiddle sample number used for majority voting. SM = 9 for normal speed and SM =5 for double speed mode.Rslow is the ratio o

Page 61

153ATmega16(L)2466B–09/01Multi-processor Communication ModeSetting the Multi-processor Communication Mode (MPCM) bit in UCSRA enables a fil-tering fun

Page 62

154ATmega16(L)2466B–09/01Accessing UBRRH/ UCSRC RegistersThe UBRRH register shares the same I/O location as the UCSRC register. Thereforesome special

Page 63

155ATmega16(L)2466B–09/01Read Access Doing a read access to the UBRRH or the UCSRC register is a more complex operation.However, in most applications,

Page 64

156ATmega16(L)2466B–09/01The transmit buffer can only be written when the UDRE flag in the UCSRA register isset. Data written to UDR when the UDRE fla

Page 65

157ATmega16(L)2466B–09/01• Bit 1 - U2X: Double the USART tranSmission SpeedThis bit only has effect for the asynchronous operation. Write this bit to

Page 66

158ATmega16(L)2466B–09/01• Bit 0 - TXB8: Transmit Data Bit 8TXB8 is the 9th data bit in the character to be transmitted when operating with serialfram

Page 67 - 8-bit Timer/Counter0

159ATmega16(L)2466B–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(charact

Page 68 - Timer/Counter Clock

16ATmega16(L)2466B–09/01EEPROM Data Memory The ATmega16 contains 512 bytes of data EEPROM memory. It is organized as a sep-arate data space, in which

Page 69 - DATA BU S

160ATmega16(L)2466B–09/01• Bit 11:0 - UBRR11:0: USART Baud Rate RegisterThis is a 12-bit register which contains the USART baud rate. The UBRRH contai

Page 70

161ATmega16(L)2466B–09/01Table 69. Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued)Baud Rate (bps)fosc = 3.6864 MHz fos

Page 71

162ATmega16(L)2466B–09/010.5M 0 0.0% 1 0.0% - - 2 -7.8% 1 -7.8% 3 -7.8%1M--00.0%----0-7.8%1-7.8%Max (1)0.5Mbps 1Mbps 691.2kbps 1.3824Mbps 921.6kbps 1.

Page 72

163ATmega16(L)2466B–09/01Two-wire Serial InterfaceFeatures • Simple Yet Powerful and Flexible Communication Interface, Only two Bus Lines Needed• Both

Page 73

164ATmega16(L)2466B–09/01Electrical Interconnection As depicted in Figure 76, both bus lines are connected to the positive supply voltagethrough pull-

Page 74

165ATmega16(L)2466B–09/01Figure 78. START, REPEATED START and STOP ConditionsAddress Packet Format All address packets transmitted on the TWI bus are

Page 75

166ATmega16(L)2466B–09/01more bytes, it should inform the transmitter by sending a NACK after the final byte. TheMSB of the data byte is transmitted f

Page 76

167ATmega16(L)2466B–09/01• Different masters may use different SCL frequencies. A scheme must be devised to synchronize the serial clocks from all mas

Page 77

168ATmega16(L)2466B–09/01Figure 83. Arbitration between Two MastersNote that arbitration is not allowed between:• A REPEATED START condition and a da

Page 78

169ATmega16(L)2466B–09/01Overview of the TWI ModuleThe TWI module is comprised of several submodules, as shown in Figure 84. All regis-ters drawn in a

Page 79

17ATmega16(L)2466B–09/01tion, the EEDR contains the data read out from the EEPROM at the address given byEEAR.The EEPROM Control Register – EECR• Bits

Page 80

170ATmega16(L)2466B–09/01Bus Interface Unit This unit contains the Data and Address Shift register (TWDR), a START/STOP Con-troller and Arbitration de

Page 81

171ATmega16(L)2466B–09/01TWI register descriptionTWI Bit Rate Register – TWBR• Bits 7..0 - TWI Bit Rate RegisterTWBR selects the division factor for t

Page 82

172ATmega16(L)2466B–09/01• Bit 4 - TWSTO: TWI STOP Condition BitWriting the TWSTO bit to one in master mode will generate a STOP condition on the 2-wi

Page 83

173ATmega16(L)2466B–09/01shifting a byte. This occurs when the TWI interrupt flag (TWINT) is set by hardware.Note that the data register cannot be ini

Page 84

174ATmega16(L)2466B–09/01Figure 85. Interfacing the Application to the TWI in a Typical Transmission1. The first step in a TWI transmission is to tra

Page 85

175ATmega16(L)2466B–09/01written. Writing a one to TWINT clears the flag. The TWI will not start any opera-tion as long as the TWINT bit in TWCR is se

Page 86

176ATmega16(L)2466B–09/01Assembly code example C example Comments1ldi r16, (1<<TWINT)|(1<<TWSTA)|(1<<TWEN)out TWCR, r16TWCR = (1<

Page 87

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

Page 88

178ATmega16(L)2466B–09/01Figure 86. Data Transfer in Master Transmitter ModeA START condition is sent by writing the following value to TWCR:TWEN mus

Page 89

179ATmega16(L)2466B–09/01After a repeated START condition (state $10) the 2-wire Serial Interface can access thesame slave again, or a new slave witho

Page 90

18ATmega16(L)2466B–09/01EEWE has been set, the CPU is halted for two cycles before the next instruction isexecuted.• Bit 0 - EERE: EEPROM Read EnableT

Page 91

180ATmega16(L)2466B–09/01Figure 87. Formats and States in the Master Transmitter ModeMaster Receiver Mode In the master receiver mode, a number of da

Page 92

181ATmega16(L)2466B–09/01Figure 88. Data Transfer in Master Receiver ModeA START condition is sent by writing the following value to TWCR:TWEN must b

Page 93

182ATmega16(L)2466B–09/01Table 74. Status Codes for Master Receiver Mode Status Code(TWSR)Prescaler Bitsare 0Status of the 2-wire Serial Busand 2-wir

Page 94

183ATmega16(L)2466B–09/01Figure 89. Formats and States in the Master Receiver ModeSlave Receiver Mode In the slave receiver mode, a number of data by

Page 95

184ATmega16(L)2466B–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 s

Page 96

185ATmega16(L)2466B–09/01Table 75. Status Codes for Slave Receiver Mode Status Code(TWSR)Prescaler Bitsare 0Status of the 2-wire Serial Bus and2-wire

Page 97

186ATmega16(L)2466B–09/01Figure 91. Formats and States in the Slave Receiver ModeSlave Transmitter Mode In the slave transmitter mode, a number of da

Page 98

187ATmega16(L)2466B–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 s

Page 99

188ATmega16(L)2466B–09/01Table 76. Status Codes for Slave Transmitter ModeStatus Code(TWSR)Prescaler Bitsare 0Status of the 2-wire Serial Bus and2-wi

Page 100

189ATmega16(L)2466B–09/01Figure 93. Formats and States in the Slave Transmitter ModeMiscellaneous States There are two status codes that do not corre

Page 101

19ATmega16(L)2466B–09/01The following code examples show one assembly and one C function for writing to theEEPROM. The examples assume that interrupts

Page 102

190ATmega16(L)2466B–09/01Combining Several TWI ModesIn some cases, several TWI modes must be combined in order to complete the desiredaction. Consider

Page 103

191ATmega16(L)2466B–09/01Several different scenarios may arise during arbitration, as described below:• Two or more masters are performing identical c

Page 104

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

Page 105

193ATmega16(L)2466B–09/01• Bit 7 - ACD: Analog Comparator DisableWhen this bit is written logic one, the power to the analog comparator is switched of

Page 106

194ATmega16(L)2466B–09/01Analog Comparator Multiplexed InputIt is possible to select any of the ADC7..0 pins to replace the negative input to the ana-

Page 107

195ATmega16(L)2466B–09/01Analog to Digital ConverterFeatures • 10-bit Resolution• 0.5 LSB Integral Non-Linearity• ±2 LSB Absolute Accuracy• TBD - 260

Page 108

196ATmega16(L)2466B–09/01Figure 98. Analog to Digital Converter Block SchematicOperation The ADC converts an analog input voltage to a 10-bit digital

Page 109

197ATmega16(L)2466B–09/01amplified value then becomes the analog input to the ADC. If single ended channels areused, the gain amplifier is bypassed al

Page 110

198ATmega16(L)2466B–09/01Figure 99. ADC Auto Trigger LogicUsing the ADC Interrupt Flag as a trigger source makes the ADC start a new conversionas soo

Page 111

199ATmega16(L)2466B–09/01setting the ADEN bit in ADCSRA. The prescaler keeps running for as long as the ADENbit is set, and is continuously reset when

Page 112

2ATmega16(L)2466B–09/01Pin Configurations Figure 1. Pinouts ATmega16(XCK/T0) PB0(T1) PB1(INT2/AIN0) PB2(OC0/AIN1) PB3(SS) PB4(MOSI) PB5(MISO)

Page 113

20ATmega16(L)2466B–09/01The next code examples show assembly and C functions for reading the EEPROM. Theexamples assume that interrupts are controlled

Page 114

200ATmega16(L)2466B–09/01Figure 102. ADC Timing Diagram, Single ConversionFigure 103. ADC Timing Diagram, Auto Triggered ConversionFigure 104. ADC

Page 115

201ATmega16(L)2466B–09/01Differential Gain Channels When using differential gain channels, certain aspects of the conversion need to betaken into cons

Page 116

202ATmega16(L)2466B–09/01If Auto Triggering is used, the exact time of the triggering event can be indeterministic.Special care must be taken when upd

Page 117

203ATmega16(L)2466B–09/01If the user has a fixed voltage source connected to the AREF pin, the user may not usethe other reference voltage options in

Page 118

204ATmega16(L)2466B–09/01Figure 105. Analog Input CircuitryAnalog Noise Canceling TechniquesDigital circuitry inside and outside the device generates

Page 119

205ATmega16(L)2466B–09/01Figure 106. ADC Power ConnectionsOffset Compensation SchemesThe gain stage has a built-in offset cancellation circuitry that

Page 120

206ATmega16(L)2466B–09/01Figure 107. Offset Error• Gain error: After adjusting for offset, the gain error is found as the deviation of the last trans

Page 121

207ATmega16(L)2466B–09/01Figure 109. Integral non-Linearity (INL)• Differential Non-Linearity (DNL): The maximum deviation of the actual code width (

Page 122

208ATmega16(L)2466B–09/01ADC Conversion Result After the conversion is complete (ADIF is high), the conversion result can be found inthe ADC Result re

Page 123

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

Page 124

21ATmega16(L)2466B–09/01I/O Memory The I/O space definition of the ATmega16 is shown in “Register Summary” on page 290.All ATmega16 I/Os and periphera

Page 125

210ATmega16(L)2466B–09/01• Bits 4:0 - MUX4:0: Analog Channel and Gain Selection BitsThe value of these bits selects which combination of analog inputs

Page 126

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

Page 127

212ATmega16(L)2466B–09/01The ADC Data Register – ADCL and ADCHADLAR = 0:ADLAR = 1:When an ADC conversion is complete, the result is found in these two

Page 128

213ATmega16(L)2466B–09/01Special FunctionIO Register – SFIOR• Bit 7:5 - ADTS2:0: ADC Auto Trigger SourceIf ADATE in ADCSRA is written to one, the valu

Page 129

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

Page 130

215ATmega16(L)2466B–09/01The IEEE std. 1149.1 also specifies an optional TAP signal; TRST – Test ReSeT –which is not provided.When the JTAGEN fuse is

Page 131

216ATmega16(L)2466B–09/01Figure 113. TAP Controller State DiagramTAP Controller The TAP controller is a 16-state finite state machine that controls t

Page 132

217ATmega16(L)2466B–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 133

218ATmega16(L)2466B–09/01• 2 single Program Memory break-points + 1 Program Memory break point with mask (“range break point”)• 2 single Program Memor

Page 134

219ATmega16(L)2466B–09/01On-chip Debug Related Register in I/O MemoryOn-chip Debug Register – OCDRThe OCDR register provides a communication channel f

Page 135

22ATmega16(L)2466B–09/01System Clock and Clock OptionsClock Systems and their DistributionFigure 11 presents the principal clock systems in the AVR an

Page 136

220ATmega16(L)2466B–09/01IEEE 1149.1 (JTAG) Boundary-scanFeatures • JTAG (IEEE std. 1149.1 Compliant) Interface• Boundary-scan Capabilities According

Page 137

221ATmega16(L)2466B–09/01Bypass Register The Bypass register consists of a single shift-register stage. When the Bypass registeris selected as path be

Page 138

222ATmega16(L)2466B–09/01Figure 115. Reset RegisterBoundary-scan Chain The Boundary-scan Chain has the capability of driving and observing the logic

Page 139

223ATmega16(L)2466B–09/01SAMPLE_PRELOAD; $2 Mandatory JTAG instruction for pre-loading the output latches and talking a snap-shot ofthe input/output p

Page 140

224ATmega16(L)2466B–09/01Boundary-scan Chain The Boundary-scan chain has the capability of driving and observing the logic levels onthe digital I/O pi

Page 141

225ATmega16(L)2466B–09/01Figure 117. General Port Pin Schematic Diagram(1)Note: 1. See Boundary-scan descriptin for details.Boundary-scan and the Two

Page 142

226ATmega16(L)2466B–09/01Figure 118. Additional Scan Signal for the Two-wire InterfaceScanning the RESET Pin The RESET pin accepts 5V active low logi

Page 143

227ATmega16(L)2466B–09/01Figure 120. Boundary-scan Cells for Oscillators and Clock OptionsTable 89 summaries the scan registers for the external cloc

Page 144

228ATmega16(L)2466B–09/01Figure 121. Analog ComparatorFigure 122. General Boundary-scan Cell used for Signals for Comparator and ADCACBGBANDGAPREFER

Page 145

229ATmega16(L)2466B–09/01Scanning the ADCFigure 123 shows a block diagram of the ADC with all relevant control and observe signals. The Boundary-scan

Page 146

23ATmega16(L)2466B–09/01Asynchronous Timer Clock – clkASYThe Asynchronous Timer clock allows the Asynchronous Timer/Counter to be clockeddirectly from

Page 147

230ATmega16(L)2466B–09/01Table 91. Boundary-scan Signals for the ADC Signal NameDirection as Seenfrom the ADC DescriptionRecommended Input when not i

Page 148

231ATmega16(L)2466B–09/01Note: Incorrect setting of the switches in Figure 123 will make signal contention and may damage the part. There are several

Page 149

232ATmega16(L)2466B–09/01If the ADC is not to be used during scan, the recommended input values from Table 91should be used. The user is recommended n

Page 150

233ATmega16(L)2466B–09/01Figure 124. ADC Timing Diagram and Timing ConstraintsAs an example, consider the task of verifying a 1.5V ± 5% input signal

Page 151

234ATmega16(L)2466B–09/01Using this algorithm, the timing constraint on the HOLD signal constrains the TCK clockfrequency. As the algorithm keeps HOLD

Page 152

235ATmega16(L)2466B–09/01ATmega16 Boundary-scan OrderTable 94 shows the Scan order between TDI and TDO when the Boundary-scan chainis selected as data

Page 153

236ATmega16(L)2466B–09/01112 MUXEN_7 ADC111 MUXEN_6110 MUXEN_5109 MUXEN_4108 MUXEN_3107 MUXEN_2106 MUXEN_1105 MUXEN_0104 NEGSEL_2103 NEGSEL_1102 NEGSE

Page 154

237ATmega16(L)2466B–09/0181 PB5.Data Port B80 PB5.Control79 PB5.Pullup_Enable78 PB6.Data77 PB6.Control76 PB6.Pullup_Enable75 PB7.Data74 PB7.Control73

Page 155

238ATmega16(L)2466B–09/0146 PD5.Data Port D45 PD5.Control44 PD5.Pullup_Enable43 PD6.Data42 PD6.Control41 PD6.Pullup_Enable40 PD7.Data39 PD7.Control38

Page 156

239ATmega16(L)2466B–09/01Note: PRIVATE_SIGNAL1 should always be scanned in as zero.Boundary-scan Description Language FilesBoundary-scan Description L

Page 157

24ATmega16(L)2466B–09/01For resonators, the maximum frequency is 8 MHz with CKOPT unprogrammed and16 MHz with CKOPT programmed. C1 and C2 should alway

Page 158

240ATmega16(L)2466B–09/01Boot Loader Support – Read-While-Write Self-ProgrammingThe Boot Loader Support provides a real Read-While-Write self-programm

Page 159

241ATmega16(L)2466B–09/01Note that the user software can never read any code that is located inside the RWWsection during a Boot Loader software opera

Page 160

242ATmega16(L)2466B–09/01Figure 125. Read-While-Write vs. No Read-While-WriteRead While Write(RWW) SectionNo Read While Write (NRWW) SectionZ-pointer

Page 161

243ATmega16(L)2466B–09/01Figure 126. Memory SectionsNote: The parameters in the figure above are given in Table 100 on page 252.Boot Loader Lock Bits

Page 162

244ATmega16(L)2466B–09/01Note: 1. "1" means unprogrammed, "0´means programmedNote: 1. "1" means unprogrammed, "0´means p

Page 163

245ATmega16(L)2466B–09/01Note: 1. "1" means unprogrammed, "0´means programmedStore Program Memory Control Register – SPMCRThe Store Pro

Page 164

246ATmega16(L)2466B–09/01page address is taken from the high part of the Z pointer. The data in R1 and R0 areignored. The PGWRT bit will auto-clear up

Page 165

247ATmega16(L)2466B–09/01Figure 127. Addressing the Flash during SPM(1)Note: 1. The different variables used in Figure 127 are listed in Table 102 on

Page 166

248ATmega16(L)2466B–09/01Performing Page Erase by SPMTo execute page erase, set up the address in the Z pointer, write "X0000011" toSPMCR an

Page 167

249ATmega16(L)2466B–09/01See Table 96 and Table 97 for how the different settings of the Boot Loader Bits affectthe Flash access.If bits 5..2 in R0 ar

Page 168

25ATmega16(L)2466B–09/01The CKSEL0 fuse together with the SUT1..0 fuses select the start-up times as shown inTable 5.Notes: 1. These options should on

Page 169

250ATmega16(L)2466B–09/01correctly. Secondly, the CPU itself can execute instructions incorrectly, if the supplyvoltage for executing instructions is

Page 170

251ATmega16(L)2466B–09/01call Do_spmadiw ZH:ZL, 2sbiw loophi:looplo, 2 ;use subi for PAGESIZEB<=256brne Wrloop; execute page writesubi ZL, low(PAGE

Page 171

252ATmega16(L)2466B–09/01Note: 1. The different BOOTSZ fuse configurations are shown in Figure 126Note: 1. For details about these two section, see “N

Page 172

253ATmega16(L)2466B–09/01Memory ProgrammingProgram And Data Memory Lock BitsThe ATmega16 provides six Lock bits which can be left unprogrammed ("

Page 173

254ATmega16(L)2466B–09/01Notes: 1. Program the fuse bits before programming the Lock bits.2. "1" means unprogrammed, "0´means programme

Page 174

255ATmega16(L)2466B–09/01Notes: 1. The default value of SUT1..0 results in maximum start-up time. SeeTable 10 on page27 for details.2. The default set

Page 175

256ATmega16(L)2466B–09/01The XA1/XA0 pins determine the action executed when the XTAL1 pin is given a posi-tive pulse. The bit coding is shown in Tabl

Page 176

257ATmega16(L)2466B–09/01Table 108. Pin Values used to Enter Programming ModePin Symbol ValuePAGEL Prog_enable[3] 0XA1 Prog_enable[2] 0XA0 Prog_enabl

Page 177

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

Page 178

259ATmega16(L)2466B–09/014. Give XTAL1 a positive pulse. This loads the address low byte.C. Load Data Low Byte1. Set XA1, XA0 to '01'. This

Page 179

26ATmega16(L)2466B–09/01When this oscillator is selected, start-up times are determined by the SUT fuses asshown in Table 6.Note: 1. These options sho

Page 180

260ATmega16(L)2466B–09/01Figure 129. Addressing the Flash which is Organized in PagesNote: 1. PCPAGE and PCWORD are listed in Table 111 on page 257.F

Page 181

261ATmega16(L)2466B–09/01Programming the EEPROM The EEPROM is organized in pages, see Table 112 on page 257. When programmingthe EEPROM, the program d

Page 182

262ATmega16(L)2466B–09/015. Set BS1 to "1". The Flash word high byte can now be read at DATA.6. Set OE to "1".Reading the EEPROM T

Page 183

263ATmega16(L)2466B–09/01Figure 132. Mapping between BS1, BS2 and the Fuse- and Lock Bits during ReadReading the Signature Bytes The algorithm for re

Page 184

264ATmega16(L)2466B–09/01Figure 134. Parallel Programming Timing, Loading Sequence with TimingRequirements(1)Note: 1. The timing requirements shown i

Page 185

265ATmega16(L)2466B–09/01Notes: 1. tWLRH is valid for the Write Flash, Write EEPROM, Write Fuse Bits and Write LockBits commands.2. tWLRH_CE is vali

Page 186

266ATmega16(L)2466B–09/01Serial Programming Pin MappingFigure 136. Serial Programming and VerifyNote: If the device is clocked by the internal oscill

Page 187

267ATmega16(L)2466B–09/01power-up. In this case, RESET must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set

Page 188

268ATmega16(L)2466B–09/01least tWD_EEPROM before programming the next byte. See Table 115 for tWD_EEPROMvalue.Figure 137. Serial Programming Waveform

Page 189

269ATmega16(L)2466B–09/01Note: a = address high bitsb = address low bitsH = 0 - Low byte, 1 - High Byteo = data outi = data inx = don"t careTable

Page 190

27ATmega16(L)2466B–09/01Note: 1. This option should not be used when operating close to the maximum frequency ofthe device.Calibrated Internal RC Osci

Page 191

270ATmega16(L)2466B–09/01Serial Programming CharacteristicsFigure 138. Serial Programming TimingNote: 1. 2 tCLCL for fck < 12 MHz, 3 tCLCL for fck

Page 192

271ATmega16(L)2466B–09/01Figure 139. State Machine Sequence for Changing the Instruction WordAVR_RESET ($C) The AVR specific public JTAG instruction

Page 193

272ATmega16(L)2466B–09/01PROG_COMMANDS ($5) The AVR specific public JTAG instruction for entering programming commands via theJTAG port. The 15-bit Pr

Page 194

273ATmega16(L)2466B–09/01When the contents of the register is equal to the programming enable signature, pro-gramming via the JTAG port is enabled. Th

Page 195

274ATmega16(L)2466B–09/01Table 118. JTAG Programming Instruction Set a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o

Page 196

275ATmega16(L)2466B–09/015c. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx5d. Read Data Byte 0110011_bbbbbbbb0110010_000000000110011_0000000

Page 197

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

Page 198

277ATmega16(L)2466B–09/01Figure 142. State Machine Sequence for Changing/Reading the Data WordVirtual Flash Page Load RegisterThe Virtual Flash Page

Page 199

278ATmega16(L)2466B–09/01Figure 143. Virtual Flash Page Load RegisterVirtual Flash Page Read RegisterThe Virtual Flash Page Read register is a virtua

Page 200

279ATmega16(L)2466B–09/01Programming Algorithm All references below of type “1a”, “1b”, and so on, refer to Table 118.Entering Programming Mode 1. Ent

Page 201

28ATmega16(L)2466B–09/01Oscillator Calibration Register – OSCCAL• Bits 7..0 - CAL7..0: Oscillator Calibration ValueWriting the calibration byte to thi

Page 202

280ATmega16(L)2466B–09/016. Enter JTAG instruction PROG_COMMANDS.7. Write the page using programming instruction 2g.8. Poll for Flash write complete u

Page 203

281ATmega16(L)2466B–09/01Programming the Fuses 1. Enter JTAG instruction PROG_COMMANDS.2. Enable Fuse write using programming instruction 6a.3. Load d

Page 204

282ATmega16(L)2466B–09/01Electrical CharacteristicsAbsolute Maximum Ratings*Operating Temperature... -55°C to +125°C*NO

Page 205

283ATmega16(L)2466B–09/01Notes: 1. “Max” means the highest value where the pin is guaranteed to be read as low2. “Min” means the lowest value where th

Page 206

284ATmega16(L)2466B–09/018] The sum of all IOH, for ports D4-D7, should not exceed 100 mAIf IOH exceeds the test condition, VOH may exceed the related

Page 207

285ATmega16(L)2466B–09/012-wire Serial Interface CharacteristicsTable 121 describes the requirements for devices connected to the 2-wire Serial Bus. T

Page 208

286ATmega16(L)2466B–09/015. This requirement applies to all ATmega16 2-wire Serial Interface operation. Otherdevices connected to the 2-wire Serial Bu

Page 209

287ATmega16(L)2466B–09/01Figure 147. SPI Interface Timing Requirements (Master Mode)Figure 148. SPI Interface Timing Requirements (Slave Mode)MOSI(D

Page 210

288ATmega16(L)2466B–09/01ADC Characteristics – Preliminary DataNotes: 1. Values aren guidelines only. Actual values are TBD.2. Minimum for AVCC is 2.7

Page 211

289ATmega16(L)2466B–09/01ATmega16 Typical Characteristics – Preliminary DataThe following charts show typical behavior. These figures are not tested d

Page 212

29ATmega16(L)2466B–09/01When this clock source is selected, start-up times are determined by the SUT fuses asshown in Table 12.Timer/Counter Oscillato

Page 213

290ATmega16(L)2466B–09/01Register Summary Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page$3F ($5F) SREG I T H S V N Z C 7$3E ($5E) S

Page 214

291ATmega16(L)2466B–09/01Notes: 1. When the OCDEN fuse is unprogrammed, the OSCCAL register is always accessed on this address. Refer to the debuggers

Page 215

292ATmega16(L)2466B–09/01Instruction Set Summary Mnemonics Operands Description Operation Flags #ClocksARITHMETIC AND LOGIC INSTRUCTIONSADD Rd, Rr Add

Page 216

293ATmega16(L)2466B–09/01BRIE k Branch if Interrupt Enabled if ( I = 1) then PC ← PC + k + 1 None 1 / 2BRID k Branch if Interrupt Disabled if ( I =

Page 217

294ATmega16(L)2466B–09/01CLH Clear Half Carry Flag in SREG H ← 0 H 1MCU CONTROL INSTRUCTIONSNOP No Operation None 1SLEEP Sleep (see specific descr. f

Page 218

295ATmega16(L)2466B–09/01Ordering InformationSpeed (MHz) Power Supply Ordering Code Package Operation Range8 2.7 - 5.5V ATmega16L-8ACATmega16L-8PC44A4

Page 219

296ATmega16(L)2466B–09/01Packaging Information44A1.20(0.047) MAX10.10(0.394) 9.90(0.386)SQ12.25(0.482)11.75(0.462)SQ0.75(0.030)0.45(0.018)0.15(0.006)

Page 220

297ATmega16(L)2466B–09/0140P652.71(2.075)51.94(2.045)PIN113.97(0.550)13.46(0.530)0.38(0.015)MIN0.56(0.022)0.38(0.015)REF15.88(0.625)15.24(0.600)1.65(0

Page 221

© 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 222

3ATmega16(L)2466B–09/01Overview The ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhancedRISC architecture. By executing powerf

Page 223

30ATmega16(L)2466B–09/01Power Management and Sleep ModesSleep modes enable the application to shut down unused modules in the MCU, therebysaving power

Page 224

31ATmega16(L)2466B–09/01Idle Mode When the SM2..0 bits are written to 000, the SLEEP instruction makes the MCU enterIdle Mode, stopping the CPU but al

Page 225

32ATmega16(L)2466B–09/01asynchronous timer should be considered undefined after wake-up in Power-save modeif AS2 is 0.This sleep mode basically halts

Page 226

33ATmega16(L)2466B–09/01Analog Comparator When entering Idle Mode, the Analog Comparator should be disabled if not used. Whenentering ADC Noise Reduct

Page 227

34ATmega16(L)2466B–09/01System Control and ResetResetting the AVR During reset, all I/O registers are set to their initial values, and the program sta

Page 228

35ATmega16(L)2466B–09/01Figure 15. Reset LogicNotes: 1. Values are guidelines only. Actual values are TBD.2. The Power-on Reset will not work unless

Page 229

36ATmega16(L)2466B–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 T

Page 230

37ATmega16(L)2466B–09/01Figure 18. External Reset During OperationBrown-out Detection ATmega16 has an On-chip Brown-out Detection (BOD) circuit for m

Page 231

38ATmega16(L)2466B–09/01Watchdog Reset When the Watchdog times out, it will generate a short reset pulse of 1 CK cycle dura-tion. On the falling edge

Page 232

39ATmega16(L)2466B–09/01Internal Voltage ReferenceATmega16 features an internal bandgap reference. This reference is used for Brown-out Detection, and

Page 233

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

Page 234

40ATmega16(L)2466B–09/01Figure 21. Watchdog TimerWatchdog Timer Control Register – WDTCR• Bits 7..5 - Res: Reserved BitsThese bits are reserved bits

Page 235

41ATmega16(L)2466B–09/01Note: 1. Values are guidelines only. Actual values are TBD.The following code example shows one assembly and one C function fo

Page 236

42ATmega16(L)2466B–09/01Interrupts This section describes the specifics of the interrupt handling as performed inATmega16. For a general explanation o

Page 237

43ATmega16(L)2466B–09/01Note: 1. The Boot Reset Address is shown in Table 100 on page 252. For the BOOTRST fuse“1” means unprogrammed while “0” means

Page 238

44ATmega16(L)2466B–09/01When the BOOTRST fuse is unprogrammed, the boot section size set to 2K bytes andthe IVSEL bit in the GICR register is set befo

Page 239

45ATmega16(L)2466B–09/01Moving Interrupts Between Application and Boot SpaceThe General Interrupt Control Register controls the placement of the inter

Page 240

46ATmega16(L)2466B–09/01Assembly Code ExampleMove_interrupts:; Enable change of interrupt vectorsldi r16, (1<<IVCE)out GICR, r16; Move interrupt

Page 241

47ATmega16(L)2466B–09/01I/O PortsIntroduction All AVR ports have true Read-Modify-Write functionality when used as general digitalI/O ports. This mean

Page 242

48ATmega16(L)2466B–09/01Ports as General Digital I/OThe ports are bi-directional I/O ports with optional internal pull-ups. Figure 23 shows afunctiona

Page 243

49ATmega16(L)2466B–09/01enabled state is fully acceptable, as a high-impedant environment will not notice the dif-ference between a strong high driver

Page 244

5ATmega16(L)2466B–09/01Port B (PB7..PB0) Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for eachbit). The Port B

Page 245

50ATmega16(L)2466B–09/01ceeding positive clock edge. As indicated by the two arrows tpd,max and tpd,min, a singlesignal transition on the pin will be

Page 246

51ATmega16(L)2466B–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 247

52ATmega16(L)2466B–09/01Alternate Port Functions Most port pins have alternate functions in addition to being general digital I/Os. Figure26 shows how

Page 248

53ATmega16(L)2466B–09/01The following subsections shortly describe the alternate functions for each port, andrelate the overriding signals to the alte

Page 249

54ATmega16(L)2466B–09/01Alternate Functions of Port A Port A has an alternate function as analog input for the ADC as shown in Table 22. Ifsome Port A

Page 250

55ATmega16(L)2466B–09/01Alternate Functions of Port B The Port B pins with alternate functions are shown in Table 25.The alternate pin configuration i

Page 251

56ATmega16(L)2466B–09/01• MOSI - Port B, Bit 5MOSI: SPI Master data output, slave data input for SPI channel. When the SPI isenabled as a slave, this

Page 252

57ATmega16(L)2466B–09/01 Table 26. Overriding Signals for Alternate Functions in PB7..PB4SignalName PB7/SCK PB6/MISO PB5/MOSI PB4/SSPUOE SPE • MSTR S

Page 253

58ATmega16(L)2466B–09/01Alternate Functions of Port C The Port C pins with alternate functions are shown in Table 28. If the JTAG interface isenabled,

Page 254

59ATmega16(L)2466B–09/01an open drain driver with slew-rate limitation. When this pin is used by the 2-wire SerialInterface, the pull-up can still be

Page 255

6ATmega16(L)2466B–09/01AVR CPU CoreIntroduction This section discusses the AVR core architecture in general. The main function of theCPU core is to en

Page 256

60ATmega16(L)2466B–09/01Alternate Functions of Port D The Port D pins with alternate functions are shown in Table 31.The alternate pin configuration i

Page 257

61ATmega16(L)2466B–09/01USART forces this pin to be an input, the pull-up can still be controlled by the PORTD0bit.Table 32 and Table 33 relate the al

Page 258

62ATmega16(L)2466B–09/01Register Description for I/O PortsPort A Data Register – PORTAPort A Data Direction Register – DDRAPort A Input Pins Address –

Page 259

63ATmega16(L)2466B–09/01Port C Input Pins Address – PINCPort D Data Register – PORTDPort D Data Direction Register – DDRDPort D Input Pins Address – P

Page 260

64ATmega16(L)2466B–09/01External Interrupts The external interrupts are triggered by the INT0, INT1, and INT2 pins. Observe that, ifenabled, the inter

Page 261

65ATmega16(L)2466B–09/01• Bit 1, 0 - ISC01, ISC00: Interrupt Sense Control 0 Bit 1 and Bit 0The External Interrupt 0 is activated by the external pin

Page 262

66ATmega16(L)2466B–09/01interrupt is activated on rising and/or falling edge of the INT1 pin or level sensed. Activityon the pin will cause an interru

Page 263

67ATmega16(L)2466B–09/018-bit Timer/Counter0 with PWMTimer/Counter0 is a general purpose, single channel, 8-bit Timer/Counter module. Themain features

Page 264

68ATmega16(L)2466B–09/01The double buffered Output Compare Register (OCR0) is compared with theTimer/Counter value at all times. The result of the com

Page 265

69ATmega16(L)2466B–09/01Depending of the mode of operation used, the counter is cleared, incremented, or dec-remented at each timer clock (clkT0). clk

Page 266

7ATmega16(L)2466B–09/01an arithmetic operation, the Status Register is updated to reflect information about theresult of the operation.Program flow is

Page 267

70ATmega16(L)2466B–09/01OCR0 compare register to either top or bottom of the counting sequence. The synchro-nization prevents the occurrence of odd-le

Page 268

71ATmega16(L)2466B–09/01Figure 30. Compare Match Output Unit, SchematicThe general I/O port function is overridden by the output compare (OC0) from t

Page 269

72ATmega16(L)2466B–09/01Normal Mode The simplest mode of operation is the normal mode (WGM01:0 = 0). In this mode thecounting direction is always up (

Page 270

73ATmega16(L)2466B–09/01quency of fOC0 = fclk_I/O/2 when OCR0 is set to zero (0x00). The waveform frequency isdefined by the following equation:The N

Page 271

74ATmega16(L)2466B–09/01pin is set as output. The PWM waveform is generated by setting (or clearing) the OC0register at the compare match between OCR0

Page 272

75ATmega16(L)2466B–09/01Figure 33. Phase Correct PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOV0) is set each time the counter reaches

Page 273

76ATmega16(L)2466B–09/01Figure 34. Timer/Counter Timing Diagram, no PrescalingFigure 35 shows the same timing data, but with the prescaler enabled.Fi

Page 274

77ATmega16(L)2466B–09/01Figure 37 shows the setting of OCF0 and the clearing of TCNT0 in CTC mode.Figure 37. Timer/Counter Timing Diagram, Clear Time

Page 275

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

Page 276

79ATmega16(L)2466B–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 o

Page 277

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

Page 278

80ATmega16(L)2466B–09/01Output Compare Register – OCR0The Output Compare Register contains an 8-bit value that is continuously comparedwith the counte

Page 279

81ATmega16(L)2466B–09/01Timer/Counter0 and Timer/Counter1 PrescalersTimer/Counter1 and Timer/Counter0 share the same prescaler module, but thetimer/co

Page 280

82ATmega16(L)2466B–09/01than half the system clock frequency (fExtClk < fclk_I/O/2) given a 50/50% duty cycle. Sincethe edge detector uses sampling

Page 281

83ATmega16(L)2466B–09/0116-bit Timer/Counter1The 16-bit Timer/Counter unit allows accurate program execution timing (event man-agement), wave generati

Page 282

84ATmega16(L)2466B–09/01Figure 40. 16-bit Timer/Counter Block Diagram(1)Note: 1. Refer to Figure 1 on page 2, Table 25 on page 55, and Table 31 on pa

Page 283

85ATmega16(L)2466B–09/01(OC1A/B). See “Output Compare Units” on page 91. The compare match event will alsoset the compare match flag (OCF1A/B) which c

Page 284

86ATmega16(L)2466B–09/01Accessing 16-bit RegistersThe TCNT1, OCR1A/B, and ICR1 are 16-bit registers that can be accessed by the AVRCPU via the 8-bit d

Page 285

87ATmega16(L)2466B–09/01The following code examples show how to do an atomic read of the TCNT1 register con-tents. Reading any of the OCR1A/B or ICR1

Page 286

88ATmega16(L)2466B–09/01The following code examples show how to do an atomic write of the TCNT1 registercontents. Writing any of the OCR1A/B or ICR1 r

Page 287

89ATmega16(L)2466B–09/01Figure 41. Counter Unit Block DiagramSignal description (internal signals):Count Increment or decrement TCNT1 by 1.Direction

Page 288

9ATmega16(L)2466B–09/01Figure 4. AVR CPU General Purpose Working RegistersMost of the instructions operating on the Register file have direct access

Page 289

90ATmega16(L)2466B–09/01Input Capture Unit The Timer/Counter incorporates an input capture unit that can capture external eventsand give them a time-s

Page 290

91ATmega16(L)2466B–09/01For more information on how to access the 16-bit registers refer to “Accessing 16-bitRegisters” on page 86.Input Capture Trigg

Page 291

92ATmega16(L)2466B–09/01cleared by software by writing a logical one to its I/O bit location. The waveform genera-tor uses the match signal to generat

Page 292

93ATmega16(L)2466B–09/01I/O location is written by the CPU, the TEMP register will be updated by the value writ-ten. Then when the low byte (OCR1xL) i

Page 293

94ATmega16(L)2466B–09/01Figure 44. Compare Match Output Unit, SchematicThe general I/O port function is overridden by the output compare (OC1x) from

Page 294

95ATmega16(L)2466B–09/01Normal Mode The simplest mode of operation is the normal mode (WGM13:0 = 0). In this mode thecounting direction is always up (

Page 295

96ATmega16(L)2466B–09/01this feature is not desirable. An alternative will then be to use the fast PWM mode usingOCR1A for defining TOP (WGM13:0 = 15)

Page 296

97ATmega16(L)2466B–09/01Figure 46. Fast PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOV1) is set each time the counter reaches TOP. Inad

Page 297

98ATmega16(L)2466B–09/01seting (or clearing) the OC1x register at the compare match between OCR1x andTCNT1, and clearing (or setting) the OC1x registe

Page 298 - 2466B–09/01/xM

99ATmega16(L)2466B–09/01Figure 47. Phase Correct PWM Mode, Timing DiagramThe Timer/Counter overflow flag (TOV1) is set each time the counter reaches

Comments to this Manuals

No comments