OK, I need some answers to my ADC questions. I’m a ADC first timer here so bear with me.
I have a16F870 and I want to display an analog voltage (0.00-5.00V) on an LCD display. Presently I can:
1. Display the ADC voltage as a number between 0 – 255.
2. Display the ADC voltage as a number between 0 - 5 (1 volt resolution)
Here is an example of my code:
RESULT VAR BYTE
ADCIN 0, RESULT
LCDOUT $FE, 1
LCDOUT "ADC VALUE:"
LCDOUT $FE, $C0
LCDOUT DEC RESULT ‘ displays number 0 - 255
PAUSE 2000
RESULT = RESULT / 51
LCDOUT $FE, 1
LCDOUT "VOLTAGE VALUE:"
LCDOUT $FE, $C0
LCDOUT DEC RESULT ‘ displays number 0 – 5
What I really want to do is display the ADC voltage as a number between 0.00 – 5.00 with TWO decimal digits.
To display RESULT with two decimals, can I just multiply RESULT by 100, and use the DIG command to display three discreet digits, and the decimal point????????????
I tried this, but the display shows values between 0 – 2.55V. Strangely, it gives these readings twice when adjusting my 5k pot from off to full scale!
i.e. (off) 0 to 2.55 (half way) then 0 to 2.55 (full scale)
Maybe I need to use trickier math or higher ADC resolution????????????
This brings me to my next question.
The above example uses DEFINE ADC_BITS 8. I am guessing this is why my RESULT value is sampled over 255 steps.
I have tried using ADC_BITS 10, to display RESULT in the range of 0 to 1023, but this doesn’t work using the above code. Any ideas????????????
Sorry for the long winded post, (I know I dread reading long posts too), but I hope I have given you brainiacs enough clues to solve my dilemma.
Cheers
Bookmarks