Edit - but I did it a bad way. The correct way is described here.
Here is the setup code to get a comparator interrupt running with the IR sensor connected to analog pin A0 for AIN1 and using the internal reference voltage for AIN0.
- Code: Select all
// start interrupt for IR
ACSR &= ~(1<<ACIE); // disable interrupts on AC
// Connect ADC multiplexer to the negative input to the Analog Comparatpr
ADCSRA &= ~(1<<ADEN); // turn off ADC
AC_REGISTER |= (1<<ACME); // Enable multiplexer, so we can select analog pin to AIN1. See chap 23.2 ATmegaU32
ACSR &= ~(1<<ACD); // switch on the AC
ACSR |= (1<<ACBG); // set Internal Voltage Reference (1V1) for AIN0
ADMUX &= ~31;
ADMUX |= ((1<<MUX0)|(1<<MUX1)|(1<<MUX2)); // set analog comparator negative input to ADC0 (A0)
AC_REGISTER &= ~bit(MUX5);
ACSR &= ~(1<<ACIS0); // falling trigger
ACSR |= (1<<ACIS1);
ACSR |= (1<<ACIE); // re-enable interrupts on AC
SREG |= (1<<SREG_I); // GLOBALLY enable interrupts
I can now detect the RPM of the disc - not long now until I hook up the PID to control the speed and we should have a non-moving image.
The step after that will be to sync the pulses from the video and then we'll have a locked frame. But first, the PID controlling speed....