Rainbow-electronics ATmega32L User Manual

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

  • Download
  • Add to my manuals
  • Print
  • Page
    / 313
  • 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
131 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
32K Bytes of In-System Self-Programmable Flash
Endurance: 10,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
1024 Bytes EEPROM
Endurance: 100,000 Write/Erase Cycles
2K 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
Byte-oriented Two-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, 44-lead TQFP, and 44-pad MLF
Operating Voltages
2.7 - 5.5V for ATmega32L
4.5 - 5.5V for ATmega32
Speed Grades
0 - 8 MHz for ATmega32L
0 - 16 MHz for ATmega32
8-bit
Microcontroller
with 32K Bytes
In-System
Programmable
Flash
ATmega32
ATmega32L
Preliminary
Rev. 2503C–AVR–10/02
Page view 0
1 2 3 4 5 6 ... 312 313

Summary of Contents

Page 1 - Features

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

Page 2

10ATmega32(L) 2503C–AVR–10/02The X-register, Y-register and Z-registerThe registers R26..R31 have some added functions to their general purpose usage.

Page 3

100ATmega32(L) 2503C–AVR–10/02Figure 47. Phase Correct PWM Mode, Timing DiagramThe Timer/Counter Overflow Flag (TOV1) is set each time the counter re

Page 4

101ATmega32(L)2503C–AVR–10/02for the output when using phase correct PWM can be calculated by the followingequation:The N variable represents the pres

Page 5

102ATmega32(L) 2503C–AVR–10/02Figure 48. Phase and Frequency Correct PWM Mode, Timing DiagramThe Timer/Counter Overflow Flag (TOV1) is set at the sam

Page 6

103ATmega32(L)2503C–AVR–10/02The extreme values for the OCR1x Register represents special cases when generatinga PWM waveform output in the phase corr

Page 7

104ATmega32(L) 2503C–AVR–10/02Figure 51 shows the count sequence close to TOP in various modes. When using phaseand frequency correct PWM mode the OCR

Page 8

105ATmega32(L)2503C–AVR–10/0216-bit Timer/Counter Register DescriptionTimer/Counter1 Control Register A – TCCR1A• Bit 7:6 – COM1A1:0: Compare Output M

Page 9

106ATmega32(L) 2503C–AVR–10/02Note: 1. A special case occurs when OCR1A/OCR1B equals TOP and COM1A1/COM1B1 isset. In this case the compare match is ig

Page 10 - ATmega32(L)

107ATmega32(L)2503C–AVR–10/02A FOC1A/FOC1B strobe will not generate any interrupt nor will it clear the timer in ClearTimer on Compare match (CTC) mod

Page 11

108ATmega32(L) 2503C–AVR–10/02Timer/Counter1 Control Register B – TCCR1B• Bit 7 – ICNC1: Input Capture Noise CancelerSetting this bit (to one) activat

Page 12

109ATmega32(L)2503C–AVR–10/02If external pin modes are used for the Timer/Counter1, transitions on the T1 pin willclock the counter even if the pin is

Page 13

11ATmega32(L)2503C–AVR–10/02Instruction Execution TimingThis section describes the general access timing concepts for instruction execution. TheAVR CP

Page 14

110ATmega32(L) 2503C–AVR–10/02Input Capture Register 1 – ICR1H and ICR1LThe Input Capture is updated with the counter (TCNT1) value each time an event

Page 15

111ATmega32(L)2503C–AVR–10/02Timer/Counter Interrupt Flag Register – TIFRNote: This register contains flag bits for several Timer/Counters, but only T

Page 16

112ATmega32(L) 2503C–AVR–10/028-bit Timer/Counter2 with PWM and Asynchronous OperationTimer/Counter2 is a general purpose, single channel, 8-bit Timer

Page 17

113ATmega32(L)2503C–AVR–10/02The double buffered Output Compare Register (OCR2) is compared with theTimer/Counter value at all times. The result of th

Page 18

114ATmega32(L) 2503C–AVR–10/02top Signalizes that TCNT2 has reached maximum value.bottom Signalizes that TCNT2 has reached minimum value (zero).Depend

Page 19

115ATmega32(L)2503C–AVR–10/02The OCR2 Register is double buffered when using any of the Pulse Width Modulation(PWM) modes. For the normal and Clear Ti

Page 20

116ATmega32(L) 2503C–AVR–10/02Figure 56. Compare Match Output Unit, SchematicThe general I/O port function is overridden by the Output Compare (OC2)

Page 21

117ATmega32(L)2503C–AVR–10/02Normal Mode The simplest mode of operation is the Normal mode (WGM21:0 = 0). In this mode thecounting direction is always

Page 22

118ATmega32(L) 2503C–AVR–10/02quency of fOC2 = fclk_I/O/2 when OCR2 is set to zero (0x00). The waveform frequency isdefined by the following equation:

Page 23

119ATmega32(L)2503C–AVR–10/02pin is set as output. The PWM waveform is generated by setting (or clearing) the OC2register at the compare match between

Page 24

12ATmega32(L) 2503C–AVR–10/02– the External Interrupt Request 0. The Interrupt Vectors can be moved to the start ofthe Boot Flash section by setting t

Page 25

120ATmega32(L) 2503C–AVR–10/02Figure 59. Phase Correct PWM Mode, Timing DiagramThe Timer/Counter Overflow Flag (TOV2) is set each time the counter re

Page 26

121ATmega32(L)2503C–AVR–10/02Figure 60. Timer/Counter Timing Diagram, no PrescalingFigure 61 shows the same timing data, but with the prescaler enabl

Page 27

122ATmega32(L) 2503C–AVR–10/02Figure 63 shows the setting of OCF2 and the clearing of TCNT2 in CTC mode.Figure 63. Timer/Counter Timing Diagram, Clea

Page 28

123ATmega32(L)2503C–AVR–10/02Note: 1. The CTC2 and PWM2 bit definition names are now obsolete. Use the WGM21:0 def-initions. However, the functionalit

Page 29

124ATmega32(L) 2503C–AVR–10/02.Note: 1. A special case occurs when OCR2 equals TOP and COM21 is set. In this case, thecompare match is ignored, but th

Page 30

125ATmega32(L)2503C–AVR–10/02Output Compare Register – OCR2The Output Compare Register contains an 8-bit value that is continuously comparedwith the c

Page 31

126ATmega32(L) 2503C–AVR–10/02Asynchronous Operation of Timer/Counter2When Timer/Counter2 operates asynchronously, some considerations must be taken.•

Page 32

127ATmega32(L)2503C–AVR–10/02from Power-down or Standby mode due to unstable clock signal upon start-up, no matter whether the Oscillator is in use or

Page 33

128ATmega32(L) 2503C–AVR–10/02Timer/Counter Interrupt Flag Register – TIFR• Bit 7 – OCF2: Output Compare Flag 2The OCF2 bit is set (one) when a compar

Page 34

129ATmega32(L)2503C–AVR–10/02For Timer/Counter2, the possible prescaled selections are: clkT2S/8, clkT2S/32, clkT2S/64,clkT2S/128, clkT2S/256, and clk

Page 35

13ATmega32(L)2503C–AVR–10/02When using the SEI instruction to enable interrupts, the instruction following SEI will beexecuted before any pending inte

Page 36

