+ TCCR0A = _BV(WGM00);
+ TCCR0B = _BV(CS02) | _BV(CS00); // 1 kHz
+ OCR0A = 10; // 100 Hz
+ TIMSK |= _BV(OCIE0A);
+ DDRA |= _BV( PA0 );
+
+ clock = 0;
+}
+
+static void inline tmr_handler()
+{
+ unsigned char c = clock & 0x7F;
+ ++clock;
+
+ if (c == 10 || c == 30)
+ led_on();
+
+ if (c == 20 || c == 40)
+ led_off();
+
+ log_word(adcval);
+ if (adcval != 0xFFEE) {
+ adcval = 0xFFEE;
+
+ ADCSRA |= _BV(ADIE) | _BV(ADSC);
+ }
+}
+
+ISR(TIMER0_COMPA_vect)
+{
+ tmr_handler();
+}
+
+/* ------------ PWM ----------- */
+
+static void inline init_pwm()
+{
+ /* Async clock */
+ PLLCSR = _BV(LSM) | _BV(PLLE);
+ _delay_ms(1);
+ while (PLLCSR & _BV(PLOCK) == 0)
+ ;
+ PLLCSR |= _BV(PCKE);