DM timing microsecond?


Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6455
Posted: 01:31am 16 Mar 2012      

I did this for an ultrasonic range detector.
58 uS delay equals 1 cm so a sound frequency of 17241 Hz was used.

Every 100mS, the program sends a start pulse out pin 15 then waits for the return pulse.
The sound output is connected to pin 11 which does the timing.

settick 100, mainloop
waitloop:
if cnt=0 then goto waitloop
if cnt <650 then print cnt*10
cnt=0
goto waitloop
end

mainloop:
cnt=0
sound 17241, 20000
setpin 15, 8
pin(15)=0
pulse 15, 0.02
pause 0.03
setpin 15, 6, begincount
ireturn

begincount:
setpin 15, 7, endcount
setpin 11, 5
ireturn

endcount:
cnt=pin(11)
sound 17241, 0
setpin 15, 2
ireturn

VK7JH
MMedit