4 #define BIT(n) (1<<(n))
6 static void timer_start(uint8_t num, uint32_t period)
19 else if(period<0x4000)
21 cs = BIT(CS01) | BIT(CS00);
24 else if(period<0x10000)
31 cs = BIT(CS02) | BIT(CS00);
45 else if(period<0x80000)
50 else if(period<0x400000)
52 cs = BIT(CS11) | BIT(CS10);
55 else if(period<0x1000000)
62 cs = BIT(CS12) | BIT(CS10);
68 TCCR1B = BIT(WGM12) | cs;
82 else if(period<0x2000)
84 cs = BIT(CS21) | BIT(CS20);
87 else if(period<0x4000)
92 else if(period<0x8000)
94 cs = BIT(CS22) | BIT(CS20);
97 else if(period<0x10000)
99 cs = BIT(CS22) | BIT(CS21);
104 cs = BIT(CS22) | BIT(CS21) | BIT(CS20);
112 TIMSK2 = BIT(OCIE2A);
116 void timer_start_hz(uint8_t num, uint32_t freq_p, uint8_t freq_q)
118 timer_start(num, F_CPU*freq_q/freq_p);
121 void timer_start_us(uint8_t num, uint32_t us)
123 timer_start(num, F_CPU/1000000*us);
126 void timer_stop(uint8_t num)