Shop OBEX P1 Docs P2 Docs Learn Events
eeprom counting dilemma — Parallax Forums

eeprom counting dilemma

MichaelDeFalcoMichaelDeFalco Posts: 19
edited 2007-08-09 03:34 in BASIC Stamp
Hi all:

I think I have a mental block.
I am able to store values with the read and write commands to eeprom-no problem.
However, when I turn power off and restart when I begin storing counts to eeprom the data gets over-written
-as I would expect.·

Is there a way to save my counted data and keep incrementing the memory location from my last power down.
I am using a simple "count=count+1"·command to increment the memory reading and writing it into another variable "count_total".

Any direction would be appreciated.

Thanks...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
M.D.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-02 20:36
    What do you want to do with the count? You could always copy the counter to a save location in the EEPROM on power up so you'd have the current count and the count at power on.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-02 20:53
    If there is at least one value that the data you write cannot take, you can initialize your EEPROM by writing this value in every location. Then, when you power up, just scan through the EEPROM until you encounter that value. That will be your next location to write. This method, if applicable, has the advantage that you don't need to keep writing a pointer to the same EEPROM address after each data write, which might eventually wear out that location.

    -Phil
  • MichaelDeFalcoMichaelDeFalco Posts: 19
    edited 2007-08-02 21:05
    Thanks for the quick reply.
    Sorry for the diatribe...

    This goes back to my question of storing large counts of last week-I need to have the current count available in a memory location(s)
    for upload/download to a computer. (counting parts in real time)

    If I do save the last count, I will need to add totals of several saved locations-I need a total count (in the millions) for Preventative Mainenance Schedules as well as daily batch counting.

    I would like to keep the system to a few eeprom locations if possible-there could be 50 of these in a single facility.
    We would like to minimize the number of registers on a computer system network if possible.

    I am pretty new at programming stamps-but am seeing many advantages over PLC's.

    Thanks for any comments!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    M.D.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-02 21:25
    I'm still confused over what you're functionally trying to do with these counts. Particularly if you have something other than a plain BS2, you will have plenty of locations for counts since the other BS2 models have more than 2K of EEPROM space. The Stamps share EEPROM between program and persistent data. The other models also have volatile RAM (either 64 or 128 bytes) that goes away when the power goes off.

    Can you give a simple flowchart-like functional description of what you're doing with these counts?
  • MichaelDeFalcoMichaelDeFalco Posts: 19
    edited 2007-08-02 21:54
    Mike: Sorry for the confusion

    1. each time a machine cycles I close a switch on an input
    2. I increment the count "count=count+1"
    3. I send this count to a variable "count_total"
    4. I store the "count_total" data to eeprom location 1 via write command for later retrieval via serial port to a computer system

    If power is turned off (overnight) and begin counting again; the eeprom location is over-written and I loose the accumulated count
    from the previous day. I can't afford to loose the accumulated data - this ties into a quality system...

    I hope this helps-Thanks again for your patience

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    M.D.
  • NewzedNewzed Posts: 2,503
    edited 2007-08-02 22:44
    Store the count in EEPROM also, and read it·each time the Stamp boots up.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-02 23:06
    Basically, you keep several counts in a series of word variables in EEPROM and, on power up, you throw away the last and copy the next to last value to the last, etc. Sort of like:[noparse][[/noparse]code]
    for i = 4 to 1
    read 2*i-2,word count
    write 2*i,word count
    next
    [noparse][[/noparse]code]
    At this point, you can continue counting using EEPROM location 0. This way, if you have a power failure, you've got the last few counts. I'm not sure if the READ/WRITE <addr>,word <var> is the correct syntax to read/write a word. Check the manual.
  • rixterrixter Posts: 95
    edited 2007-08-09 02:00
    I've done something similar to this with the logging of GPS coordinates on my BS2. I write a longitude value and latitude value (a byte and a word length variable for each), to EEPROM followed by a '99' (or another value you wouldn't be using in your data) in the next EEPROM location. Subsequent logging increments the EEPROM location counter in my code to overwrite the '99' with the next longitude value, followed by the next latitude value and a '99' again. This way I am "pushing" along a '99' on the back end of my real data that signals "end of data". This let's me perform a read operation of the GPS data afterward that stops reading when it gets to the '99'. This way I can log a variable number of coordinates but will always know where the end of the most recent logging session is after power off. Some logging sessions may have 50 plotted coordinates, others 200 or more. You could do something similar to make your program not write additional data until you first performed a read loop looking for the "end of data" marker. Then you would start your writes there and continue beyond, always slapping on that end of data value as the last write.

    To throw in a related question amongst my solution, I was wondering if readers of this post know how EEPROM memory is addressed on the BS chips that have multiple banks of EEPROM. I realize that program code must be spread across program slots. But what about addressing EEPROM for extended logging abilities? The BS2pe advertises data logging applications, so I assume the extra memory is in fact addressable from the program slot 0? Any help appreciated on this.

    Thank you.

    Rick
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-09 02:02
    rixter,
    Look at the description of the STORE command. It sets the memory slot to be used by the READ/WRITE commands.
  • rixterrixter Posts: 95
    edited 2007-08-09 03:34
    Aha... perfecto! This is what I was looking for and should have known. Most interesting is that the STORE command is not available to the BS2e or BS2SX even though they have the extra EEPROM over the BS2 and can utilize this space with the RUN command for program code. I'll keep this in mind when I look at Stamps beyond the BS2 for my projects eventually. I'd like to store some other data returned from the GPS module in addition to longitude and latitude, but memory constraints have limited me. 30k of storage would do wonders to bail me out though.

    Thank you much.

    Rick
Sign In or Register to comment.