void config_timer1() { TCCR1A = 0; TCCR1B = 0; TCNT1 = 0; // tc = f_cpu / (prescaler * f_needed) - 1 = f_cpu / prescaler * time - 1 OCR1A = (F_CPU / PRESCALER) * SAMPLING_INTERVAL_S - 1; // Calculate the compare value TCCR1B |= (1 << WGM12); // CTC mode TCCR1B |= (1 << CS12); // 256 prescaler } void init_timer1() { TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt }