Shop OBEX P1 Docs P2 Docs Learn Events
Prop as Real Time Clock ? — Parallax Forums

Prop as Real Time Clock ?

RaymanRayman Posts: 14,162
edited 2007-10-08 00:41 in Propeller 1
Ok, I've already bought some "DS1302 Timekeeping Chip".· And I see there is already code posted to interface to it.

But, couldn't a spare cog be programmed to do the same thing?· The proto and demo boards come with a cyrstal oscillator (maybe it's not as precise as the 32.768 kHz one?).· It seems a cog could just watch the CNT and increment a ms register every 80,000 clocks.· I guess days/month and leap years would take some code to handle, but it doesn't seem too tough...

The one really nice thing that the DS1302 has is a second Vcc input that can come from a backup coin cell lithium battery.· I'm not exactly sure how to implement this with the Prop.· I'm not even sure it would run off a 3V lithium cell...
«1

Comments

  • NewzedNewzed Posts: 2,503
    edited 2007-10-05 12:30
    Don't try to substitute for the regular clock crystal.· It has a load capacitance of 6.5pf, which is what the 1302 is designed for.· The Prop crystal has a load capacitance of 20pf.· And the lithium coin cell works just fine.

    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
    ·
  • NewzedNewzed Posts: 2,503
    edited 2007-10-05 12:39
    Another little note - the 1302 does not "run" off the coin cell.· That battery is only to keep the current time and date stored and to keep the clock oscillator running so it will keep time.· A new coin cell should last about 6 or 7 years.

    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
    ·
  • BradCBradC Posts: 2,601
    edited 2007-10-05 13:06
    Check the RTC cog in my thermostat project.. it's turned out to be incredibly accurate over a period of weeks..

    Maybe I'm just lucky with my crystal though..
  • Mark BramwellMark Bramwell Posts: 56
    edited 2007-10-05 13:24
    I would think that the problem is not accuracy but power-fail backup. How did you set the time in your RTC cog and what happens during a power blip? Or do you have a battery backup for the prop?
  • BradCBradC Posts: 2,601
    edited 2007-10-05 13:32
    Yeah, there is no power fail backup.. the rtc is set over usb-serial from an ntp based timesource when the PC powers back up..

    I don't have a power problem here.. we get less than 20 mins downtime per year, and my UPS will cover that standing on its head [noparse]:)[/noparse]
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 13:38
    I'm thinking about using a 3 V lithium battery with a germanium diode across Vcc. But, I don't know if the Prop will run at 2.7 V or not...
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-10-05 14:24
    2.7V basically gives you no margin for error. Doesn't the Prop reset if it dips below 2.7V? Read sec. 3.3 in the Prop Data Sheet V0.3

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 15:26
    True. Maybe the best thing is to add a supercapacitor across the regulated 5 V supply. I see one for $5 that should power the prop for at least an hour (1.5 F, 5.5 WVDC).
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-10-05 15:32
    Rayman,

    Instead of a diode, use a MOSFET with the gate tied to the drain. This will "act" like a diode without the voltage drop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-05 15:37
    You could use an electronic watch and feed the signal that would normally pulse the hands as your oscillator and feed that to a counter running in a cog, it would be as accurate as the watch was.

    Graham
  • David BDavid B Posts: 591
    edited 2007-10-05 15:50
    The 32768 kHz crystals are good for low-power operation but they're not designed for particularly precise timekeeping. See http://www.maxim-ic.com/appnotes.cfm/an_pk/58 where 32768 kHz crystals are shown as having typically +/- 20 PPM stability.

    Any crystal would need either temperature control, or temperature-sensitive circuit adjustments, or temperature-based software correction, or periodic adjustment based on an external time source to keep accurate time for the long term.

    When I started experimenting with high-gain op-amps, I used to pick up lots of interference by 100 kHz signal bursts that I eventually learned were from a LORAN station a few hundred miles away. But later on, I learned that LORAN signals can be used for the most precise time syncronization short of GPS or your own atomic clock. They're much better than WWV (a U.S. precision time broadcast station) because the low frequency isn't as subject to the atmospheric path variations. If a propeller used a cog to detect and lock onto the LORAN pulses, you could design a clock as precise as a GPS-based clock.

    But LORAN doesn't transmit time-of-day, just raw pulses at extremely precise intervals (except for some new experimental stations that are transmitting that info). So to get you past a power failure you would need some way to restore the time of day, whether WWV, or GPS, or a battery or capacitor backed RTC.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-05 16:23
    I assume you mean 32768 Hz not kHz. It depends what you want, when I personally want to know what time it is I'm happy with my watch but if I was doing navigation I might not be.

    Graham
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-05 16:47
    Just some remarks (done of course already elsewhere smile.gif )
    (a) There is nothing special with 32768 crystals. They are extraordinary tiny, and they deliver 1 second by a simple division by 2^16. That are all their merrits.

    (b) All crystals are extremely precise (someone mentioned 20 ppm) as long as temperature variations are limited. However they need a very specific adaptation of capacity to run at the frequency printed on them, as ALL capacities around them add to their behavior. It generally suffices to add a small 20pf trim cap from XINPUT to griund and adjust it.

    (c) Without that correction most likely ALL crystals will run around 0.01% faster than expected (=some seconds per day!)
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 17:35
    As a side note, I think I should have got DS1307 (saw this chip mentioned in another thread) chips (why doesn't Parallax sell these?) as they have an I2C interface. Then, I could put it on the same bus as the EEPROM and not use up any IO ports...
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 20:50
    Beau: Can you (or anyone) recommend a mosfet to try? I just tried it with a big, fat power mosfet (IRFP260N) and a CR2032 and it didn't work... Only got 2.4 V for Vdd on the demo board. Guess that wasn't enough...
    If you know of one that I can find at Radio Shack, I'll like try it this weekend...
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-10-05 21:16
    @Beau: would tying the gate to the drain give it sufficient Vgs to switch fully on? The gate threshold voltage is between 2V and 4V for that device.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 21:57
    Well, I bought the only MOSFET they had at Radio Shack, it's a IRF510 power, n-channel, 60V. Vgs(th)=2 to 4 V, Rds(on)=0.6.

    It may have been the power led on the demo board loading it down. I'm going to try this one on a proto board.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-10-05 22:13
    Rayman said...
    True. Maybe the best thing is to add a supercapacitor across the regulated 5 V supply. I see one for $5 that should power the prop for at least an hour (1.5 F, 5.5 WVDC).
    Is that a general description of something widely available (1.5F 5.5Wvdc) or something specific that needs $5? If the later, what/where is it?
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-05 22:37
    Look for "Gold Cap".
    Note: This is just a trade name: No gold in it smile.gif
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 22:47
    I was looking at Digikey.com part# P11343-ND . It's a Panasonic "SG series gold" "Electric Double Layer Capacitor" (whatever that means).
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 23:06
    I just tried the IRF510 on the proto board with a CR2032 and it didn't work either. Power led lights up dimmly but, no TV output (had the graphics demo loaded).

    Maybe it's better I just get some DS1307 chips...
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-05 23:07
    It describes the "technology" used: it's a very specific electrolyte...
    Gold Caps tolerate low voltage only (2V5; 5 V types are 2 in series) and are susceptable to higher temperature...

    But there is a new generation of "super caps" in the make: They use carbon nano-technology and soon will supersede recharcheables... Having the same capacity (1000F) , but unlimited recharge cycles and - if you can supply the current - can be recharged in seconds rather than hours.
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 23:26
    Where is Beau's DS1307 object? I just saw it mentioned as being in the Object Exchange, but I can't find it there!
  • RaymanRayman Posts: 14,162
    edited 2007-10-05 23:33
    I just tried my CR2032 directly across VDD and VSS on the proto board and it wouldn't boot up... So, no wonder it won't work with the mosfet!
  • NewzedNewzed Posts: 2,503
    edited 2007-10-05 23:48
    The CR2032 has a capacity of 45mah.· It is not designed to "power" anything that exceeds a current drain of about 50ua.· I hve been reading all your posts and the responses.· Why don't you just go with a DS1302 and the CR2032?· It is so easy and so simple.

    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
    ·
  • RaymanRayman Posts: 14,162
    edited 2007-10-06 00:58
    I think I'll use the DS1307 so I don't use up any extra pins...
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-10-06 01:12
    Beau, I don't see how that mosfet circuit could work. To turn on, the n-ch mosfet gate has to be at least Vgs higher than the source. The circuit you proposed is basically a source follower, and the output to the Prop will be no higher than Vdd-Vgs. That is worse than a diode, as Mosfet Vgs is usually much higher than a diode forward drop of 0.6 or less. Also, power mosfets like the IRF series have a secondary diode in reverse from source to drain, so that would not be good for use with a non-rechargeable battery. There are circuits that use a p-ch mosfet or PNP to achieve low overhead, but they take a separate threshold detector to drive the gate.

    General info on a mosfet for use with the Prop: Fnd one that starts with IRL instead of IRF. (IRL530) The L stands for low threshold, or logic level threshold.

    Sid, the capacity of the CR2032 is 240 mAh (source, energizer.com). The continuous current rated on their data sheets is 190 microamps and they also specify for pulse output at 7.5 mA. I have used CR2032s to power data loggers and with careful attention to power budget and with use of capacitors to supply the pulses, they can be a very economical and light weight power source. The Prop can go a long time operating on 4 microamps in RCSLOW mode, with occasional blips to higher power. Sid, I meant to ask you, have you experimented with the DS1338? It is the 3 volt version of the DS1307.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • rjo_rjo_ Posts: 1,825
    edited 2007-10-06 05:03
  • kenmackenmac Posts: 96
    edited 2007-10-06 06:35
    Hi folks,
    In a recent project I used Cog 0 as an RTC, with Cog1 handling the time/date display function and other Cogs used for miscellaneous external control functions.
    As the unit is only powered up for 8 hours/day, it was necessary to provide battery backup to maintain the clock activity.
    It was set up with a Pin dedicated to monitoring the main supply, and when that went off, all Cogs other than Cog0 were shutdown, reducing the Prop's load to <1mA (Xtal 5mHz)
    When the main power is restored, the operation returns to normal, with all "off" Cog's re-started.
    I used a 140mAH NiMh battery pack (cordless phone unit) fed via a PNP transistor(BC558) and a diode.
    The mainpower is obtained from a voltage regulator (LM317T) adjusted for 3.9V and also fed via a diode, resulting in approx. 3.3V at the Prop.
    A 1000uF capacitor is across the Prop's power pin to ensure smooth changeover.
    When the main power is present, the transistor is biased off the main +ve voltage is connected directly to the base.
    If the power goes off, the transistor is biased on, ( resistor from base to 0V) allowing the prop. to be fed from the battery.
    The battery is charged via resistor from the voltage that feeds the regulator.
    The timing of the RTC can be adjusted per program delay very precisely because the dedicated Cog program path doesn't change - i.e. there are no variations in program overheads.
    The major factor in variations in timing accuracy will of course still be the temperature effects on the Xtal.
    I haven't yet tried for the absolute maximum accuracy, just sufficient for practical maintenance of the real time - it is only checked/adjusted every two weeks.
    Unfortunately I couldn't upload the schematic because it is Open Office format (.odg).

    Summarising:
    Normal Power
    - Prop sees power via monitoring pin, starts all Cogs.
    - transistor is biased off by main power
    - battery is charged via resistor (trimpot)

    Power Off
    - Prop. sees no power on monitoring pin, shuts down all cogs except Cog0, reducing load to minimum (<1mA)
    - transistor turned on , allows battery to feed the Prop.
    - Cog0 continues normal clock timing.

    The battery size is chosen to suit the expected maximum "non-power" period that will be experienced. (like several days!)


    kenmac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Perth, Western Australia
    Time Zone = GMT + 8
  • JoeCreateJoeCreate Posts: 36
    edited 2007-10-06 08:28
    Click the PDF button in Open Office and upload the PDF file.
Sign In or Register to comment.