beautypg.com

4 clear timer on compare match (ctc) 16-bit mode, 5 8-bit input capture mode, 6 16-bit input capture mode – Rainbow Electronics ATmega8HVD User Manual

Page 78: 6 input capture unit, Atmega4hvd/8hvd

background image

78

8052B–AVR–09/08

ATmega4HVD/8HVD

are no special cases to consider in the Normal mode, a new counter value can be written any-
time. The Output Compare Unit can be used to generate interrupts at some given time.

16.5.4

Clear Timer on Compare Match (CTC) 16-bit Mode

In Clear Timer on Compare 16-bit mode, OCRAnA/B Registers are used to manipulate the
counter resolution, see

Table 16-2 on page 76

for bit settings. In CTC mode the counter is

cleared to zero when the counter value (TCNTn) matches OCRnA/B, where OCRnB repre-
sents the eight most significant bits and OCRnA represents the eight least significant bits.
OCRnA/B defines the top value of the counter, hence also its resolution. This mode allows
greater control of the Compare Match output frequency. It also simplifies the operation of
counting external events.

An interrupt can be generated each time the counter reaches the TOP value by using the
OCFnA flag. If the interrupt is enabled, the interrupt handler routine can be used for updating
the TOP value. However, changing the TOP to a value close the BOTTOM when the counter
is running with none or a low prescaler value must be done with care since the CTC mode
does not have the double buffering feature. If the new value written to OCRnA/B is lower than
the current value of TCNTn, the counter will miss the Compare Match. The counter will then
have to count to its maximum value (0xFFFF) and wrap around starting at 0x0000 before
Compare Match can occur. As for the 16-bit Mode, the TOVn Flag is set in the same timer
clock cycle that the counter counts from MAX to 0x0000.

16.5.5

8-bit Input Capture Mode

The Timer/Counter can be used in a 8-bit Input Capture mode, see

Table 16-2 on page 76

for

bit settings. For full description, see

”Input Capture Unit” on page 78

.

16.5.6

16-bit Input Capture Mode

The Timer/Counter can also be used in a 16-bit Input Capture mode, see

Table 16-2 on page

76

for bit settings. For full description, see

”Input Capture Unit” on page 78

.

16.6

Input Capture Unit

The Timer/Counter incorporates an Input Capture unit that can capture external events and
give them a time-stamp indicating time of occurrence. The external signal indicates an event,
or multiple events. For Timer/Counter0, the events can be applied via the PC0 pin (ICP00), or
alternatively via the osi_posedge pin on the Oscillator Sampling Interface (ICP01). For
Timer/Counter1, the events can be applied by the Battery Protection Interrupt (ICP10) or alter-
natively by the Voltage Regulator Interrupt (ICP11). The time-stamps can then be used to
calculate frequency, duty-cycle, and other features of the signal applied. Alternatively the time-
stamps can be used for creating a log of the events.

The Input Capture unit is illustrated by the block diagram shown in

Figure 16-4 on page 79

.

The elements of the block diagram that are not directly a part of the Input Capture unit are gray
shaded.