1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Real Time Clock Code (RTC) for PIC family

Discussion in 'Embedded' started by tomcee, Nov 17, 2010.

  1. tomcee

    tomcee Guest


    What is the latest RTC code anyone could recommend for the PIC (16f)

    My requirements are simplicity and low power, with LCD display and
    perhaps RS232 interface.

    Is the Microchip AN582 as good as it gets?

    tomcee, Nov 17, 2010
    1. Advertisements

  2. tomcee

    hamilton Guest

    The problem with this type of RTC is drift.

    As the temp changes the clock may run fast or slow.

    Even chips like the DS1307 can run fast: http://www.sparkfun.com/products/99

    Clean power and low temp drive will help, but ....

    As far as "as good as it gets" tells me you want something for nothing.

    Well, you get what you pay for. :-/

    hamilton, Nov 17, 2010
    1. Advertisements

  3. I guess if you have double-digit watts, space and money to spare, you
    can use a rubidium reference and get pretty decent drift over
    temperature & time. Or, cheaper, and lower power, use GPS (or GLONASS
    or Galileo or Baidu etc. when/where possible), but the signal may not
    always be available.
    Spehro Pefhany, Nov 17, 2010
  4. First Microchip application notes often contain errors,
    to the point where example code is simply wrong and obviously never tested in real life.
    Using a LCD conflicts with 'low power', as a small LCDs often already used a few mA,
    and much more if backlight is used.RS232 also conflict will ow power, if you want to use a MAX232 or something,
    but RS232 could be powered from the serial port control lines with the right software on the PC side.
    If you want the clock to keep anywhere near correct time over longer periods you
    will need a crystal oscillator, and some calibration feature.
    You can also get withing a few seconds per day using the internal oscillator
    and software calibration, say via RS232, if the temperature stays constant (say indoors).
    That is what I do here for example:
    Have a look at the code.
    This one also drives an LCD display, the clock interrupt code is the same as above:
    Jan Panteltje, Nov 17, 2010
  5. tomcee

    Martin Brown Guest

    The venerable 16F877 has just about enough legs to direct drive a 4
    digit LCD and will draw about 15uA doing it off 3v. Hardware is the PIC
    and a watch crystal. I did this once because I wanted a low power
    sidereal rate clock and the price for a custom crystal was outrageous.

    Hard to get a simpler hardware solution than making the PIC do it.
    Remember to load the crystal correctly and trim it and the result is
    likely to be OK. Miss out the trimmer and you can easily end up with
    something that drifts 15s/month or so. Some older amateur telescope
    drives have this problem and the makers fixed it by adding a GPS feature!

    Martin Brown
    Martin Brown, Nov 17, 2010
  6. Don't 90% of the worlds digital alarm clocks work like this? I thought
    "they" precisely controlled the long term cumulative frequency error of
    the mains for this very reason?
    John Devereux, Nov 17, 2010

  7. Of course they do, although the reason the power networks are so
    carefully synchronized has little to do with the power companies’
    interest in the accuracy of your clocks. Each powerplant is a (very)
    large AC generator. They basically just wire up all the power plants
    in a single grid in parallel - if the phases were not precisely
    synchronized it wouldn't work any better than a device in which you
    inserted some of the batteries upside down. Moving power between
    grids is trickier, simply because they are not synchronized. High
    voltage DC is somewhat popular for that task, and people still use
    motor/generator sets.

    Some electromechanical clocks take advantage of the same by using
    synchronous motors to drive the clock mechanism.

    But there is a ton of noise on the mains, which requires some care if
    you want to get a good 60Hz (or 50Hz) pulse.
    robertwessel2, Nov 17, 2010
  8. tomcee

    Don McKenzie Guest

    This may give you something to ponder:

    Cheers Don...


    Don McKenzie

    Site Map: http://www.dontronics.com/sitemap
    E-Mail Contact Page: http://www.dontronics.com/email
    Web Camera Page: http://www.dontronics.com/webcam
    No More Damn Spam: http://www.dontronics.com/spam

    USB Isolator 1000VDC For Protecting Your PC OR Laptop

    These products will reduce in price by 5% every month:
    Don McKenzie, Nov 17, 2010
  9. You seem to have an entirely different meaning for the term "LCD" in
    mind than --- well, pretty much everybody else. To a rather reasonable
    approximation, LCDs consume no power whatsoever. They're just a
    capacitor that you charge once, and then you top up that charge every
    once in a long while.

    Unless you happen to be in the enormously lucky position of having e-ink
    displays at your disposal, or don't want to show what your device is
    doing at all, there's just about no way you'll beat a simple LCD on
    power consumption.
    Hans-Bernhard Bröker, Nov 17, 2010
  10. tomcee

    jacko Guest

    You can either low pass the mains signal scaled down, or square up the
    mains signal using a schmitt inverter, and then use a monostable
    counter set to just lower than the required frequency and ignore any
    state changes for one counter period. Another option is to scale down
    the mains and compare the half wave rectifications of the positive and
    negative by a potential divider and a neutral comparator... BE CAREFUL
    and maintain any NEEDED isolation.

    Or use a highly tuned atomic time signal receiver, or use a known AM
    carrier signal (can be acurate depending on station).
    jacko, Nov 17, 2010
  11. tomcee

    Rich Grise Guest

    True - you need counters, too. ;-)

    Rich Grise, Nov 17, 2010
  12. tomcee

    Martin Brown Guest

    This is incorrect. An LCD will fade out in a couple of seconds if you
    apply DC and may suffer permanent damage if left DC polarised for a long
    time. The dark state is when AC is applied to the segment - though a
    relatively slow AC signal is enough to do it and power consumption for a
    bare metal 4 digit LCD driver is tiny. But you have to use the right low
    power driver chipset.

    Jan is thinking of the matrix LCD displays commonly used with PICs that
    have an "intelligent" controller and take commands off a 4 or 8 line
    bus. They do tend to draw a few mA but are much simpler to control.
    A bare LCD is very low current consumption, but you have to generate the
    waveforms to drive it directly. It only gets hairy when you want to
    multiplex a displays off the rather finite number of IO pins on a PIC.

    Martin Brown
    Martin Brown, Nov 17, 2010
  13. I just soldered in a 16 x 2 character LCD (Hitachi controller),
    and WITHOUT backlight it is almost 2mA.
    WITH backlight much much more.
    Jan Panteltje, Nov 17, 2010
  14. So what exactly did you think I wrote about a "rather reasonable
    approximation" for?
    Hans-Bernhard Bröker, Nov 17, 2010
  15. tomcee

    Martin Brown Guest

    That isn't a bare metal LCD display. The right chipset can do it with a
    current draw that is not much different to the self discharge rate of
    the battery. I have done it with a PIC and about 15uA for a 4 digit
    display (including the current for the CPU itself).

    The Hitachi controllers are easy to use but not energy efficient. You
    are into bespoke LCD controller territory for low current work. Though a
    PIC can be made to drive simple LCD displays directly.

    Ultra low power displays with many switchable sites requires ePaper
    technology with no need to periodically refresh the chroma sites. Power
    there is only needed to switch colour state.

    Martin Brown
    Martin Brown, Nov 17, 2010
  16. Yeah, down in the uA range, depending on size, operating voltage, type
    etc., which might be less than the self-discharge of a smallish
    JP's probably thinking of an alphanumeric LCD module (like those based
    on the HD44780 type of controller chip), which indeed uses a mA or
    more, rather than the 'bare glass' type of LCD (plus current in the
    bias network, plus a lot more for the backlight, if present).
    Spehro Pefhany, Nov 17, 2010
  17. tomcee

    John Temples Guest

    There are many PICs with easy-to-use, low-power, built-in LCD drivers.
    John Temples, Nov 17, 2010
  18. It's pretty simple to control _some_ 'bare glass' with _some_ PICs..
    especially the ones with built-in LCD controllers (static to
    quad-plexed). Set up the hardware and it runs, you just have to flip
    bits for segments on/off. Not enough segments for dot matrix displays,
    but plenty for segment displays plus some annunciators.
    Spehro Pefhany, Nov 17, 2010
  19. A reasonable approximation to "uses no power" is a device that runs on
    one set of batteries for roughly as long as the stated shelf life of
    those batteries. LCD-based wrist watches and alarm clocks routinely
    manage that. TV remotes and pocket calculators often come close.
    Hans-Bernhard Bröker, Nov 17, 2010
  20. The subject was PIC, and making LCD scan signals with PIC is not so simple.
    No body in his sane mind will do that, everybody uses a LCD module with some ASICs on it.
    Jan Panteltje, Nov 17, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.