EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Real Time Clock Code (RTC) for PIC family

Started by tomcee November 17, 2010
On Nov 17, 2:06=A0pm, jacko <jackokr...@gmail.com> wrote:
> On Nov 17, 7:24=A0pm, "robertwess...@yahoo.com" > > > > > > <robertwess...@yahoo.com> wrote: > > On Nov 17, 12:50=A0pm, John Devereux <j...@devereux.me.uk> wrote: > > > > Jim Stewart <jstew...@jkmicro.com> writes: > > > > Rob Gaddi wrote: > > > > >> Way too expensive. Just plug into the mains and learn to count to =
60 or
> > > >> 50 as the case may be. Doing so without electrocution is left as a=
n
> > > >> exercise for the reader. > > > > > Have you ever successfully done this? =A0I ask > > > > because I've never seen an implementation that > > > > was more accurate than a $2 crystal and clock > > > > chip. > > > > Don't 90% of the worlds digital alarm clocks work like this? I though=
t
> > > "they" precisely controlled the long term cumulative frequency error =
of
> > > the mains for this very reason? > > > Of course they do, although the reason the power networks are so > > carefully synchronized has little to do with the power companies=92 > > interest in the accuracy of your clocks. =A0Each powerplant is a (very) > > large AC generator. =A0They 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. =A0Moving power between > > grids is trickier, simply because they are not synchronized. =A0High > > 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. > > 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.
It can be simpler and more reliable to just have your own 60Hz* timer (or more precisely, a reasonable multiple of that from which you can derive the 60Hz signal), and then use what you pull off the mains to correct for drift. That makes it easy to deal with various sorts of missed zero crossings (since you know where it's supposed to be, plus or minus a percent or two), and, as you mentioned, you can use that same internal timer to filter much of the noise that you can see between the zero crossings. It also leads to a setup where you can run a device without depending on the mains (obviously practical only if there's another power source), but you might get a bit of time drift while the power is out. I believe that's what the "better" line powered alarm clocks (the one's with a backup battery) do, and at least the clock is powered by the battery, even if the display is not. *60Hz chauvinism not to be taken too seriously
Hans-Bernhard Br&#4294967295;ker wrote:
> On 17.11.2010 22:01, Michael A. Terrell wrote: > >> Wht do you consider reasonable? > > 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.
I've got a credit-card sized calculator that has no battery at all - just a little puny PV cell about 1/4" X 3/4". The calc. doesn't even have an "off" button - all you do is slide it into its handy little leatherette case. ;-) Heh - I just checked, and I still have my Casio Fx-115v calculator http://www.mrmartinweb.com/images/calculator/cafx.jpg and it's fully PV-powered. :-) Cheers! Rich * PV == photovoltaic
On Nov 17, 5:50=A0pm, Jan Panteltje <pNaonStpealm...@yahoo.com> wrote:
> On a sunny day (Wed, 17 Nov 2010 16:16:45 -0500) it happened Spehro Pefha=
ny
> <speffS...@interlogDOTyou.knowwhat> wrote in > <r6h8e61q9s27iai28hqu0psha0c9cfb...@4ax.com>: > > > > > > >On Wed, 17 Nov 2010 20:41:10 +0100, Hans-Bernhard Br=F6ker > ><HBBroe...@t-online.de> wrote: > > >>On 17.11.2010 18:40, Jan Panteltje wrote: > > >>> Using a LCD conflicts with 'low power', as a small LCDs often already=
used a few mA,
> > >>You seem to have an entirely different meaning for the term "LCD" in > >>mind than --- well, pretty much everybody else. =A0To a rather reasonab=
le
> >>approximation, LCDs consume no power whatsoever. =A0They're just a > >>capacitor that you charge once, and then you top up that charge every > >>once in a long while. > > >Yeah, down in the uA range, depending on size, operating voltage, type > >etc., which might be less than the self-discharge of a smallish > >battery. > > >>Unless you happen to be in the enormously lucky position of having e-in=
k
> >>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. > > >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). > > Yes, Ok sorry to all, > I did not know there were PICs with a LCD scanning module build in. > I would like to hear what the OP wants, backlight? > For many applications backlight is a must.- Hide quoted text - > > - Show quoted text -
Jan: My initial concern is to not worry about backlight. Thank you for your postings - I will study these further. On the backlighting topic, I am quite curious to test the pulsed performance of using a white LED with a CR2032 cell. I have connected a CR2032 directly to a white LED directly (yes, directly - relying on the internal resistance of the CR2032), and it remained illuminated for almost a week! TomC
In article <JaCdndGEmqci_HnRnZ2dnUVZ_qmdnZ2d@earthlink.com>,=20
mike.terrell@earthlink.net says...
>=20 > Hans-Bernhard Br=F6ker wrote: > >=20 > > On 17.11.2010 22:01, Michael A. Terrell wrote: > >=20 > > > Wht do you consider reasonable? > >=20 > > 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. >=20 >=20 > Really? Watch batteries last me about a year.
Do you press the illumination button often? The battery in my last Casio at least 3 years. At the end of that time, the crystal and housing were worn enough that I just bought another of the same model. I was a bit=20 surprised that the same model was still available.
>=20 > TV remotes and pocket calculators often come close. >=20 >=20 > TV remote batteries last a few months, far short of the three to four > year, 'Use By date' on the labels. I normally use solar power > calculators, or the one built into every computer I have. >=20
You must do a lot of channel surfing. We get about 3 years per set of AA alkalines on our remotes. Of course, the more commands you=20 send through that IR LED on the front of the remote, the shorter the=20 battery life. The remotes on less expensive TVs often come with cheaper zinc-carbon batteries. IIRC, they have less than 1/3 the capacity of alkaline=20 cells. Mark Borgerson
In article <ic1pfm$22g$2@news.eternal-september.org>,=20
richg@example.net.invalid says...
> Hans-Bernhard Br=F6ker wrote: > > On 17.11.2010 22:01, Michael A. Terrell wrote: > >=20 > >> Wht do you consider reasonable? > >=20 > > 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. >=20 > I've got a credit-card sized calculator that has no battery at all -=20 > just a little puny PV cell about 1/4" X 3/4". The calc. doesn't even > have an "off" button - all you do is slide it into its handy little > leatherette case. ;-) >=20 > Heh - I just checked, and I still have my Casio Fx-115v calculator > http://www.mrmartinweb.com/images/calculator/cafx.jpg > and it's fully PV-powered. :-) >=20
I have one of those also. On the back, it says that it has an LR44 battery inside. I guess that is why it works with the solar cell covered up. I have to change the 4 Akaline N-cells in my 1980's vintage HP-41C=20 calculator about every 5 years. Since I don't use it every day, I probably lose as much to self-discharge as to operating current. Mark Borgerson
In article <i90er7-hva.ln1@radagast.org>, dplatt@radagast.org says...
> In article <ic19sm$cqa$1@news.eternal-september.org>, > Jim Stewart <jstewart@jkmicro.com> wrote: > > >I don't know how 90% of the world's digital alarm > >clocks work. I just know that I've seen several > >60hz-derived clocks over the years and they all > >suffered from erratically gaining time from noise > >on the line. > > > >I'm sure that a reliable mains-frequency clock can > >be designed. I'm also pretty sure that you can't > >do it with a comparator and a few resistors.
A lot of the newer alarm clocks use a WWVB 60KHz receiver to keep the clock time accurate. They have a backup supply to handle short power outages and recalibrate themselves at regular intervals.
> > The way I'd do it, would be to use a reliable, reasonably-close-to- > a-known-frequency oscillator (an off-the-shelf quartz crystal type) > as a short-term internal time base, which was then frequency- > locked to the power-line input via a periodic sampling (e.g. 60 HZ) > via a microcontroller of some sort. Don't use the actual > zero-crossing events of the powerline... as you point out, this would > be vulnerable to false triggering due to line noise. Instead, > implement a software PLL, with a suitable averaging loop time. > > This technique has an additional benefit. If you run the micro and > oscillator from a battery-backed-up power supply, and add a bit of > "smarts" to the software, you can automatically disable the PLL > tracking whenever the 60 Hz signal goes away, and just do your > time-counting based on the current pulse-count rate of the internal > oscillator. > > In effect, you would have a "line-frequency-standard disciplined" > quartz crystal oscillator, rather than trying to use the line > frequency directly as a timing source. > > A similar technique is used in the VE2ZAZ frequency standard (and, no > doubt, numerous others) which use the slow and jitter-prone "pulse per > second" output from a good GPS receiver to discipline a quartz- > crystal oscillator. By using an averaging period of an hour or two, > you can get *very* close to an exact 10.00000000 MHz signal... and the > firmware in the controller will automatically reject any timing > samples which further from this rate than a margin you select due to > noise or jitter or hardware glitches. >
What is your definition of "jitter-prone" for the GPS 1PPS output? I've used a number of inexpensive OEM modules that quote sync to UTC within +/-60nS. For a battery-powered system, the 50 to 75mA drain of a GPS chip might be excessive if it was left on all the time. However, I suppose you could turn on the GPS for a few minutes an hour to recalibrate the local crystal oscillator. How often you would need to turn on the GPS depends a lot on the rate of temperature change the clock will experience. My wristwatch turns on an internal 60KHZ WWBV receiver every night to check the time and correct the internal clock. Digikey has similar time code recievers for about four bucks. I don't know what they require in support components, but I think it will be cheaper than the VE2ZAZ standard---which apparently costs up to $200, depending on what you have in your junk box. http://pages.cs.wisc.edu/~timc/e/gpsdo.html After all, this is to develop a people-readable clock--- not a stable 10MHZ oscillator for RF usage. Mark Borgerson
On 17/11/2010 22:37, Jan Panteltje wrote:
> On a sunny day (Wed, 17 Nov 2010 11:23:25 -0800) it happened Tim Wescott > <tim@seemywebsite.com> wrote in > <Au6dnWdGtfK-sXnRnZ2dnUVZ_gidnZ2d@web-ster.com>: > >> On 11/17/2010 09:40 AM, Jan Panteltje wrote: >>> On a sunny day (Wed, 17 Nov 2010 07:56:13 -0800 (PST)) it happened tomcee >>> <tomcees_pc@yahoo.com> wrote in >>> <e83dfb22-5c13-4ab0-8aa8-cc5915cfca55@o14g2000yqe.googlegroups.com>: >>> >>>> Hello: >>>> >>>> What is the latest RTC code anyone could recommend for the PIC (16f) >>>> family? >>>> >>>> My requirements are simplicity and low power, with LCD display and >>>> perhaps RS232 interface. >>>> >>>> Is the Microchip AN582 as good as it gets? >>>> >>>> Thanks, >>>> TomC >>> >>> First Microchip application notes often contain errors, >>> to the point where example code is simply wrong and obviously never tested in real life. >> >> As do app notes from many other companies. >> >>> Using a LCD conflicts with 'low power', as a small LCDs often already used a few mA, >> >> A module perhaps, but just an LCD display, properly driven, is >> exceedingly low power -- or haven't you noticed what digital watches >> use, and how long their batteries last? > > The subject was PIC, and making LCD scan signals with PIC is not so simple.
It isn't trivial, but it isn't all that difficult either. Provided that you only want to drive a single 4 digit display or less most 40 pin PICs have enough IO pins. The rest is just a SMOP.
> No body in his sane mind will do that, everybody uses a LCD module with some ASICs on it.
Oh no they don't! Bare metal is cheaper and much much lower power. Regards, Martin Brown
On 17/11/2010 21:56, Spehro Pefhany wrote:
> On Wed, 17 Nov 2010 20:47:58 +0000, Martin Brown > <|||newspam|||@nezumi.demon.co.uk> wrote: > >> On 17/11/2010 19:41, Hans-Bernhard Br&#4294967295;ker wrote: >>> On 17.11.2010 18:40, Jan Panteltje wrote: >>> >>>> Using a LCD conflicts with 'low power', as a small LCDs often already >>>> used a few mA, >>> >>> 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. >> >> 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. > > 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.
They have obviously moved on a bit since I last used one in 2001. Which modern ones do you recommend for a 4 and 6 digit display? I had a look on Microchip but didn't spot anything obvious about direct drive of LCD functionality. But I did spot an RTC implementation: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en546209 (which may interest the OP) It was for an amateur astronomer friend who wanted a sidereal clock that did not need to be accompanied everywhere by a car battery. http://www.awrtech.co.uk/sc110dat.htm Mine will run for years on a pair of AA cells drawing just 15uA. Trimming is all done in software. Obviously no crystal oven! These days you can get an iPhone app to do the same job for pennies. Regards, Martin Brown
On a sunny day (Thu, 18 Nov 2010 08:15:00 +0000) it happened Martin Brown
<|||newspam|||@nezumi.demon.co.uk> wrote in
<_f5Fo.35696$qg3.34420@newsfe14.iad>:

