Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ATtiny104_Datasheet.pdf
Скачиваний:
0
Добавлен:
12.02.2026
Размер:
3.8 Mб
Скачать

 

 

 

 

 

 

 

 

 

 

 

 

 

Signal Name

Description

 

 

 

 

 

 

clkT0

Timer/Counter clock.

 

 

TOP

Signalize that TCNT0 has reached maximum value.

 

 

 

 

 

 

BOTTOM

Signalize that TCNT0 has reached minimum value (zero).

 

 

 

 

 

The 16-bit counter is mapped into two 8-bit I/O memory locations: Counter High (TCNT0H) containing the upper eight bits of the counter, and Counter Low (TCNT0L) containing the lower eight bits. The TCNT0H Register can only be accessed indirectly by the CPU. When the CPU does an access to the TCNT0H I/O location, the CPU accesses the high byte temporary register (TEMP). The temporary register is updated with the TCNT0H value when the TCNT0L is read, and TCNT0H is updated with the temporary register value when TCNT0L is written. This allows the CPU to read or write the entire 16-bit counter value within one clock cycle via the 8-bit data bus.

Note:  That there are special cases when writing to the TCNT0 Register while the counter is counting will give unpredictable results. These special cases are described in the sections where they are of importance.

Depending on the selected mode of operation, the counter is cleared, incremented, or decremented at each timer clock (clkT0). The clock clkT0 can be generated from an external or internal clock source, as selected by the Clock Select bits in the Timer/Counter0 Control Register B (TCCR0B.CS[2:0]). When no clock source is selected (CS[2:0]=0x0) the timer is stopped. However, the TCNT0 value can be accessed by the CPU, independent of whether clkT0 is present or not. A CPU write overrides (i.e., has priority over) all counter clear or count operations.

The counting sequence is determined by the setting of the Waveform Generation mode bits in the Timer/ Counter Control Registers A and B (TCCR0B.WGM0[3:2] and TCCR0A.WGM0[1:0]). There are close connections between how the counter behaves (counts) and how waveforms are generated on the Output Compare outputs OC0x. For more details about advanced counting sequences and waveform generation, see Modes of Operation.

The Timer/Counter Overflow Flag in the TC0 Interrupt Flag Register (TIFR0.TOV) is set according to the mode of operation selected by the WGM0[3:0] bits. TOV can be used for generating a CPU interrupt.

17.9.Input Capture Unit

The Timer/Counter0 incorporates an Input Capture unit that can capture external events and give them a time-stamp indicating time of occurrence. The external signal indicating an event, or multiple events, can be applied via the ICP0 pin or alternatively, via the analog-comparator unit. The time-stamps can then be used to calculate frequency, duty-cycle, and other features of the signal applied. Alternatively the timestamps can be used for creating a log of the events.

The Input Capture unit is illustrated by the block diagram below. The elements of the block diagram that are not directly a part of the Input Capture unit are gray shaded. The lower case “n” in register and bit names indicates the Timer/Counter number.

Atmel ATtiny102 / ATtiny104 [DATASHEET] 132

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016

Figure 17-5. Input Capture Unit Block Diagram for TC0

DATA BUS (8-bit)

TEMP (8-bit)

ICRnH (8-bit)

ICRnL (8-bit)

 

TCNTnH (8-bit)

TCNTnL (8-bit)

WRITE

ICRn (16-bit Register)

 

TCNTn (16-bit Counter)

 

ACO*

ACIC*

ICNC

ICES

 

 

Comparator

 

Noise

Edge

ICFn (Int.Req.)

 

 

 

 

 

 

Canceler

Detector

ICPn

 

 

 

 

 

 

 

 

Note:  The “n” in the register and bit names indicates the device number (n = 0 for Timer/Counter 0), and the “x” indicates Output Compare unit (A/B).

When a change of the logic level (an event) occurs on the Input Capture pin (ICP0), or alternatively on the Analog Comparator output (ACO), and this change confirms to the setting of the edge detector, a capture will be triggered: the 16-bit value of the counter (TCNT0) is written to the Input Capture Register (ICR0).

The Input Capture Flag (ICF) is set at the same system clock cycle as the TCNT0 value is copied into the ICR0 Register. If enabled (TIMSK0.ICIE=1), the Input Capture Flag generates an Input Capture interrupt. The ICF0 Flag is automatically cleared when the interrupt is executed. Alternatively the ICF Flag can be cleared by software by writing '1' to its I/O bit location.

Reading the 16-bit value in the Input Capture Register (ICR0) is done by first reading the low byte (ICR0L) and then the high byte (ICR0H). When the low byte is read form ICR0L, the high byte is copied into the high byte temporary register (TEMP). When the CPU reads the ICR0H I/O location it will access the TEMP Register.

The ICR0 Register can only be written when using a Waveform Generation mode that utilizes the ICR0 Register for defining the counter’s TOP value. In these cases the Waveform Generation mode bits (WGM0[3:0]) must be set before the TOP value can be written to the ICR0 Register. When writing the ICR0 Register, the high byte must be written to the ICR0H I/O location before the low byte is written to ICR0L.

See also Accessing 16-bit Timer/Counter Registers.

17.9.1.Input Capture Trigger Source

The main trigger source for the Input Capture unit is the Input Capture pin (ICP0). Timer/Counter0 can alternatively use the Analog Comparator output as trigger source for the Input Capture unit. The Analog Comparator is selected as trigger source by setting the Analog Comparator Input Capture (ACIC) bit in

Atmel ATtiny102 / ATtiny104 [DATASHEET] 133

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016