130ATmega32(L) 2503C–AVR–10/02Serial Peripheral Interface – SPIThe Serial Peripheral Interface (SPI) allows high-speed synchronous data transferbetwee

Page 37

131ATmega32(L)2503C–AVR–10/02When configured as a Master, the SPI interface has no automatic control of the SS line.This must be handled by user softw

Page 38

132ATmega32(L) 2503C–AVR–10/02The following code examples show how to initialize the SPI as a master and how to per-form a simple transmission. DDR_SP

Page 39

133ATmega32(L)2503C–AVR–10/02The following code examples show how to initialize the SPI as a Slave and how to per-form a simple reception.Note: 1. The

Page 40

134ATmega32(L) 2503C–AVR–10/02SS Pin FunctionalitySlave Mode When the SPI is configured as a Slave, the Slave Select (SS) pin is always input. WhenSS

Page 41

135ATmega32(L)2503C–AVR–10/02• Bit 4 – MSTR: Master/Slave SelectThis bit selects Master SPI mode when written to one, and Slave SPI mode when writtenl

Page 42

136ATmega32(L) 2503C–AVR–10/02SPI Status Register – SPSR• Bit 7 – SPIF: SPI Interrupt FlagWhen a serial transfer is complete, the SPIF flag is set. An

Page 43

137ATmega32(L)2503C–AVR–10/02Data Modes There are four combinations of SCK phase and polarity with respect to serial data,which are determined by cont

Page 44

138ATmega32(L) 2503C–AVR–10/02USART The Universal Synchronous and Asynchronous serial Receiver and Transmitter(USART) is a highly flexible serial comm

Page 45

139ATmega32(L)2503C–AVR–10/02The dashed boxes in the block diagram separate the three main parts of the USART(listed from the top): Clock Generator, T

Page 46

14ATmega32(L) 2503C–AVR–10/02AVR ATmega32 MemoriesThis section describes the different memories in the ATmega32. The AVR architecturehas two main memo

Page 47

140ATmega32(L) 2503C–AVR–10/02Figure 70. Clock Generation Logic, Block DiagramSignal description:txclk Transmitter clock (Internal Signal).rxclk Rece

Page 48

141ATmega32(L)2503C–AVR–10/02Note: 1. The baud rate is defined to be the transfer rate in bit per second (bps).BAUD Baud rate (in bits per second, bps

Page 49

142ATmega32(L) 2503C–AVR–10/02Figure 71. Synchronous Mode XCK Timing.The UCPOL bit UCRSC selects which XCK clock edge is used for data sampling andwh

Page 50

143ATmega32(L)2503C–AVR–10/02The USART Character SiZe (UCSZ2:0) bits select the number of data bits in the frame.The USART Parity mode (UPM1:0) bits e

Page 51

144ATmega32(L) 2503C–AVR–10/02USART Initialization The USART has to be initialized before any communication can take place. The initial-ization proces

Page 52

145ATmega32(L)2503C–AVR–10/02Data Transmission – The USART TransmitterThe USART Transmitter is enabled by setting the Transmit Enable (TXEN) bit in th

Page 53

146ATmega32(L) 2503C–AVR–10/02Sending Frames with 9 Data BitIf 9-bit characters are used (UCSZ = 7), the ninth bit must be written to the TXB8 bit inU

Page 54

147ATmega32(L)2503C–AVR–10/02either write new data to UDR in order to clear UDRE or disable the Data Register emptyInterrupt, otherwise a new interrup

Page 55

148ATmega32(L) 2503C–AVR–10/02Data Reception – The USART ReceiverThe USART Receiver is enabled by writing the Receive Enable (RXEN) bit in theUCSRB Re

Page 56

149ATmega32(L)2503C–AVR–10/02Receiving Frames with 9 DatabitsIf 9 bit characters are used (UCSZ=7) the ninth bit must be read from the RXB8 bit inUCSR

Page 57

15ATmega32(L)2503C–AVR–10/02SRAM Data Memory Figure 9 shows how the ATmega32 SRAM Memory is organized.The lower 2144 Data Memory locations address the

Page 58

150ATmega32(L) 2503C–AVR–10/02The receive function example reads all the I/O registers into the register file before anycomputation is done. This give

Page 59

151ATmega32(L)2503C–AVR–10/02The PE bit is set if the next character that can be read from the receive buffer had a par-ity error when received and th

Page 60

152ATmega32(L) 2503C–AVR–10/02Figure 73. Start Bit SamplingWhen the clock recovery logic detects a high (idle) to low (start) transition on the RxDli

Page 61

153ATmega32(L)2503C–AVR–10/02Figure 75. Stop Bit Sampling and Next Start Bit SamplingThe same majority voting is done to the stop bit as done for the

Page 62

154ATmega32(L) 2503C–AVR–10/02Table 61 and Table 62 list the maximum receiver baud rate error that can be tolerated.Note that Normal Speed mode has hi

Page 63

155ATmega32(L)2503C–AVR–10/02Multi-processor Communication ModeSetting the Multi-processor Communication mode (MPCM) bit in UCSRA enables a fil-tering

Page 64

156ATmega32(L) 2503C–AVR–10/02Accessing UBRRH/ UCSRC RegistersThe UBRRH Register shares the same I/O location as the UCSRC Register. Thereforesome spe

Page 65

157ATmega32(L)2503C–AVR–10/02Read Access Doing a read access to the UBRRH or the UCSRC Register is a more complex opera-tion. However, in most applica

Page 66

158ATmega32(L) 2503C–AVR–10/02The transmit buffer can only be written when the UDRE flag in the UCSRA Register isset. Data written to UDR when the UDR

Page 67 - 8-bit Timer/Counter0

159ATmega32(L)2503C–AVR–10/02• Bit 2 – PE: Parity ErrorThis bit is set if the next character in the receive buffer had a Parity Error when receivedand

Page 68 - Timer/Counter Clock

16ATmega32(L) 2503C–AVR–10/02Data Memory Access Times This section describes the general access timing concepts for internal memory access.The interna

Page 69 - Waveform Generator

160ATmega32(L) 2503C–AVR–10/02do not contain data to be transmitted. When disabled, the transmitter will no longer over-ride the TxD port.• Bit 2 – UC

Page 70

161ATmega32(L)2503C–AVR–10/02• Bit 5:4 – UPM1:0: Parity ModeThese bits enable and set type of parity generation and check. If enabled, the transmit-te

Page 71 - DATA BU S

162ATmega32(L) 2503C–AVR–10/02• Bit 0 – UCPOL: Clock PolarityThis bit is used for Synchronous mode only. Write this bit to zero when Asynchronousmode

Page 72

163ATmega32(L)2503C–AVR–10/02Examples of Baud Rate SettingFor standard crystal and resonator frequencies, the most commonly used baud rates forasynchr

Page 73

164ATmega32(L) 2503C–AVR–10/02Table 69. Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued)Baud Rate (bps)fosc = 3.6864 MH

Page 74

165ATmega32(L)2503C–AVR–10/02Table 70. Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued)Baud Rate (bps)fosc = 8.0000 MHz

Page 75

166ATmega32(L) 2503C–AVR–10/02Table 71. Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued)Baud Rate (bps)fosc = 16.0000 M

Page 76

