Shop OBEX P1 Docs P2 Docs Learn Events
write command — Parallax Forums

write command

littlerichlittlerich Posts: 27
edited 2007-10-22 15:52 in BASIC Stamp
I have 4 maybe ultimately 8 words I would like to keep track of in the event of a power outage.

Having read the manual I am mindful of the limited write cycles.

For the BS2P there is approx 100k writes. So if I updated every 1/2 hour that gives me a bit over 5 years.

Any suggestions for how to do the write every half hour?

I don't have a real time clock chip and wouldn't mind avoiding that.

Some huge loop maybe that only pops out every now and then to do the write is all I can think of currently.

Cheers
Rich

Comments

  • MorrolanMorrolan Posts: 98
    edited 2007-10-15 11:48
    What about using the SLEEP or NAP commands for timing? It might not be hugely accurate, but if you calculate the maximum SLEEP time, and upon each awakening increment a counter, then once that counter reaches a specific value you can write your words to the EEPROM?

    Just a quick and dirty thought (not that kind devil.gif )

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.

    "I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
    Stephen Hawking
  • JSWrightOCJSWrightOC Posts: 49
    edited 2007-10-15 12:25
    While it is not published in the Parallax documentation for the BASIC Stamp (not that I can find anyway) the I2C EEPROM used in the Stamps performs a page write, even if only one byte is modified. The page size is either 16 bytes (for the BS2) or 64 bytes (for all others, AFAIK). What this means is if you write two byte values that happen to be on the same page, then the whole page experiences two writes. So, for a given page, the number of write cycles endured is the sum of all writes to the EEPROM in a given page. The EEPROM supports page writes (where all 16 or 64 bytes are written at once), but I do not think this is implimented in the Stamp interpreter.

    One way to work around this, if life expectancy of the EEPROM is a concern, is to divide your data up so that each byte is in a separate page.

    I know you don't want to mess with a real-time clock, but it might give you exactly what you want. Most have a couple dozen or more bytes of SRAM in conjunction with the RTC function. Writes to SRAM do not contribute to wear, like they do in Flash EEPROM; however, a constant power supply is required. Most units can operate 10+ years off of a lithium coin cell at 25C.

    On a different tangent, rather than time your "commit" writes, is there any way they can be event-driven? Example: when a user changes a setting, the setting gets written to EEPROM immediately, so it can be recalled when the system is powered on again.
  • littlerichlittlerich Posts: 27
    edited 2007-10-16 08:20
    Hey thanks guys.

    I doubt I can use NAP as the program will be running continuously and the data I want to save I would prefer to time nicely within reason as I hope to send it to a database later on. But nice thought.

    Maybe I am destined for RTC after all. I didn't realise the writes was unlimited in them, not crazy about the battery but I'll keep moving forward and see where it ends up.

    Thanks again.
    Rich
  • Andy FoxAndy Fox Posts: 46
    edited 2007-10-19 21:30
    If you're not keen on dealing with a separate battery for the RTC you could look at a DS1287 from Dallas Semiconductors: it's a RTC with a little RAM & battery in one package. It isn't a simple I2C device though.

    Or you could buy a RTC module from http://www.microresearch.us/ to save time on building the circuit.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-19 23:02
    I would suggest using a DS1302 timekeeping chip with its 32 byte RAM. This requires a crystal and a battery and uses 3 I/O pins on the Stamp. There are plenty of sample programs showing its use. Check the Nuts and Volts columns #33 and 34.

    You could also get a DS1307 mounted on a little board with a crystal and battery from Spark-Fun (www.sparkfun.com/commerce/product_info.php?products_id=99). This one has a 64 byte RAM. It requires the use of I2C which is built-in to the BS2p series devices, but has to be programmed explicitly using subroutines on the other Stamp models.

    In both cases, you'd have a place to put the data that would be maintained in the case of a power failure and you'd also have a timebase that you could use to determine when to back things up. I would suggest two separate copies of the data if possible ... maybe with a checksum (if you're using the DS1307 with its extra memory). That way, if the power fails while the memory is being updated, you'd have an older, but still valid backup.
  • FranklinFranklin Posts: 4,747
    edited 2007-10-20 01:01
    I have a device that came with my water filter. It's a fridge magnet with a blue led that turns on to remind me to change the filter EVERY TWO MONTHS! Not sure what's inside but I doubt it's a RTC. More likely a 555 timer and decade counter or such.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-10-22 15:24
    I have to agree with Mike on a DS1302…Even if you don’t use the clock, having the extra backed-up RAM is very nice and is such a small cost both financially and in terms of I/O. If you use an SPI device anywhere else on the system it would help justify it to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-10-22 15:52
    Mike,

    Futurelec also sells a DS1307 mini board with a watch battery for backup (similar to the one that Sparkfun has) for only $7.

    http://www.futurlec.com/Mini_DS1307.shtml



    -- Well after looking closer at the Sparkfun version, the watch battery is on the backside and it is smaller than the $7 one from Futurelec.
Sign In or Register to comment.