Converting A to D value to 0 to 5VDC
I wanted to take a reading off of a 10K pot using A to D on a PIC16F687 using 10 bits. I wanted to convert the A to D value of 0 to 1023 to a voltage 0 to 5V. I thought this might be helpful. Tech support helped me figure this out.
To have precision to two decimal points use.
ADCIN 3, AD_AN3_VALUE ' read channel 3 to AD_AN3_VALUE
AD_AN3_Volt = (AD_AN3_VALUE */ 500) >> 2
LCDOUT $FE, 1 ' Clear LCD screen
LCDOUT "A to D Value"
LCDOUT $FE, $C0, DEC (AD_AN3_volt/100) ,".",DEC2 AD_AN3_VOLT ,"VDC"
PAUSE 100
TO have precision to three decimal points use:
AD_AN3_Volt = (AD_AN3_VALUE */ 5000) >> 2
LCDOUT $FE, 1 ' Clear LCD screen
LCDOUT "A to D Value"
LCDOUT $FE, $C0, DEC (AD_AN3_volt/1000) ,".",DEC3 AD_AN3_VOLT ,"VDC"
0-5 ADC, PIC18F458, results show on LCD
'Here is another sample of AD convert
'the result shows on LCD
'load cell output feed to portA.3
' Sep 25, 2006
'*****************************
DEFINE OSC 4
W1 VAR WORD
include "modedefs.bas"
PAUSE 1000 'LCD takes a second to start
TRISA = 255 'PORTA all inputs
ADCON1 = 0 'PORTA Analog I/O
ADCON0.7 = 1 'Right justified.
' Initialize USART
TRISC = %10111111 'Set TX (PortC.6) to out, rest in
TXSTA = %00100000 'Enable transmit and asynchronous mode
SEROUT PORTC.6,N9600,["Citrus Counter ",254,2]
PAUSE 1000
SEROUT PORTC.6,N9600,[254,1] ' Clear screen
LOOP1:
ADCIN 3, W1
SEROUT PORTC.6,N9600,[#W1,13]
GOTO LOOP1
END
'************************************************* ******