Hi,
Thanks to replies to my last post, I now have 4 channels of ADC to serial LCD working great on a pic16f877/04. With my current setup, I can measure 0-5 volts on ch 0. Channel 1 is for displaying distance based on the output of a Sharp GP2D12 IR range finder, but I can't make it work, the readings are all over the place. I do know that the analog output from the sensor is not linear, so how do I get accurate readings throughout it's range, which is up to 80 cm.
Thanks alot,
John
code:
include "modedefs.bas"
DEFINE LOADER_USED 1
DEFINE OSC 4
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 40 ' Set sampling time in uS
' PROGRAM VARIABLES
vstep CON 1252 ' For 10-bit A/D +Vref = 5V : 5V/1023*256=1.252=vstep
div con 1000'distance multiplyer
volts VAR WORD ' Storage for A/D result
distance var word
temp var word
light var word
'ADC CONFIGURATION
TRISA = %11111111 ' Set PORTA to all input
'adcon1 = %10000000' --THIS IS BINARY EQUIV TO BELOW !!
ADCON1.7 = 1 ' 10-bit A/D RA.3 = +Vref, Set PORTA analog and right justify result
SEROUT2 portb.5,84,[12,22,17]
loop:
'ADC ROUTINE
ADCIN 0,volts ' Read A/D channel 0 to 'volts' variable
pause 10
adcin 1,distance
pause 10
ADCIN 2,temp
pause 10
ADCIN 3,light
'MATH ROUTINE
volts = volts */ vstep
DISTANCE = (distance */ div)*10
temp= temp*/25
light= light/10
'SERIAL LCD OUTPUT
SEROUT2 portb.5,84,[128,"BUSS VOLTAGE:",dec volts diG 3,".",dec2 volts,"vDC"]
serout2 portb.5,84,[148,"IR DISTANCE.:",DEC DISTANCE dig 3,".",DEC2 DISTANCE," cm "]
SEROUT2 portb.5,84,[168,"TEMPERATURE.:",DEC temp," c "]
serout2 portb.5,84,[188,"LIGHT LEVEL.:",DEC light]
Pause 50
Goto loop
End
Bookmarks