Shop OBEX P1 Docs P2 Docs Learn Events
Timestamp info — Parallax Forums

Timestamp info

pcrobotpcrobot Posts: 103
edited 2006-03-30 13:53 in BASIC Stamp
Hello,

I'm going to work on a project with my Stamp, where if a door is opened, it saves a timestamp. I'm just looking for any suggested reading on the subject of timestamps and the Stamp.

Thanks!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Robotics
ro-bot-ics (noun)
the science or technology of robots, their design, manufacture, application, use, etc.

Comments

  • aliniousalinious Posts: 51
    edited 2006-03-20 01:44
    When doing timestamping of an event, here are some things to consider:

    (1) Using an accurate timebase: For example, the DS1302 Real Time Clock can be easily interfaced to the Basic Stamp. The DS1302 will keep track of hours, minutes, seconds, month, day, date, and year in which you need to ask yourself which of these functions you want to be part of your timestamp. Here is a link to Parallax's webpage for the DS1302 ( www.parallax.com/detail.asp?product_id=604-00005). On the webpage, there is a link that will download a PDF file that shows you how to interface the DS1302 with the Basic Stamp 2.

    (2) Timestamp and Data Storage: A good question to ask yourself is how much data and for how long will I be recording (Example: a timestamp of hours, minutes, month, day, and year will require at least 6 bytes of the E2PROM)? Then, you will need to think about how much space the logging of the event will require and whether or not the Basic Stamp's E2PROM will be enough for the data log.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I learn when I succeed, but I learn more when I fail."

    Post Edited (alinious) : 3/20/2006 1:51:56 AM GMT
  • pcrobotpcrobot Posts: 103
    edited 2006-03-20 01:47
    alinious said...
    When doing timestamping of an event, here are some things to consider:

    (1) Using an accurate timebase: For example, the DS1302 Real Time Clock can be easily interfaced to the Basic Stamp. The DS1032 will keep track of hours, minutes, seconds, month, day, date, and year in which you need to ask yourself which of these functions you want to be part of your timestamp. Here is a link to Parallax's webpage for the DS1302 ( www.parallax.com/detail.asp?product_id=604-00005). On the webpage, there is a link that will download a PDF file that shows you how to interface the DS1302 with the Basic Stamp 2.

    (2) Timestamp and Data Storage: A good question to ask yourself is how much data and for how long will I be recording (Example: a timestamp of hours, minutes, month, day, and year will require at least 6 bytes of the E2PROM)? Then, you will need to think about how much space the logging of the event will require.
    Is it possible to do this without the DS1032? The longest time period that the Stamp will be with out being checked via a laptop would be 3 weeks. Most likely it'll be every week.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • aliniousalinious Posts: 51
    edited 2006-03-20 02:06
    A external Real Time Clock chip is really the only way to go to have an accurate timebase for a Basic Stamp. The Basic Stamp can not serve as an accurate time base because the delay in executing the code would make the clock inaccurate and the Basic Stamp would be tied up maintaining the clock instead of monitoring for the event to occur (door opening).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I learn when I succeed, but I learn more when I fail."
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-03-20 14:19
    The DS1302 can be powered with a CR2032 3-volt coin-cell, so the BS2 can be 'asleep' most of the time. The DS1302 is only an 8-pin DIP. Add two pins for the oscillator crystal, and two pins for the coin cell, and you're good to go. Add another 8-pin DIP (26L520? -- anyway, a small SPI interfaced eeprom chip) and you have a nice, very low power required, data logger.
  • pcrobotpcrobot Posts: 103
    edited 2006-03-22 20:58
    I'm going to try the project without the DS1302 first.

    I just need to find commands for sending a timestamp...

    And I have another question... if I send the timestamp to the EEPROM, what will happen when I pull the power? Will the info still be there?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • Tom WalkerTom Walker Posts: 509
    edited 2006-03-22 21:15
    pcrobot,
    The Stamp has no internal "clock" other than the internal "instruction clock". While you could synthesise a "timestamp-type" clock, it would probbly not be as accurate as you'd like without some VERY careful coding...down to making sure that each path through conditional blocks take exactly the same amount of time to execute. This is not a trivial task and would require that you use no "low-power" commands as these would also wreak havoc with any time-dependent code. The 1302 that has been suggested is probably the least "hair-pulling" solution to your stated requirement.

    As far as data written to the EEPROM, it is still there after power is removed. Just keep in mind that you must make some provision in your code to read the data back out. Also, each "cell" in the Stamp's EEPROM has a limited life cycle. How often you plan to write to it will determine whether the internal EEPROM, an external I2C or SPI EEPROM, FRAM, or some other solution would best fit the bill.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-03-22 23:12
    Yes, an EEPROM holds data when power is off, they're good that way.

    And an EEPROM (specifically the one in your BS2, which you access with DATA statements, and READ and WRITE (Start at address zero and work your way up, the code starts at the highest address and works its way down)) can only be written about a million times. This is a loong time if done once every 5 minutes. This is a short time if done once a second.

    So external eeproms (which have 8-pins, use SPI, and are easily interfaced with three wires) are recommended. Then if you wear it out, you replace a $1.50 eeprom, instead of a $50 BS2.
  • pcrobotpcrobot Posts: 103
    edited 2006-03-27 21:58
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    
    Seconds VAR Byte
    Minutes VAR Byte
    Hours VAR Byte
    Date VAR Byte
    Month VAR Byte
    Year VAR Byte
    
    
    
    Second=1000
    Minute=Second*60
    Hour=Minute*60
    Day=Hour*24
    Week=Day*7
    Month=
    Year=
    
    DO
    
    IF Contact is broken 'Actual code to come.
    
    THEN GOSUB timestamp
    
    LOOP
    
    timestamp:                  'Send timestamp to EEPROM
    
    Address Lastwrite+1
    


    This is what I have so far... it's kind of an outline. I still need to fill in the correct commands.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • pcrobotpcrobot Posts: 103
    edited 2006-03-29 22:36
    Any ideas?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-03-29 23:02
    Looks good so far...
  • Tom WalkerTom Walker Posts: 509
    edited 2006-03-30 13:53
    pcrobot,
    Not to belabor the point, but your code won't do anything useful. I understand that you don't have the code to read the door sensor, but, as I mentioned before, the Stamp does not have a clock, per se, that will do what you are looking for. You will need to use an external one to get the time or use a "counting" routine to synthesize your own...accepting the fact that it will not be very accurate (in microcontroller terms), and will impose certain restrictions on your program (i.e. can't do anything else while counting and looking for the door to open...if you time it right). Also, I'm not quite sure that your initial "logic" (the "Minute=", "Hour=" - type code) is going to give you any useful information. Beside the fact that everything is defined as a BYTE and would probably lead to confusion...even in your "Seconds=1000" line, I think what you "mean" to do is use division instead of multiplication.

    In short, I would recommend putting this project on hold and go through the various free texts made available by Parallax. You obviously have the drive and "just enough knowledge to be dangerous" [noparse]:)[/noparse]. I would hate to see your education get droped just because you tried something just a little too ambitious without having a little more foundation in "Stamp BASICs".

    Good Luck!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...

    Post Edited (Tom Walker) : 3/30/2006 2:06:22 PM GMT
Sign In or Register to comment.