Hello Friends,
In this example, we are using prescaler of value8. Prescaler divides the base frequency (provided by crystal or internal rc oscillator).
In this tutorial, we will learn how to generate a delay of 1second using timer0 in atmega8.
We are writing the code in Avr studio 4.
Timer 0 is a 8-bit timer means we can feed any value from 0 (0x00) to 255 (0xff)
Timing Diagram |
Machine Cycle = 1/Fosc (Fosc is 8 MHz)
M.C = 1/8 us or 0.125 us
Delay = (256-x) * 0.125 * Pre scaler (Pre scaler = 8)