167ATmega32(L)2503C–AVR–10/02Two-wire Serial InterfaceFeatures • Simple Yet Powerful and Flexible Communication Interface, Only Two Bus Lines Needed•

Page 77

168ATmega32(L) 2503C–AVR–10/02Electrical Interconnection As depicted in Figure 76, both bus lines are connected to the positive supply voltagethrough

Page 78

169ATmega32(L)2503C–AVR–10/02Figure 78. START, REPEATED START, and STOP ConditionsAddress Packet Format All address packets transmitted on the TWI bu

Page 79

17ATmega32(L)2503C–AVR–10/02The EEPROM Address Register – EEARH and EEARL• Bits 15..10 – Res: Reserved BitsThese bits are reserved bits in the ATmega3

Page 80

170ATmega32(L) 2503C–AVR–10/02any more bytes, it should inform the transmitter by sending a NACK after the final byte.The MSB of the data byte is tran

Page 81

171ATmega32(L)2503C–AVR–10/02• Different masters may use different SCL frequencies. A scheme must be devised to synchronize the serial clocks from all

Page 82

172ATmega32(L) 2503C–AVR–10/02Figure 83. Arbitration between Two MastersNote that arbitration is not allowed between:• A REPEATED START condition and

Page 83

173ATmega32(L)2503C–AVR–10/02Overview of the TWI ModuleThe TWI module is comprised of several submodules, as shown in Figure 84. All regis-ters drawn

Page 84

174ATmega32(L) 2503C–AVR–10/02Bus Interface Unit This unit contains the Data and Address Shift Register (TWDR), a START/STOP Con-troller and Arbitrati

Page 85

175ATmega32(L)2503C–AVR–10/02TWI register descriptionTWI Bit Rate Register – TWBR• Bits 7..0 – TWI Bit Rate RegisterTWBR selects the division factor f

Page 86

176ATmega32(L) 2503C–AVR–10/02until a STOP condition is detected, and then generates a new START condition to claimthe bus Master status. TWSTA must b

Page 87 - 1 = 0x1FF;

177ATmega32(L)2503C–AVR–10/02• Bits 1..0 – TWPS: TWI Prescaler BitsThese bits can be read and written, and control the bit rate prescaler. To calculat

Page 88

178ATmega32(L) 2503C–AVR–10/02• Bit 0 – TWGCE: TWI General Call Recognition Enable Bit If set, this bit enables the recognition of a General Call give

Page 89

179ATmega32(L)2503C–AVR–10/023. The application software should now examine the value of TWSR, to make sure that the START condition was successfully

Page 90

18ATmega32(L) 2503C–AVR–10/02When EEMWE has been written to one by software, hardware clears the bit to zero afterfour clock cycles. See the descripti

Page 91

180ATmega32(L) 2503C–AVR–10/02set. Writing a one to TWINT clears the flag. The TWI will then commence executing whatever operation was specified by th

Page 92

181ATmega32(L)2503C–AVR–10/02Transmission Modes The TWI can operate in one of four major modes. These are named Master Transmitter(MT), Master Receive

Page 93

182ATmega32(L) 2503C–AVR–10/02Figure 86. Data Transfer in Master Transmitter ModeA START condition is sent by writing the following value to TWCR:TWE

Page 94

183ATmega32(L)2503C–AVR–10/02After a repeated START condition (state $10) the Two-wire Serial Interface can accessthe same slave again, or a new slave

Page 95

184ATmega32(L) 2503C–AVR–10/02Figure 87. Formats and States in the Master Transmitter ModeMaster Receiver Mode In the Master Receiver mode, a number

Page 96

185ATmega32(L)2503C–AVR–10/02Figure 88. Data Transfer in Master Receiver ModeA START condition is sent by writing the following value to TWCR:TWEN mu

Page 97

186ATmega32(L) 2503C–AVR–10/02Table 75. Status Codes for Master Receiver Mode Status Code(TWSR) Prescaler Bitsare 0Status of the Two-wire SerialBus a

Page 98

187ATmega32(L)2503C–AVR–10/02Figure 89. Formats and States in the Master Receiver ModeSlave Receiver Mode In the Slave Receiver mode, a number of dat

Page 99

188ATmega32(L) 2503C–AVR–10/02The upper seven bits are the address to which the Two-wire Serial Interface will respondwhen addressed by a master. If t

Page 100

189ATmega32(L)2503C–AVR–10/02Table 76. Status Codes for Slave Receiver Mode Status Code(TWSR)Prescaler Bitsare 0Status of the Two-wire Serial Busand

Page 101 - OCnxPCPWM

19ATmega32(L)2503C–AVR–10/02The following code examples show one assembly and one C function for writing to theEEPROM. The examples assume that interr

Page 102 - OCnxPFCPWM

190ATmega32(L) 2503C–AVR–10/02Figure 91. Formats and States in the Slave Receiver ModeSlave Transmitter Mode In the Slave Transmitter mode, a number

Page 103

191ATmega32(L)2503C–AVR–10/02The upper seven bits are the address to which the Two-wire Serial Interface will respondwhen addressed by a master. If th

Page 104

192ATmega32(L) 2503C–AVR–10/02Table 77. Status Codes for Slave Transmitter ModeStatus Code(TWSR)Prescaler Bitsare 0Status of the Two-wire Serial Busa

Page 105

193ATmega32(L)2503C–AVR–10/02Figure 93. Formats and States in the Slave Transmitter ModeMiscellaneous States There are two status codes that do not c

Page 106

194ATmega32(L) 2503C–AVR–10/02Combining Several TWI ModesIn some cases, several TWI modes must be combined in order to complete the desiredaction. Con

Page 107

195ATmega32(L)2503C–AVR–10/02Several different scenarios may arise during arbitration, as described below:• Two or more masters are performing identic

Page 108

196ATmega32(L) 2503C–AVR–10/02Analog Comparator The Analog Comparator compares the input values on the positive pin AIN0 and nega-tive pin AIN1. When

Page 109

197ATmega32(L)2503C–AVR–10/02Analog Comparator Control and Status Register – ACSR• Bit 7 – ACD: Analog Comparator DisableWhen this bit is written logi

Page 110

198ATmega32(L) 2503C–AVR–10/02• Bits 1, 0 – ACIS1, ACIS0: Analog Comparator Interrupt Mode SelectThese bits determine which comparator events that tri

Page 111

199ATmega32(L)2503C–AVR–10/02Analog to Digital ConverterFeatures • 10-bit Resolution• 0.5 LSB Integral Non-linearity• ±2 LSB Absolute Accuracy• 65 - 2

Page 112

2ATmega32(L) 2503C–AVR–10/02Pin Configurations Figure 1. Pinouts ATmega32Disclaimer Typical values contained in this data sheet are based on simulati

Page 113

20ATmega32(L) 2503C–AVR–10/02The next code examples show assembly and C functions for reading the EEPROM. Theexamples assume that interrupts are contr

Page 114

200ATmega32(L) 2503C–AVR–10/02Figure 98. Analog to Digital Converter Block SchematicOperation The ADC converts an analog input voltage to a 10-bit di

Page 115

201ATmega32(L)2503C–AVR–10/02amplified value then becomes the analog input to the ADC. If single ended channels areused, the gain amplifier is bypasse

Page 116

202ATmega32(L) 2503C–AVR–10/02Figure 99. ADC Auto Trigger LogicUsing the ADC Interrupt Flag as a trigger source makes the ADC start a new conversiona

