Need help with scaling value calculation
JimTheProgrammer
Posts: 44
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?
I used the following:
1/147 = 0.0068
0.0068 * 65536 = 445.8· rounded up gives 446
Am I missing something here?
Comments
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,,,
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
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
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.
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??
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...
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)
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