Tuesday, September 28, 2010

ADC Conversions on Microchip

In order to correctly perform an ADC it is important to ensure there is enough time between enabling the ADC module to performing a conversion. Here is a code sample for PIC 16F88

#define TEMP 0x00 //AN0
#define LIGHT 0x08 //AN1

ANSEL |= 0x03; //Select AN0-1 as analog
TRISA |= 0x03; //Select RA0-1 as input
ADCON0 =0x00; //Configure A/D params

unsigned int GetA2DLevel(unsigned char channel)
unsigned int adc_result=0;
ADCON1 =0b10000000; //Configure A/D params
ADCON0 =0b11000001 | channel; //Set the channel and start A/D module
__delay_us(20); //Delay required to ensure module is operating properly
ADCON0 |= 0x04; //Start Conversion
while(ADCON0 & 0x04); //Wait for conversion
adc_result = ADRESH;
adc_result = (adc_result<<8)|ADRESL;
ADCON0 =0x00;

return adc_result;



  1. thank you for posting with the codes, i have been looking for them ever where. i wish i had stumbled upon your page earlier, it would have saved so much time for me

  2. What can I do with this piece of code? I have no idea right now.

  3. An enchanting conversation is worth remark. I perceive that you should sensible more on this point, it probably won't be a dispensed with issue yet for the most part individuals don't take a gander at these issues. To the going with! Kind respects!!movierulz2 nz


YDLidar (lidar) X4 API in golang

YDLidar X4 This is a demo of the YDLidar using a golang API. The software supplied with the device only contains the drivers in C++ an...