/*! ********************************************************************** * Function: configureRange(void) * * Include: Range.h * * Description: Configures the Range module * * Arguments: None * * Returns: None *************************************************************************/ void configureRange(void) { unsigned char config; INIT_PIN = 0; //Enable global interrupts and interrupt priority INT_SETUP() readTemp(); //Make sure the AD is configured configureAD(); CCP1_INPT = 1; INIT_TRIS = 0; //Make the INIT //Open Timer config = T1_16BIT_RW & T1_SOURCE_INT & T1_OSC1EN_OFF & T1_PS_1_1 & T1_SYNC_EXT_OFF &TIMER_INT_ON; OpenTimer1(config); config = CAPTURE_INT_ON & CAP_EVERY_RISE_EDGE; //CloseCapture1, which will clear any interrupt flags etc CloseCapture1(); //Open the input capture on compare1 OpenCapture1(config); }
// Input Capture Event Interrupt // On input capture this interrupt will get the time taken to charge the capacitor // and signal the capacitor thread to continue void __ISR(_INPUT_CAPTURE_1_VECTOR, ipl2) IC1Handler(void) { charge_time = mIC1ReadCapture(); CloseCapture1(); mIC1ClearIntFlag(); charged = 1; }
/*! ********************************************************************** * Function: rangeUltrasonic(void) * * Include: * * Description: performs an ultrasonic range reading. * Pins: * * Arguments: None * * Returns: the average of the samples * * todo remove this function? *************************************************************************/ unsigned int rangeUltrasonic(void) { unsigned int rng; configureRange(); beginUS(); rng = rangeUS(25); INIT_PIN = 0; CloseCapture1(); CloseTimer1(); return rng; }