Trouble with SRF05 on a X2 conversion

rjconway

New Member
I have made a rover robot and it worked ok on a 40x. Converting to 40X2 I have run into timing problems with servo and ultrasonic. I think the 40X was a little less perdantic

It seems that my SRF05 is having trouble running at 8 mhz

40X code runs OK
main:
for counter = 1 to 20
low 6 ' Set output pin low
pulsout 6,1 ' Send a pulse to start the ranging
pulsin 0,1,w1 ' Recieve timed pulse from SRF05/04
w3=w1*10 ' Calculate distance
w3=w3/58
'debug w3
pause 10
next counter ' Wait before next pulse
return

Now the code will run on a 40X2 will run OK if I use the "setfreq m4" however the X2 conversion looks like this and I do not see a W1 or W3 values in debug.

main:
for counter = 1 to 20
low 6 ' Set output pin low
pulsout B.6,2 ' Send a pulse to start the ranging
pulsin D.0,2,w1 ' Recieve timed pulse from SRF05/04
w3=w1*10 ' Calculate distance
w3=w3/58
debug w3
pause 10
next counter ' Wait before next pulse
return

ANy assistance appreciated.

rob
 

Chavaquiah

Senior Member
I think pulsin D.0,2,w1 does not make much sense. The second argument is supposed to be the state (0=low, 1=high) of the pulse. I suppose "2" should be "1".

Also, when going from 4MHz to 8MHz, pulsin halves the time unit for the measurement (i.e., for the same timing, returns double the result). This should be compensated so your w3=w1*10 should become w3=w1*5.
 

hippy

Ex-Staff (retired)
This is a bug in the Conversion Wizard; "PULSIN pin,state,var" has been prcoessed as if it were like "COUNT pin,time,var" so has doubled the 'state' which it interpreted as 'time'. This will be fixed.

@ Chavaquiah : Thanks for the analysis.

@ rconway : Apologies for the mistake. Edit the 2 back to 1 and change 'w3=w1*10' to 'w3=w1*5'.
 
Top