Jean-Pierre du Plessis
Newbie level 6
Hi can someone please help me. I changed my project. I am using all 6 ADC inputs. An internal volatage refrance. At the moment it is posible to sample and convert 4 of the 6 inputs. I sampling all 4 CH of the adc and then converting it. This is my adc setup code and adc reading code.
My question is how do I sample all 6 inputs and convert them to go and read them out of the buffers. I tried using the example on page of the refrance manual. I am not sure how to use the interupt bit. When it will be set. Please help me.
Code:
void enableADC(void) {
ADCON1bits.ADON = 0; //ADC Module is off
ADCON3bits.ADCS = 2; // TAD = TCY*(ADCS + 1); Tcy = 25ns; Min TAD = 75ns
ADCON1bits.FORM = 0; // Integer
ADCON1bits.ADSIDL = 0; //Discontinue module in idle mode
ADCON1bits.SSRC = 7; // Automatic Conversion Sequence
ADCON1bits.SIMSAM = 1; //Samples multiple channels in sequence
ADCON1bits.ASAM = 0; // Auto sampeling, after last sample
ADCON2bits.VCFG = 0; // VrefH = AVdd / VrefL = AVss
ADCON2bits.CSCNA = 0; // Scan inputs CH0+
ADCON2bits.CHPS = 2; // Channel CH0 CH1 CH2 conversance
ADCON2bits.SMPI = 0; // Increments the DMA address after completion of every sample/conversion operation
ADCON2bits.ALTS = 0; // Always use MUX A input multiplexer
ADCON2bits.BUFM = 0;
ADCHSbits.CH0SA = 3; //Channel 0 Positive Input Select for MUX A Multiplexer Setting bits
ADCHSbits.CH123SA = 0; //Channel 1, 2, 3 Positive Input Select for MUX A Multiplexer Setting bit
ADCHSbits.CH0NA = 0; //Channel 0 Negative Input Select for MUX A Multiplexer Setting bit
ADCHSbits.CH123NA = 0; //Channel 1, 2, 3 Negative Input Select for MUX A Multiplexer Setting bits
ADCON3bits.ADRC = 0; // ADC Clock Derived from System Clock
ADCON3bits.SAMC = 1; // Auto Sample Time bits TAD
ADCON1bits.ADON = 1; // Turn ADC on
ADCON1bits.SAMP = 1; //Start sampeling
return;
}
ADCON1bits.DONE = 0;
ADCON1bits.SAMP = 1; // Start Conversion
while (!ADCON1bits.DONE); // Wait for convert
Nop();
My question is how do I sample all 6 inputs and convert them to go and read them out of the buffers. I tried using the example on page of the refrance manual. I am not sure how to use the interupt bit. When it will be set. Please help me.