Ultrasonic sensor, PWM or PULSIN

tuti993

New Member
Should I use a Pwm signal or a Pulsin

symbol trig = 3 'Define output pin for Trigger pulse (A, M , X, X1 parts)

symbol trig = b.3 'Define output pin for Trigger pulse (M2, X2 parts)

symbol echo = 6 'Define input pin for Echo pulse (A, M, X, X1 parts)

symbol echo = c.6 'Define input pin for Echo pulse (M2, X2 parts)

symbol range = w1 '16 bit word variable for range



main:

pulsout trig,2 'produce 20uS trigger pulse (must be minimum of 10uS)

pulsin echo,1,range 'measures the range in 10uS steps

pause 20 'recharge period after ranging completes


'now convert range to cm (divided by 5.8) or inches (divided by 14.8)

'as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead


let range = range * 10/58 'multiply by 10 then divide by 58

debug range 'display range via debug command

goto main 'and around forever


'Note that X2 parts operate at 8MHz instead of 4MHz and so modify the calculation
'let range = range * 10/58/2 'multiply by 10 then divide by 58 then divide by2
 

Attachments

nick12ab

Senior Member
The reason there's both PULSOUT and PULSIN is because the data send request has to be sent to the ultrasonic sensor first before the ultrasonic sensor gives the PICAXE the signals. What you've asked isn't very clear to me but I hope this is the response you're looking for.

Also, the tags you need around the code part is [code][/code] rather than [img][/img]
 

hippy

Technical Support
Staff member
Should I use a Pwm signal or a Pulsin
Attached Files 14C01.pdf‎
If using an SRF005 untrasonic distance module you would use that code with its PULSIN.

The PDF is just for an ultrasound sensor which is a component used by the SRF005 and similar.

If you are referring to Page 4 ( as in another post ) then I'm not sure what that circuit is / does and cannot advise on what program code would have to be used with it. I would expect you would have to add additional hardware to make it a workable solution.

The easy option is to use an SRF005 module.
 
Top