8 #include <avr/interrupt.h>
9 #include <util/delay.h>
13 if (ACSR & (1 << ACO)) {
15 /* turn of comparator on detection */
22 EMPTY_INTERRUPT(TIM0_COMPA_vect);
24 static void switch_idle(void)
26 set_sleep_mode(SLEEP_MODE_IDLE);
30 static void init_board(void)
36 static void set_ref_voltage(void)
38 DDRB |= (1 << DDB1); /* set PB0 as output */
40 TCCR0A |= (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
41 TCCR0B |= (1 << CS00); /* clk/1024 prescaler */
42 OCR0B = 0x20; /* 25% duty cycle */
44 TIMSK = (1 << OCIE0B); /* enable interrupts for overflow and compare */
47 static void config_comparator(void)
50 ADCSRB |= (1 << ACME); /* multiplex enable */
52 /* Use admux to set alternative negative pin */
53 //ADMUX |= (1 << MUX0);
55 /* enable interal reference for
57 * When the bandgap reference is connected to the Analog Comparator (by setting the ACBG bit in ACSR). */
58 ACSR &= ~(1 << ACD); /* enable comparator */
61 DIDR0 |= (1 << AIN1D) | (1 << AIN0D);
63 ACSR |= (1 << ACIE); /* enable interrupts */