18.6.3 Example 3
Below is the code example to configure RDC to generate an excitation signal. The CIC filter is configured for external signal source mode.
RDC Configuration Code
int main()
{
/*Excitation output remap goes here*/
/*ADC configuration goes here*/
/*CIC filter configuration */
_CICOSRIE = 1; // Enable output sample read interrupt
CICCON1bits.CH0EN = 1; // Enable CIC filter channel 0
CICCON1bits.CH1EN = 1; // Enable CIC filter channel 1
CICCON1bits.INSRC = 0; /* CIC filter channels are fed from sampled values of
excitation signal*/
CICCON1bits.ORDER = 0; // CIC filter in order 1
CICDECIMbits.DECIM = 3; // filter length is 4
CICCON1bits.POLSEL = 0; // CIC uses RDC excitation signal for polarity
CICCON1bits.DEMODEN = 1; // Demodulation is enabled
CICCON1bits.ON = 1; // CIC filter is enabled
/*RDC configuration to generate excitation signal*/
RDCINSELbits.IMUX0 = 0; // CIC filter channel 0 is sourced with digital samples by ADC
// module instance 1
RDCINSELbits.ICHAN0 = 0; // ADC1 channel 0 sources CIC filter channel 0
RDCINSEL.IMUX1 = 1; /* CIC filter channel 1 is sourced with digital samples by
ADC module instance 2*/
RDCINSELbits.ICHAN1 = 1; // ADC2 channel 1 sources CIC filter channel 1
RDCEXCCONbits.EXCFDIV = 1; // (RDC input clock/16)
RDCEXCDLYbits.EXCFBDLY = 10; // Feedback delay of 10 system clock cycles
RDCEXCDLYbits.ADCTRGDLY = 1; /* 1 RDC clock phase delay between RDC excitation clock
output signal and the trigger signal to ADC*/
RDCCONbits.ON = 1; // Enable RDC block
RDCEXCCONbits.SYNCCNT = 255; /* Sync pulse will be generated after counting 255 RDC
clocks*/
RDCEXCCONbits.EXCSYNCEN = 1; // Enable synchronization
while(1);
}
void __attribute__((interrupt, no_auto_psv)) _CICOUTInterrupt(void)
{
_CICOSRIF = 0; // Clear output sample read interrupt flag
/*Read CIC0OUT and CIC1OUT register here*/
}
