Hi,
I’m trying to interface a QTR-1RC with an AVR xMega32A4. I have the input connected to PC5 and am following the advice from the product page and from the Atmel Timer Counter Application note AVR1306. I set the pin to an output and drive it high. wait 20us for the cap to charge, then configure the pin for input capture, change the direction to input and try to read the the input capture register. I can see very nice results on the scope that match the ones shown in the product page and that change properly depending on the reflectivity of the surface. The line charges nicely to 3.3V, then decays. but my input capture fails for some reason. I get stuck waiting for the Interrupt Capture Flag to be set. Is it missing the falling edge? Can anyone see anything in my code that might cause this?
Thanks for the help,
-j
Code:
//Take a reading on QTR Sensor
PORTC.DIR |= (1 << PIN5); //set middle sensor as output
PORTC.OUT |= (1 << PIN5); //drive high to charge capacitor
_delay_us(20); //wait for cap to charge
PORTC.PIN5CTRL = PORT_ISC_FALLING_gc; //set input to trigger on falling edge
EVSYS_CH0MUX = EVSYS_CHMUX_PORTC_PIN5_gc; //Set PC5 as multiplex input for Event Ch0
//Configure TCC1 for Input capture
TCC1.CTRLD = (TCC1.CTRLD & ~( TC1_EVSEL_gm | TC1_EVACT_gm )) | TC_EVSEL_CH0_gc | TC_EVACT_CAPT_gc;
//Enable Input Capture Channel B
TCC1.CTRLB |= TC1_CCBEN_bm;
//Activate TC by setting clock
TCC1.CTRLA |= TC_CLKSEL_DIV8_gc;
PORTC.DIR &= ~(1 << PIN5); //change pin to input
do {
//wait for input capture
} while (!(TCC1.INTFLAGS & TC1_CCBIF_bm));
//record
IR.middle = TCC1.CCB;