>On 17/11/2010 22:37, Jan Panteltje wrote: >> On a sunny day (Wed, 17 Nov 2010 11:23:25 -0800) it happened Tim Wescott >> <tim@seemywebsite.com> wrote in >> <Au6dnWdGtfK-sXnRnZ2dnUVZ_gidnZ2d@web-ster.com>: >> >>> On 11/17/2010 09:40 AM, Jan Panteltje wrote: >>>> On a sunny day (Wed, 17 Nov 2010 07:56:13 -0800 (PST)) it happened tomcee >>>> <tomcees_pc@yahoo.com> wrote in >>>> <e83dfb22-5c13-4ab0-8aa8-cc5915cfca55@o14g2000yqe.googlegroups.com>: >>>> >>>>> Hello: >>>>> >>>>> What is the latest RTC code anyone could recommend for the PIC (16f) >>>>> family? >>>>> >>>>> My requirements are simplicity and low power, with LCD display and >>>>> perhaps RS232 interface. >>>>> >>>>> Is the Microchip AN582 as good as it gets? >>>>> >>>>> Thanks, >>>>> TomC >>>> >>>> First Microchip application notes often contain errors, >>>> to the point where example code is simply wrong and obviously never tested in real life. >>> >>> As do app notes from many other companies. >>> >>>> Using a LCD conflicts with 'low power', as a small LCDs often already used a few mA, >>> >>> A module perhaps, but just an LCD display, properly driven, is >>> exceedingly low power -- or haven't you noticed what digital watches >>> use, and how long their batteries last? >> >> The subject was PIC, and making LCD scan signals with PIC is not so simple. > >It isn't trivial, but it isn't all that difficult either. Provided that >you only want to drive a single 4 digit display or less most 40 pin PICs >have enough IO pins. The rest is just a SMOP.
Yes, well I was talking for myself I guess, I like the DIL PICs, so > 40 pins would likely be a no go. But also to avoid DC you need a very precise drive wave I think. I do not know how much a few uS asymmetry would work out on the LCD in the long term in the form of DC.
>> No body in his sane mind will do that, everybody uses a LCD module with some ASICs on it. > >Oh no they don't! Bare metal is cheaper and much much lower power.
Yes my apologies for that remark, I did not know PICs exists with build in LCD drive hardware.
>Regards, >Martin Brown >
On a sunny day (Wed, 17 Nov 2010 16:03:46 -0800 (PST)) it happened tomcee
<tomcees_pc@yahoo.com> wrote in
<acd3f780-321e-4c1f-b964-c1b777bdda21@l17g2000yqe.googlegroups.com>:

>My initial concern is to not worry about backlight. Thank you for >your postings - I will study these further. > >On the backlighting topic, I am quite curious to test the pulsed >performance of using a white LED with a CR2032 cell. I have connected >a CR2032 directly to a white LED directly (yes, directly - relying on >the internal resistance of the CR2032), and it remained illuminated >for almost a week! > >TomC
Modern LEDs are very efficient, and will still light up visibly with only a few uA. I have a couple of CR2430 3V cells on the desk that I sometimes use as LED tester in the same way :-) Those cells are now many years old (>5?). But the text LCD modules usually need a quite a few mA. The one I am just designing in uses green LEDs, 2 x 16 char, is specified at max 630 mA peak in pulse mode, and 100 cd/m^2 at 130 mA DC. But you can get away with much lower current in absolute dark. Add a backlight switch' perhaps.

Memfault Beyond the Launch