Shop OBEX P1 Docs P2 Docs Learn Events
Ping)) Problems with SX/B — Parallax Forums

Ping)) Problems with SX/B

Basic JimBasic Jim Posts: 106
edited 2009-10-25 03:22 in General Discussion
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

Comments

  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-04-28 20:03
    ·Then convert the BS1 code, not the BS2 code.·Then try adding an 400 - 500us pauseus between your pulsout and pulsin. To make up for the speed difference of the BS1 and SX



    Post Edited (Capt. Quirk) : 4/28/2007 9:11:50 PM GMT
  • Basic JimBasic Jim Posts: 106
    edited 2007-04-28 20:33
    Hello Capt. Quirk,

    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
  • Basic JimBasic Jim Posts: 106
    edited 2007-04-28 20:34
    Also tries 180 and it chokes
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-04-28 21:11
    I have been editing my response, while you posted.

    Try this




    Post Edited (Capt. Quirk) : 4/28/2007 9:41:59 PM GMT
  • JonnyMacJonnyMac Posts: 9,212
    edited 2007-04-28 22:09
    I've use the Ping with SX/B; in a project where I needed to read distance with one-inch resolution I used this function:

    FUNC Get_Inches
      HIGH PingIO
      PAUSEUS 10
      LOW PingIO
      PAUSEUS 5
      INPUT PingIO
      tmpB1 = 0
      \ JNB PingIO, $
      DO
        INC tmpB1
        PAUSEUS 73.746
      LOOP UNTIL PingIO = 0
      RETURN tmpB1
      ENDFUNC
    
    



    This takes advantage the the ability to use fractional values with PAUSEUS (works for PAUSE, too).
  • Basic JimBasic Jim Posts: 106
    edited 2007-04-29 23:57
    Thank you Captain Quirk,

    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.
  • Basic JimBasic Jim Posts: 106
    edited 2007-04-30 00:01
    Thank you JonnyMac,

    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.
  • DosManDanDosManDan Posts: 179
    edited 2007-04-30 04:07
    I had the Ping working to 10ft, which I believe is the max distance. It was reading the distance, then speaking the measurement using the Quadravox sound module Parallax sold in the past. It would say how many feet and inches something was from the sensor. The sound was for testing so I could walk in front of it and not have to watch the debug window.

    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
  • Basic JimBasic Jim Posts: 106
    edited 2007-05-01 00:01
    Hi 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.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-05-01 01:25
    I don't know if you noticed this in the Parallax Ping PDF or not, but their tests were based off a 40" elevation from the ground.
  • JonnyMacJonnyMac Posts: 9,212
    edited 2007-05-01 02:11
    I cleaned up my code and have running program -- resolution is one inch or one centimeter, depending on a Conditional Compilation setting. You could divide those constants by ten to increase the resolution of the return value, but you're still working within the resolution of the sensor which, I believe, is one centimeter.
  • YendorYendor Posts: 288
    edited 2007-05-01 14:52
    Jon, I'm not understanding why a delay is needed... is this just another way to do it?

    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
  • JonnyMacJonnyMac Posts: 9,212
    edited 2007-05-01 16:00
    Yes, my program is just another way to handle the sensor (and conserve code space). The *, /, and ** operators generate a lot of code so I was looking for a way not to use them.
  • Basic JimBasic Jim Posts: 106
    edited 2007-05-01 16:37
    Captain Quirk,
    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
  • Basic JimBasic Jim Posts: 106
    edited 2007-05-01 16:59
    JonnyMac,

    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.
  • Basic JimBasic Jim Posts: 106
    edited 2007-05-01 17:18
    Hi Yendor,

    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.
  • JonnyMacJonnyMac Posts: 9,212
    edited 2007-05-01 21:06
    My demo duplicates the processes employed by PULSOUT and PULSIN, albeit manually, so that I have more finite control and don't have to use multiplication or division operators. It's one solution of many that could work.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-05-02 02:00
  • YendorYendor Posts: 288
    edited 2007-05-03 01:51
    Yes, the Thereping code is from Vern Graner, and capt. quirk helped with the url (thanks). It's not SX/B (it's in PBASIC) but was easy enough to translate. Sir Jon's article in N&V was also helpful (Column #119, 03/2005 - "Ping - I See You"), that you can get off of the Parallax web site. Actually, now that I'm looking at it, I think I used Jon's code, not Vern's. That's why Jon's new technique threw me off.

    Necessity is the mother of invention!

    We're really lucky to have a forum such as this with such great suppport!
  • Matthias09Matthias09 Posts: 47
    edited 2009-10-25 03:22
    Hey guys,

    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
Sign In or Register to comment.