AVR 8515 Timer Programming
AVR 8515 Timer Programming
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.
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
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.