Shop OBEX P1 Docs P2 Docs Learn Events
Need help with scaling value calculation — Parallax Forums

Need help with scaling value calculation

JimTheProgrammerJimTheProgrammer Posts: 44
edited 2008-02-11 03:28 in Propeller 1
I have a maxbotics ez-1 sonar ranging sensor. Its sends a PW equal to 147 microseconds per inch. My calculations show that the scaling factor I need to divide my pw input value by is 446. But the resulting range is way off. Does the propeller require·a different value than 65536 like the BS2p?



I used the following:

1/147 = 0.0068


0.0068 * 65536 = 445.8· rounded up gives 446


Am I missing something here?

Comments

  • AleAle Posts: 2,363
    edited 2008-02-09 16:42
    To achieve what exactly ? 65536 /147= 445.82 446 and what ?....
    Use the propeller and a couple of waitpeq and waitpne to measure the time between rise and fall. The minimum time period is 1 cycle @ 80 MHz = 12.5 ns... that will be your resolution,,, There are more complicated ways of doing it,,,
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-09 17:25
    It looks like you want to calculate the INCHES from some accumultaed TICKS during the pulse by multiplication... But something like 65536 is in 99.99% of all cases an irrelevant number for the propeller.

    Do what Ale suggests.

    INCHES = TICKS*100/(8*147000)

    might be what you are lookong for, i.e. a divider of 8*1470 = 11_760
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2008-02-09 17:49
    Jim,

    The corresponding number on the Prop is 2^32 = 4,294,967,296. (On the Stamp, it is the word size there, 2^16=65536).


    Then 4,294,967,296 * 0.0068 = 29,205,777.6128

    With the time in microseconds, using the ** operator,

    inches := microseconds ** 29_205_778

    If you want it in units of 0.01 inch, then

    inches1 := microseconds ** 2_920_577_761

    It is important to understand how it works. It is very useful for scaling. The ** operator effectively uses the fraction
    29_205_778 / 4_294_967_296
    as the closest approximation (with denominator 2^32), to the desired fraction, 0.0068 =
    68/10000.
    Of course with the Prop, that approximation is quite accurate, much better than it could be with the equivalent ** operator on the Stamp. Note that the division by 2^32 is implicit in the ** operator.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • JimTheProgrammerJimTheProgrammer Posts: 44
    edited 2008-02-10 01:24
    Okay..I am at my last gasp here. I decided to move to a serial method but the examples I see do not seem to work.

    Does anyone have a example in SPIN of how to get the range value sent by the EZ-1?

    Product link and datasheets are here:

    http://www.sparkfun.com/commerce/product_info.php?products_id=8504


    Much appreciated as I am going nuts here.
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-10 08:32
    Jim,
    your request is most out of any sensible context, and we are just guessing what you could mean. Tracy and me gave you the best background information possible.

    Please tell us: What is your input and what do you need for output??
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-10 08:45
    The datasheet says the pulswidth (max 37 ms) has to be converted according to 147 µs/inch.

    So when you count clocks (12.5 ns) it's the formula I gave above (inch = clocks/11_760)
    When you count something else, it will be something else - of course...
  • JimTheProgrammerJimTheProgrammer Posts: 44
    edited 2008-02-10 14:56
    Well the serial function doesn't work either...and I have sent MaxBotics an email to get more information.
    I gave up on the pulse width issue as well. The timings are supposed to be handled in EZ-1 itself so all I have to do it take the output
    apply the scale factor and thats my range. Which never worked either. As this point I give up.


    repeat
    outa[noparse][[/noparse]27] := 0
    outa[noparse][[/noparse]27] := 1
    bs2.Serin_Wait(28,@myString,"R",9600,0,8) ' Accept string passing pointer for variable
    outa[noparse][[/noparse]27] := 0
    clock.PauseMSec(250)
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2008-02-11 03:28
    The sensor also has an analog output that you can hook up to a handheld voltmeter. (Do you have one?) It should read,
    inches = volts / 0.01

    Also, you canhook the serial output of the sensor right to a PC running something like hyperterminal. There are a lot of things that could be wrong with your Prop setup that could cause it not to work. Maybe bs2.serin_wait is not started properly, or maybe the pulsewidth code is not correct.

    These outside tests using a voltmeter or HTPE are sanity checks, and Maxbotics tech support is going to ask that sort of question anyway.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.