Page 117 - (Toggle)

203ATmega32(L)2503C–AVR–10/02setting the ADEN bit in ADCSRA. The prescaler keeps running for as long as the ADENbit is set, and is continuously reset

Page 118

204ATmega32(L) 2503C–AVR–10/02Figure 102. ADC Timing Diagram, Single ConversionFigure 103. ADC Timing Diagram, Auto Triggered ConversionFigure 104.

Page 119

205ATmega32(L)2503C–AVR–10/02Differential Gain Channels When using differential gain channels, certain aspects of the conversion need to betaken into

Page 120 - OCnPCPWM

206ATmega32(L) 2503C–AVR–10/02If Auto Triggering is used, the exact time of the triggering event can be indeterministic.Special care must be taken whe

Page 121

207ATmega32(L)2503C–AVR–10/02external voltage. If no external voltage is applied to the AREF pin, the user may switchbetween AVCC and 2.56V as referen

Page 122

208ATmega32(L) 2503C–AVR–10/02Figure 105. Analog Input CircuitryAnalog Noise Canceling TechniquesDigital circuitry inside and outside the device gene

Page 123

209ATmega32(L)2503C–AVR–10/02Offset Compensation SchemesThe gain stage has a built-in offset cancellation circuitry that nulls the offset of differen-

Page 124

21ATmega32(L)2503C–AVR–10/02I/O Memory The I/O space definition of the ATmega32 is shown in “Register Summary” on page 297.All ATmega32 I/Os and perip

Page 125

210ATmega32(L) 2503C–AVR–10/02• Integral Non-linearity (INL): After adjusting for offset and gain error, the INL is the maximum deviation of an actual

Page 126

211ATmega32(L)2503C–AVR–10/02ADC Conversion Result After the conversion is complete (ADIF is high), the conversion result can be found inthe ADC Resul

Page 127

212ATmega32(L) 2503C–AVR–10/02Example: ADMUX = 0xED (ADC3 - ADC2, 10x gain, 2.56V reference, left adjusted result) Voltage on ADC3 is 300 mV, voltage

Page 128

213ATmega32(L)2503C–AVR–10/02less of any ongoing conversions. For a complete description of this bit, see “The ADCData Register – ADCL and ADCH” on pa

Page 129

214ATmega32(L) 2503C–AVR–10/02Note: 1. The differential input channels are not tested for devices in PDIP Package. This fea-ture is only guaranteed to

Page 130

215ATmega32(L)2503C–AVR–10/02• Bits 2:0 – ADPS2:0: ADC Prescaler Select BitsThese bits determine the division factor between the XTAL frequency and th

Page 131

216ATmega32(L) 2503C–AVR–10/02• ADC9:0: ADC Conversion ResultThese bits represent the result from the conversion, as detailed in “ADC ConversionResult

Page 132

217ATmega32(L)2503C–AVR–10/02JTAG Interface and On-chip Debug SystemFeatures • JTAG (IEEE std. 1149.1 Compliant) Interface• Boundary-scan Capabilities

Page 133

218ATmega32(L) 2503C–AVR–10/02The IEEE std. 1149.1 also specifies an optional TAP signal; TRST – Test ReSeT –which is not provided.When the JTAGEN Fus

Page 134

219ATmega32(L)2503C–AVR–10/02Figure 113. TAP Controller State DiagramTAP Controller The TAP controller is a 16-state finite state machine that contro

Page 135

22ATmega32(L) 2503C–AVR–10/02System Clock and Clock OptionsClock Systems and their DistributionFigure 11 presents the principal clock systems in the A

Page 136

220ATmega32(L) 2503C–AVR–10/02this state is left by setting TMS high. While the instruction is shifted in from the TDI pin, the captured IR-state 0x01

Page 137

221ATmega32(L)2503C–AVR–10/02• 2 single Program Memory Break Points + 1 Program Memory Break Point with mask (“range Break Point”)• 2 single Program M

Page 138

222ATmega32(L) 2503C–AVR–10/02On-chip Debug Related Register in I/O MemoryOn-chip Debug Register – OCDRThe OCDR Register provides a communication chan

Page 139

223ATmega32(L)2503C–AVR–10/02IEEE 1149.1 (JTAG) Boundary-scanFeatures • JTAG (IEEE std. 1149.1 Compliant) Interface• Boundary-scan Capabilities Accord

Page 140

224ATmega32(L) 2503C–AVR–10/02Bypass Register The Bypass Register consists of a single Shift Register stage. When the Bypass Regis-ter is selected as

Page 141 - 2503C–AVR–10/02

225ATmega32(L)2503C–AVR–10/02Figure 115. Reset RegisterBoundary-scan Chain The Boundary-scan Chain has the capability of driving and observing the lo

Page 142

226ATmega32(L) 2503C–AVR–10/02SAMPLE_PRELOAD; $2 Mandatory JTAG instruction for pre-loading the output latches and talking a snap-shot ofthe input/out

Page 143

227ATmega32(L)2503C–AVR–10/02Boundary-scan Chain The Boundary-scan chain has the capability of driving and observing the logic levels onthe digital I/

Page 144

228ATmega32(L) 2503C–AVR–10/02Figure 117. General Port Pin Schematic Diagram(1)Note: 1. See Boundary-scan descriptin for details.Boundary-scan and th

Page 145

229ATmega32(L)2503C–AVR–10/02Figure 118. Additional Scan Signal for the Two-wire InterfaceScanning the RESET Pin The RESET pin accepts 5V active low

Page 146

23ATmega32(L)2503C–AVR–10/02Asynchronous Timer Clock – clkASYThe Asynchronous Timer clock allows the Asynchronous Timer/Counter to be clockeddirectly

Page 147

230ATmega32(L) 2503C–AVR–10/02Figure 120. Boundary-scan Cells for Oscillators and Clock OptionsTable 90 summaries the scan registers for the external

Page 148

231ATmega32(L)2503C–AVR–10/02Figure 121. Analog ComparatorFigure 122. General Boundary-scan Cell used for Signals for Comparator and ADCACBGBANDGAPR

Page 149

232ATmega32(L) 2503C–AVR–10/02Scanning the ADCFigure 123 shows a block diagram of the ADC with all relevant control and observe signals. The Boundary-

Page 150

233ATmega32(L)2503C–AVR–10/02Table 92. Boundary-scan Signals for the ADC Signal NameDirection as Seenfrom the ADC DescriptionRecommended Input when N

Page 151

234ATmega32(L) 2503C–AVR–10/02Note: Incorrect setting of the switches in Figure 123 will make signal contention and may damage the part. There are sev

Page 152

235ATmega32(L)2503C–AVR–10/02If the ADC is not to be used during scan, the recommended input values from Table 92should be used. The user is recommend

Page 153

236ATmega32(L) 2503C–AVR–10/02Using this algorithm, the timing constraint on the HOLD signal constrains the TCK clockfrequency. As the algorithm keeps

Page 154

237ATmega32(L)2503C–AVR–10/02ATmega32 Boundary-scan OrderTable 94 shows the scan order between TDI and TDO when the Boundary-scan chain isselected as

Page 155

