20m2 and SR04 sensor

#1
I would like to use multitasking with a Picaxe 20M2 and a SR04 ultrasonic distance sensor
How do i acheave a 10us pulse at 4Mhz to triger the sensor?
 
#8
this works at setfreqm8 but not with setfreqm4
;Ultrasonic distance sensor

Symbol trig=c.4

Symbol echo=c.6

symbol inch=w12

distance:

setfreq m8

PulsOut trig,1 ;start a reading

PulsIn echo, 1, w13 ;return value in w13

let inch=w13*10/148/2 ;convert in inch in w13

debug

setfreq m4

goto distance
 

Technical

Technical Support
Staff member
#9
Indeed. That is why you must use the same pin for both on that particular model sensor, as per the example linked.
 

darb1972

Senior Member
#10
this works at setfreqm8 but not with setfreqm4
;Ultrasonic distance sensor

Symbol trig=c.4

Symbol echo=c.6

symbol inch=w12

distance:

setfreq m8

PulsOut trig,1 ;start a reading

PulsIn echo, 1, w13 ;return value in w13

let inch=w13*10/148/2 ;convert in inch in w13

debug

setfreq m4

goto distance
Hello

Just a tip. Best to put your code into the preferred forum format using the code insert function on the top task bar so it then looks like below. Good habit and particularly handy when posting large code snippets. Also makes it easier to follow and keeps your formatting, such as tabs/indents in the correct layout.

Code:
;Ultrasonic distance sensor


    Symbol trig=c.4
    Symbol echo=c.6
    symbol inch=w12

distance:

setfreq m8

PulsOut trig,1    ;start a reading

PulsIn echo, 1, w13 ;return value in w13

let inch=w13*10/148/2    ;convert in inch in w13

debug

setfreq m4

goto distance
 
Top