Hi,
Hook up a 10k potentiometer (or whatever you have in your drawer) to i.e AN0. Vdd on one side of the pot. GND on the other and the wiper goes to AN0. Put a 0.1 uF cap between wiper and GND to reduce noice .Connect the servo on i.e PORTB.1 ... if you use a voltage meter on the wiper and adjust the voltage to ~3 V you should get a 1.5 ms pulse every 20ms. Now you can turn the pot and then you can try the end positions... your LCD will be great here.
DEFINE ADC_BITS 8
' DEFINE YOUR LCD SETTINGS HERE
SERVO1 Var PORTB.1
AD0 var word
SERVO1_Pulse var byte
Total_Delay var word
n var byte
TRISA 255 ' PORTA to input
?????????? 'set up as analog CHECK DATASHEET for you PIC
?????????? ' turn off comparators CHECK DATASHEET
n=0
Goto main
update_LCD:
n=0 'reset LCD loop counter
'Here you write your LCD code to send the Servo1_pulse value to your LCD
RETURN
main:
ADCIN 0, AD0 'READ POT
SERVO1_Pulse=AD0*10 'Scale value max = 2550 us
SERVO1=1 'Start the servo pulse
Pauseus(SERVO1_Pulse) 'wait a while
CH1=0 'Stop the pulse
Total_Delay=(20000-Servo1_Pulse) 'calculate loop delay so we
Pauseus(Total_Delay) 'get approx 20 ms loop time
N=n+1
if n>=50 then gosub update_LCD 'update LCD every 50 loops i.e once per second
goto main
end
try it and if it doesnt work let me know so I can help. This code is untested but should work if you set up the analog port correctly. After this you will atleast know how far your servo will travel.
/me




Bookmarks