238ATmega32(L) 2503C–AVR–10/02112 MUXEN_7 ADC111 MUXEN_6110 MUXEN_5109 MUXEN_4108 MUXEN_3107 MUXEN_2106 MUXEN_1105 MUXEN_0104 NEGSEL_2103 NEGSEL_1102

Page 156

239ATmega32(L)2503C–AVR–10/0281 PB5.Data Port B80 PB5.Control79 PB5.Pullup_Enable78 PB6.Data77 PB6.Control76 PB6.Pullup_Enable75 PB7.Data74 PB7.Contro

Page 157

24ATmega32(L) 2503C–AVR–10/02Crystal Oscillator XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which canbe configured f

Page 158

240ATmega32(L) 2503C–AVR–10/0246 PD5.Data Port D45 PD5.Control44 PD5.Pullup_Enable43 PD6.Data42 PD6.Control41 PD6.Pullup_Enable40 PD7.Data39 PD7.Contr

Page 159

241ATmega32(L)2503C–AVR–10/02Notes: 1. PRIVATE_SIGNAL1 should always be scanned in as zero.2. PRIVATE_SIGNAL2 should always be scanned in as zero.Boun

Page 160

242ATmega32(L) 2503C–AVR–10/02Boot Loader Support – Read-While-Write Self-ProgrammingThe Boot Loader Support provides a real Read-While-Write Self-Pro

Page 161

243ATmega32(L)2503C–AVR–10/02Note that the user software can never read any code that is located inside the RWWsection during a Boot Loader software o

Page 162

244ATmega32(L) 2503C–AVR–10/02Figure 125. Memory Sections(1)Note: 1. The parameters in the figure above are given in Table 100 on page 253.Boot Loade

Page 163

245ATmega32(L)2503C–AVR–10/02Note: 1. “1” means unprogrammed, “0” means programmedNote: 1. “1” means unprogrammed, “0” means programmedEntering the Bo

Page 164

246ATmega32(L) 2503C–AVR–10/02Note: 1. “1” means unprogrammed, “0” means programmedStore Program Memory Control Register – SPMCRThe Store Program Memo

Page 165

247ATmega32(L)2503C–AVR–10/02• Bit 2 – PGWRT: Page WriteIf this bit is written to one at the same time as SPMEN, the next SPM instruction withinfour c

Page 166

248ATmega32(L) 2503C–AVR–10/02Figure 126. Addressing the Flash during SPM(1)Note: 1. The different variables used in Figure 126 are listed in Table 1

Page 167

249ATmega32(L)2503C–AVR–10/02Performing Page Erase by SPMTo execute Page Erase, set up the address in the Z-pointer, write “X0000011” toSPMCR and exec

Page 168

25ATmega32(L)2503C–AVR–10/02The CKSEL0 Fuse together with the SUT1..0 fuses select the start-up times as shown inTable 5.Notes: 1. These options shoul

Page 169

250ATmega32(L) 2503C–AVR–10/02See Table 96 and Table 97 for how the different settings of the Boot Loader bits affectthe Flash access.If bits 5..2 in

Page 170

251ATmega32(L)2503C–AVR–10/02correctly. Secondly, the CPU itself can execute instructions incorrectly, if the supplyvoltage for executing instructions

Page 171

252ATmega32(L) 2503C–AVR–10/02call Do_spmadiw ZH:ZL, 2sbiw loophi:looplo, 2 ;use subi for PAGESIZEB<=256brne Wrloop; execute page writesubi ZL, low

Page 172

253ATmega32(L)2503C–AVR–10/02ATmega32 Boot Loader ParametersIn Table 100 through Table 102, the parameters used in the description of the self pro-gra

Page 173

