Using Timer
Using Timer
(ATmega16)
WS 06/07
Timer Ù Counter
Timer
- Counts clock signal (measures time)
- Clock divider can be used (for longer time intervals)
- Example: switch an LED every second
Counter
- Counts external events
- Example: switch an LED after 20 external events
Folie 2
1
Atmega16´s Timer/Counter
Timer/Counter0:
- 8bit
Timer/Counter1:
- 16bit
Timer/Counter2:
- 8bit
Folie 3
ATmega16 – Timer/Counter0
Control Register
Timer
Overflow IR
Counter Register
Compare Register
Folie 4
2
ATmega16 – Timer/Counter0
Control Register
Counter
Overflow IR
Counter Register
Compare Register
Folie 5
Timer/Counter
Folie 6
3
Example Timer0
//blinks LEDs at PORTA with 22,888Hz (6MHz system clock)
#include <avr/io.h>
Folie 7