Shop OBEX P1 Docs P2 Docs Learn Events
BS2p PULSIN Variable Units — Parallax Forums

BS2p PULSIN Variable Units

paolo grigionipaolo grigioni Posts: 15
edited 2011-05-13 02:39 in BASIC Stamp
Hi,
I have a BS2p (firmware V 1.5) and I'm trying to measure distance with a Ping sensor.
In the reference Manual there is a table with Variable units: for BS2p it writes 0.8 usec but in the demo program example there is 0.75 usec in declarations. Which is the correct value?
Thanks
Paolo

Comments

  • ZootZoot Posts: 2,227
    edited 2011-05-05 08:17
    Post the code.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-05 08:22
    All the documentation I've seen specifies 0.8us as the unit for the BS2p for PULSIN and most other I/O statements involving timing. I don't know why a demo program would use 0.75us unless it were to simplify calculations. 3/4 is much easier to deal with using binary integer arithmetic than 8/10 or 4/5 and there's less than a 7% error involved.
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-05 09:10
    Hi Mike,
    if you take a lookat the thread "Pulsin for BS2P" linked below in "similar threads" you could read that older Firmware use 0.75 instead of 0.8.
    So i think my BS2P should use 0.8, but (there is always a but) if I try to calculate Speed of sound from D= C* t (where t = Num_Impulse *0.8 /2) I get value of C of about 300 m/sec !!!
    But my office room is not a freezer, it is at +21/+24 °C so I should get C about 342-345 m/sec. Why this? also using 0.75 I get C values lower than expected. It seems that a good value for scale should be about 0.72. What's going wrong?

    PS: Zoot actually i'm at home and the prog is on office PC. tomorrow morning (here in Italy) i'll post but i'm using the standard "Get_Sonar" subroutine
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-05 09:39
    The timing is set by a resonator on the BS2p module. These are pretty accurate and very reliable. They are temperature sensitive, but we're talking about a couple of percent over a much wider temperature range than what you're experiencing, not 10% or more. It would be nice if you had some way to measure pulse width or frequency. You could use PULSOUT to produce a pulse of known width or FREQOUT to produce a pulse train of known frequency and measure the output to see how close it was to what was expected. These use the same timebase (the resonator) as PULSIN.
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-05 12:30
    Thanks Mike,
    tomorrow I'll try it. If the scale value will be 0.8 (as expected), could the problem i get come from Ping offset (D= C *t +D0)? I measure distance from the front of Ping sensor to the target.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-05 12:44
    How can we answer your questions without adequate information? Once you post your code and provide more details about how you have your PING set up, maybe we can give better advice.
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-06 02:00
    Attached you will find my code
    thanks again to all
    MLX_SHT_ping_DAQ.bs2
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-06 09:48
    Mike I've checked the scale for Pulsout using USB Oscilloscope and I get 0.8 value. using 1250 I've read 10 msec, 2000 16 and 2500 20.
    thanks for this idea, now I've a fixed starting point ...... but my problem is unsolved, too.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-06 10:06
    Whatever code you've posted can't possibly be your real program. There are variables and pin definitions that are undefined. Please post your actual code, whatever it is that you say doesn't work.
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-06 10:18
    Sorry I don't know what's happened but the get_sonar subroutine I've posted is an old version that I've used to compare two Ping sensors. actually this subroutine is:

    Get_Sonar:

    Ping = IsLow
    PULSOUT Ping, Trigger ' activate sensor
    PULSIN Ping, 1, rawDist ' measure echo pulse
    PAUSE 500
    ' rawDist2 = rawDist2 '*/ $0C0 ' convert to uS
    ' rawDist = rawDist / 2 ' remove return trip
    RETURN

    Ping pin is 12
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-06 13:04
    There's not much to say. When you call Get_Sonar, the PING will be triggered, then rawDist will be set to the number of 0.8uS it takes for the first echo to return. That's all pretty obvious, but it's all I can say with the information provided.
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-06 13:21
    What other information you think you need?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-05-07 11:16
    I don't know what's going on here, but I have attached the Ping Demo that Jon Williams wrote.
    It works with all varieties of BS2.

    Ping_Demo.BS2
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-09 02:32
    Hi
    today I've made some test with BS2, BS2p, Ping and usb Oscilloscope. I get signal from SIG PING pin.
    Distance from Ping face to target was 15,2 cm for BS2p test and 15,0 cm for BS2 test.
    Results are in zip files attached. They contain:
    *.bmp file showing oscilloscope incoming signal
    *.txt and *. xls files with data coming from oscilloscope
    *.txt file with data caming from debug terminal

    1) In BS2p test, if we compare duration of returning impulse with the time of flight (Tof) calculated from rawDist */ Scale we get that the correct value for Scale should be 0,75 and not 0,8.

    2) In both tests, Speed of sound (C=dist/(Tof/2)) is less than 331,45 (the value at 0°C). But my room is well above 0 °C. So I think that Ping distance have an offset i.e. dist=d0+C*Tof/2.

    What do you think about?
    thanks Paolo
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-05-09 05:55
    I don't expect the Ping))) to be accurate to a high degree. It does what it does adequately, but I wouldn't buy one intending to split hairs with it.
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-09 06:14
    Hi again, just another little test with BS2p. I've inserted a PULSOUT as shown below.
    Results are in attached file.
    While pulsout creates an 800 usec impulse as expected (1000 units * 0.8usec/unit)
    ping return echo has duration with a scale equal to 0.75 instead of 0.8 as in prevoious tests.

    Does the problem come from Ping?




    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    '
    ' I/O Definitions
    '
    Ping PIN 0
    '
    ' Constants
    '
    Trigger CON 13
    'Scale1 CON $200
    Scale1 CON $0CD ' raw x 0.80 = uS
    Scale2 CON $0C0 ' raw x 0.75 = uS
    IsLow CON 0
    '
    ' Variables
    '
    rawDist VAR Word ' Ping raw measurement
    tempo1 VAR Word
    tempo2 VAR Word
    '
    [ Program Code ]
    Main2:
    GOSUB Get_Sonar ' get sensor value
    DEBUG "Ping N° Impulse... ", DEC rawDist," Two way Tof usec (Scale=2)... ", DEC tempo1," Two way Tof usec (Scale=0.75)... ", DEC tempo2, CR

    PAUSE 2000 ' minimum delay between readings
    GOTO Main2
    END

    '
    ' Subroutines
    '
    Get_Sonar:
    Ping = IsLow
    PULSOUT Ping, Trigger ' activate sensor
    PULSIN Ping, 1, rawDist ' measure echo pulse
    PULSOUT 1, 1000
    tempo1 = rawDist */ Scale1 ' convert to uS
    tempo2 = rawDist */ Scale2 ' convert to uS
    ' tempo = tempo / 2
    PAUSE 500
    RETURN

    ping_PULSOUT.zip
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-09 09:22
    PJ Allen wrote: »
    I don't expect the Ping))) to be accurate to a high degree. It does what it does adequately, but I wouldn't buy one intending to split hairs with it.

    Hi PJ,
    do you know a more accurate sonar that can be used with BS2p?
  • PublisonPublison Posts: 12,366
    edited 2011-05-09 10:21
    Paolo,

    Could you define your accuracy requirements?

    Ultrasonic, and even IR detectors have their limits. I'm sure you don't want to get into a laser interferometer setup.

    Hi PJ,
    do you know a more accurate sonar that can be used with BS2p?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-05-09 16:45
    PG,
    I'm not trying to sell the product short, the datasheet states, "precise, non-contact distance measurements".

    On page 3 [of 12] of the #28015 datasheet there is this note:
    "The percent error over the sensor’s operating range of 0 to 70 ° C is significant, in the magnitude of 11 to 12 percent. The use of conversion constants to account for air temperature may be incorporated into
    your program (as is the case in the example BS2 program given in the Example Programs section below).
    Percent error and conversion constant calculations are introduced in Chapter 2 of Smart Sensors and
    Applications..."

    So, as you're trying to wring out every bit of accuracy that you can, you'll have to modify the "conversion constant" in the example program as your situation requires.

    Post Edit -- > 2 days later and no follow up. Oh well.
  • paolo grigionipaolo grigioni Posts: 15
    edited 2011-05-13 02:39
    Hi PJ,
    thank you for your infos and datasheet, I've an old one (v1.3) that doesn't mention that error.
    Stated that the formula is:
    C=d/(k*N) where C=speed of sound, d=target distance, k=scale (0.8 for BS2p) and N=pulse number
    I thought that if the target is at 1 m (at room temperature) I could get a % error for d about 10^-3 (1mm/1m) and for N about 3^10-4 (1 pulse/3600 counted pulses) in order to get an error on C less than 1 m/s that was my need.
    Now i know (unfotunately) that this isn't possible with Ping, even if I don't understand where the problem arises: maybe in the timing sequence?
    So probably I need another kind of ultrasonic sensor to get my target.
    thanks again
    Paolo
Sign In or Register to comment.