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;


Roomba Dashboard - A cli dashboard for irobot create 2

Roomba Dashboard Background: Roomba-Dash is a cli dashboard for the IRobot Create 2 platform. I got the roomba because I wanted to bu...