PDA

View Full Version : Converting A to D value to 0 to 5VDC



jblackann
- 18th July 2006, 17:34
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"

minmin
- 25th September 2006, 20:54
'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
'************************************************* ******

b1arrk5
- 27th September 2006, 00:40
I was just working on a little project, and had a little problem getting exactly what I needed from the A/D, and I noticed your post. Perfect. I only needed to make two minor changes and it now works great.
Thanks,

Jerry.