ATmega16 Timer 0
ATmega16 Timer 0
Microcontroller Timer/Counter:
- The timer and counter functions in the microcontroller simply count
(increment TCNT) in sync with the microcontroller clock. However, the
counter can only count up to either 256 (8-bit counter), or 65535 (16-bit
counter).
Block Diagram:
Prescaler:
- It is simply a way for the counter to skip a certain number of
microcontroller clock ticks. The AVR microcontrollers allow prescaling
(skipping) numbers of: 8, 64, 256 and 1024
- Changing CS00, CS01 and CS02 bits of the timer control register results
in changing the effective prescaler or choosing to sync with the external
clock signal connected to pin T0
- Normal Mode
• The counter starts to increase until it reaches its maximum value
then it resets to zero and sets the timer0 overflow flag.
Status Register:
- The seventh bit of the status register is the global interrupt flag, that
must be set to one to allow any interrupt signal
𝑹𝒆𝒒𝒖𝒊𝒓𝒆𝒅 𝑫𝒆𝒍𝒂𝒚
𝑻𝒊𝒎𝒆𝒓 𝑪𝒐𝒖𝒏𝒕 (𝑶𝑪𝑹𝟎) = −𝟏
𝑻𝒊𝒎𝒆𝒓 𝑪𝒍𝒐𝒄𝒌 𝑻𝒊𝒎𝒆 𝑷𝒆𝒓𝒊𝒐𝒅
Using Interrupt:
void main () {
// Configure Port A as O/P
DDRA = 0xFF;
// Initialize Port A with 0x00 value (switch off the leds)
PORTA = 0x00;
void main () {
// Configure Port A as O/P
DDRA = 0xFF;
// Initialize Port A with 0x00 value (switch off the leds)
PORTA = 0x00;
// Once the timer is finished the OCF bit will be set to one and the
microcontroller will break from the while loop and continue executing
the remaining code