The Sharp distance sensor is powered from 5 volts, the same as your PIC. I just take the Sharp output direct to the PIC with a 1 uF smoothing capacitor from the sensor output to ground. The Sharp updates every 40 mSecs or so and the smoothing capacitor is probably unnecessary but I usually smooth all inputs to the ADC out of habit.
After setting up ADCON0 and ADCON1 I leave at least 50 uSecs for the ADC to settle before I set the Go/Done bit to start the conversion.
Code snips for a PIC 16F877A
ReadSharpSensor: ' channel 5
ADCON0 = %11101001
ADCON1 = %10000000
gosub getadcval
Height = adcval
This is the GetADC subroutine
GetADCVal: ' the calling point needs to set ADCON0 & ADCON1 first
pauseus 50
clearwdt
ADCON0.2 = 1 ' starts conversion
WaitConversion: ' get ADC result
IF ADCON0.2 = 1 then waitconversion ' loop until conversion ends
adcval.highbyte = ADRESH ' upper two bits of result
adcval.lowbyte = ADRESL ' lower eight bits of result
return
HTH
Brian
Bookmarks