254ATmega32(L) 2503C–AVR–10/02Memory ProgrammingProgram And Data Memory Lock BitsThe ATmega32 provides six Lock bits which can be left unprogrammed (“

Page 174

255ATmega32(L)2503C–AVR–10/02Notes: 1. Program the fuse bits before programming the Lock bits.2. “1” means unprogrammed, “0” means programmedFuse Bits

Page 175

256ATmega32(L) 2503C–AVR–10/02Notes: 1. The default value of SUT1..0 results in maximum start-up time. SeeTable 10 on page28 for details.2. The defaul

Page 176

257ATmega32(L)2503C–AVR–10/02Parallel Programming Parameters, Pin Mapping, and CommandsThis section describes how to parallel program and verify Flash

Page 177

258ATmega32(L) 2503C–AVR–10/02Table 108. Pin Values used to Enter Programming ModePin Symbol ValuePAGEL Prog_enable[3] 0XA1 Prog_enable[2] 0XA0 Prog_

Page 178

259ATmega32(L)2503C–AVR–10/02Parallel ProgrammingEnter Programming Mode The following algorithm puts the device in Parallel Programming mode:1. Apply

Page 179

26ATmega32(L) 2503C–AVR–10/02Low-frequency Crystal OscillatorTo use a 32.768 kHz watch crystal as the clock source for the device, the Low-fre-quency

Page 180

260ATmega32(L) 2503C–AVR–10/02Programming the Flash The Flash is organized in pages, see Table 111 on page 258. When programming theFlash, the program

Page 181

261ATmega32(L)2503C–AVR–10/02G. Load Address High byte1. Set XA1, XA0 to “00”. This enables address loading.2. Set BS1 to “1”. This selects high addre

Page 182

262ATmega32(L) 2503C–AVR–10/02Figure 129. Programming the Flash Waveforms(1)Note: 1. “XX” is don’t care. The letters refer to the programming descrip

Page 183

263ATmega32(L)2503C–AVR–10/02Programming the EEPROM The EEPROM is organized in pages, see Table 112 on page 258. When programmingthe EEPROM, the progr

Page 184

264ATmega32(L) 2503C–AVR–10/025. Set BS1 to “1”. The Flash word high byte can now be read at DATA.6. Set OE to “1”.Reading the EEPROM The algorithm fo

Page 185

265ATmega32(L)2503C–AVR–10/02Programming the Lock Bits The algorithm for programming the Lock bits is as follows (refer to “Programming theFlash” on p

Page 186

266ATmega32(L) 2503C–AVR–10/02Parallel Programming CharacteristicsFigure 133. Parallel Programming Timing, Including some General TimingRequirementsF

Page 187

267ATmega32(L)2503C–AVR–10/02Figure 135. Parallel Programming Timing, Reading Sequence (within the Same Page)with Timing Requirements(1)Note: 1. The

Page 188

268ATmega32(L) 2503C–AVR–10/02Notes: 1. tWLRH is valid for the Write Flash, Write EEPROM, Write Fuse bits and Write Lockbits commands.2. tWLRH_CE is

Page 189

269ATmega32(L)2503C–AVR–10/02Chip Erase instruction. The Chip Erase operation turns the content of every memorylocation in both the Program and EEPROM

Page 190

27ATmega32(L)2503C–AVR–10/02When this Oscillator is selected, start-up times are determined by the SUT fuses asshown in Table 8.Note: 1. This option s

Page 191

270ATmega32(L) 2503C–AVR–10/02Data Polling Flash When a page is being programmed into the Flash, reading an address location withinthe page being prog

Page 192

271ATmega32(L)2503C–AVR–10/02Note: a = address high bitsb = address low bitsH = 0 – Low byte, 1 – High Byteo = data outi = data inx = don’t careTable

Page 193

272ATmega32(L) 2503C–AVR–10/02SPI Serial Programming CharacteristicsFor Characteristics of SPI module, see “SPI Timing Characteristics” on page 288.Pr

Page 194

273ATmega32(L)2503C–AVR–10/02Figure 138. State Machine Sequence for Changing the Instruction WordAVR_RESET ($C) The AVR specific public JTAG instruct

Page 195

274ATmega32(L) 2503C–AVR–10/02PROG_COMMANDS ($5) The AVR specific public JTAG instruction for entering programming commands via theJTAG port. The 15-b

Page 196

275ATmega32(L)2503C–AVR–10/02Programming Enable Register The Programming Enable Register is a 16-bit register. The contents of this register iscompare

Page 197

276ATmega32(L) 2503C–AVR–10/02Table 117. JTAG Programming Instruction Set a = address high bits, b = address low bits, H = 0 – Low byte, 1 – High By

Page 198

277ATmega32(L)2503C–AVR–10/025c. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx5d. Read Data Byte 0110011_bbbbbbbb0110010_000000000110011_000

Page 199

278ATmega32(L) 2503C–AVR–10/02Notes: 1. This command sequence is not required if the seven MSB are correctly set by the previous command sequence (whi

Page 200

279ATmega32(L)2503C–AVR–10/02Figure 141. State Machine Sequence for Changing/Reading the Data WordVirtual Flash Page Load RegisterThe Virtual Flash P

Page 201

28ATmega32(L) 2503C–AVR–10/02When this Oscillator is selected, start-up times are determined by the SUT fuses asshown in Table 10. XTAL1 and XTAL2 sho

Page 202

280ATmega32(L) 2503C–AVR–10/02Figure 142. Virtual Flash Page Load RegisterVirtual Flash Page Read RegisterThe Virtual Flash Page Read Register is a v

Page 203

281ATmega32(L)2503C–AVR–10/02Programming Algorithm All references below of type “1a”, “1b”, and so on, refer to Table 117.Entering Programming Mode 1.

Page 204

282ATmega32(L) 2503C–AVR–10/02Reading the Flash 1. Enter JTAG instruction PROG_COMMANDS.2. Enable Flash read using programming instruction 3a.3. Load

Page 205

283ATmega32(L)2503C–AVR–10/025. Poll for Fuse write complete using programming instruction 6d, or wait for tWLRH (refer to Table 113 on page 267).6. L

Page 206

284ATmega32(L) 2503C–AVR–10/02Electrical CharacteristicsAbsolute Maximum Ratings*DC Characteristics Operating Temperature...

Page 207

285ATmega32(L)2503C–AVR–10/02Notes: 1. “Max” means the highest value where the pin is guaranteed to be read as low2. “Min” means the lowest value wher

Page 208

286ATmega32(L) 2503C–AVR–10/026] The sum of all IOH, for ports C0 - C7, should not exceed 200 mA.If IOH exceeds the test condition, VOH may exceed the

Page 209

287ATmega32(L)2503C–AVR–10/02Two-wire Serial Interface CharacteristicsTable 120 describes the requirements for devices connected to the Two-wire Seria

Page 210

288ATmega32(L) 2503C–AVR–10/025. This requirement applies to all ATmega32 Two-wire Serial Interface operation. Otherdevices connected to the Two-wire

Page 211

289ATmega32(L)2503C–AVR–10/02Figure 146. SPI Interface Timing Requirements (Master Mode)Figure 147. SPI Interface Timing Requirements (Slave Mode)MO

Page 212

29ATmega32(L)2503C–AVR–10/02External Clock To drive the device from an external clock source, XTAL1 should be driven as shown inFigure 14. To run the

Page 213

290ATmega32(L) 2503C–AVR–10/02ADC Characteristics – Preliminary DataTable 122. ADC Characteristics Symbol Parameter Condition Min Typ Max UnitsResolu

Page 214

291ATmega32(L)2503C–AVR–10/02Notes: 1. Minimum for AVCC is 2.7V.2. Maximum for AVCC is 5.5V.VINTInternal Voltage Reference 2.3 2.56 2.7 VRREFReference

Page 215

292ATmega32(L) 2503C–AVR–10/02ATmega32 Typical Characteristics – Preliminary DataThe following charts show typical behavior. These figures are not tes

Page 216

293ATmega32(L)2503C–AVR–10/02Figure 148. RC Oscillator Frequency vs. Temperature (the devices are calibrated to1 MHz at Vcc = 5V, T=25c)Figure 149.

Page 217

294ATmega32(L) 2503C–AVR–10/02Figure 150. RC Oscillator Frequency vs. Temperature (the devices are calibrated to2 MHz at Vcc = 5V, T=25c)Figure 151.

Page 218

295ATmega32(L)2503C–AVR–10/02Figure 152. RC Oscillator Frequency vs. Temperature (the devices are calibrated to4 MHz at Vcc = 5V, T=25c)Figure 153.

Page 219

296ATmega32(L) 2503C–AVR–10/02Figure 154. RC Oscillator Frequency vs. Temperature (the devices are calibrated to 8MHz at Vcc = 5V, T=25c)Figure 155.

Page 220

297ATmega32(L)2503C–AVR–10/02Register SummaryAddress 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 8$3E ($5E

Page 221

298ATmega32(L) 2503C–AVR–10/02Notes: 1. When the OCDEN Fuse is unprogrammed, the OSCCAL Register is always accessed on this address. Refer to the debu

Page 222

299ATmega32(L)2503C–AVR–10/02Instruction Set SummaryMnemonics Operands Description Operation Flags #ClocksARITHMETIC AND LOGIC INSTRUCTIONSADD Rd, Rr

Page 223

3ATmega32(L)2503C–AVR–10/02Overview The ATmega32 is a low-power CMOS 8-bit microcontroller based on the AVR enhancedRISC architecture. By executing po

Page 224

30ATmega32(L) 2503C–AVR–10/02Power Management and Sleep ModesSleep modes enable the application to shut down unused modules in the MCU, therebysaving

Page 225

300ATmega32(L) 2503C–AVR–10/02BRIE k Branch if Interrupt Enabled if ( I = 1) then PC ← PC + k + 1 None 1 / 2BRID k Branch if Interrupt Disabled if (

Page 226

301ATmega32(L)2503C–AVR–10/02CLH Clear Half Carry Flag in SREG H ← 0 H 1MCU CONTROL INSTRUCTIONSNOP No Operation None 1SLEEP Sleep (see specific desc

Page 227

302ATmega32(L) 2503C–AVR–10/02Ordering InformationSpeed (MHz) Power Supply Ordering Code Package Operation Range8 2.7 - 5.5V ATmega32L-8ACATmega32L-8P

Page 228

303ATmega32(L)2503C–AVR–10/02Packaging 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.

Page 229

304ATmega32(L) 2503C–AVR–10/0240P652.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

Page 230

305ATmega32(L)2503C–AVR–10/0244M1 2325 Orchard Parkway San Jose, CA 95131TITLE44M1, 44-pad ,7 x 7 x 1.0 mm body, lead pitch 0.50mmMicro lead frame

Page 231

306ATmega32(L) 2503C–AVR–10/02ErrataATmega32 Rev. A There are no errata for this revision of ATmega32.

Page 232

307ATmega32(L)2503C–AVR–10/02Data Sheet Change Log for ATmega32Please note that the referring page numbers in this section are referred to this docu-m

Page 233

iATmega32(L)2503C–AVR–10/02Table of Contents Features...

Page 234

iiATmega32(L) 2503C–AVR–10/02Minimizing Power Consumption ... 32System Control a

Page 235

31ATmega32(L)2503C–AVR–10/02Idle Mode When the SM2..0 bits are written to 000, the SLEEP instruction makes the MCU enterIdle mode, stopping the CPU bu

Page 236

iiiATmega32(L)2503C–AVR–10/02Compare Match Output Unit ... 115Modes of Opera

Page 237

ivATmega32(L) 2503C–AVR–10/02ADC Conversion Result... 211JTAG Interfa

Page 238

vATmega32(L)2503C–AVR–10/02External Clock Drive Waveforms ... 286External Clock Dri

Page 239

Printed on recycled paper.© Atmel Corporation 2002.Atmel Corporation makes no warranty for the use of its products, other than those expressly contai

Page 240

32ATmega32(L) 2503C–AVR–10/02Asynchronous Timer should be considered undefined after wake-up in Power-savemode if AS2 is 0.This sleep mode basically h

Page 241

33ATmega32(L)2503C–AVR–10/02Analog Comparator When entering Idle mode, the Analog Comparator should be disabled if not used. Whenentering ADC Noise Re

Page 242

34ATmega32(L) 2503C–AVR–10/02System Control and ResetResetting the AVR During Reset, all I/O Registers are set to their initial values, and the progra

Page 243

35ATmega32(L)2503C–AVR–10/02Figure 15. Reset LogicNotes: 1. The Power-on Reset will not work unless the supply voltage has been below VPOT(falling).2

Page 244

36ATmega32(L) 2503C–AVR–10/02Power-on Reset A Power-on Reset (POR) pulse is generated by an On-chip detection circuit. The detec-tion level is defined

Page 245

37ATmega32(L)2503C–AVR–10/02External Reset An External Reset is generated by a low level on the RESET pin. Reset pulses longerthan the minimum pulse w

Page 246

38ATmega32(L) 2503C–AVR–10/02Watchdog Reset When the Watchdog times out, it will generate a short reset pulse of one CK cycle dura-tion. On the fallin

Page 247

39ATmega32(L)2503C–AVR–10/02Internal Voltage ReferenceATmega32 features an internal bandgap reference. This reference is used for Brown-out Detection,

Page 248

4ATmega32(L) 2503C–AVR–10/02The AVR core combines a rich instruction set with 32 general purpose working registers.All the 32 registers are directly c

Page 249

40ATmega32(L) 2503C–AVR–10/02Watchdog Timer Control Register – WDTCR• Bits 7..5 – Res: Reserved BitsThese bits are reserved bits in the ATmega32 and w

Page 250

41ATmega32(L)2503C–AVR–10/02The following code example shows one assembly and one C function for turning off theWDT. The example assumes that interrup

Page 251

42ATmega32(L) 2503C–AVR–10/02Interrupts This section describes the specifics of the interrupt handling as performed inATmega32. For a general explanat

Page 252

43ATmega32(L)2503C–AVR–10/02Note: 1. The Boot Reset Address is shown in Table 100 on page 253. For the BOOTRSTFuse “1” means unprogrammed while “0” me

Page 253

44ATmega32(L) 2503C–AVR–10/02When the BOOTRST Fuse is unprogrammed, the Boot section size set to 4K bytes andthe IVSEL bit in the GICR Register is set

Page 254

45ATmega32(L)2503C–AVR–10/02Moving Interrupts Between Application and Boot SpaceThe General Interrupt Control Register controls the placement of the I

Page 255

46ATmega32(L) 2503C–AVR–10/02• Bit 0 – IVCE: Interrupt Vector Change EnableThe IVCE bit must be written to logic one to enable change of the IVSEL bit

Page 256

47ATmega32(L)2503C–AVR–10/02I/O PortsIntroduction All AVR ports have true Read-Modify-Write functionality when used as general digitalI/O ports. This

Page 257

48ATmega32(L) 2503C–AVR–10/02Ports as General Digital I/OThe ports are bi-directional I/O ports with optional internal pull-ups. Figure 23 shows afunc

Page 258

49ATmega32(L)2503C–AVR–10/02enabled state is fully acceptable, as a high-impedant environment will not notice the dif-ference between a strong high dr

Page 259

5ATmega32(L)2503C–AVR–10/02Port B (PB7..PB0) Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for eachbit). The Po

Page 260

50ATmega32(L) 2503C–AVR–10/02succeeding positive clock edge. As indicated by the two arrows tpd,max and tpd,min, asingle signal transition on the pin

Page 261

51ATmega32(L)2503C–AVR–10/02The following code example shows how to set port B pins 0 and 1 high, 2 and 3 low, anddefine the port pins from 4 to 7 as

Page 262

52ATmega32(L) 2503C–AVR–10/02Unconnected pins If some pins are unused, it is recommended to ensure that these pins have a definedlevel. Even though mo

Page 263

53ATmega32(L)2503C–AVR–10/02Table 21 summarizes the function of the overriding signals. The pin and port indexesfrom Figure 26 are not shown in the su

Page 264

54ATmega32(L) 2503C–AVR–10/02Special Function I/O Register – SFIOR• Bit 2 – PUD: Pull-up disableWhen this bit is written to one, the pull-ups in the I

Page 265

55ATmega32(L)2503C–AVR–10/02Alternate Functions of Port B The Port B pins with alternate functions are shown in Table 25.The alternate pin configurati

Page 266

56ATmega32(L) 2503C–AVR–10/02DDB6. When the pin is forced by the SPI to be an input, the pull-up can still be con-trolled by the PORTB6 bit.• MOSI – P

Page 267

57ATmega32(L)2503C–AVR–10/02 Table 26. Overriding Signals for Alternate Functions in PB7..PB4SignalName PB7/SCK PB6/MISO PB5/MOSI PB4/SSPUOE SPE • MS

Page 268

58ATmega32(L) 2503C–AVR–10/02Alternate Functions of Port C The Port C pins with alternate functions are shown in Table 28. If the JTAG interface isena

Page 269

59ATmega32(L)2503C–AVR–10/02• TCK – Port C, Bit 2TCK, JTAG Test Clock: JTAG operation is synchronous to TCK. When the JTAG inter-face is enabled, this

Page 270

6ATmega32(L) 2503C–AVR–10/02AVR CPU CoreIntroduction This section discusses the AVR core architecture in general. The main function of theCPU core is

Page 271

60ATmega32(L) 2503C–AVR–10/02Note: 1. When enabled, the Two-wire Serial Interface enables slew-rate controls on the outputpins PC0 and PC1. This is no

Page 272

61ATmega32(L)2503C–AVR–10/02• OC1A – Port D, Bit 5OC1A, Output Compare Match A output: The PD5 pin can serve as an external outputfor the Timer/Counte

Page 273

62ATmega32(L) 2503C–AVR–10/02 Register Description for I/O PortsPort A Data Register – PORTAPort A Data Direction Register – DDRAPort A Input Pins Add

Page 274

63ATmega32(L)2503C–AVR–10/02Port B Input Pins Address – PINBPort C Data Register – PORTCPort C Data Direction Register – DDRCPort C Input Pins Address

Page 275

64ATmega32(L) 2503C–AVR–10/02External Interrupts The External Interrupts are triggered by the INT0, INT1, and INT2 pins. Observe that, ifenabled, the

Page 276

65ATmega32(L)2503C–AVR–10/02• Bit 1, 0 – ISC01, ISC00: Interrupt Sense Control 0 Bit 1 and Bit 0The External Interrupt 0 is activated by the external

Page 277

66ATmega32(L) 2503C–AVR–10/02ISC10) in the MCU General Control Register (MCUCR) define whether the ExternalInterrupt is activated on rising and/or fal

Page 278

67ATmega32(L)2503C–AVR–10/028-bit Timer/Counter0 with PWMTimer/Counter0 is a general purpose, single channel, 8-bit Timer/Counter module. Themain feat

Page 279

68ATmega32(L) 2503C–AVR–10/02The double buffered Output Compare Register (OCR0) is compared with theTimer/Counter value at all times. The result of th

Page 280

69ATmega32(L)2503C–AVR–10/02BOTTOM Signalize that TCNT0 has reached minimum value (zero).Depending of the mode of operation used, the counter is clear

Page 281

7ATmega32(L)2503C–AVR–10/02an arithmetic operation, the Status Register is updated to reflect information about theresult of the operation.Program flo

Page 282

70ATmega32(L) 2503C–AVR–10/02The OCR0 Register is double buffered when using any of the Pulse Width Modulation(PWM) modes. For the normal and Clear Ti

Page 283

71ATmega32(L)2503C–AVR–10/02Figure 30. Compare Match Output Unit, SchematicThe general I/O port function is overridden by the Output Compare (OC0) fr

Page 284

72ATmega32(L) 2503C–AVR–10/02Normal Mode The simplest mode of operation is the normal mode (WGM01:0 = 0). In this mode thecounting direction is always

Page 285

73ATmega32(L)2503C–AVR–10/02quency of fOC0 = fclk_I/O/2 when OCR0 is set to zero (0x00). The waveform frequency isdefined by the following equation:Th

Page 286

74ATmega32(L) 2503C–AVR–10/02pin is set as output. The PWM waveform is generated by setting (or clearing) the OC0register at the compare match between

Page 287

75ATmega32(L)2503C–AVR–10/02Figure 33. Phase Correct PWM Mode, Timing DiagramThe Timer/Counter Overflow Flag (TOV0) is set each time the counter reac

Page 288

76ATmega32(L) 2503C–AVR–10/02Timer/Counter Timing DiagramsThe Timer/Counter is a synchronous design and the timer clock (clkT0) is thereforeshown as a

Page 289

77ATmega32(L)2503C–AVR–10/02Figure 36. Timer/Counter Timing Diagram, Setting of OCF0, with Prescaler (fclk_I/O/8)Figure 37 shows the setting of OCF0

Page 290

78ATmega32(L) 2503C–AVR–10/028-bit Timer/Counter Register DescriptionTimer/Counter Control Register – TCCR0• Bit 7 – FOC0: Force Output CompareThe FOC

Page 291

79ATmega32(L)2503C–AVR–10/02When OC0 is connected to the pin, the function of the COM01:0 bits depends on theWGM01:0 bit setting. Table 39 shows the C

Page 292

8ATmega32(L) 2503C–AVR–10/02Status Register The Status Register contains information about the result of the most recently executedarithmetic instruct

Page 293

80ATmega32(L) 2503C–AVR–10/02If external pin modes are used for the Timer/Counter0, transitions on the T0 pin willclock the counter even if the pin is

Page 294

81ATmega32(L)2503C–AVR–10/02Timer/Counter Interrupt Flag Register – TIFR• Bit 1 – OCF0: Output Compare Flag 0The OCF0 bit is set (one) when a compare

Page 295

82ATmega32(L) 2503C–AVR–10/02Timer/Counter0 and Timer/Counter1 PrescalersTimer/Counter1 and Timer/Counter0 share the same prescaler module, but theTim

Page 296

83ATmega32(L)2503C–AVR–10/02than half the system clock frequency (fExtClk < fclk_I/O/2) given a 50/50% duty cycle. Sincethe edge detector uses samp

Page 297

84ATmega32(L) 2503C–AVR–10/0216-bit Timer/Counter1 The 16-bit Timer/Counter unit allows accurate program execution timing (event man-agement), wave ge

Page 298

85ATmega32(L)2503C–AVR–10/02Figure 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 o

Page 299

86ATmega32(L) 2503C–AVR–10/02(OC1A/B). See “Output Compare Units” on page 92. The compare match event will alsoset the Compare Match Flag (OCF1A/B) wh

Page 300

87ATmega32(L)2503C–AVR–10/02Accessing 16-bit RegistersThe TCNT1, OCR1A/B, and ICR1 are 16-bit registers that can be accessed by the AVRCPU via the 8-b

Page 301

88ATmega32(L) 2503C–AVR–10/02The following code examples show how to do an atomic read of the TCNT1 Registercontents. Reading any of the OCR1A/B or IC

Page 302

89ATmega32(L)2503C–AVR–10/02The following code examples show how to do an atomic write of the TCNT1 Registercontents. Writing any of the OCR1A/B or IC

Page 303

9ATmega32(L)2503C–AVR–10/02• Bit 0 – C: Carry FlagThe Carry Flag C indicates a carry in an arithmetic or logic operation. See the “Instruc-tion Set De

Page 304

90ATmega32(L) 2503C–AVR–10/02Figure 41. Counter Unit Block DiagramSignal description (internal signals):Count Increment or decrement TCNT1 by 1.Direc

Page 305

91ATmega32(L)2503C–AVR–10/02Input Capture Unit The Timer/Counter incorporates an input capture unit that can capture external eventsand give them a ti

Page 306

92ATmega32(L) 2503C–AVR–10/02For more information on how to access the 16-bit registers refer to “Accessing 16-bitRegisters” on page 87.Input Capture

Page 307

93ATmega32(L)2503C–AVR–10/02be cleared by software by writing a logical one to its I/O bit location. The Waveform Gen-erator uses the match signal to

Page 308

94ATmega32(L) 2503C–AVR–10/02byte I/O location is written by the CPU, the TEMP Register will be updated by the valuewritten. Then when the low byte (O

Page 309

95ATmega32(L)2503C–AVR–10/02Figure 44. Compare Match Output Unit, SchematicThe general I/O port function is overridden by the Output Compare (OC1x) f

Page 310

96ATmega32(L) 2503C–AVR–10/02Normal Mode The simplest mode of operation is the Normal mode (WGM13:0 = 0). In this mode thecounting direction is always

Page 311

97ATmega32(L)2503C–AVR–10/02this feature is not desirable. An alternative will then be to use the fast PWM mode usingOCR1A for defining TOP (WGM13:0 =

Page 312

98ATmega32(L) 2503C–AVR–10/02Figure 46. Fast PWM Mode, Timing DiagramThe Timer/Counter Overflow Flag (TOV1) is set each time the counter reaches TOP.

Page 313

99ATmega32(L)2503C–AVR–10/02seting (or clearing) the OC1x Register at the compare match between OCR1x andTCNT1, and clearing (or setting) the OC1x Reg

Comments to this Manuals

No comments