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;
}
Mindfront Technologies blog site for Microcontroller circuits and other electronics projects.
Subscribe to:
Post Comments (Atom)
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...
-
My original idea for this project was simply to try and interface the WINTEK WD-C2401P lcd panel to the pic (see my previous post). I figure...
-
Roomba Dashboard Background: Roomba-Dash is a cli dashboard for the IRobot Create 2 platform. I got the roomba because I wanted to bu...
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
ReplyDeleteWhat can I do with this piece of code? I have no idea right now.
ReplyDeleteAn 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
ReplyDeleteHarrahs Casino - Jordan 16 Retro
ReplyDeleteHarrahs Casino has a huge range 해외 배당 of slot machines in the air jordan 18 retro yellow to us rooms. They have a selection of over 700 titles air jordan 18 retro yellow good website that have replica air jordan 18 retro varsity red different types of game. You replica air jordan 18 retro yellow can play at Harrah's