Botched

ADC Code

Heres the code required to get the dspic30f ADC running. Again this is all written in mplab with the C30 compiler. This example sets up the ADC module, then uses it to sample AN2. The sample time is set using the for statement to wait for a preset number of clock cycles.

void setupadc()
{
   ADPCFG = 0xFFC3; // all PORTB = Digital; RB2,RB3,RB4,RB5 = analog
   ADCON3 = 0x0002; // Manual Sample, Tad = internal 2 Tcy
   ADCON1bits.ADON = 1; // turn ADC ON
}
setupadc();
ADCHS = 0x0002; // Selects channel
ADCON1bits.SAMP = 1; // start sampling ...
for(x=0;x<100;x++);{}
   ADCON1bits.SAMP = 0; // start Converting
while (!ADCON1bits.DONE); // conversion done?
   ADCValue = ADCBUF0; // yes then get ADC value
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.