Shop OBEX P1 Docs P2 Docs Learn Events
Time Keeping? — Parallax Forums

Time Keeping?

orrinbareorrinbare Posts: 32
edited 2011-09-09 20:47 in BASIC Stamp
I have a project going that will require a fairly accurate time. it will in theory operate 24 hours per day for the lifetime of the device with no human intervention (it will only DO something for about 30 seconds total during each day but will have to keep time and monitor push button status the rest of the time. i am using the BS2, i know how to program a "counter" but would it stay accurate? i don't have a lot of i/o pins to work with MAYBE 2, preferably 1, i could use something like this

http://www.parallax.com/Store/Components/AllIntegratedCircuits/tabid/154/CategoryID/31/List/0/SortField/0/Level/a/ProductID/234/Default.aspx

but just looking over the pdf for it, it will need more than one of my i/o pins, right?

also found

http://www.parallax.com/Store/Components/AllIntegratedCircuits/tabid/154/CategoryID/31/List/0/SortField/0/catpageindex/3/Level/a/ProductID/233/Default.aspx

this being a "time keeping chip" instead of a "timer" this sounds a lot more useful. i confess though, i read the pdf's on these and i don't understand a lot of it. has anyone reading this used either of these before? thoughts or opinions?

Comments

  • orrinbareorrinbare Posts: 32
    edited 2011-08-06 23:20
    Also, i know its going to come up eventually YES i did do a search for "clock", "time" etc and got a few links, one of them was talking about the second chip i linked, but his links to sample code etc are broken, then i found another link and the chip he refers to doesn't come up in a search so i'm guessing its no longer available.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-06 23:42
    The only way you're going to get "fairly accurate time" over some long period of time is to use something like the DS1302. There's a discussion on the use of this chip with a Stamp in the Nuts and Volts Columns. You go to Parallax's main webpage and click on the Resources tab. There will be a link to the Nuts and Volts Columns index. I think the pair of columns is in volumn 1. You'll need 3 I/O pins. Depending on what you're doing with the other I/O pins, you may be able to share one or two between the DS1302 and some other function.

    There are other techniques for timekeeping, but there's nothing quite as straightforward as using something like the DS1302.
  • TorTor Posts: 2,010
    edited 2011-08-07 05:41
    The DS1302 contains a full clock with 12/24 hours, and a calendar. Is there some alternative out there that works something like this:
    1) A counter which counts in seconds
    2) Another counter which counts nanoseconds (or at least microseconds) into the next second
    3) A way of reading out number of seconds, number of nanoseconds
    4) Preferably also a way of (re-)setting the counter to a known value (whole seconds would be good enough, nanos may start on 0)
    5) or, at least, resetting to zero unless 4) can be done.

    With a chip like that you would have essentially everything needed for Unix-style timekeeping. A 32-bit counter could hold number of seconds since 1970 until 2038.

    -Tor
  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-07 07:46
    @Tor - You won't find a "chip" that combines those two functions for a number of reasons. Something like the DS1302 is designed for very low power so it can run off a small battery for a long time. That's why it uses a 32KHz crystal and only provides a 1 second resolution. A nanosecond or microsecond counter would take significantly higher power by orders of magnitude. A Stamp wouldn't have this kind of scale of timekeeping anyway because, with some exceptions, it works on a scale of hundreds of microseconds. That's the minimum execution time of basic operations. A Propeller could be used to maintain the kind of clock you mentioned. It can be run with a 100MHz system clock giving a resolution for the system clock of 10ns. A simple program that runs in one cog could provide the kind of clock you're talking about.
  • orrinbareorrinbare Posts: 32
    edited 2011-08-07 10:16
    @ Mike, i don't know why i keep forgetting to check the nuts and volts column. it really is a wealth of knowledge! I'm not sure how you would use 1 i/o for 2 different functions though, but i'll see if i can find that in nuts and volts as well. I made the decision to go ahead and buy the DS1302 today so we'll see how it works. also saw i needed the little crystal to go with it so i got it to. that should be basically everything i need right?

    @Lean, thats the page with the 3 main links broken. it is still useful though, as it has a wiring diagram and 3 downloadable code examples for BS2
  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-07 12:12
    There are 3 I/O lines needed for the DS1302, a chip enable line, a clock line, and a bidirectional data line. When the chip enable line is low, the DS1302 ignores the clock line and the data line. You could use these for some other purpose then, like controlling an ADC or I/O expander of some kind, as long as you can disable this other device when you need to read or write to the DS1302.
  • orrinbareorrinbare Posts: 32
    edited 2011-08-07 21:00
    its funny how you start a project and you have a couple pins to spare for "future add ons etc" then before your even done with it you're thinking, ok, what can i cannibalize for another pin?? hahaha. I'll have enough pins for it, what the other pins have to do i don't think i can use for the enable so it'll just have to have 3. i found one of my parts that's not absolutely necessary so it will work
  • ercoerco Posts: 20,256
    edited 2011-08-08 08:43
    This type of question comes up regularly. Apparently people love DS1302s, using multiple IO pins and generally overcomplicating things that could be quite simple.

    I'm going even further out on my KISS limb to suggest that you consider hacking a cheap wristwatch. I've done it numerous times and they work reliably for YEARS. Every watch in the dollar store has an easily-set (?) daily alarm feature that outputs a 1.5V+ signal to a piezo beeper. A Stamp can easily detect that signal on a single pin and trigger a routine. Once triggered, your code simply needs to ignore the alram beeping for a minute or two until it stops and resets for the next day. I have also used the hourly chime to trigger things.

    A lot cheaper & simpler than futzing with an external RTC chip, especially for an app where you simply need to trigger once a day. And you can change the alarm trigger time using the watch buttons, no computer reprogramming needed. And there's a FREE LCD display included on every watch!
  • orrinbareorrinbare Posts: 32
    edited 2011-08-08 13:40
    @erco, awesome idea! i'd have to get one that has 2 alarms though, it will do something twice a day for a total of 30 seconds or so. remember my chicken door project? its for that. open in the mornin, close at night. like the idea though, i may consider using that!
  • dead-eyedead-eye Posts: 2
    edited 2011-09-09 20:47
    I've been working in television stations for the past 15 years or so, and what is typically used to keep the time for the stations, nowadays, are GPS Clocks. Why not use a GPS module and extract the time/date data from it and disregard the long/lat/alt data?
Sign In or Register to comment.