Shop OBEX P1 Docs P2 Docs Learn Events
math help — Parallax Forums

math help

ArchiverArchiver Posts: 46,084
edited 2003-06-17 22:42 in General Discussion
can someone please help me make a BS2 to do this math problem:

N*3600/M

N could be up to 700
M could be up to 18000

If you use a calculator you will get "140"
but if you use the stamp you get "1"

Please help
TC

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-05-03 23:48
    Is there a reason you couldn't compute:

    N*36/(M/100)

    M/100 ranges from 0-180, so no problem there.

    N*36 ranges from 0-25200 so that's OK.

    then the division should be OK too.

    If you are doing lots of math or want more precision, consider one of our
    math coprocessors (http://www.al-williams.com/awce/pak1.htm) but honestly I
    don't think you need it just for this.

    Good Luck!

    Al Williams
    AWC
    * 8 channels of PWM:
    http://www.al-williams.com/awce/pak5.htm


    >
    Original Message
    > From: aconti@n... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Yi-fvVzvkVDfjRY5Th88-zN0VusOAwhpZmgWqZe-wjuvQcPj5Ak7N_UBCOWqJmRkPF-EEhmnJyx_t80T]aconti@n...[/url
    > Sent: Thursday, May 03, 2001 5:34 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] math help
    >
    >
    > can someone please help me make a BS2 to do this math problem:
    >
    > N*3600/M
    >
    > N could be up to 700
    > M could be up to 18000
    >
    > If you use a calculator you will get "140"
    > but if you use the stamp you get "1"
    >
    > Please help
    > TC
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-21 00:53
    can someone please help me with a math problem? I am redesigning my digital dash project. I am going to use the PULSIN command. I hooked up a small project to my car and found out that at 1000 RPM the stamp reads 4000 units ( 8 ms ). I am basing this on the time it takes to get to one cylinder to another ( 1·- 0 - 1 transition I am measuring the·time of 0 ). As RPM's go up the time goes down, that is where I am having the problem. If anyone has·any ideas, it will help.

    Remember,

    4000 units = 1000 RPM
    4001 units = less than 1000 RPM
    3999 units = more than 1000 RPM

    Thanks,
    TC
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-21 05:54
    Hi TC,

    units is some reciproke function of rpm

    check out units = 4000 * (1000 / rpm) or rpm = 1000 * (4000 / units)

    Greetings peter
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-21 07:44
    Hi TC,

    units is some reciproke function of rpm

    check out units = 4000 * (1000 / rpm)
    rpm = 1000 * (4000 / units)

    use units = (4000 / sqr rpm) * (1000 / sqr rpm) due to integer math
    roundings
    use rpm = (1000 / sqr units) * (4000 / sqr units) ditto

    Greetings peter
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-21 16:30
    >"Anthony Conti" <aconti@n...> wrote:
    >>can someone please help me with a math problem? I am redesigning my
    >>digital dash project. I am going to use the PULSIN command. I
    >>hooked up a small project to my car and found out that at 1000 RPM
    >>the stamp reads 4000 units ( 8 ms ). I am basing this on the time
    >>it takes to get to one cylinder to another ( 1 - 0 - 1 transition I
    >>am measuring the time of 0 ). As RPM's go up the time goes down,
    >>that is where I am having the problem. If anyone has any ideas, it
    >>will help.
    >> Remember,
    >> 4000 units = 1000 RPM
    >>4001 units = less than 1000 RPM
    >>3999 units = more than 1000 RPM
    >
    Peter Verkaik wrote:
    >Hi TC,
    >units is some reciproke function of rpm
    >check out units = 4000 * (1000 / rpm) or rpm = 1000 * (4000 / units)
    >Greetings peter
    >...
    >use units = (4000 / sqr rpm) * (1000 / sqr rpm) due to integer math
    >roundings
    >use rpm = (1000 / sqr units) * (4000 / sqr units) ditto


    Hi TC,

    As Peter said, it is a reciprocal
    rpm = 4000000 / units
    The stamp best handles that in steps, because it can't handle large
    numbers directly.

    One way to get good accuracy is by long division. That is, the
    remainder from each division step is then used to calculate another
    digit. Try this for three digits display:

    ' pulsin not shown,,1000,rpm-->4000 units
    units=units/4 ' 1000rpm-->1000 units
    rpm = 10000/units*100 + (10000//units*10/units*10) +
    (10000//units*10//units*10/units)

    That works mathematically down to 152 rpm. (The limitation on the
    low end comes from having to multiply the remainder term times
    10--the raw pulsin value will get up to 6553 at about 610 rpm--that
    value/4 will get up to 6553 at about 152 rpm.)

    Here the same thing as an iteration:

    'pulsin not shown, 1000,rpm-->4000 units
    units=units/4
    rpm=10000/units
    rpm1=10000//units*10
    for i=0 to 1
    rpm=rpm*10+(rpm1/units) ' quotient
    rpm1=rpm1//units*10 ' remainder
    next
    ' exit here with rpm=1000 when pulsin=>4000

    That can be extended to double precision if necessary.

    The following version kicks out digits to a display. It does not
    accumulate the rpm value in a variable, so it can be carried out to
    as many decimal places as you want.

    rpm1 var word ' this algorithm works for rpm>152
    i var nib
    loop:
    gosub getPulsinUnits 'not shown 1000rpm-->4000 units
    units=units/4
    rpm1=10000/units
    debug CR,"rpm=",dec rpm1 ' kick out first quotient
    rpm1=10000//units*10 ' first remainder*10
    for i=0 to 5
    debug dec1 (rpm1/units) ' kick out a digit
    rpm1=rpm1//units*10 ' calculate remainder*10
    if if i<>1 then nextrpm
    debug "." ' print decimal point after i=1 digit
    nextrpm
    next ' exits with 3 digits printed after the decimal point
    goto loop

    I hope that helps. Yes, it is kind of a pain to do the reciprocal
    math on the BS2!


    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com/BS2index.htm <-- more BS2 math stuff
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-23 01:50
    Hi TC,

    Actually 7501876/1071 = 7004.55275 so you want 7005
    The error is due to the stamp's integer math.
    60499/1071=56.48832 but is calculated as 56
    so 56*31*4 gives 6944
    which is ((6944-7005)/7005)*100%=-0.87% below real result. This is not bad
    at all.

    If you would calculate the 60499/X to one digit after the decimal point you
    would get
    60499/1071=56.5
    so 56.5*31*4=7006 which is (almost) correct.

    Calculate fraction*10 (i.e 0.48832*10=4.8832 -> should be rounded to 5)
    (60499//1071)*10/1071=4 'integral part
    (60499//1071)*10//1071=946 'rest term
    calculate 0 or 1 to round off (<0.5 gives 0, >=0.5 gives 1)
    946*2/1071=1
    correction=(4+1)*4*31/10=62
    result=6944+62=7006

    Y=(60499/X*4*31)+(((60499//X*10/X)+(60499//X*10//X*2/X))*4*31/10)
    Things go still wrong if 60499//X>6553 i.e. for X=50000 for example, or if
    X>=60500

    Using 7501875 instead of 7501876 gives you better factorization:

    7501875=3*5*5*5*5*4001=1875*4001
    Now you can use 4001/X*1875

    Y0 = 4001/X 'integral
    Y1 = 4001//X*10/X 'first decimal
    Y2 = 4001//X*10//X*10/X '2nd decimal
    Y3 = 4001//X*10//X*10//X*10/X '3rd decimal
    R = 4001//X*10//X*10//X*10//X*2/X 'correction for 3rd decimal
    Y = (Y0*1875)+(Y1*1875/10)+(Y2*1875/100)+((Y3+R)*1875/1000)

    Example for X=1071 (7501875/1071=7004.55182 -> we want 7005)
    4001/1071=3.73576=3.736
    Y0 = 4001/1071=3
    Y1 = 4001//1071*10/1071=7
    Y2 = 4001//1071*10//1071*10/1071=3
    Y3 = 4001//1071*10//1071*10//1071*10/1071=5
    R = 4001//1071*10//1071*10//1071*10//1071*2/1071=1
    Y =
    (3*1875)+(7*1875/10)+(3*1875/100)+((5+1)*1875/1000)=5625+1312+56+11=7004

    The important thing for factorization is: no factor must be grater than 6553
    otherwise
    calculating a decimal using factor*10 gives overflow.
    So if a big constant can not be factorized using only factors<6554 then you
    must select
    the nearest big constant that does, otherwise the above method does not work
    for all X.
    (By the way, for X=0 there is no solution).

    Hope this helps.
    Greetings peter.
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-23 17:45
    >can someone please help me make a BS2 to do this math problem:
    >
    >N*3600/M
    >
    >N could be up to 700
    >M could be up to 18000
    >
    >If you use a calculator you will get "140"
    >but if you use the stamp you get "1"
    >
    >Please help
    >TC

    Hi TC,
    I had missed this question. Try this:


    ' compute Y=N/M*3600
    N var word ' input: numerator N<32768
    M var word ' denominator M<32768
    Y var word ' result =N*3600/M, integer
    F var word ' for computation of fractional part
    J var nib ' index

    main: ' demo program
    for N=100 to 700 step 100 ' demo numbers
    for M=1000 to 18000 step 1000
    debug dec N,tab,dec M ' show inputs
    gosub divide
    debug tab,dec Y,CR ' show result
    next
    next
    end

    divide: ' subroutine
    Y=N/M*3600 ' integer part
    F=0 ' initialize
    for J=15 to 0 ' 16 bits
    N=N//M<<1 ' remainder*2
    F.bit0(J)=N/M ' next bit
    next
    Y=F**3600+Y ' rescale
    return


    -- regards,
    Thomas Tracy Allen Ph.D.
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com/BS2math2.htm <-- explains how it works
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-23 20:31
    TC,
    The little program I posted earlier today needs a local variable in
    the divide subroutine, so that the numerator can step through values
    in the for-next loop in the demo. Corrected version:

    ' Tracy Allen @
    ' http://www.emesystems.com
    ' compute Y=N/M*3600
    N var word ' input: numerator N<32768
    M var word ' denominator M<32768
    Y var word ' result =N*3600/M, integer
    F var word ' local var for divide routine
    X var word ' local var for divide routine
    J var nib ' index
    '
    main: ' demo program
    for N=100 to 700 step 100 ' demo numbers
    for M=100 to 18100 step 2000
    debug dec N,tab,dec M ' show inputs
    gosub divide
    debug tab,dec Y,CR ' show result
    next
    next
    end
    '
    divide: ' subroutine
    Y=N/M*3600 ' integer part
    X=N ' local numerator
    F=0 ' initialize
    for J=15 to 0 ' 16 bits
    X=X//M<<1 ' remainder*2
    F.bit0(J)=X/M ' next bit
    next
    Y=F**3600+Y ' rescale
    return


    -- regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-24 06:28
    >Thanks Tracy, but Al helped me with it, he gave me
    >
    >Nx36/(M/100) = MPH
    >
    >this is the formlua for miles per hours ( speed ). Where M = pulses
    >per mile, and N = reading from the count camand, and 3600 = 60x60. I
    >will try your formiua and see witch is better.

    Integer division M/100 may compromise accuracy more than you want.
    For example, when M=199, then M/100=1, not 1.99 or 2. Slightly
    better result would come from Nx72/(M+25/50). (given that N<700,
    N*72 fits in a word variable).

    The method I suggested using long division is never off by more than
    one, however, at the expense of a much longer calculation.

    If M is a constant (is it?), you can simplify the formula greatly and
    still have great accuracy.


    >Also, do you know of a
    >way I can convert MPH (standerd) to Km/h (metric)?

    ' kmph = mph * 1.60934
    ' stamp:
    kmph = mph */ 412
    ' the above always rounds off low
    ' for better roundoff:
    kmph = mph*10 */ 412 +5/10


    >
    >Thanks for the input. always looking for a better idea.
    >
    >TC

    You're welcome.

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-24 13:24
    Absolutely dividing M by 100 is going to cost accuracy.

    One way to get a little extra in a case like this is to use fixed point. So
    to calculate M/100 you might say:

    M1=M*10 ' convert to .1 units
    M1=M1/100 ' do division
    M1=(M1+5)/10 ' convert back to units with rounding

    So if you are dividing 199/100, the steps look like this:

    M1=1990
    M1=19
    M1=(24)/10 = 2

    Which is a closer answer than 1. Of course, this assumes that M1<=6553. You
    can also "round in binary"

    M1=M*2 ' add 1 extra bit
    M1=M1/100
    M1=(M1+1)/2

    or

    M1=398
    M1=3
    M1=(4)/2=2

    Same answer in this case and M only has to be <=32K

    The long division will always be more accurate, I suspect. Of course, a
    PAK-I or PAK-II would also take care of this very easily plus add much
    flexibility.

    Regards,

    Al Williams
    AWC
    *Connect your Stamp to the Internet:
    http://www.al-williams.com/awce/netporter.htm


    >
    Original Message
    > From: Tracy Allen [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=VyNRWW_TiHyy7YDdVepl9wMLcoytFKfkJ8cwxOaMcxiWAIuefyuk1EfionYv6jhLcdZD6CMnb_PwaYa2gw]tracy@e...[/url
    > Sent: Thursday, May 24, 2001 12:29 AM
    > To: aconti@n...; basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] re: math help
    >
    >
    > >Thanks Tracy, but Al helped me with it, he gave me
    > >
    > >Nx36/(M/100) = MPH
    > >
    > >this is the formlua for miles per hours ( speed ). Where M = pulses
    > >per mile, and N = reading from the count camand, and 3600 = 60x60. I
    > >will try your formiua and see witch is better.
    >
    > Integer division M/100 may compromise accuracy more than you want.
    > For example, when M=199, then M/100=1, not 1.99 or 2. Slightly
    > better result would come from Nx72/(M+25/50). (given that N<700,
    > N*72 fits in a word variable).
    >
    > The method I suggested using long division is never off by more than
    > one, however, at the expense of a much longer calculation.
    >
    > If M is a constant (is it?), you can simplify the formula greatly and
    > still have great accuracy.
    >
    >
    > >Also, do you know of a
    > >way I can convert MPH (standerd) to Km/h (metric)?
    >
    > ' kmph = mph * 1.60934
    > ' stamp:
    > kmph = mph */ 412
    > ' the above always rounds off low
    > ' for better roundoff:
    > kmph = mph*10 */ 412 +5/10
    >
    >
    > >
    > >Thanks for the input. always looking for a better idea.
    > >
    > >TC
    >
    > You're welcome.
    >
    > -- regards,
    > Tracy Allen
    > electronically monitored ecosystems
    > mailto:tracy@e...
    > http://www.emesystems.com
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-24 15:07
    I have had this problem in PLC's and I put the calculations in
    a spreadsheet. I had to round the numbers in the fields that the
    Stamp would truncate.

    Then I can see where the calculation fails by being too high or too
    low. In one app, I had a check to see if it was under "X" and
    multiply by 1,000, between "X" and "Y" multiply by 100, you get the
    idea.

    The resolution came out much better than I had hoped.

    Hope this helps.

    Dave



    --- In basicstamps@au.egroups.com, "Al Williams" <alw@a...> wrote:
    > Absolutely dividing M by 100 is going to cost accuracy.
    >
    > One way to get a little extra in a case like this is to use fixed
    point. So
    > to calculate M/100 you might say:
    >
    > M1=M*10 ' convert to .1 units
    > M1=M1/100 ' do division
    > M1=(M1+5)/10 ' convert back to units with rounding
    >
    > So if you are dividing 199/100, the steps look like this:
    >
    > M1=1990
    > M1=19
    > M1=(24)/10 = 2
    >
    > Which is a closer answer than 1. Of course, this assumes that
    M1<=6553. You
    > can also "round in binary"
    >
    > M1=M*2 ' add 1 extra bit
    > M1=M1/100
    > M1=(M1+1)/2
    >
    > or
    >
    > M1=398
    > M1=3
    > M1=(4)/2=2
    >
    > Same answer in this case and M only has to be <=32K
    >
    > The long division will always be more accurate, I suspect. Of
    course, a
    > PAK-I or PAK-II would also take care of this very easily plus add
    much
    > flexibility.
    >
    > Regards,
    >
    > Al Williams
    > AWC
    > *Connect your Stamp to the Internet:
    > http://www.al-williams.com/awce/netporter.htm
    >
    >
    > >
    Original Message
    > > From: Tracy Allen [noparse][[/noparse]mailto:tracy@e...]
    > > Sent: Thursday, May 24, 2001 12:29 AM
    > > To: aconti@n...; basicstamps@y...
    > > Subject: [noparse][[/noparse]basicstamps] re: math help
    > >
    > >
    > > >Thanks Tracy, but Al helped me with it, he gave me
    > > >
    > > >Nx36/(M/100) = MPH
    > > >
    > > >this is the formlua for miles per hours ( speed ). Where M =
    pulses
    > > >per mile, and N = reading from the count camand, and 3600 =
    60x60. I
    > > >will try your formiua and see witch is better.
    > >
    > > Integer division M/100 may compromise accuracy more than you want.
    > > For example, when M=199, then M/100=1, not 1.99 or 2. Slightly
    > > better result would come from Nx72/(M+25/50). (given that N<700,
    > > N*72 fits in a word variable).
    > >
    > > The method I suggested using long division is never off by more
    than
    > > one, however, at the expense of a much longer calculation.
    > >
    > > If M is a constant (is it?), you can simplify the formula greatly
    and
    > > still have great accuracy.
    > >
    > >
    > > >Also, do you know of a
    > > >way I can convert MPH (standerd) to Km/h (metric)?
    > >
    > > ' kmph = mph * 1.60934
    > > ' stamp:
    > > kmph = mph */ 412
    > > ' the above always rounds off low
    > > ' for better roundoff:
    > > kmph = mph*10 */ 412 +5/10
    > >
    > >
    > > >
    > > >Thanks for the input. always looking for a better idea.
    > > >
    > > >TC
    > >
    > > You're welcome.
    > >
    > > -- regards,
    > > Tracy Allen
    > > electronically monitored ecosystems
    > > mailto:tracy@e...
    > > http://www.emesystems.com
    > >
    > >
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-25 05:32
    >>> MPH=N*3600/M
    > > If M is a constant (is it?), you can simplify the formula greatly and
    > > still have great accuracy.
    >
    >It is, some what. M = Pulses per mile that comes from the transmission. If I
    >change tires ( either bigger or smaller ) or if I change the rear end gear
    >ratio my Pulses per mile will change. So I made my program to learn what the
    >pulses per mile are, and store it to the EEPROM, then read the EEPROM and
    >put it in a variable ( I wish I could Make it a constant )

    Well, when you have your program learn the new pulses per mile, don't
    store that directly in the eeprom. Instead, calculate
    X=(3600/M)*65536 and store that in the eeprom. Then the running
    calculation to update your display will be much faster.
    MPH=N**X

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-28 21:10
    >Tracy, It sounds like it will work but M can = 8000 and if you do it on a
    >calculator ( 3600 / 8000 ) = 0.45 (witch the stamp can not do) then *65535
    > I know what you mean "65536" ) = 29490.75. If you do it like the stamp
    >3600/8000 = 1 then *65535 = 65535. I understand where you are going, You are
    >trying to make my stamp faster, That is an idea that I never thought of.
    >maybe this will help.

    The question is, I think, how do you come up with the factor 29491
    that you can store in eeprom to make your subsequent calcs faster?

    x var word
    y var word
    z var word
    i var nib

    x=3600 ' X>Y
    y=8000 ' y comes from your calibration measurement
    z=0
    for i=15 to 0
    X=X//Y<<1 ' remainder*2
    Z.bit0(I)=X/Y ' next bit
    next
    write cal0,z.byte0 ' store in eeprom
    write cal1,z.byte1

    The result is the number in eeprom, 29491. Simple, huh? The simple
    binary division loop is calculating 3600/8000*65536 = 0.45*65536 =
    29491. Then the run-time calculation is simply:
    read cal0,z.byte0
    read cal1,z.byte1
    MPH = X ** z

    which using ** is effectively calculating MPH=X*29491/65536.
    29491/65536 is a close approximation to 3600/8000.

    This is typical of calibration problems. If the run-time calculation
    involves multiplying a variable times a fractional constant, then the
    calibration step will involve calculating a constant divided by a
    variable. The long division routine is perfect for this.

    >
    >Thank You for your input. Keep them coming I am enjoying the fact that the
    >GURUS of programming and math are helping a newbe learn how to program. "
    >Thank You"
    >
    >TC
    >

    You're welcome! Funny as it may seem, I actually enjoy these integer
    math problems!

    -- Tracy


    >
    Original Message
    >From: Tracy Allen <tracy@e...>
    >Sent: Friday, May 25, 2001 12:32 AM
    >Subject: Re: math help
    > > >>> MPH=N*3600/M
    > > > > If M is a constant (is it?), you can simplify the formula greatly and
    > > > > still have great accuracy.
    > > >
    > > >It is, some what. M = Pulses per mile that comes from the transmission.
    >If I
    > > >change tires ( either bigger or smaller ) or if I change the rear end
    >gear
    > > >ratio my Pulses per mile will change. So I made my program to learn what
    >the
    > > >pulses per mile are, and store it to the EEPROM, then read the EEPROM and
    > > >put it in a variable ( I wish I could Make it a constant )
    > >
    > > Well, when you have your program learn the new pulses per mile, don't
    > > store that directly in the eeprom. Instead, calculate
    > > X=(3600/M)*65536 and store that in the eeprom. Then the running
    > > calculation to update your display will be much faster.
    > > MPH=N**X
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-16 03:05
    I need help on trying to find out how to do this math formula using the BS2p.

    R = ( ( 1 / ( units * .00000075 ) ) / 4 ) * 60

    using PULSIN
    ' PULSIN pin, 1, units

    I am looking for no more then %1 of error but I am looking for less. also the
    end output could be in multiplies of 10. EI 10,20,30,100,110,120 ect.

    please help
    thanks
    aj

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-16 04:15
    Hi AJ,

    I'm sure Tracy will have some magic way to do this. However, one thing
    to look at is using a PAK I, II, or IX coprocessor to do the math. This
    gives you 32-bit floating point math and it quite easy to use from the
    Stamp. See http://www.al-williams.com/pak1.htm

    Good luck!

    Al Williams
    AWC
    * 8 channels of PWM
    http://www.al-williams.com/awce/pak5.htm



    >
    Original Message
    > From: Anthony Conti [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Nss_VvKkowpriDLoiplQ6yif5L4qqpwyx4WAN4uGs8dshno80ozgSxebLA3Pi52p4as8rOdAZxbOJA]aconti@s...[/url
    > Sent: Sunday, June 15, 2003 9:06 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] math help
    >
    >
    > I need help on trying to find out how to do this math formula
    > using the BS2p.
    >
    > R = ( ( 1 / ( units * .00000075 ) ) / 4 ) * 60
    >
    > using PULSIN
    > ' PULSIN pin, 1, units
    >
    > I am looking for no more then %1 of error but I am looking
    > for less. also the end output could be in multiplies of 10.
    > EI 10,20,30,100,110,120 ect.
    >
    > please help
    > thanks
    > aj
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-16 05:11
    I might just do that. There are other problems that I will be using.

    thanks
    aj



    --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...> wrote:
    > Hi AJ,
    >
    > I'm sure Tracy will have some magic way to do this. However, one
    thing
    > to look at is using a PAK I, II, or IX coprocessor to do the math.
    This
    > gives you 32-bit floating point math and it quite easy to use from
    the
    > Stamp. See http://www.al-williams.com/pak1.htm
    >
    > Good luck!
    >
    > Al Williams
    > AWC
    > * 8 channels of PWM
    > http://www.al-williams.com/awce/pak5.htm
    >
    >
    >
    > >
    Original Message
    > > From: Anthony Conti [noparse][[/noparse]mailto:aconti@s...]
    > > Sent: Sunday, June 15, 2003 9:06 PM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] math help
    > >
    > >
    > > I need help on trying to find out how to do this math formula
    > > using the BS2p.
    > >
    > > R = ( ( 1 / ( units * .00000075 ) ) / 4 ) * 60
    > >
    > > using PULSIN
    > > ' PULSIN pin, 1, units
    > >
    > > I am looking for no more then %1 of error but I am looking
    > > for less. also the end output could be in multiplies of 10.
    > > EI 10,20,30,100,110,120 ect.
    > >
    > > please help
    > > thanks
    > > aj
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    > > Subject and Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    > >
    > >
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-17 19:30
    What is the expected range of your "units"?

    Simplifying, I come up with:

    R = 20000000/units

    So one way that gives three significant figures would be

    R = (20000/units * 10) + (20000//units *10 /units)

    For example, suppose units=255. Then the correct answer to 5 digits
    is 78431. The Stamp formula gives 784, which you would print out
    with two more zeros. The best accuracy will come with pulsin
    readings around 250.

    There are more accurate ways to do the reciprocal.
    http://www.emesystems.com/BS2math2.htm#Reciprocal
    or even at full precision:
    http://www.emesystems.com/BS2math6.htm


    -- Tracy




    >I need help on trying to find out how to do this math formula using the BS2p.
    >
    >R = ( ( 1 / ( units * .00000075 ) ) / 4 ) * 60
    >
    >using PULSIN
    >' PULSIN pin, 1, units
    >
    >I am looking for no more then %1 of error but I am looking for less.
    >also the end output could be in multiplies of 10. EI
    >10,20,30,100,110,120 ect.
    >
    >please help
    >thanks
    >aj
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-17 21:55
    Tracy

    the expected range will be from 2000 to 65535.
    where 2000 = units, & R = 10,000. 65535 = units, & R = 300 ( 305.1 )

    also the con "4" could change to "3" at a later date

    thanks
    AJ


    > What is the expected range of your "units"?
    >
    > Simplifying, I come up with:
    >
    > R = 20000000/units
    >
    > So one way that gives three significant figures would be
    >
    > R = (20000/units * 10) + (20000//units *10 /units)
    >
    > For example, suppose units=255. Then the correct answer to 5
    digits
    > is 78431. The Stamp formula gives 784, which you would print out
    > with two more zeros. The best accuracy will come with pulsin
    > readings around 250.
    >
    > There are more accurate ways to do the reciprocal.
    > http://www.emesystems.com/BS2math2.htm#Reciprocal
    > or even at full precision:
    > http://www.emesystems.com/BS2math6.htm
    >
    >
    > -- Tracy
    >
    >
    >
    >
    > >I need help on trying to find out how to do this math formula
    using the BS2p.
    > >
    > >R = ( ( 1 / ( units * .00000075 ) ) / 4 ) * 60
    > >
    > >using PULSIN
    > >' PULSIN pin, 1, units
    > >
    > >I am looking for no more then %1 of error but I am looking for
    less.
    > >also the end output could be in multiplies of 10. EI
    > >10,20,30,100,110,120 ect.
    > >
    > >please help
    > >thanks
    > >aj
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-17 22:42
    That range you have, 2000 to 65535, allows this other approximation.

    X var word ' 256<=X<=65535 <-- your units in this range
    Y var word ' 256<=Y<=65535 output <-- the result
    J var nib ' helper variable

    X=5555 ' for example

    reciprocal:
    J=ncd X - 8
    Y=65535/X*256+(65535//X<<(8-J)/(X>>J))
    Y=Y**12589+Y ' renormalize to 20000000/X
    debug cr,dec X,tab, dec Y
    ' with X=5555, Y=3600 (correct value is 3600.36)
    ' with X=55555, Y=358 (correct value is 360.0036)

    Your output range will be 305 to 10000. The formula works by finding
    2^24/X, then renormalizing (Y=Y**12586+Y) to a numerator of 20000000.
    More explanation here:
    <http://www.emesystems.com/BS2math2.htm#Reciprocal>. If "4" becomes
    3, it will only affect the renormalization. (Y=Y**38630+Y).

    Is that enough accuracy? It will be well within 1%.

    -- regards,
    Tracy





    >Tracy
    >
    >the expected range will be from 2000 to 65535.
    >where 2000 = units, & R = 10,000. 65535 = units, & R = 300 ( 305.1 )
    >
    >also the con "4" could change to "3" at a later date
    >
    >thanks
    >AJ
    >
    >
    >> What is the expected range of your "units"?
    >>
    >> Simplifying, I come up with:
    >>
    >> R = 20000000/units
    >>
    >> So one way that gives three significant figures would be
    >>
    >> R = (20000/units * 10) + (20000//units *10 /units)
    >>
    >> For example, suppose units=255. Then the correct answer to 5
    >digits
    >> is 78431. The Stamp formula gives 784, which you would print out
    >> with two more zeros. The best accuracy will come with pulsin
    >> readings around 250.
    >>
    >> There are more accurate ways to do the reciprocal.
    >> http://www.emesystems.com/BS2math2.htm#Reciprocal
    >> or even at full precision:
    >> http://www.emesystems.com/BS2math6.htm
    >>
    >>
    >> -- Tracy
    >>
    >>
    >>
    >>
    >> >I need help on trying to find out how to do this math formula
    >using the BS2p.
    >> >
    >> >R = ( ( 1 / ( units * .00000075 ) ) / 4 ) * 60
    >> >
    >> >using PULSIN
    >> >' PULSIN pin, 1, units
    >> >
    >> >I am looking for no more then %1 of error but I am looking for
    >less.
    >> >also the end output could be in multiplies of 10. EI
    >> >10,20,30,100,110,120 ect.
    >> >
    >> >please help
    >> >thanks
    >> >aj
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the
    >Subject and Body of the message will be ignored.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.