Shop OBEX P1 Docs P2 Docs Learn Events
Math Question — Parallax Forums

Math Question

ArchiverArchiver Posts: 46,084
edited 2003-05-14 22:09 in General Discussion
Jeff-

Something like this ought to work:


hex_out DATA $00,$20,$7D,$FE

READ hex_out + (time_var + 1 / 400), speed


where time_var holds the result of the RCTIME operation.


Steve

On 8 Feb 01 at 22:06, Jeff Mitchell wrote:

> I would like to convert a variable that ranges between 400 and 1800
> dec. into 4 proportional hex numbers. (0,20,7D,FE)
> I.E. if rctime returns a variable of >400 and <800 then output hex0
> if >800
> and <1200 then hex20 etc..

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-02-08 22:21
    On 9 Feb 01 at 1:30, Jeff Mitchell wrote:

    > ...
    > hex_out Data $00, $20,$7d,$fe
    > read hex_out + (500 +1/400), speed 'the result with a
    > variable
    > of 500 will be 1.25. will the .25 be ignored?

    Correct. All division on the Stamp yields integer results.

    > Why do you have the equation written as (time_var +1 / 400) instead
    > of
    > (time_var / 400) ?

    It was meant to fit your "if rctime returns a variable of >400 and
    <800 then output hex0 if >800 and <1200 then hex20 etc.." criteria.
    It yields $00 for 0 <= time_var < 399, $20 for 399 <= time_var <
    799 and so on. Looking at it again, it could stand some
    improvement. If the difference between (for example) 398 and 399 has
    little significance in your application, I'd go with the simpler
    (time_var / 400), or modify the expression to slide the break-off
    points one way or the other (careful not to generate some negative
    intermediate or final results).

    Steve
  • ArchiverArchiver Posts: 46,084
    edited 2001-02-09 02:06
    I would like to convert a variable that ranges between 400 and 1800 dec.
    into 4 proportional hex numbers. (0,20,7D,FE)
    I.E. if rctime returns a variable of >400 and <800 then output hex0 if >800
    and <1200 then hex20 etc..

    Right now I have a bunch of if then statements that say if variable is
    between 400 and 800 then speed1. 800 to 1200 goto speed2 etc. There must be
    a simpler way to modify the variable. I would like to save code and just say
    If variable is greater than 0 goto speed: and let speed use the variable to
    figure out what hex number to send.

    Any suggestions?

    Jeff.
  • ArchiverArchiver Posts: 46,084
    edited 2001-02-09 05:30
    >Jeff-

    >Something like this ought to work:
    >hex_out DATA $00,$20,$7D,$FE
    >READ hex_out + (time_var + 1 / 400), speed
    >where time_var holds the result of the RCTIME operation.
    >Steve

    Thanks Steve!

    So if my time_var is say 500, the read command will only go to the "1"
    location and disregard everything after
    the decimal ?

    hex_out Data $00, $20,$7d,$fe
    read hex_out + (500 +1/400), speed 'the result with a variable
    of 500 will be 1.25. will the .25 be ignored?

    Why do you have the equation written as (time_var +1 / 400) instead of
    (time_var / 400) ?
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-13 20:50
    Hello,
    I'm going to use my digital weigh scale indicator to monitor the weight of
    packages.The weight of package is 5 digits for example,"08275" displayed as
    08.275 Kg with decimal point.There are several thousand of packages and I
    want to get their sum of weight in ton at the end of the day,for
    example,"52742" which will be displayed as 52.742 Ton.
    How can I compute this with the stamp closer to correct result?

    Thank You
    Mohamed Refky

    _________________________________________________________________
    The new MSN 8: smart spam protection and 2 months FREE*
    http://join.msn.com/?page=features/junkmail
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-14 04:14
    --- In basicstamps@yahoogroups.com, "Mohamed REFKY" <refky@h...>
    wrote:
    > Hello,
    > I'm going to use my digital weigh scale indicator to monitor the
    weight of
    > packages.The weight of package is 5 digits for example,"08275"
    displayed as
    > 08.275 Kg with decimal point.There are several thousand of packages
    and I
    > want to get their sum of weight in ton at the end of the day,for
    > example,"52742" which will be displayed as 52.742 Ton.
    > How can I compute this with the stamp closer to correct result?
    >
    > Thank You
    > Mohamed Refky
    >
    > _________________________________________________________________
    > The new MSN 8: smart spam protection and 2 months FREE*
    > http://join.msn.com/?page=features/junkmail

    Hi Mohamed,

    not to answer your question, but how did you plan on making sure no
    one weighed the same package twice ?

    seems a bar-code scan would be very advnatagous.

    won't the basic running
    weight=running weight+package
    keep a running track ?
    if running weight is greater than 2,000 (I'm thinking pounds here)
    tons is greater than 2,000 then tons=tons+1 and
    running weight=running weight - 2000 you just subtract 2000 pounds
    (1,000 kilos?) from the running weight as you add a one to the tons.

    that way you keep track of tons and the remaining weight is held
    at the end of the day, all you need do is to either display the
    remaining kilos or convert the remaining weight to fractions of a ton.

    or, you could show tons as one value and the remainder in kilos. so
    your output could be 52 tons, 742 kilos
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-14 12:04
    Mohamed,

    > I'm going to use my digital weigh scale indicator to monitor the weight of
    > packages.

    Do you have a digital weigh scale module connected up to your BS2?
    Do you know what model etc it is?

    Of all the modules i've seen, I not spotted a weight module...


    Cheers

    Kev/.
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-14 12:50
    just divide by 1000

    jim
    http://www.geocities.com/jimforkin2003/

    Original Message
    From: Mohamed REFKY [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=JZ9VtVPqCTfoMyHCnTF-Zms5-zESAX1Zlx5KZ8S-UVJHDllQyjULzYiDP10-qBkYXcEAa70Rzw]refky@h...[/url
    Sent: Tuesday, May 13, 2003 3:51 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Math question


    Hello,
    I'm going to use my digital weigh scale indicator to monitor the weight of
    packages.The weight of package is 5 digits for example,"08275" displayed as
    08.275 Kg with decimal point.There are several thousand of packages and I
    want to get their sum of weight in ton at the end of the day,for
    example,"52742" which will be displayed as 52.742 Ton.
    How can I compute this with the stamp closer to correct result?

    Thank You
    Mohamed Refky

    _________________________________________________________________
    The new MSN 8: smart spam protection and 2 months FREE*
    http://join.msn.com/?page=features/junkmail


    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-05-14 16:06
    >Hello,
    >I'm going to use my digital weigh scale indicator to monitor the weight of
    >packages.The weight of package is 5 digits for example,"08275" displayed as
    >08.275 Kg with decimal point.There are several thousand of packages and I
    >want to get their sum of weight in ton at the end of the day,for
    >example,"52742" which will be displayed as 52.742 Ton.
    >How can I compute this with the stamp closer to correct result?
    >
    >Thank You
    >Mohamed Refky

    Are you using the Pelouze scale that is available from McMaster Carr?

    8.275 is stored in the stamp as 8275, then several thousand packages
    could add up to 8275000 or more, too much for 16 bits. One metric
    ton is 1000 kilos, which would be 1000000 in this scheme, also larger
    than 16 bits. The total weight might be something like 8.275111
    metric tons, if you carry it out to full precision.


    One approach would be to carry to a second word when the total weight
    exceeds 10 kilos (10000 in the Stamp):

    allWeight0=allweight0+thisWeight
    allWeight1=allWeight0/10000 + allWeight1 ' carry to high word
    allWeight0=allWeight0//10000 ' low word stays < 10000
    debug dec dec allWeight1/100,".",dec2 allWeight1,dec4 allWeight0
    ' displays running total
    ' 3 places left of the decimal, 6 to right of decimal.

    That could record up to 655.350000 metric tons, 655350.000 kilos.


    Another approach would be to use double precision binary. The carry
    occurs not at 10000 but at 65536:

    thisWeight var word ' one package
    allWeight0 var word ' low word of running total
    allWeight1 var word ' high word of running total
    ' ...
    addWeights: ' Z=X+Y in 16:16 notation
    allWeight0 = allweight0 + thisWeight
    if allWeight0<thisWeight then allWeight1=allWeight1+1 ' carry (pbasic 2.5)

    Then at the end of the day, you have to kick out that double
    precision bianry number as decimal digits to your display. A
    subroutine to do that is described on my web site at:

    http://www.emesystems.com/BS2math6.htm#showdubdec

    The routine would have to insert the decimal point 6 positions from
    the right to get the answer in metric tons.
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-14 22:09
    No,I'm not using the Pelouze scale,I have built a load cell based digital
    weigh scale indicator with 2 setpoints using the Basic Stamp.I use the
    MAX7219 to drive 5 digits led display.

    I have a project using this indicator (Liquid Filler) posted in the customer
    applications section on Parallax web site.

    Thank You
    Mohamed Refky


    >From: Tracy Allen <tracy@e...>
    >Reply-To: basicstamps@yahoogroups.com
    >To: basicstamps@yahoogroups.com
    >Subject: Re: [noparse][[/noparse]basicstamps] Math question
    >Date: Wed, 14 May 2003 08:06:00 -0700
    >
    > >Hello,
    > >I'm going to use my digital weigh scale indicator to monitor the weight
    >of
    > >packages.The weight of package is 5 digits for example,"08275" displayed
    >as
    > >08.275 Kg with decimal point.There are several thousand of packages and I
    > >want to get their sum of weight in ton at the end of the day,for
    > >example,"52742" which will be displayed as 52.742 Ton.
    > >How can I compute this with the stamp closer to correct result?
    > >
    > >Thank You
    > >Mohamed Refky
    >
    >Are you using the Pelouze scale that is available from McMaster Carr?
    >
    >8.275 is stored in the stamp as 8275, then several thousand packages
    >could add up to 8275000 or more, too much for 16 bits. One metric
    >ton is 1000 kilos, which would be 1000000 in this scheme, also larger
    >than 16 bits. The total weight might be something like 8.275111
    >metric tons, if you carry it out to full precision.
    >
    >
    >One approach would be to carry to a second word when the total weight
    >exceeds 10 kilos (10000 in the Stamp):
    >
    > allWeight0=allweight0+thisWeight
    > allWeight1=allWeight0/10000 + allWeight1 ' carry to high word
    > allWeight0=allWeight0//10000 ' low word stays < 10000
    > debug dec dec allWeight1/100,".",dec2 allWeight1,dec4 allWeight0
    > ' displays running total
    > ' 3 places left of the decimal, 6 to right of decimal.
    >
    >That could record up to 655.350000 metric tons, 655350.000 kilos.
    >
    >
    >Another approach would be to use double precision binary. The carry
    >occurs not at 10000 but at 65536:
    >
    > thisWeight var word ' one package
    > allWeight0 var word ' low word of running total
    > allWeight1 var word ' high word of running total
    > ' ...
    > addWeights: ' Z=X+Y in 16:16 notation
    > allWeight0 = allweight0 + thisWeight
    > if allWeight0<thisWeight then allWeight1=allWeight1+1 ' carry (pbasic
    >2.5)
    >
    >Then at the end of the day, you have to kick out that double
    >precision bianry number as decimal digits to your display. A
    >subroutine to do that is described on my web site at:
    >
    > http://www.emesystems.com/BS2math6.htm#showdubdec
    >
    >The routine would have to insert the decimal point 6 positions from
    >the right to get the answer in metric tons.
    >
    >
    >
    >
    >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/
    >
    >

    _________________________________________________________________
    Add photos to your messages with MSN 8. Get 2 months FREE*.
    http://join.msn.com/?page=features/featuredemail
Sign In or Register to comment.