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

Keeping Real Time

Martin HebelMartin Hebel Posts: 1,239
edited 2006-04-22 09:49 in Propeller 1
Hope everyone has a Happy Easter and the bunny puts a Propeller in everyone's basket!

I'm developing an application that will require keeping-time, but requires very low power consumption. I would like to have the Propeller keep the time to minimize current draw by outside device, but I will be changing the speed on a frequent basis, again to minimize power. The internal RC will be no-where stable enough for this, and was considering tapping the 5MHz oscillator for the clock timing even when in low-speed mode for a consistent time base.

My question is, is the counting by the cogs' counters indepent of cog speed, or does it rely on the cog timing for logic, such as performing an add to PHSA on a rising edge pulse? That is, can I count at 5MHz even if the cog is running at a lower speed?

I know even using the external oscillator timing may be an issue, but I'll have a network going and another node can perform synchronization at regular intervals.

Any suggestions or thoughts on low-current, relatively stable time keeping? It doesn't need to be HH:MM:SS, elapsed seconds would be fine.

Thanks,
Martin

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Southern Illinois University Carbondale - Electronic Systems Technologies

Personal Links with plenty of BASIC Stamp info
StampPlot - Graphical Data Acquisition and Control

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-16 20:10
    Marty,

    I developed the attached timer object (included in demo archive)·that I'm ultimately going to blow-out into a full clock/calendar.· I beleive that using clkfreq and the cnt register will give proper timing (as accurate as the source) no matter what the frequency is, and the code will adjust to frequency changes.· Am I wrong?· I've only run it at 80 MHz (5 MHz x 16), and haven't yet experimented with frequency changes -- though Chip has looked at the code a couple times an never flagged any potential problems.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-04-17 01:32
    Hi Jon,
    I need to crash here in a few and I won't have a chance to look at it until tomorrow in any depth, but thanks. My concern is if it's based on the system counter timing, when I shift down to the internal 12KHz RC (? need to check that spec), all accuracy will be lost as it can be a very wide range based on temperature... and as my units will be outside, I can't rely on that for accuracy.

    Thanks why I was wondering if the counters could keep up with an external clock source running faster possibly than the system clock. They are not standard up counters, so I'm not sure what the architecture would allow. Maybe I simply need to test it out.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2006-04-17 02:32
    Hi Marty, I'll risk a reply. The low frequency oscillator is nominal 20khz, so the /4 instruction rate is only 5khz. When RCslow is selected, the 5mhz oscillator could be turned on, but it draws a lot of current in comparison to the RCslow mode by itself, and you could not use it for clocking the cog counters anyway. COG counters are synchronous and will be able to count a symmetrical input pulse stream only up to 1/2 of the master clock frequency. With the 20khz RCslow, that limits it to well under 10khz.

    The POSEDGE detector mode works by ANDing together the state of the pin one time frame back with the state of the pin two time frames back. If those are different, (0-->1), then FRQ is added to PHS. For a simple counter, FRQ=1, so the count advances by one for each 0-->1 edge detected. The fastest it can operate would be if the 0101010101 sequence is exactly synchronized with the internal clock, that is 1/2 of the master clock frequency. So with the 20khz oscillator, the maximum safe input frequency to the cog counter would be something well under 10 khz. With the 80mhz clock, the maximum would be 40mhz. I don't know what can be achieved in practice.

    Why not add an external RTC chip like the DS1307 or the PCF8583? Either one of those can keep accurate time, based on a 32768hz xtal, draw less than one microamp while running, and there is the option of using the 1 second square wave output, or reading the clock registers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-17 02:42
    If you're considering an RTC, you might look into one with an EEPROM -- I've ordered samples of this part to try with the Propeller:

    http://www.ramtron.com/lib/literature/datasheets/FM31xx_r2.2.pdf

    I'm not sure if it qualifies as "low power" per Marty's requirement, but it does look like an interesting device for use in Propeller projects.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-04-17 13:55
    Thanks Jon and Tracy,
    It looks like the DS1307 would probably be the best choice then,·and I was considering the DS1302 just because we used it in Industrial Control text.·

    Thanks again for clarifying the counter operation, I thought that would be case.
    -Martin


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2006-04-17 17:11
    The DS1302 could also work, and has the advantage that you can get it in p-dip (if that is a consideration) and it has the versatile backup power options.

    The I2C DS1307 (or DS1338 for 3.3 volt operation with Propeller) has the extra pin that is configurable as an accurate 1 second square wave output. I consider the square wave and the NV-RAM an indispensible system resource. For example, with Propeller, the one second pulse can be used to determine the actual frequency of the 20khz oscillator, which can then be used for low power timing functions at <10 microamps power. These are SMT parts. No p-dip. Note that the Vdd power to the DS1307 (along with the pull up resistors) have to be powered down to let the chip run off of the backup battery, in order to achieve the minimum power drain.

    Another neat option is the DS3232, which is the "extremely accurate) TXCO version, including the crystal and a temperature compensation circuit in a 20 pin, 0.3" SOIC. The usual caveats with Maxim/Dallas parts applies--can we really order less than 5000?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-18 06:20
    The Dallas Systems chips have an added benefit of some RAM for backup. If not a lot is needed, it seems much cheaper than the RAMTON solution if you are not requiring a substantial amount.

    Nonetheless, it seems that you could duplicate a Dallas Systems RTC in an SX-20 or SX-28 and have it be an all Parallax product.
    After all, if cost is a factor - why purchase someone else's product? I suspect you could have the extra available RAM too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • william chanwilliam chan Posts: 1,326
    edited 2006-04-21 07:43
    Kramer,

    Have you tried connecting a 32.768Khz clock crystal directly to the SX's OSC1 and OSC2 pins?

    Does it work without capacitors? Does it keep real time accurately?


    Thanks.

    William

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-21 10:06
    Hi William,
    The SX28 document mentions the 32K speed in LOW POWER oscillator mode.

    I believe the ideal condition is to use two 6pf capacitors, but I haven't got to it yet.
    Some might say that the leads to the OSC are enough capacitance.

    I have been looking at how to set up a trickle charge for a Lithium 3.7V BU battery. Or a 3V button battery. Or maybe a Super Capacitor with the SX.

    It would be a lot easier at +5 volts and I would have more battery options [noparse][[/noparse]NiMh or NiCd], but the Propeller is a 3.3V format.

    I am thinking that I needed a geranium diode as a blocking diode. [noparse][[/noparse]lower voltage drop]. I am not sure that one can handle the power.

    I could run the Sx at 3.0 volts backup, 3.3 volts regular -- but would the battery charge from an IO pin and a current limiting resistor? How do I shut down the pin when the system shuts down.

    This RTC is part of my own Propeller 'dream board'. Phillips actually has a very nice I2C clock chip with 96 bytes of NV RAM for about $2 to $3, so it seem to be really a moot point in terms of cost. They may be much easier to buy in small quantity than Dallas Semi.

    Try looking for Philips PCF 8563p or PCF 8583P at www.futurlec.com

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • parskoparsko Posts: 501
    edited 2006-04-21 10:22
    I ordered a few DS1388's from Dallas last year. I got an email from them this week saying that my address was wrong when they tried to ship it (little do they know that I have moved to Europe since). So they shipped them to me here in europe, 11 months after I placed my order. Talk about having difficulty getting chips from Dallas Semi....

    When I called, I didn't even remember what I ordered!

    -Parsko
  • william chanwilliam chan Posts: 1,326
    edited 2006-04-21 10:31
    Dear Kramer,

    Your idea of using the SX20 as a RTC struck me totally as a brilliant idea!
    Why didn't I think of that earlier?
    Since the SX's recent price reduction, it would essentially be the same price as the Philips or Dallas parts,
    and we are more familliar with the SX.

    I think the Lithium or Button batteries shouldn't be charged, since they are non-rechargable.

    You mentioned germanium diodes, are they the same as schokkty diodes?

    What if the SX hangs, and gets restarted by the watchdog, would the date and time be lost?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-04-21 14:43
    parsko said...
    I ordered a few DS1388's from Dallas last year. I got an email from them this week saying that my address was wrong when they tried to ship it (little do they know that I have moved to Europe since). So they shipped them to me here in europe, 11 months after I placed my order. Talk about having difficulty getting chips from Dallas Semi....

    When I called, I didn't even remember what I ordered!

    -Parsko
    I ordered a sample of Ramtron's newest parallel FRAM·chip, they waited a year before sending it, forgot to include my apartment number, and when FedEx called them to inquire what to do they instructed FedEx to destroy the package, so long $35 chip·and just hours before I went to pick it up in person. I haven't bothered to reorder because Im certain I wont be at this address a year from now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10

    Post Edited (Paul Baker) : 4/21/2006 3:25:34 PM GMT
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-21 15:01
    William,
    From what I understand most diodes have a .6 to .7 voltage drop.
    That brings me down form 3.3 volts to the 2.7-2.6 range. Not good.

    Since the brown out on the SX-20 is 2.6 volts and from what I understand there are potential boot problems if you try to impliment no Brown Out, I need another diode.

    Geranium maybe wrong. Yes 'hot carrier' or Schottky diodes will have a forward drop of 0.25 volts. So, life is good if one can provide enough power. We can have some headroom on the BrownOut feature.

    I wasn't aware that the 3 Volt Button and Lithium batteries were not rechargible. Still if they do their job well - who cares? You don't have to concern yourself with a recharge system.

    3 NiCads would be attractive at 3.6volts, but the diode blocking remains a problem with getting a full charge unless a pulsed output is used with something like a series of diodes and capacitors to get the voltage back above the charging threshold. The 3.7 Lithium Polymer has similar appeal and similar problems.

    But you can see that it gets complicated and messy while the competion has a RTC in a neat package. Still, the NiCads like a Charge rate of about 1/20th for sustained trickle charge, so 20ma from one SX pin might charge a 400ma/h reserve. A smaller charge rate is possible in some cases and more reserve.

    And, all these fixes are individually attractive custom features for deploying the SX with the Propeller. You may want the Sx just to do other things and charge a system BU battery as well. You may want a a clock with 12 alarm timers and so on. You may want a UART with ram buffer. All the SX needs to do is link via an I2C slave interface.

    It could all get quite eligant as a way to accessorize the Propeller with minimal support chips.

    What if the SX hangs? You could have periodic writes to EEPROM to fall back on and a flag to indicate that the time is somewhat inaccurate. There is a method of writing to a ring of EEPROM addresses to significantly extend the number of writes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan

    Post Edited (Kramer) : 4/21/2006 5:49:52 PM GMT
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2006-04-21 16:28
    It is difficult make an oscillator that draws the level of low current typical in dedicated RTC chips. RTCs like the DS1302 operate at a current well under 0.5 microamp from the 3 volt coin cell, so even a 50mAh cell can last 10 years. It would be hard to match that with an SX chip; the SX20A data sheet suggests 150 microamps at 32khz/3 volts. A PIC12F629 will be typically 20 microamps at 32khz/3 volts. Low current oscillators are usually a Pierce (single inverter or single transistor) configuration, not the two-inverter configuration usually found in microcontrollers. The Pierce circuit might be built with special narrow gate fets, startup time long, good stability, low consumption.

    Battery switchover circuits with very low voltage drop can be made with a mosfet set up to switch to the ON state and connect the battery when the main power goes low. These circuits take several additional parts (many more than the simple dual Schottky diode approach), so you are best off with a premade one from (you guessed it) Maxim or other vendors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-22 09:49
    Well there seems to be several dilemmas with timekeeping.·

    I removed my post that claimed the DS1305 was I2C, it is SPI and would require different interface to the Propeller.· The goal is to exploit in I2C pins that have been provided to the fullest.· The DS1307 is still available for I2C in a 16pin DIP.

    Regarding timekeeping....

    While the Propeller can do it, it distracts resources from other uses and in many ways time keeping is a peripheral convience.· If you need or want all your COGs to do other things -- this task easily gets moved to a slave.·

    Using Dallas Semi chips become a selection problem because they don't have a lot of I2C as they seem to have to pay a royalty to Phillips, so prefer SPI for lower costs. Count is generally down to 1 second.· DS has resident battery or supercap BU for 10 years of operation.· DS is the only one that offers 'burst mode' download, but I suspect that the SXes could mimic that also. [noparse][[/noparse]DS has the most features and complexity].· They do have the TXO which is far more accurate than XTAL.

    Using Phillips you get a lot of RAM [noparse][[/noparse]240 bytes is cheap]·for you money and 0.1 sec timing, but no accomodation for a BU battery.

    Using an SX-20 or SX-28 may not be the best option for power, but it can do timekeeping and other jobs too with the user being in control of all the options.

    Since most time-keeping chips are 8 pins, the advantage of going to 28 pins is that you can set up peripherial i/o to drive an LCD along with the clock/timer function.· That is not the only option, but it is a good useful example of how the two might work together.·Or, you can add 8 I/O pins to compensate for the ones that the I2C buss is using.·Of course, this leads back to having either a 'complete system' BU battery, an odd-ball creating scheme,·or none at all.

    It seems DS has the BU battery feature tied up. But, from what I understand that anything in the way of a small order is hard to get.· There is an Aussie vendor that provides DS and Philips --· www.futurlec.com

    Personally I think Phillips is quite nice as the additional clock/calendar with an 8 pin dip and 240 bytes.· You could have a 3V Lithium battery without charge. Use a barrier diode to provide power only to the clock IC, and most likely not notice the missing DS features.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Sign In or Register to comment.