Shop OBEX P1 Docs P2 Docs Learn Events
Ping sensor with Pic 16f877a problem!! — Parallax Forums

Ping sensor with Pic 16f877a problem!!

ricorimtoricorimto Posts: 1
edited 2011-05-08 15:41 in Accessories
hello,
i 've connected ping sensor with pic 16f877a and one servo , trying to make the servo stops every time the ping detects objects, here's the code i'm using with picbasic :

main:
i var byte
distance var byte
cms var byte
trisb=0

run:
servo:
for i =0 to 174
pulsout 7,170
pause 20
next i
gosub getdistance

if cms <40 then stopservo
goto servo
getdistance:
low 1
pulsout 1,1
low 1
pulsin 1,1,distance
distance=distance/2
cms=distance*9
return

stopservo:
pulsout 7,150
pause 5000
goto run

end


please help!!!

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-05-08 15:41
    From the look of it it should stop for about 5 seconds, however your 'stop servo' routine need to be updated at about 50Hz, so the stop servo section that reads...
    stopservo:
    pulsout 7,150
    pause 5000
    goto run
    

    might be better off looking something like this...
    stopservo:
    for i =0 to 174
    pulsout 7,150
    pause 20
    next i
    pause 5000
    goto run
    



    ...Also, you might want to increase cms to a WORD value
    ...similar to how you have it in the regular servo routine.
Sign In or Register to comment.