Shop OBEX P1 Docs P2 Docs Learn Events
twice a day — Parallax Forums

twice a day

NamNoriNamNori Posts: 4
edited 2013-07-01 20:01 in Propeller 1
Looking for some advice... I'm wanting to use the propeller to toggle an IO pin twice a day (i.e. start at low, then at time X set HIGH, then some time Y later, perhaps even 8 hours later as an example, set LOW, then repeat the next day). My first thought was to leverage the DS1302 RTC chip which could certainly drive the prop IO to go HIGH at 10:00AM, then LOW at 8:00PM. But perhaps this is over-kill and there is a simpler way to attack this?

Thoughts?

Thanks!
-marc

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-29 21:57
    The Propeller's system clock is 32 bits, so with an 80MHz system clock, it rolls over roughly every 50 seconds. It would be convenient to use it to create a one second timer, then use that to keep track of the time of day. You could dedicate a cog to this and it would keep a time of day clock which you could set or reset as needed. If you need lower power, you could run the Propeller at a slower system clock speed or you could use the DS1302 or other RTC chip for battery backup.

    Here's a link to a clock object in the Propeller Object Exchange. There are also DS1302 drivers in the ObEx if you want to go that route. Search there for DS1302.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-06-30 06:58
    NamNori wrote: »
    But perhaps this is over-kill and there is a simpler way to attack this?

    The simple logger in propforth uses the interanl counter as 64 bit (double), and thus provides unique microsencond timestamp for like 7,000 years. After you calibate for drift, its nuts-dead-on as long as the temperature doesn't change. If the temperature change is cyclic, warm in day cool at night but consistent, it drifts in and out and stays pretty much on. The drift is microseconds so its less than the error read or setting the time in many cases, and you can adjust for you specifial situation.

    Simple logger needs no extra parts. If you have more than 32k of records to store, you can add an SD card and go for zillions of records. If you are not logging (why not, its free), you don't even need an SD.
  • localrogerlocalroger Posts: 3,451
    edited 2013-06-30 07:19
    As Mike notes you can't just use WAITCNT to establish delays longer than 50 seconds or so, but if you look over the examples for WAITCNT in the propmanual you'll see that you can do very accurate short delays even in Spin, and then just count those to do longer delays:
    time := cnt 'initialize
    repeat
      repeat constant(12 * 60 * 60) '12 hours in seconds
        waitcnt(time += clkfreq)
      !outa[pin] 'this happens every 12 hours
    
  • Alex.StanfieldAlex.Stanfield Posts: 198
    edited 2013-06-30 08:15
    NamNori wrote: »
    Looking for some advice... I'm wanting to use the propeller to toggle an IO pin twice a day (i.e. start at low, then at time X set HIGH, then some time Y later, perhaps even 8 hours later as an example, set LOW, then repeat the next day). My first thought was to leverage the DS1302 RTC chip which could certainly drive the prop IO to go HIGH at 10:00AM, then LOW at 8:00PM. But perhaps this is over-kill and there is a simpler way to attack this?

    Thoughts?

    Thanks!
    -marc

    Besides the other excellent suggestions posted, you need to determine if you need to do that at the same clock time (i.e: 8AM) each day or not. If yes then you will need an RTC since there will be no way to know what time it is after a reboot in case of a power failure or other event that results in a reboot.

    Alex
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-06-30 15:04
    Alex makes a fair point: it's easy enough to code an RTC in Spin (see attached), but a reboot will reset this clock. I've also attached a schematic and my code for the DS1337 RTC.
  • kwinnkwinn Posts: 8,697
    edited 2013-07-01 20:01
    You can also use a backup battery for the propeller and use one of the cogs as a Real Time Clock.
Sign In or Register to comment.