Excuse the stupid title, but apparently I am the victim of the notorious "too long title" bug. I wanted the title to be, "PBP ADC to voltage conversion help."
I want to read a pot, and convert its ADC10 digital value to voltage. Each step represents .004V. My conversion routine works up through a digital value of 999, but is wrong at 1000 and above. For example a digital value of 903 converts to a voltage of 3.612 (correct), but a digital value of 1007 converts to 4.24V when it should be 4.024V. The PicBasic Pro code follows; please tell me how to correct it. Thanks.
I want to read a pot, and convert its ADC10 digital value to voltage. Each step represents .004V. My conversion routine works up through a digital value of 999, but is wrong at 1000 and above. For example a digital value of 903 converts to a voltage of 3.612 (correct), but a digital value of 1007 converts to 4.24V when it should be 4.024V. The PicBasic Pro code follows; please tell me how to correct it. Thanks.
Rich (BB code):
start:
ADCIN 0, left_pot 'Reads analog voltage on AN0, converts it to 10-bit
'digital value, and stores it as left_pot.
y = (left_pot*4)
whole = y/1000
decimal = y//1000
LCDOUT $FE,1,"Left Pot = ", DEC left_pot 'Clears LCD screen, displays
'"Left Pot = " and the decimal value of left_pot.
lcdout $FE,$C0,"Voltage = ", #whole, ".", #decimal