Shop OBEX P1 Docs P2 Docs Learn Events
number more than 65535 again — Parallax Forums

number more than 65535 again

ArchiverArchiver Posts: 46,084
edited 2002-03-02 16:00 in General Discussion
Hello,
Before I have got from Tracy Allen the tricks to count up to a number more
than 65535 and using MAX7219 to display it.This time I think I have
something different,in my project"Digital Weigh Scale Indicator"I have the
following equation to convert the o/p code from 16 bit A/D to grams weight
using MAX7219 with 5 digits display:
weight=ADdata** 34464 + ADdata
where ADdata is the code in 16-bit word length.

From the equation the max. reading is 65535 grams weight ,so how can I get
readings up to 99999 grams weight?

Thank You
Mohamed Refky



_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-02-27 07:09
    Hi Mohamed.

    So, the scale has a capacity of 100000 weight units, and at full
    capacity it rolls out an ADC count of 65536. So the conversion from
    count to weight is
    weight = ADdata * (100000/65536) = ADdata * 1.525879
    which in Stampese as you say is coded as:
    weight=ADdata ** 34464 + ADdata

    The critical ADC value is ADdata>42949. Like this:
    42949**34464+42949 = 65534
    which is okay and fits in one word, but
    42950**34464+42950 = 65536
    overflows a word and shows up as 0 on the Stamp. It is the correct
    value minus 65536. The solution is to keep track of the carry, when
    the ADdata>42949. Only one bit of carry is necessary, because the
    weight is <100000. Your program will have to use a a double
    precision divide by ten to get the number back to the 16-bit range.
    Here is example code:

    ' enter here with ADread, from 0 to 65535
    rm var nib ' remainder for divide by 10
    carry var bit ' carry bit
    ' now compute carry and weight modulo 65536
    carry=ADdata min 42949-42949 max 1 ' 1 if ADdata>42949
    weight=ADdata ** 34464 + ADdata ' modulo 65536
    ' now divide double precision value /10
    rm = ADdata//10 +6 ' preliminary remainder
    ADdata=6553+(ADdata/10)+(rm/10) ' double precision divide
    rm=rm//10 ' final remainder
    debug "weight=",dec4 ADdata, dec1 rm,cr

    I hope that helps.

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com



    >Hello,
    >Before I have got from Tracy Allen the tricks to count up to a number more
    >than 65535 and using MAX7219 to display it.This time I think I have
    >something different,in my project"Digital Weigh Scale Indicator"I have the
    >following equation to convert the o/p code from 16 bit A/D to grams weight
    >using MAX7219 with 5 digits display:
    > weight=ADdata** 34464 + ADdata
    >where ADdata is the code in 16-bit word length.
    >
    > >From the equation the max. reading is 65535 grams weight ,so how can I get
    >readings up to 99999 grams weight?
    >
    >Thank You
    >Mohamed Refky
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-27 08:31
    Oops, I forgot to roll the carry into the formula for the double
    precision divide in my last post. More background info at
    <http://www.emesystems.com/BS2math6.htm#method1>

    > ' enter here with ADread, from 0 to 65535
    > rm var nib ' remainder for divide by 10
    > carry var bit ' carry bit
    > ' now compute carry and weight modulo 65536
    > carry=ADdata min 42949-42949 max 1 ' 1 if ADdata>42949
    > weight=ADdata ** 34464 + ADdata ' modulo 65536
    > ' now divide double precision value /10
    > rm = ADdata//10 +(6*carry) ' preliminary remainder
    > ADdata=(6553*carry)+(ADdata/10)+(rm/10) ' double precision divide
    > rm=rm//10 ' final remainder
    > debug "weight=",dec4 ADdata, dec1 rm,cr

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-28 18:07
    May I get example with a number to explain the code.
    I use MAX7219,so how can I display the result.

    Thank You
    Mohamed Refky


    >From: Tracy Allen <tracy@e...>
    >Reply-To: basicstamps@yahoogroups.com
    >To: basicstamps@yahoogroups.com
    >Subject: Re: [noparse][[/noparse]basicstamps] number more than 65535 again
    >Date: Wed, 27 Feb 2002 00:31:58 -0800
    >
    >Oops, I forgot to roll the carry into the formula for the double
    >precision divide in my last post. More background info at
    ><http://www.emesystems.com/BS2math6.htm#method1>
    >
    > > ' enter here with ADread, from 0 to 65535
    > > rm var nib ' remainder for divide by 10
    > > carry var bit ' carry bit
    > > ' now compute carry and weight modulo 65536
    > > carry=ADdata min 42949-42949 max 1 ' 1 if ADdata>42949
    > > weight=ADdata ** 34464 + ADdata ' modulo 65536
    > > ' now divide double precision value /10
    > > rm = ADdata//10 +(6*carry) ' preliminary remainder
    > > ADdata=(6553*carry)+(ADdata/10)+(rm/10) ' double precision divide
    > > rm=rm//10 ' final remainder
    > > debug "weight=",dec4 ADdata, dec1 rm,cr
    >
    > -- Tracy
    >
    >
    >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/
    >
    >




    _________________________________________________________________
    Send and receive Hotmail on your mobile device: http://mobile.msn.com
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-28 23:53
    >May I get example with a number to explain the code.
    >I use MAX7219,so how can I display the result.
    >
    >Thank You
    >Mohamed Refky

    Maybe you give me the example number, then I will try to explain. I
    do not want to have to look up the protocol for the MAX7219!

    -- best regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-01 18:31
    A code for example of 49152 from the A/D is corresponding to 75000 grams
    weight.
    In calculator:
    weight=ADdata**34464+ADdata
    =(49152*34464)/65536+49152=75000
    then the program display the result:
    weight=dispVal
    gosub MaxDisplay


    >From: Tracy Allen <tracy@e...>
    >Reply-To: basicstamps@yahoogroups.com
    >To: basicstamps@yahoogroups.com
    >Subject: Re: [noparse][[/noparse]basicstamps] number more than 65535 again
    >Date: Thu, 28 Feb 2002 15:53:09 -0800
    >
    > >May I get example with a number to explain the code.
    > >I use MAX7219,so how can I display the result.
    > >
    > >Thank You
    > >Mohamed Refky
    >
    >Maybe you give me the example number, then I will try to explain. I
    >do not want to have to look up the protocol for the MAX7219!
    >
    > -- best regards
    > Tracy Allen
    > electronically monitored ecosystems
    > http://www.emesystems.com
    > mailto:tracy@e...
    >
    >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/
    >
    >




    _________________________________________________________________
    Join the world’s largest e-mail service with MSN Hotmail.
    http://www.hotmail.com
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-02 16:00
    > > >May I get example with a number to explain the code.
    > > >I use MAX7219,so how can I display the result.


    >A code for example of 49152 from the A/D is corresponding to 75000 grams
    >weight.
    >In calculator:
    >weight=ADdata**34464+ADdata
    > =(49152*34464)/65536+49152=75000
    >then the program display the result:
    >weight=dispVal
    >gosub MaxDisplay

    Hi Mohamed,

    The total weight, maximum 999999, cannot be held in one Stamp 16 bit
    word. So your MaxDisplay routine will have to deal with at least one
    more bit of data. In the following, as it ends up, one word holds
    four digits from 0 to 9999, and an additional nib holds the last
    digit, 0 to 9.


    rm var nib ' remainder for divide by 10
    carry var bit ' carry bit
    ADdata var word ' from weight scale
    j var nib ' for loop

    gosub getADdata ' not shown
    ' returns ADdata, in general from 0 to 65535
    ' say ADdata=49152, weight =49152*1.5258789062=75000grams

    ' now compute carry and weight modulo 65536
    ' notes follow program listing
    carry=ADdata min 42949-42949 max 1 ' Note A
    weight=ADdata ** 34464 + ADdata ' Note B

    ' now divide double precision, weight /10
    rm = weight//10 +(6*carry) ' Note C
    weight=(6553*carry)+(weight/10)+(rm/10) ' Note D
    rm=rm//10 ' Note E

    ' show the result on debug
    debug "weight=",dec weight, dec1 rm,cr ' Note F

    ' show result on MAX7219 (untested)
    low load
    shiftout dpin,cpin,msbfirst,[noparse][[/noparse]9,$ff] ' Note G
    high load
    for j=3 to 0 ' Note H
    low load
    shiftout dpin,cpin, msbfirst,[noparse][[/noparse]j+2,weight dig j)]
    high load
    next
    low load
    shiftout dpin,cpin, msbfirst,[noparse][[/noparse]1,rm] ' Note I
    high load
    end
    ' Notes <mailto:tracy@o...>
    ' Note A: compute carry
    ' 49152 min 42949 = 49152
    ' 49152 -42949 = 6203
    ' 6203 max 1 = 1 = carry bit
    ' Note B: compute weight modulo 65536
    ' 49152 ** 34464 = 25848 (49152*0.5258789)
    ' 25848 + 49152 = 9464 Stamp loses high bit to fit word!!
    ' note that (75000=65536+9464)
    ' The total weight is now expressed in base 2^16
    ' as 1*65536 + 9464, the "1" is the carry bit
    ' Note C: preliminary remainder
    ' 9464//10 = 4
    ' 4 + (6*1) = 10
    ' Note D: double precision divide
    ' (6553*1)+(9464/10)+(rm/10) = (6553)+(946)+(1)=7500
    ' 4 most significant digits of weight fit in one word
    ' Note E: final remainder
    ' 10//10 = 0
    ' this is the least significant digit of the weight
    ' Note F: show result
    ' Stamp holds "7500" in weight, and "0" in rm.
    ' prints in two chunks
    ' Note G:
    ' SPI command 9 to select the BCD mode of the MAX7219 on all
    ($ff) digits
    ' framed with load pin low, command executed when load goes high
    ' CAVEAT--I have not tested these MAX7219 routines.
    ' Note H:
    ' SPI loop to send 4 most significant digits to MAX7219
    ' sends most significant digit first to positions j+2={5,4,3,and 2}
    ' operator weight dig j picks off the digits one by one
    ' framed with load pin low, command executed when load goes high
    ' Note I:
    ' SPI command sends least significant digit rm to MAX7219
    ' puts it in digit 1 position on the display
    ' framed with load pin low, command executed when load goes high

    That was fun! I hope I didn't slip too many typos in there.

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com
Sign In or Register to comment.