calculation for timer

This commit is contained in:
ccppi 2024-03-01 10:49:07 +01:00
parent dc9bec7594
commit 4b8c5a46e9

14
main.c
View File

@ -125,3 +125,17 @@ int map(int value, int old_min, int old_max,int new_min, int new_max)
{ {
return (new_max/old_max*value); return (new_max/old_max*value);
} }
void setupTimer(void)
{
TCCR1 = (1<<CS13)|(1<<CS12)|(1<<CS11)|(1<<CS10)| //CK/16384
(1<<CTC1); //clear timer on compare match
GTCCR = 0; //default values should be ok
OCR1A = 255; //Compare value of timer / overflow , sets OCF1A
//
}
/*
* 1/(30Mhz/16384) *255 = 0.139264s Time for one overflow
* 1024 = 0.008704s
* 2024 = 0.017204s
* 255/0.017204*0.001=15 counts = 1ms