I am working with a PIC 18F4550. I am using it to translate an analog voltage to digital and then send that information via the USB port.
This is the snippet of code being used.
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_0_TAD, ADC_CH0 & ADC_INT_OFF & ADC_REF_VREFPLUS_VREFMINUS & ADC_REF_VREFPLUS_VREFMINUS, 0);
Delay10TCYx(5);
ConvertADC(); //START ADC Conversion
while( BusyADC() ); // Wait for ADC conversion
buffer[0] = ADRESL;
buffer[1] = ADRESH;
CloseADC(); // Disable A/D converter
The PIC is using an external 20mHz crystal.
The voltage applied to Vref+ is 5V and at Vref- it is 0V.
The voltage being applied at AN0 is being read by my multimeter as 1.079V but when I acquire the voltage with the pick I get values that dance around this value. For instance in 20 samples I saw these readings.
220 = 1074.2187 V
221 = 1079.101563 V
222 = 1083.9843 V
I would expect the values to be constant since the input voltage is not varying.
This is my first use of an analog to digital converter and so I do not know if this is as good as it gets or if I am doing something wrong.
Any help would be greatly appreciated.
TIA,
Tim Blue
This is the snippet of code being used.
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_0_TAD, ADC_CH0 & ADC_INT_OFF & ADC_REF_VREFPLUS_VREFMINUS & ADC_REF_VREFPLUS_VREFMINUS, 0);
Delay10TCYx(5);
ConvertADC(); //START ADC Conversion
while( BusyADC() ); // Wait for ADC conversion
buffer[0] = ADRESL;
buffer[1] = ADRESH;
CloseADC(); // Disable A/D converter
The PIC is using an external 20mHz crystal.
The voltage applied to Vref+ is 5V and at Vref- it is 0V.
The voltage being applied at AN0 is being read by my multimeter as 1.079V but when I acquire the voltage with the pick I get values that dance around this value. For instance in 20 samples I saw these readings.
220 = 1074.2187 V
221 = 1079.101563 V
222 = 1083.9843 V
I would expect the values to be constant since the input voltage is not varying.
This is my first use of an analog to digital converter and so I do not know if this is as good as it gets or if I am doing something wrong.
Any help would be greatly appreciated.
TIA,
Tim Blue