Hello Everybody,

I have written a program for a PIC 16F685. I can't get it to work. It should read the pressure from a sensor (it does), indicate via LCD the voltage as converted (it does), light up an led for on pressure, high pressure, or low pressure (it does), and then move a servo accordingly (the servo buzzes but no consistant movement). I have read several books and still dont' understand the a/d conversion commands I simply copied them, perhaps there is my problem but I can't figure out how to get it fixed. If I play around with the commands, or the Physical and porgrammed location of the servo, I can sometimes get the servo to work, but then the LED's stop working. After a week of trying to figure it out it is time to humbly admit defeat and ask for help. I will eventually want to add a couple buttons to control the logic, but I need to get this workign first. Any help is greatly appreciated, and below is my current code:

'************************************************* ***************
'* Name : pressure reader.BAS *
'* Author : [Leon Wilde ] *
'* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 8/23/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************

Include "modedefs.bas"
' variables
res var word ' a/d converter result
volts var word ' result of converersion in mV
width var word
servopos var word
conv con 19 '5000/256=19.53, take 19
TRISA = 1 ' RA0 (an0) is input
TRISB = 0 ' RB AS OUTPUT
TRISC = 0
LED1 var portB.6
LED2 VAR PORTB.5
LED3 VAR PORTB.4
servo var portb.7
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
ADCON1 = 2 ' PORTA is analog
clear
SERVOPOS = 150
pause 10




'initialization

for width = 1 to 100
pulsout portC.6, SERVOPOS
pause 10
next
pause 10



serout portc.7, 2400, [12,1,14] ' CLEAR SERIAL LCD

start:

PAUSE 10
for width = 1 to 100
pulsout portC.6,servopos
pause 10
next
LED1 = 0
LED2 = 0
LED3 = 0

PAUSE 10





' START A/C CONVERSION

ADCIN 0, res ' Read channel 0 to res



'WAIT UNTIL CONVERSION IS COMPLETE

VOLTS = RES * CONV

serout portc.7, 2400, [12,1,14]
serout portc.7, 2400, ["V=", #VOLTS]

if volts < 1040 Then goto tooshallow

IF VOLTS > 1066 THEN goto toodeep

goto goodpressure

PAUSE 1000
GOTO start

tooshallow:
LED1 = 1
servopos = 50
goto start

goodpressure:
LED2 = 1
servopos = 100
goto start

toodeep:
LED3 = 1
servopos = 150
goto start

end