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;

}

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...