#include <avr/io.h>
void TimerInit();
unsigned char periode;
/*
prescaller 8 , Xtal 16MHz
tick = 8/16Mhz= 0.5 us
delay=counter*tick
delay=counter*0.5us
counter=delayus/0.5us
untuk sampling rate 32 khz maka Tsampling= 1/40Khz= 25 us
counter = 25/0.5 us = 50
nilai TCNT1= -62,5 -> karena counter up
*/
int main(void) {
DDRB |= _BV(PB7);
TimerInit();
while (1) {
if (TIFR0&(1<<TOV0)) {
TCNT0= (unsigned char)-50;
//clear flag
TIFR0|=(1<<TOV0);
PORTB ^= (1 << PB7);
}
}
}
void TimerInit(void) {
TCNT0 = (unsigned char) -50; // reset counter
TCCR0B = (1 << CS01) ; //prescaller 8
}