AVR 8515 Timer
Programming
Timers in Atmega8515
Many computer applications require
accurate timing.
Examples include:
recording the time when an event occurs,
calculating the time difference between
events,
performing tasks at specific or periodic
times,
creating accurate time delays,
generating waveforms of certain shape,
period, or duty cycle.
ATmega8515 has two timers: Timer 0
and Timer 1.
Each timer is associated with a counter
and a clock signal.
The counter is incremented by 1 in
every clock cycle of the timer.
The clock signal of a timer can come
from
the internal system clock or
an external clock source.
Overview of Timers in Atmega 8515
Timer 0 Block Diagram
TIMER AND PRESCALAR
Timer Overview
When the internal system clock is used,
a pre-scaler can be applied to make the
timer count at a slower rate.
Example:
Consider a system clock of 8Mhz (i.e.
0.125s per cycle).
Suppose that a timer pre-scaler of 64 is
used.
Then, timer will increment every 8s
(0.125*64).
Timer 0
So we have 3 registers associated
with timer0
TCNT0
TCCR0
TIFR ( for flag TOV0)
TCCR0
TCCR0
TIFR
Input Capture:
Input signal is connected to a pin, called input
capture, of the timer.
When a preset event (rising edge, falling edge,
change) occurs on
this pin, the current timer value is automatically
stored in a register.
Output Compare:
A timer typically has a pin, called output compare.
When the timer reaches a preset value, the
output compare pin can be automatically changed to
logic 0 or logic 1.