texasdeathstyle
Newbie level 5
I am trying to read the analog outputs from a dual-axis accelerometer. These outputs are fed to the RA0/AN0 and RA1/AN1 pins of the PIC. So I need to set up the ADC of the pic in order to interpret these values. I have done coding for the program but I find that even when the accelerometer is on a level plane, the output values after conversion are not consistent. They seem to be constantly changing which shouldn't happen in the first place if the accelerometer is not tilted. Is my ADC setup correct ? My oscillation freq is 4Mhz.
Code:
void Output(void){
OpenADC(ADC_LEFT_JUST & ADC_FOSC_8 & ADC_0_TAD, ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ,13);
Delay10TCYx( 5 ); // Delay for 50TCY
// SetChanADC(ADC_CH0);
Delay10TCYx(100);
ConvertADC();
while(BusyADC());
Y_AN0 = ADRESH;
SetChanADC(ADC_CH1);
Delay10TCYx(100);
ConvertADC();
while(BusyADC());
X_AN1= ADRESH;
CloseADC();
Serial_out(); // Serial out to computer
}