Ping)) Problems with SX/B
Basic Jim
Posts: 106
Hello all,
I am trying to convert a BS2 program to SX/B to use with a Ping)) sensor. The problem·I’m running into is that SX/B doesn’t seem to want to let a Word variable operate. The number in the variable is never higher than 80. This limits PING)) to about 4 inch distance where I need it to detect objects about 6 feet away. It should be able to easily do it as the specs say it can sense out to about 3 meters. If I change the Tim var. to byte from Word it seems to have no effect on the program. I just don’t see why I can’t get Tim to be greater that 80 unless the problem is with the pulsein parameters. but Itried different parms and nothing works. I have been trying to make this work for two nights now with no luck. I suspect I'm missing something basic here. (wouldn't be the first time.)
Thanks,
Jim W.
' =========================================================================
'·· File...... PING)).SXB
'·· Purpose... To sense an object 6 to 8 feet away
'·· Author....·
'·· E-mail....·
'·· Started...
'·· Updated...
' =========================================================================
' Program Description
'
' Device Settings
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
' Constants
'
' Variables
'
Tim ·Var word··· 'Never seems to go over 80 should hold some large number
'
· INTERRUPT
'
· PROGRAM Start
' =========================================================================
Pgm_ID:
· DATA· "SX/B Template", 0
'
' Subroutines / Jump Table
lights·sub
'
Start:
· ' initialization code here
Main:
DO
PULSOUT RC.7, 5·· 'maybe not the right parm? tried experimrnting with no luck
PULSIN· RC.7, 1, Tim ' I think the distance problem is here!
watch tim··············· ' Tim always equals 80 but goes lower as object comes closer
·if Tim < 250 then
break
gosub lights
endif
High rb.5
high rb.4
high rb.3
high rb.2
high rb.1
pauseus 200
loop
lights:
if tim < 79 then
low RB.5
endif
if tim < 70 then ' these work but in inches not in feet
low RB.4
endif
if tim < 60 then
low RB.3
endif
if tim < 50 then
low RB.2
endif
if tim < 40 then
low RB.1
endif
if tim < 30 then
low RB.0
endif
pauseus 1009
return
· GOTO Main
I am trying to convert a BS2 program to SX/B to use with a Ping)) sensor. The problem·I’m running into is that SX/B doesn’t seem to want to let a Word variable operate. The number in the variable is never higher than 80. This limits PING)) to about 4 inch distance where I need it to detect objects about 6 feet away. It should be able to easily do it as the specs say it can sense out to about 3 meters. If I change the Tim var. to byte from Word it seems to have no effect on the program. I just don’t see why I can’t get Tim to be greater that 80 unless the problem is with the pulsein parameters. but Itried different parms and nothing works. I have been trying to make this work for two nights now with no luck. I suspect I'm missing something basic here. (wouldn't be the first time.)
Thanks,
Jim W.
' =========================================================================
'·· File...... PING)).SXB
'·· Purpose... To sense an object 6 to 8 feet away
'·· Author....·
'·· E-mail....·
'·· Started...
'·· Updated...
' =========================================================================
' Program Description
'
' Device Settings
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
' Constants
'
' Variables
'
Tim ·Var word··· 'Never seems to go over 80 should hold some large number
'
· INTERRUPT
'
· PROGRAM Start
' =========================================================================
Pgm_ID:
· DATA· "SX/B Template", 0
'
' Subroutines / Jump Table
lights·sub
'
Start:
· ' initialization code here
Main:
DO
PULSOUT RC.7, 5·· 'maybe not the right parm? tried experimrnting with no luck
PULSIN· RC.7, 1, Tim ' I think the distance problem is here!
watch tim··············· ' Tim always equals 80 but goes lower as object comes closer
·if Tim < 250 then
break
gosub lights
endif
High rb.5
high rb.4
high rb.3
high rb.2
high rb.1
pauseus 200
loop
lights:
if tim < 79 then
low RB.5
endif
if tim < 70 then ' these work but in inches not in feet
low RB.4
endif
if tim < 60 then
low RB.3
endif
if tim < 50 then
low RB.2
endif
if tim < 40 then
low RB.1
endif
if tim < 30 then
low RB.0
endif
pauseus 1009
return
· GOTO Main
SXB
2K
Comments
Post Edited (Capt. Quirk) : 4/28/2007 9:11:50 PM GMT
Adding a 18-20 ms pause doesn't seem to work. I think the key is that I should be seeing a higher number than 80 when I poll the Tim var using debug. I can't figure out why I don't.
Thanks,
Jim W.
DO
PULSOUT RC.7, 5
pause 18················ 'Doesn't work tim·always =0 with pause. pauseus·18-20 doesn't·affect opperation
PULSIN· RC.7, 1, Tim ' I think the distance problem is here! should be some larger number
watch tim··············· ' Tim always equals 80 but goes lower as object comes closer
·if Tim < 250 then
break
gosub lights
endif
Try this
Post Edited (Capt. Quirk) : 4/28/2007 9:41:59 PM GMT
This takes advantage the the ability to use fractional values with PAUSEUS (works for PAUSE, too).
I will work on this tonight. My goal is to sense when a vehicle comes wihtin 8 feet of the sensor then it would send a signal to do the next function. Your BS1 to SXB converted program is a great help however, increasing the pause doesn't seem to increase the distance. Although I'm still experimenting I'm still stuck to about 5 to 8 inch distance. The PING)) features clearly states that '• Range – 2 cm to 3 m (0.8 in to 3.3 yrds)' But all the software examples that I have seen only seem to cover about 6-8 inches. Has anyone been able to make PING)) work at a seven foot or so distance? I'll keep working on increasing the distance tonight and tomorrow.
Best,
Jim W.
That is an interesting function that I would never have figured out how to do. I will add it to my tool box. If I can't make PING)) work the way I want it to, maybe I could build an ultrasonic ruler with it. Either way it might increase the accuracy of the distance finder by leaps! I look forward to start experimenting with it.
By the way, make sure the sensor isn't sitting on something like a table top. It has to be up off the surface a bit, otherwise, it seems to detect that. I'm building Halloween props, so I have the Ping sensor paired up with the PIR sensor, which detects movement out to 20 ft. Not sure what you are building, but you can use the two together pretty effectively. I'm using them for safety switches in case people get to close to a prop. I use the PIR sensor to detect movement, then turn on the PING sensor to make sure people aren't within 5ft of the prop. Yes, it is fenced off, but someone will always find a way to lean over or sneak too close.
Dan
Good point about the sensor location. Right now it's just pluged into the PDB. I'll try raising it a few inches. Can you tell me what pause number you are using to get 10 feet distance? I imagine there must be a rule like no pause 0 to 6 inches, pause 450 5 to six feet or something like that.
Thanks,
Jim W.
I thought PULSIN does the waiting, for you...
Jim, I think the issue is that you're watching 1 byte instead of 2 bytes for you - if it always comes back as '80' that's one byte, and you need to watch TIM as a word. Jon fixed that for you in his sample code, but I'm surprised it doesn't come up as 2 bytes.
Most is 'borrowed' code from the Thereping code, and some older of Jon's Code, but works for me with the SX.
Scale CON 10 ' PING))): raw x 10.00 = uS
RawToIn CON $0379 ' 1 / 73.746
RawToCm CON $08D1 ' 1 / 29.034
LOW Ping ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, 1, rawDist ' measure echo pulse
rawDist = rawDist * Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
then rawDist can be made into inches or cm
inches = rawDist ** RawToIn ' convert to inches
cm = rawDist ** RawToCm ' convert to centimeters
Note that inches, cm, & rawDist are words.
Hope this helps!
Rodney
I remembered reading something about that in a the PDF file last year after DosmanDan pointed it out. I have been on the road for the last six months and now that I'm back I'm trying to pick up where I left off. Unfortunately, my memory seems to have turned from static memory to dynamic memory with a poor refresh clock.
Jim
Post Edited (Basic Jim) : 5/1/2007 4:42:16 PM GMT
I tried your code and it works fine! It looks like you are not using pulsin and pulsout to have better control of the sensor? Probably generates less machine code too! Thanks for all your help.
Best,
Jim W.
I agree with you. On the example the I posted for some reason TIM would never display any number larger than 80. I need to study this ping stuff a little deeper. There are a lot of potenial uses that come to mind. Can you tell me where you downloaded the thereping code from? I would like to read that article.
Thanks,
Jim W.
Necessity is the mother of invention!
We're really lucky to have a forum such as this with such great suppport!
just wanted to let you know: I drove my Ping with Captain Quirks code but got in heavy problems regarding other components on my system changing the Ping output when active (like a stepper motor). I did intensive testing and what I found out: Responsible is the 450us pause that is suggested btw. pulseout and pulsein. That's not good. Reducing it to a normal 5us (like JonnyMac suggested) helped.
Just wanted to let you know guys, as I just spend half a day to figure this out and want to keep you from similar trouble, as you all helped me a lot too!
Matthias