tur_bot
- 16th March 2008, 17:57
hello everybody
I have few problems with my ultrasonic ranger the SRF04.
I managed to make it work with a pic 16f84 to measure distances in inches and centimeters and display the results on a serial lcd. worked really fine.
then i tried to use the pic 16f88 with an internal clock ; but the lcd displays 0cm and 0 inches all the time which means that the SRF04 is not doing the job (the internal clock is working by the way. i tested it with another code)
here is a part of my code in picbasic pro:
DEFINE OSC 4
INTRC_OSC_NOCLKOUT
INTRC_IO
OSCCON=%01101000
include "modedefs.bas"
trisa = %11111111
trisb = %00000000
lcd var portb.7
'piezo var portb.4
trigger var portb.6
echo var porta.0
baud con N2400
dist_raw var word
dist_inch var word
dist_cm var word
conv_inch con 15
conv_cm con 6
low trigger
serout lcd,baud,[254,1] 'clear lcd screen
pause 1000
serout lcd,baud,[254,128,"-sonar ranger-"]
'sound piezo,[100,10,50,5,70,10,50,2] 'make startup sound
pause 1000 'pause 1 sec
serout lcd,baud,[254,128,"inches: "] 'set up the lcd display
serout lcd,baud,[254,192,"centimeters: "]
main:
gosub sr_sonar
serout lcd,baud,[254,135,#dist_inch," "] 'display the disance in inches
serout lcd,baud,[254,204,#dist_cm," "] 'display the distance in cm
goto main
end
sr_sonar:
pulsout trigger,1 'send a 10us trigger pulse
pulsin echo,1,dist_raw 'start timing the pulse width
'on echo pin
dist_inch = (dist_raw/conv_inch)
dist_cm = (dist_raw/conv_cm)
pause 1
return
i suppose that the pins of the pic are not inputing or outputing the right datas. may be because i did not set the input and output properly.
i had been strogling for few days , please help me to make it work.
thanx
regards
I have few problems with my ultrasonic ranger the SRF04.
I managed to make it work with a pic 16f84 to measure distances in inches and centimeters and display the results on a serial lcd. worked really fine.
then i tried to use the pic 16f88 with an internal clock ; but the lcd displays 0cm and 0 inches all the time which means that the SRF04 is not doing the job (the internal clock is working by the way. i tested it with another code)
here is a part of my code in picbasic pro:
DEFINE OSC 4
INTRC_OSC_NOCLKOUT
INTRC_IO
OSCCON=%01101000
include "modedefs.bas"
trisa = %11111111
trisb = %00000000
lcd var portb.7
'piezo var portb.4
trigger var portb.6
echo var porta.0
baud con N2400
dist_raw var word
dist_inch var word
dist_cm var word
conv_inch con 15
conv_cm con 6
low trigger
serout lcd,baud,[254,1] 'clear lcd screen
pause 1000
serout lcd,baud,[254,128,"-sonar ranger-"]
'sound piezo,[100,10,50,5,70,10,50,2] 'make startup sound
pause 1000 'pause 1 sec
serout lcd,baud,[254,128,"inches: "] 'set up the lcd display
serout lcd,baud,[254,192,"centimeters: "]
main:
gosub sr_sonar
serout lcd,baud,[254,135,#dist_inch," "] 'display the disance in inches
serout lcd,baud,[254,204,#dist_cm," "] 'display the distance in cm
goto main
end
sr_sonar:
pulsout trigger,1 'send a 10us trigger pulse
pulsin echo,1,dist_raw 'start timing the pulse width
'on echo pin
dist_inch = (dist_raw/conv_inch)
dist_cm = (dist_raw/conv_cm)
pause 1
return
i suppose that the pins of the pic are not inputing or outputing the right datas. may be because i did not set the input and output properly.
i had been strogling for few days , please help me to make it work.
thanx
regards