ATmega32A Datasheet - Sunrom Technologies
ATmega32A Datasheet - Sunrom Technologies ATmega32A Datasheet - Sunrom Technologies
ATmega32A16.7 Compare Match Output UnitThe Compare Output mode (COM1x1:0) bits have two functions. The Waveform Generator usesthe COM1x1:0 bits for defining the Output Compare (OC1x) state at the next compare match.Secondly the COM1x1:0 bits control the OC1x pin output source. Figure 16-5 shows a simplifiedschematic of the logic affected by the COM1x1:0 bit setting. The I/O Registers, I/O bits, and I/Opins in the figure are shown in bold. Only the parts of the general I/O Port Control Registers(DDR and PORT) that are affected by the COM1x1:0 bits are shown. When referring to theOC1x state, the reference is for the internal OC1x Register, not the OC1x pin. If a System Resetoccur, the OC1x Register is reset to “0”.Figure 16-5.Compare Match Output Unit, SchematicCOMnx1COMnx0FOCnxWaveformGeneratorDQOCnx10OCnxPinDQDATABUSPORTDQDDRclk I/OThe general I/O port function is overridden by the Output Compare (OC1x) from the WaveformGenerator if either of the COM1x1:0 bits are set. However, the OC1x pin direction (input or output)is still controlled by the Data Direction Register (DDR) for the port pin. The Data DirectionRegister bit for the OC1x pin (DDR_OC1x) must be set as output before the OC1x value is visibleon the pin. The port override function is generally independent of the Waveform Generationmode, but there are some exceptions. Refer to Table 16-2, Table 16-3 and Table 16-4 fordetails.The design of the output compare pin logic allows initialization of the OC1x state before the outputis enabled. Note that some COM1x1:0 bit settings are reserved for certain modes ofoperation. See “Register Description” on page 112.The COM1x1:0 bits have no effect on the Input Capture unit.16.7.1 Compare Output Mode and Waveform GenerationThe Waveform Generator uses the COM1x1:0 bits differently in normal, CTC, and PWM modes.For all modes, setting the COM1x1:0 = 0 tells the Waveform Generator that no action on theOC1x Register is to be performed on the next compare match. For compare output actions in thenon-PWM modes refer to Table 16-2 on page 112. For fast PWM mode refer to Table 16-3 onpage 113, and for phase correct and phase and frequency correct PWM refer to Table 16-4 onpage 113.8155C–AVR–02/11102
ATmega32AA change of the COM1x1:0 bits state will have effect at the first compare match after the bits arewritten. For non-PWM modes, the action can be forced to have immediate effect by using theFOC1x strobe bits.16.8 Modes of OperationThe mode of operation, that is, the behavior of the Timer/Counter and the output compare pins,is defined by the combination of the Waveform Generation mode (WGM13:0) and Compare Outputmode (COM1x1:0) bits. The Compare Output mode bits do not affect the counting sequence,while the Waveform Generation mode bits do. The COM1x1:0 bits control whether the PWM outputgenerated should be inverted or not (inverted or non-inverted PWM). For non-PWM modesthe COM1x1:0 bits control whether the output should be set, cleared or toggle at a comparematch (See “Compare Match Output Unit” on page 102.)For detailed timing information refer to “Timer/Counter Timing Diagrams” on page 110.16.8.1 Normal ModeThe simplest mode of operation is the Normal mode (WGM13:0 = 0). In this mode the countingdirection is always up (incrementing), and no counter clear is performed. The counter simplyoverruns when it passes its maximum 16-bit value (MAX = 0xFFFF) and then restarts from theBOTTOM (0x0000). In normal operation the Timer/Counter Overflow Flag (TOV1) will be set inthe same timer clock cycle as the TCNT1 becomes zero. The TOV1 Flag in this case behaveslike a 17th bit, except that it is only set, not cleared. However, combined with the timer overflowinterrupt that automatically clears the TOV1 Flag, the timer resolution can be increased by software.There are no special cases to consider in the Normal mode, a new counter value can bewritten anytime.The Input Capture unit is easy to use in Normal mode. However, observe that the maximuminterval between the external events must not exceed the resolution of the counter. If the intervalbetween events are too long, the timer overflow interrupt or the prescaler must be used toextend the resolution for the capture unit.The output compare units can be used to generate interrupts at some given time. Using the outputcompare to generate waveforms in Normal mode is not recommended, since this will occupytoo much of the CPU time.16.8.2 Clear Timer on Compare Match (CTC) ModeIn Clear Timer on Compare or CTC mode (WGM13:0 = 4 or 12), the OCR1A or ICR1 Registerare used to manipulate the counter resolution. In CTC mode the counter is cleared to zero whenthe counter value (TCNT1) matches either the OCR1A (WGM13:0 = 4) or the ICR1 (WGM13:0 =12). The OCR1A or ICR1 define the top value for the counter, hence also its resolution. Thismode allows greater control of the compare match output frequency. It also simplifies the operationof counting external events.The timing diagram for the CTC mode is shown in Figure 16-6. The counter value (TCNT1)increases until a compare match occurs with either OCR1A or ICR1, and then counter (TCNT1)is cleared.8155C–AVR–02/11103
- Page 52 and 53: ATmega32AIf PORTxn is written logic
- Page 54 and 55: ATmega32AThe following code example
- Page 56 and 57: ATmega32AFigure 12-5. Alternate Por
- Page 58 and 59: ATmega32ATable 12-3.Table 12-4 and
- Page 60 and 61: ATmega32A• MOSI - Port B, Bit 5MO
- Page 62 and 63: ATmega32A12.3.3 Alternate Functions
- Page 64 and 65: ATmega32ATable 12-11. Overriding Si
- Page 66 and 67: ATmega32A12.4 Register Description1
- Page 68 and 69: ATmega32A12.4.13 PIND - Port D Inpu
- Page 70 and 71: ATmega32Alow level interrupt is sel
- Page 73 and 74: ATmega32A14. 8-bit Timer/Counter0 w
- Page 75 and 76: ATmega32ASignal description (intern
- Page 77 and 78: ATmega32Athe OCR0 value, the compar
- Page 79 and 80: ATmega32AFigure 14-5.CTC Mode, Timi
- Page 81 and 82: ATmega32AThe PWM resolution for the
- Page 83 and 84: ATmega32AFigure 14-9. Timer/Counter
- Page 85 and 86: ATmega32ATable 14-2. Waveform Gener
- Page 87 and 88: ATmega32AThe Output Compare Registe
- Page 89 and 90: ATmega32AFigure 15-1.T1/T0 Pin Samp
- Page 91 and 92: ATmega32A16. 16-bit Timer/Counter11
- Page 93 and 94: ATmega32Aput Compare Units” on pa
- Page 95 and 96: ATmega32Athe main code and the inte
- Page 97 and 98: ATmega32A16.5 Counter UnitThe main
- Page 99 and 100: ATmega32AThe ICR1 Register can only
- Page 101: ATmega32ARegister to either TOP or
- Page 107: ATmega32AThe PWM resolution for the
- Page 110: ATmega32AUsing the ICR1 Register fo
- Page 113 and 114: ATmega32ATable 16-3 shows the COM1x
- Page 115 and 116: ATmega32A• Bit 7 - ICNC1: Input C
- Page 117 and 118: ATmega32AThe Input Capture is updat
- Page 119 and 120: ATmega32A17. 8-bit Timer/Counter2 w
- Page 121 and 122: ATmega32AFigure 17-2.DATA BUSCounte
- Page 123 and 124: ATmega32AThe setup of the OC2 shoul
- Page 125 and 126: ATmega32AFigure 17-5.CTC Mode, Timi
- Page 127 and 128: ATmega32A17.7.4 Phase Correct PWM M
- Page 129 and 130: ATmega32AFigure 17-9. Timer/Counter
- Page 131 and 132: ATmega32A• If Timer/Counter2 is u
- Page 133 and 134: ATmega32AA FOC2 strobe will not gen
- Page 135 and 136: ATmega32A17.11.2 TCNT2 - Timer/Coun
- Page 137 and 138: ATmega32A17.11.7 SFIOR - Special Fu
- Page 139 and 140: ATmega32Acommunication cycle when p
- Page 141 and 142: ATmega32AAssembly Code Example (1)S
- Page 143 and 144: ATmega32A18.3 SS Pin Functionality1
- Page 145 and 146: ATmega32A18.3.4 SPSR - SPI Status R
- Page 147 and 148: ATmega32A19. USART19.1 Features19.2
- Page 149 and 150: ATmega32A19.2.1 AVR USART vs. AVR U
- Page 151 and 152: ATmega32ATable 19-1.Operating ModeA
<strong>ATmega32A</strong>16.7 Compare Match Output UnitThe Compare Output mode (COM1x1:0) bits have two functions. The Waveform Generator usesthe COM1x1:0 bits for defining the Output Compare (OC1x) state at the next compare match.Secondly the COM1x1:0 bits control the OC1x pin output source. Figure 16-5 shows a simplifiedschematic of the logic affected by the COM1x1:0 bit setting. The I/O Registers, I/O bits, and I/Opins in the figure are shown in bold. Only the parts of the general I/O Port Control Registers(DDR and PORT) that are affected by the COM1x1:0 bits are shown. When referring to theOC1x state, the reference is for the internal OC1x Register, not the OC1x pin. If a System Resetoccur, the OC1x Register is reset to “0”.Figure 16-5.Compare Match Output Unit, SchematicCOMnx1COMnx0FOCnxWaveformGeneratorDQOCnx10OCnxPinDQDATABUSPORTDQDDRclk I/OThe general I/O port function is overridden by the Output Compare (OC1x) from the WaveformGenerator if either of the COM1x1:0 bits are set. However, the OC1x pin direction (input or output)is still controlled by the Data Direction Register (DDR) for the port pin. The Data DirectionRegister bit for the OC1x pin (DDR_OC1x) must be set as output before the OC1x value is visibleon the pin. The port override function is generally independent of the Waveform Generationmode, but there are some exceptions. Refer to Table 16-2, Table 16-3 and Table 16-4 fordetails.The design of the output compare pin logic allows initialization of the OC1x state before the outputis enabled. Note that some COM1x1:0 bit settings are reserved for certain modes ofoperation. See “Register Description” on page 112.The COM1x1:0 bits have no effect on the Input Capture unit.16.7.1 Compare Output Mode and Waveform GenerationThe Waveform Generator uses the COM1x1:0 bits differently in normal, CTC, and PWM modes.For all modes, setting the COM1x1:0 = 0 tells the Waveform Generator that no action on theOC1x Register is to be performed on the next compare match. For compare output actions in thenon-PWM modes refer to Table 16-2 on page 112. For fast PWM mode refer to Table 16-3 onpage 113, and for phase correct and phase and frequency correct PWM refer to Table 16-4 onpage 113.8155C–AVR–02/11102