Datasheet
out TCNTnL,r16
; Restore global interrupt flag
out SREG,r18
ret
C Code Example
(1)
void TIM16_WriteTCNTn( unsigned int i )
{
unsigned char sreg;
unsigned int i;
/* Save global interrupt flag */
sreg = SREG;
/* Disable interrupts */
_CLI();
/* Set TCNTn to i */
TCNTn = i;
/* Restore global interrupt flag */
SREG = sreg;
}
Note: 1. See About Code Examples.
The assembly code example requires that the r17:r16 Register pair contains the value to be written to
TCNTn.
Related Links
About Code Examples on page 20
20.3.1. Reusing the Temporary High Byte Register
If writing to more than one 16-bit register where the High byte is the same for all registers written, then the
High byte only needs to be written once. However, note that the same rule of atomic operation described
previously also applies in this case.
20.4. Timer/Counter Clock Sources
The Timer/Counter can be clocked by an internal or an external clock source. The clock source is
selected by the clock select logic which is controlled by the clock select (CSn2:0) bits located in the
Timer/Counter Control Register B (TCCRnB). For details on clock sources and prescaler, see Timer/
Counter3, Timer/Counter2, and Timer/Counter1 Prescalers.
Related Links
Timer/Counter3, Timer/Counter2, and Timer/Counter1 Prescalers on page 134
20.5. Counter Unit
The main part of the 16-bit Timer/Counter is the programmable 16-bit bi-directional counter unit. The
figure below shows a block diagram of the counter and its surroundings.
Atmel ATmega64A [DATASHEET]
Atmel-8160E-ATmega64A_Datasheet_Complete-09/2015
142