Shop OBEX P1 Docs P2 Docs Learn Events
Counting using large Numbers — Parallax Forums

Counting using large Numbers

ArchiverArchiver Posts: 46,084
edited 2001-06-20 02:35 in General Discussion
I need to store and be able to recall a number
from BS2 eeprom memory. The number will exceed
the word level. Can someone give me an idea about
working with large numbers and how to read and
write them to eeprom? Should I do it, a single
digit at a time. Any Help Please???

TIA
Gill
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-06-17 04:46
    What do you need to do with the number? If you are
    going to display it, a BCD-type concept may work well.
    In BCD, binary-code decimal, each base-ten digit is
    stored in four bits - same as with hexadecimal. It is
    a pain when doing calculations, but may be useful to
    store and display long decimal numbers. Please give
    more detail on context.

    Bob Pence

    --- GL Controls <glcontrols@h...> wrote:
    > I need to store and be able to recall a number
    > from BS2 eeprom memory. The number will exceed
    > the word level. Can someone give me an idea about
    > working with large numbers and how to read and
    > write them to eeprom? Should I do it, a single
    > digit at a time. Any Help Please???
    >
    > TIA
    > Gill
    >
    _________________________________________________________________
    > Get your FREE download of MSN Explorer at
    > http://explorer.msn.com
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed
    > with. 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/
    >
    >


    __________________________________________________
    Do You Yahoo!?
    Spot the hottest trends in music, movies, and more.
    http://buzz.yahoo.com/
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-17 05:04
    The stamp needs to count Cycles on a machine,
    Store and act upon a Batch count and keep a
    total cycle count. I need to be able to display
    the batch count and total count on an LCD
    along with storing both in EEprom.
    The batch count can be kept to less than 65000
    The total will be quite large. Cycle count for
    one day could be as much as 57600 (2 Cycles a second)
    I was thinking I could store each digit as a seperate
    nibble in eeprom. I also could display it using the
    same method. I am not sure of the best way to do it.

    Thanks
    Gill





    >What do you need to do with the number? If you are
    >going to display it, a BCD-type concept may work well.
    >In BCD, binary-code decimal, each base-ten digit is
    >stored in four bits - same as with hexadecimal. It is
    >a pain when doing calculations, but may be useful to
    >store and display long decimal numbers. Please give
    >more detail on context.
    >
    >Bob Pence
    >
    >--- GL Controls <glcontrols@h...> wrote:
    > > I need to store and be able to recall a number
    > > from BS2 eeprom memory. The number will exceed
    > > the word level. Can someone give me an idea about
    > > working with large numbers and how to read and
    > > write them to eeprom? Should I do it, a single
    > > digit at a time. Any Help Please???
    > >

    _________________________________________________________________
    Get your FREE download of MSN Explorer at http://explorer.msn.com
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-17 05:40
    At 6/17/2001 Sunday 12:04 AM, GL Controls promulgated:
    >The stamp needs to count Cycles on a machine,
    >Store and act upon a Batch count and keep a
    >total cycle count. I need to be able to display
    >the batch count and total count on an LCD
    >along with storing both in EEprom.
    >The batch count can be kept to less than 65000
    >The total will be quite large. Cycle count for
    >one day could be as much as 57600 (2 Cycles a second)
    >I was thinking I could store each digit as a seperate
    >nibble in eeprom. I also could display it using the
    >same method. I am not sure of the best way to do it.
    >
    >Thanks
    >Gill
    >
    >Gill -

    You might consider a factor variable. When the batch counter nearly
    approaches overflow, add 1 to the batch counter, and subtract the value you
    chose to represent the limit value.

    Example in pseudo code -

    batch_limit = 32000 '(arbitrary limit in a word size variable)
    batch_count = 0
    factor = 0

    Process:
    ' Do whatever you need to here on input
    If process_ended then End_Process '(set by some external routine)
    batch_count = batch_count + 1
    If batch_count < batch_limit then Process:
    factor = factor + 1
    batch_count = batch_count - batch_limit
    Goto Process:

    End_Process:
    'batch_count now contains the remaining items
    'factor contains the multiples of batch_limit

    END

    That should give you a starting point for counting.

    Regards,

    Bruce Bates
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-18 01:25
    Yes, Binary-Coded Decimal (BCD) stores one digit in
    each nibble, just a decimal digit instead of a hex
    digit - e.g. 10011001 ('99') stored in an EEPROM byte
    would represent decimal ninety-nine, not 128 + 16 + 8
    + 1 = 16*9 + 1*9 = 153 decimal. So to store this
    value, you need to convert to decimal, e.g.:

    storbyte.HIGHNIB = x//100/10
    storbyte.LOWNIB = x//10
    WRITE eploc, storbyte
    ' 255 stored as 01010101 (DEC 55), need
    ' to account for numbers over DEC 100
    ' 00 to 99 stored correctly as is

    Bob Pence

    --- GL Controls <glcontrols@h...> wrote:
    > The stamp needs to count Cycles on a machine,
    > Store and act upon a Batch count and keep a
    > total cycle count. I need to be able to display
    > the batch count and total count on an LCD
    > along with storing both in EEprom.
    > The batch count can be kept to less than 65000
    > The total will be quite large. Cycle count for
    > one day could be as much as 57600 (2 Cycles a
    > second)
    > I was thinking I could store each digit as a
    > seperate
    > nibble in eeprom. I also could display it using the
    > same method. I am not sure of the best way to do
    > it.
    >
    > Thanks
    > Gill
    >
    >
    >
    >
    >
    > >What do you need to do with the number? If you are
    > >going to display it, a BCD-type concept may work
    > well.
    > >In BCD, binary-code decimal, each base-ten digit is
    > >stored in four bits - same as with hexadecimal. It
    > is
    > >a pain when doing calculations, but may be useful
    > to
    > >store and display long decimal numbers. Please give
    > >more detail on context.
    > >
    > >Bob Pence
    > >
    > >--- GL Controls <glcontrols@h...> wrote:
    > > > I need to store and be able to recall a number
    > > > from BS2 eeprom memory. The number will exceed
    > > > the word level. Can someone give me an idea
    > about
    > > > working with large numbers and how to read and
    > > > write them to eeprom? Should I do it, a single
    > > > digit at a time. Any Help Please???
    > > >
    >
    >
    _________________________________________________________________
    > Get your FREE download of MSN Explorer at
    > http://explorer.msn.com
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed
    > with. 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/
    >
    >


    =====
    Regards,

    Bob Pence

    NOTE: This mail is sent using my wireless phone. Calling me at 1 (610) 563-6198
    is preferred to a reply. If replying to this email address, please do not quote
    the original message.

    __________________________________________________
    Do You Yahoo!?
    Spot the hottest trends in music, movies, and more.
    http://buzz.yahoo.com/
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-19 00:49
    >The stamp needs to count Cycles on a machine,
    >Store and act upon a Batch count and keep a
    >total cycle count. I need to be able to display
    >the batch count and total count on an LCD
    >along with storing both in EEprom.
    >The batch count can be kept to less than 65000
    >The total will be quite large. Cycle count for
    >one day could be as much as 57600 (2 Cycles a second)
    >I was thinking I could store each digit as a seperate
    >nibble in eeprom. I also could display it using the
    >same method. I am not sure of the best way to do it.
    >
    >Thanks
    >Gill


    Hi Gill,

    One way is to store numbers up to 10000 in each word, so that two
    words will count up to 100,000,000. It is easy to keep track of the
    count and display it. At two counts per second, the eeprom would
    wear out very fast. Would it be feasible for the program to update
    the eeprom count only occasionally, like once every 100 counts, and
    at the end of each day? If you have some battery backed RAM, that
    would be better. Some real time clock chips have RAM locations
    available for you to store data of this sort (with no danger of
    wearing it out!).

    ' pin signal to count on P0, active high
    ' serial SEETRON led on P1
    ' values stored in eeprom at locations 0 to 3
    XC0 var word ' count, low word
    XC1 var word ' count, high word
    j var nib ' for lcd digit output

    restart:
    ' read in the old count values
    for j=0 to 3
    read j,XC0(j)
    next


    counter:
    if in0=0 then counter ' no count yet
    ' now count 1
    XC0=XC0+1 // 10000 ' increment low word modulo 10000
    XC1 = XC1+1-(XC0 max 1) ' high word +1 when XC0=0
    debug "count = ",dec4 XC1,dec4 XC0,CR
    if XC0//100 then lcdshow ' write to eeprom only at 100 counts
    eepromwrite:
    for j=0 to 3
    write j,XC0(j)
    next

    lcdshow:
    ' now display the digits on the lcd
    serout 1, $4054,[noparse][[/noparse]home] ' home the lcd
    for j=3 to 0 ' high word, most sig dig first
    serout 1,$4054,XC1 dig j
    next
    for j=3 to 0 ' low word
    serout 1,$4054,XC0 dig j
    next

    counterwait: ' counter signal debounce
    branch in0,[noparse][[/noparse]counter,counterwait]


    -- best regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-19 04:20
    I want to say Thank you to Bob, Tracy and Jon. You
    guys have helped me to understand what I needed to know
    to create and use this counter, Thanks again

    Gill
    _________________________________________________________________
    Get your FREE download of MSN Explorer at http://explorer.msn.com
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-19 04:57
    Didn't realize this morning I wasn't copying to the
    list. Here's what I sent Gill earlier.

    Byte or word x to BCD is as below - mod x by 10^(N+1)
    and divide by 10^N to get the 10^N's place, then store
    result (which will be 0..9) as nibble. Displaying as
    BCD just depends on continuing to deal with the
    nibble.

    READ eploc, storbyte ' say storbyte is 10011001 for 99
    DEBUG DEC storbyte ' no good, displays 153
    DEBUG DEC storbyte.HIGHNIB, storbyte.LOWNIB ' ok - 99

    However, for you application - as I'd recommend for
    any application of BCD, which is fraught with danger
    from my viewpoint - consider an alternate
    implementation. Keep a running total of up to 10000
    cycles, then update two EEPROM bytes to permanently
    tally, well, decakilocycles.

    cycles VAR WORD
    dkcycs VAR WORD
    ' code
    cycles = cycles + 1
    IF cycles > 9999 THEN TALLY
    RtnFrTly:
    ' more code
    .
    .
    TALLY:
    cycles = cycles - 10000
    READ 0, dkcycs.HIGHBYTE
    READ 1, dkcycs.LOWBYTE
    dkcycs = dkcycs + 1
    WRITE 0, dkcycs.HIGHBYTE
    WRITE 1, dkcycs.LOWBYTE
    GOTO RtnFrTly

    When its time to display, just

    DEBUG DEC dkcycs, DEC4 cycles ' DEC4 retain leading
    0's

    This method yields 655359999 cycles, which at 2
    seconds per cycles will allow the equipment to run for
    41.5 years continuously without rolling over the
    count. Also, the EEPROM locations are written to at
    most 65536 times, which is less than the 100,000
    writes guaranteed on most Stamps, without having to
    check for the low byte exceeding 255. Finally, no BCD
    interpretation is required, which is always a good
    thing. This could be done with a BCD implementation if
    more counts are required, in which case an EEPROM
    location would be needed as a pointer to the start of
    the value, and possibly one for length, because the
    data will have to move as writes exceed 100,000.

    Bob Pence

    > >--- GL Controls <glcontrols@h...> wrote:
    > > > Thanks, sounds like you are right on target.
    > > > One more thing, Can you tell me which part
    > > > is the conversion formula to BCD. I am sure
    > > > its in there but I am not sure which part it is?
    > > >
    > > > Thanks Again
    > > > Gill
    > > >
    > > >
    > > >
    >
    >*******************************************************
    > > >
    > > > Yes, Binary-Coded Decimal (BCD) stores one digit
    > in
    > > > each nibble, just a decimal digit instead of a
    > hex
    > > > digit - e.g. 10011001 ('99') stored in an EEPROM
    > > > byte
    > > > would represent decimal ninety-nine, not 128 +
    > 16 +
    > > > 8
    > > > + 1 = 16*9 + 1*9 = 153 decimal. So to store this
    > > > value, you need to convert to decimal, e.g.:
    > > >
    > > > storbyte.HIGHNIB = x//100/10
    > > > storbyte.LOWNIB = x//10
    > > > WRITE eploc, storbyte
    > > > ' 255 stored as 01010101 (DEC 55), need
    > > > ' to account for numbers over DEC 100
    > > > ' 00 to 99 stored correctly as is
    > > >
    > > > Bob Pence
    > > >
    > > >
    > > >
    >
    >_________________________________________________________________
    > > > Get your FREE download of MSN Explorer at
    > > > http://explorer.msn.com
    > > >
    > >
    > >
    > >__________________________________________________
    > >Do You Yahoo!?
    > >Spot the hottest trends in music, movies, and more.
    > >http://buzz.yahoo.com/
    >
    >
    _________________________________________________________________
    > Get your FREE download of MSN Explorer at
    > http://explorer.msn.com
    >


    =====
    Regards,

    Bob Pence

    NOTE: This mail is sent using my wireless phone. Calling me at 1 (610) 563-6198
    is preferred to a reply. If replying to this email address, please do not quote
    the original message.

    __________________________________________________
    Do You Yahoo!?
    Spot the hottest trends in music, movies, and more.
    http://buzz.yahoo.com/
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-19 13:43
    [noparse][[/noparse]snip]

    My replies keep getting lost this morning.

    Byte or word x to BCD is as below - mod x by 10^(N+1)
    and divide by 10^N to get the 10^N's place, then store
    result (which will be 0..9) as nibble. Displaying as
    BCD just depends on continuing to deal with the
    nibble.

    READ eploc, storbyte ' say storbyte is 10011001 for 99
    DEBUG DEC storbyte ' no good, displays 153
    DEBUG DEC storbyte.HIGHNIB, storbyte.LOWNIB ' ok - 99

    However, for you application - as I'd recommend for
    any application of BCD, which is fraught with danger
    from my viewpoint - consider an alternate
    implementation. Keep a running total of up to 10000
    cycles, then update two EEPROM bytes to permanently
    tally, well, decakilocycles.

    cycles VAR WORD
    dkcycs VAR WORD
    ' code
    cycles = cycles + 1
    IF cycles > 9999 THEN TALLY
    RtnFrTly:
    ' more code
    .
    .
    TALLY:
    cycles = cycles - 10000
    READ 0, dkcycs.HIGHBYTE
    READ 1, dkcycs.LOWBYTE
    dkcycs = dkcycs + 1
    WRITE 0, dkcycs.HIGHBYTE
    WRITE 1, dkcycs.LOWBYTE
    GOTO RtnFrTly

    When its time to display, just

    DEBUG DEC dkcycs, DEC4 cycles ' DEC4 retain leading
    0's

    This method yields 655359999 cycles, which at 2
    seconds per cycles will allow the equipment to run for
    41.5 years continuously without rolling over the
    count. Also, the EEPROM locations are written to at
    most 65536 times, which is less than the 100,000
    writes guaranteed on most Stamps, without having to
    check for the low byte exceeding 255. Finally, no BCD
    interpretation is required, which is always a good
    thing. This could be done with a BCD implementation if
    more counts are required, in which case an EEPROM
    location would be needed as a pointer to the start of
    the value, and possibly one for length, because the
    data will have to move as writes exceed 100,000.

    Bob Pence

    > >--- GL Controls <glcontrols@h...> wrote:
    > > > Thanks, sounds like you are right on target.
    > > > One more thing, Can you tell me which part
    > > > is the conversion formula to BCD. I am sure
    > > > its in there but I am not sure which part it is?
    > > >
    > > > Thanks Again
    > > > Gill
    > > >
    > > >
    > > >
    >
    >*******************************************************
    > > >
    > > > Yes, Binary-Coded Decimal (BCD) stores one digit
    > in
    > > > each nibble, just a decimal digit instead of a
    > hex
    > > > digit - e.g. 10011001 ('99') stored in an EEPROM
    > > > byte
    > > > would represent decimal ninety-nine, not 128 +
    > 16 +
    > > > 8
    > > > + 1 = 16*9 + 1*9 = 153 decimal. So to store this
    > > > value, you need to convert to decimal, e.g.:
    > > >
    > > > storbyte.HIGHNIB = x//100/10
    > > > storbyte.LOWNIB = x//10
    > > > WRITE eploc, storbyte
    > > > ' 255 stored as 01010101 (DEC 55), need
    > > > ' to account for numbers over DEC 100
    > > > ' 00 to 99 stored correctly as is
    > > >
    > > > Bob Pence
    > > >
    > > >
    > > >
    >
    >_________________________________________________________________
    > > > Get your FREE download of MSN Explorer at
    > > > http://explorer.msn.com
    > > >
    > >
    > >
    > >__________________________________________________
    > >Do You Yahoo!?
    > >Spot the hottest trends in music, movies, and more.
    > >http://buzz.yahoo.com/
    >
    >
    _________________________________________________________________
    > Get your FREE download of MSN Explorer at
    > http://explorer.msn.com
    >


    __________________________________________________
    Do You Yahoo!?
    Spot the hottest trends in music, movies, and more.
    http://buzz.yahoo.com/
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-19 19:18
    Excellent work Pence!
    May I have your permission to use this also?

    Ken

    with enough thrust, pigs fly just fine.





    ---- On Tue, 19 Jun 2001, Pence Bob (bobpence_2000@y...)
    wrote:

    > [noparse][[/noparse]snip]
    >
    > My replies keep getting lost this morning.
    >
    > Byte or word x to BCD is as below - mod x by 10^(N+1)
    > and divide by 10^N to get the 10^N's place, then store
    > result (which will be 0..9) as nibble. Displaying as
    > BCD just depends on continuing to deal with the
    > nibble.
    >
    > READ eploc, storbyte ' say storbyte is 10011001 for 99
    > DEBUG DEC storbyte ' no good, displays 153
    > DEBUG DEC storbyte.HIGHNIB, storbyte.LOWNIB ' ok - 99
    >
    > However, for you application - as I'd recommend for
    > any application of BCD, which is fraught with danger
    > from my viewpoint - consider an alternate
    > implementation. Keep a running total of up to 10000
    > cycles, then update two EEPROM bytes to permanently
    > tally, well, decakilocycles.
    >
    > cycles VAR WORD
    > dkcycs VAR WORD
    > ' code
    > cycles = cycles + 1
    > IF cycles > 9999 THEN TALLY
    > RtnFrTly:
    > ' more code
    > .
    > .
    > TALLY:
    > cycles = cycles - 10000
    > READ 0, dkcycs.HIGHBYTE
    > READ 1, dkcycs.LOWBYTE
    > dkcycs = dkcycs + 1
    > WRITE 0, dkcycs.HIGHBYTE
    > WRITE 1, dkcycs.LOWBYTE
    > GOTO RtnFrTly
    >
    > When its time to display, just
    >
    > DEBUG DEC dkcycs, DEC4 cycles ' DEC4 retain leading
    > 0's
    >
    > This method yields 655359999 cycles, which at 2
    > seconds per cycles will allow the equipment to run for
    > 41.5 years continuously without rolling over the
    > count. Also, the EEPROM locations are written to at
    > most 65536 times, which is less than the 100,000
    > writes guaranteed on most Stamps, without having to
    > check for the low byte exceeding 255. Finally, no BCD
    > interpretation is required, which is always a good
    > thing. This could be done with a BCD implementation if
    > more counts are required, in which case an EEPROM
    > location would be needed as a pointer to the start of
    > the value, and possibly one for length, because the
    > data will have to move as writes exceed 100,000.
    >
    > Bob Pence
    >
    > > >--- GL Controls <glcontrols@h...> wrote:
    > > > > Thanks, sounds like you are right on target.
    > > > > One more thing, Can you tell me which part
    > > > > is the conversion formula to BCD. I am sure
    > > > > its in there but I am not sure which part it is?
    > > > >
    > > > > Thanks Again
    > > > > Gill
    > > > >
    > > > >
    > > > >
    > >
    > >*******************************************************
    > > > >
    > > > > Yes, Binary-Coded Decimal (BCD) stores one digit
    > > in
    > > > > each nibble, just a decimal digit instead of a
    > > hex
    > > > > digit - e.g. 10011001 ('99') stored in an EEPROM
    > > > > byte
    > > > > would represent decimal ninety-nine, not 128 +
    > > 16 +
    > > > > 8
    > > > > + 1 = 16*9 + 1*9 = 153 decimal. So to store this
    > > > > value, you need to convert to decimal, e.g.:
    > > > >
    > > > > storbyte.HIGHNIB = x//100/10
    > > > > storbyte.LOWNIB = x//10
    > > > > WRITE eploc, storbyte
    > > > > ' 255 stored as 01010101 (DEC 55), need
    > > > > ' to account for numbers over DEC 100
    > > > > ' 00 to 99 stored correctly as is
    > > > >
    > > > > Bob Pence
    > > > >
    > > > >
    > > > >
    > >
    >
    >_______________________________________________________________
    __
    > > > > Get your FREE download of MSN Explorer at
    > > > > http://explorer.msn.com
    > > > >
    > > >
    > > >
    > > >__________________________________________________
    > > >Do You Yahoo!?
    > > >Spot the hottest trends in music, movies, and more.
    > > >http://buzz.yahoo.com/
    > >
    > >
    >
    ________________________________________________________________
    _
    > > Get your FREE download of MSN Explorer at
    > > http://explorer.msn.com
    > >
    >
    >
    > __________________________________________________
    > Do You Yahoo!?
    > Spot the hottest trends in music, movies, and more.
    > http://buzz.yahoo.com/
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed with. 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 2001-06-20 00:54
    I had the feeling that this was not an entirely
    original thought and may have resulting from recently
    having read Tracy Allen's excellent Stamp II Math
    Notes. You'll find the kernel of the idea at:

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

    Tracy uses math instead of the limited Stamp IF...THEN
    construction, which is always ideal, albeit at the
    expense of three math ops. I don't know which is
    faster - most likely Tracy's - but since we are
    dealing with byte-size EEPROM locations to store the
    high word (and so can't just increment the low byte of
    the high word without another IF...THEN), I think my
    subroutine approach works well. However, I do risk
    losing up to 5 1/2 hours of counts on power failure.

    Regards

    Bob Pence

    --- Ken Ambrose <kenzo@u...> wrote:
    > Excellent work Pence!
    > May I have your permission to use this also?
    >
    > Ken
    >
    > with enough thrust, pigs fly just fine.
    >
    >
    >
    >
    >
    > ---- On Tue, 19 Jun 2001, Pence Bob
    > (bobpence_2000@y...)
    > wrote:
    >
    > > [noparse][[/noparse]snip]
    > >
    > > My replies keep getting lost this morning.
    > >
    > > Byte or word x to BCD is as below - mod x by
    > 10^(N+1)
    > > and divide by 10^N to get the 10^N's place, then
    > store
    > > result (which will be 0..9) as nibble. Displaying
    > as
    > > BCD just depends on continuing to deal with the
    > > nibble.
    > >
    > > READ eploc, storbyte ' say storbyte is 10011001
    > for 99
    > > DEBUG DEC storbyte ' no good, displays 153
    > > DEBUG DEC storbyte.HIGHNIB, storbyte.LOWNIB ' ok -
    > 99
    > >
    > > However, for you application - as I'd recommend
    > for
    > > any application of BCD, which is fraught with
    > danger
    > > from my viewpoint - consider an alternate
    > > implementation. Keep a running total of up to
    > 10000
    > > cycles, then update two EEPROM bytes to
    > permanently
    > > tally, well, decakilocycles.
    > >
    > > cycles VAR WORD
    > > dkcycs VAR WORD
    > > ' code
    > > cycles = cycles + 1
    > > IF cycles > 9999 THEN TALLY
    > > RtnFrTly:
    > > ' more code
    > > .
    > > .
    > > TALLY:
    > > cycles = cycles - 10000
    > > READ 0, dkcycs.HIGHBYTE
    > > READ 1, dkcycs.LOWBYTE
    > > dkcycs = dkcycs + 1
    > > WRITE 0, dkcycs.HIGHBYTE
    > > WRITE 1, dkcycs.LOWBYTE
    > > GOTO RtnFrTly
    > >
    > > When its time to display, just
    > >
    > > DEBUG DEC dkcycs, DEC4 cycles ' DEC4 retain
    > leading
    > > 0's
    > >
    > > This method yields 655359999 cycles, which at 2
    > > seconds per cycles will allow the equipment to run
    > for
    > > 41.5 years continuously without rolling over the
    > > count. Also, the EEPROM locations are written to
    > at
    > > most 65536 times, which is less than the 100,000
    > > writes guaranteed on most Stamps, without having
    > to
    > > check for the low byte exceeding 255. Finally, no
    > BCD
    > > interpretation is required, which is always a good
    > > thing. This could be done with a BCD
    > implementation if
    > > more counts are required, in which case an EEPROM
    > > location would be needed as a pointer to the start
    > of
    > > the value, and possibly one for length, because
    > the
    > > data will have to move as writes exceed 100,000.
    > >
    > > Bob Pence
    > >
    > > > >--- GL Controls <glcontrols@h...> wrote:
    > > > > > Thanks, sounds like you are right on
    > target.
    > > > > > One more thing, Can you tell me which part
    > > > > > is the conversion formula to BCD. I am sure
    > > > > > its in there but I am not sure which part it
    > is?
    > > > > >
    > > > > > Thanks Again
    > > > > > Gill
    > > > > >
    > > > > >
    > > > > >
    > > >
    > >
    >
    >*******************************************************
    > > > > >
    > > > > > Yes, Binary-Coded Decimal (BCD) stores one
    > digit
    > > > in
    > > > > > each nibble, just a decimal digit instead of
    > a
    > > > hex
    > > > > > digit - e.g. 10011001 ('99') stored in an
    > EEPROM
    > > > > > byte
    > > > > > would represent decimal ninety-nine, not 128
    > +
    > > > 16 +
    > > > > > 8
    > > > > > + 1 = 16*9 + 1*9 = 153 decimal. So to store
    > this
    > > > > > value, you need to convert to decimal, e.g.:
    > > > > >
    > > > > > storbyte.HIGHNIB = x//100/10
    > > > > > storbyte.LOWNIB = x//10
    > > > > > WRITE eploc, storbyte
    > > > > > ' 255 stored as 01010101 (DEC 55), need
    > > > > > ' to account for numbers over DEC 100
    > > > > > ' 00 to 99 stored correctly as is
    > > > > >
    > > > > > Bob Pence
    > > > > >
    > > > > >
    > > > > >
    > > >
    > >
    >
    >_______________________________________________________________
    > __
    > > > > > Get your FREE download of MSN Explorer at
    > > > > > http://explorer.msn.com
    > > > > >
    > > > >
    > > > >
    > > >
    > >__________________________________________________
    > > > >Do You Yahoo!?
    > > > >Spot the hottest trends in music, movies, and
    > more.
    > > > >http://buzz.yahoo.com/
    > > >
    > > >
    > >
    >
    ________________________________________________________________
    > _
    > > > Get your FREE download of MSN Explorer at
    > > > http://explorer.msn.com
    > > >
    > >
    > >
    > > __________________________________________________
    > > Do You Yahoo!?
    > > Spot the hottest trends in music, movies, and
    > more.
    > > http://buzz.yahoo.com/
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed
    > with. 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/
    > >
    > >
    > >
    > >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed
    > with. 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/
    >
    >


    __________________________________________________
    Do You Yahoo!?
    Get personalized email addresses from Yahoo! Mail
    http://personal.mail.yahoo.com/
  • ArchiverArchiver Posts: 46,084
    edited 2001-06-20 02:35
    Ken -

    You surely have my permission, but I got to thinking
    that recently reading Tracy Allen's excellent Stamp II
    Math Notes might have influenced me. Turns out the
    first code sample in Math Note 6 (at emesystems.com)
    implements such a counter in RAM. Tracy increments the
    high word using a clever algorithm, whereas I resort
    to the Stamp's limited If..Then capability. I think
    this is appropriate, though, because I have to deal
    with EEPROM storage.

    Regards,

    Bob Pence

    > with enough thrust, pigs fly just fine.

    Cool!

    --- Ken Ambrose <kenzo@u...> wrote:
    > Excellent work Pence!
    > May I have your permission to use this also?
    >
    > Ken
    >
    > with enough thrust, pigs fly just fine.
    >
    >
    >
    >
    >
    > ---- On Tue, 19 Jun 2001, Pence Bob
    > (bobpence_2000@y...)
    > wrote:
    >
    > > [noparse][[/noparse]snip]
    > >
    > > My replies keep getting lost this morning.
    > >
    > > Byte or word x to BCD is as below - mod x by
    > 10^(N+1)
    > > and divide by 10^N to get the 10^N's place, then
    > store
    > > result (which will be 0..9) as nibble. Displaying
    > as
    > > BCD just depends on continuing to deal with the
    > > nibble.
    > >
    > > READ eploc, storbyte ' say storbyte is 10011001
    > for 99
    > > DEBUG DEC storbyte ' no good, displays 153
    > > DEBUG DEC storbyte.HIGHNIB, storbyte.LOWNIB ' ok -
    > 99
    > >
    > > However, for you application - as I'd recommend
    > for
    > > any application of BCD, which is fraught with
    > danger
    > > from my viewpoint - consider an alternate
    > > implementation. Keep a running total of up to
    > 10000
    > > cycles, then update two EEPROM bytes to
    > permanently
    > > tally, well, decakilocycles.
    > >
    > > cycles VAR WORD
    > > dkcycs VAR WORD
    > > ' code
    > > cycles = cycles + 1
    > > IF cycles > 9999 THEN TALLY
    > > RtnFrTly:
    > > ' more code
    > > .
    > > .
    > > TALLY:
    > > cycles = cycles - 10000
    > > READ 0, dkcycs.HIGHBYTE
    > > READ 1, dkcycs.LOWBYTE
    > > dkcycs = dkcycs + 1
    > > WRITE 0, dkcycs.HIGHBYTE
    > > WRITE 1, dkcycs.LOWBYTE
    > > GOTO RtnFrTly
    > >
    > > When its time to display, just
    > >
    > > DEBUG DEC dkcycs, DEC4 cycles ' DEC4 retain
    > leading
    > > 0's
    > >
    > > This method yields 655359999 cycles, which at 2
    > > seconds per cycles will allow the equipment to run
    > for
    > > 41.5 years continuously without rolling over the
    > > count. Also, the EEPROM locations are written to
    > at
    > > most 65536 times, which is less than the 100,000
    > > writes guaranteed on most Stamps, without having
    > to
    > > check for the low byte exceeding 255. Finally, no
    > BCD
    > > interpretation is required, which is always a good
    > > thing. This could be done with a BCD
    > implementation if
    > > more counts are required, in which case an EEPROM
    > > location would be needed as a pointer to the start
    > of
    > > the value, and possibly one for length, because
    > the
    > > data will have to move as writes exceed 100,000.
    > >
    > > Bob Pence
    > >
    > > > >--- GL Controls <glcontrols@h...> wrote:
    > > > > > Thanks, sounds like you are right on
    > target.
    > > > > > One more thing, Can you tell me which part
    > > > > > is the conversion formula to BCD. I am sure
    > > > > > its in there but I am not sure which part it
    > is?
    > > > > >
    > > > > > Thanks Again
    > > > > > Gill
    > > > > >
    > > > > >
    > > > > >
    > > >
    > >
    >
    >*******************************************************
    > > > > >
    > > > > > Yes, Binary-Coded Decimal (BCD) stores one
    > digit
    > > > in
    > > > > > each nibble, just a decimal digit instead of
    > a
    > > > hex
    > > > > > digit - e.g. 10011001 ('99') stored in an
    > EEPROM
    > > > > > byte
    > > > > > would represent decimal ninety-nine, not 128
    > +
    > > > 16 +
    > > > > > 8
    > > > > > + 1 = 16*9 + 1*9 = 153 decimal. So to store
    > this
    > > > > > value, you need to convert to decimal, e.g.:
    > > > > >
    > > > > > storbyte.HIGHNIB = x//100/10
    > > > > > storbyte.LOWNIB = x//10
    > > > > > WRITE eploc, storbyte
    > > > > > ' 255 stored as 01010101 (DEC 55), need
    > > > > > ' to account for numbers over DEC 100
    > > > > > ' 00 to 99 stored correctly as is
    > > > > >
    > > > > > Bob Pence
    > > > > >
    > > > > >
    > > > > >
    > > >
    > >
    >
    >_______________________________________________________________
    > __
    > > > > > Get your FREE download of MSN Explorer at
    > > > > > http://explorer.msn.com
    > > > > >
    > > > >
    > > > >
    > > >
    > >__________________________________________________
    > > > >Do You Yahoo!?
    > > > >Spot the hottest trends in music, movies, and
    > more.
    > > > >http://buzz.yahoo.com/
    > > >
    > > >
    > >
    >
    ________________________________________________________________
    > _
    > > > Get your FREE download of MSN Explorer at
    > > > http://explorer.msn.com
    > > >
    > >
    > >
    > > __________________________________________________
    > > Do You Yahoo!?
    > > Spot the hottest trends in music, movies, and
    > more.
    > > http://buzz.yahoo.com/
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed
    > with. 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/
    > >
    > >
    > >
    > >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed
    > with. 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/
    >
    >


    =====
    Regards,

    Bob Pence

    NOTE: This mail is sent using my wireless phone. Calling me at 1 (610) 563-6198
    is preferred to a reply. If replying to this email address, please do not quote
    the original message.

    __________________________________________________
    Do You Yahoo!?
    Get personalized email addresses from Yahoo! Mail
    http://personal.mail.yahoo.com/
Sign In or Register to comment.