Hey!
I have the following code to measure distances from 3 SRF04 sensors, but it seems that once in a while the output from the terminal gets stuck? Is it just the terminal, or is my microcontroller actually freezing? Pressing reset works sometimes, and others it just advances one more time through. It seems to be random.
Any suggestions?
Thanks!
convfac con 74 ' use inches
SONAR_INIT con p16
SONAR_ECHO con p17
sonar_dist var word
output SONAR_INIT
input SONAR_ECHO
; ### Main Function ###
main
goto getDistance
goto main
; ### Get Distances ###
getDistance:
SONAR_INIT con p16
SONAR_ECHO con p17
low SONAR_INIT
pulsout SONAR_INIT, 20 '10us pulse to init reading
RCTIME SONAR_ECHO, 1, sonar_dist ; use instead of pulsin since buggy
RCTIME SONAR_ECHO, 0, sonar_dist
debug [dec sonar_dist, 13]
sonar_dist = sonar_dist / convfac
serout s_out, i9600, "Distance1: ", sdec sonar_dist, 13, 10] ;display result in terminal
;if sonar_dist < 15 then brake
;if sonar_dist > 15 then accelerate
;###############
SONAR_INIT con p18;
SONAR_ECHO con p19;
low SONAR_INIT
pulsout SONAR_INIT, 20 '10us pulse to init reading
RCTIME SONAR_ECHO, 1, sonar_dist ; use instead of pulsin since buggy
RCTIME SONAR_ECHO, 0, sonar_dist
debug [dec sonar_dist, 13]
sonar_dist = sonar_dist / convfac
serout s_out, i9600, "Distance2: ", sdec sonar_dist, 13, 10] ;display result in terminal
;#############
SONAR_INIT con p20;
SONAR_ECHO con p21;
low SONAR_INIT
pulsout SONAR_INIT, 20 '10us pulse to init reading
RCTIME SONAR_ECHO, 1, sonar_dist ; use instead of pulsin since buggy
RCTIME SONAR_ECHO, 0, sonar_dist
debug [dec sonar_dist, 13]
sonar_dist = sonar_dist / convfac
serout s_out, i9600, "Distance3: ", sdec sonar_dist, 13, 10] ;display result in terminal
return