Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Real Time Date-Clock

Status
Not open for further replies.

joe_1

Member
I have an application that I will develop that should log events and it needs to display the date-time stamp of these events.

I going to use PIC184620, and I am not so sure how to implement the date-clock, but here is what I am thinking:
1-The first time the user power the device up it will display something like:
01/01/2008 12:00AM
2-Then the user will have to set the actual date-time through menu.
3-In the C code I will have timer that runs once a minute. It will increment the minute, and if > 59 it increment the hour, and if > 11 it sets it either AM or PM Etc.
4-In the code I will have to hassle with issues like number of days in each month as well as leap years etc.

But the bigger problems are:
1- It is almost impossible to make an accurate C code 60-seconds timer.
2- What if the timer processing coincided or occurred at the same time while the processor is busy processing other interrupts, there will be delay, and that means eventually these delays will accumulate to make the time constantly off or lagging. The user will be constantly busy re-adjusting the time! One solution I could think of is to devote a second processor exclusively to the date-time, and make the main processor read the time from it (via serial or SPI or I2C etc) once every minute.


I am still in the thinking stage right now. I have not built anything yet, and if anyone had encountered this situation or has ideas, please let me know.

Thank You.
 
Hi,

You could also try a little 32k watch crystal on Timer1, and let it interrupt every second. fully detailed in the microchip manual.

Have used this method for years, its accurate to 2-3 seconds a week before any trimming.

hth
 
You could also try a little 32k watch crystal on Timer1, and let it interrupt every second. fully detailed in the microchip manual.
But that leaves the OP with all the issues he raises in his initial post.

The DS1307, takes care of all the time and calendar fucntions for him
 
Last edited:
I am still in the thinking stage right now. I have not built anything yet, and if anyone had encountered this situation or has ideas, please let me know.
I'm still sticking with my previous idea. Forget about the interfacing, you can do it with single chip. Besides, PIC24 has built-in parallel port that is handy for LCD (if you're using, of course).
 
If I need a RTC I'll either use a crystal that divides by a power of 2 (eg: 9.8304MHz) or a 32.768 kHz watch crystal. Free running timer interrupts won't lose time.
 
If I need a RTC I'll either use a crystal that divides by a power of 2 (eg: 9.8304MHz) or a 32.768 kHz watch crystal. Free running timer interrupts won't lose time.
Hogwash!

How do you correct an RTC based on that 9.8304 MHz crystal once you've determined that it's actually oscillating at 9.830470 or 9.830510 MHz?

I've had the opportunity to measure the crystal oscillator frequency on 50 or so projects using the receiver in my Icom 756PROII 'ham' transceiver which has a 0.5-ppm tcxo timebase. There's no direct connection to my receiver so I'm not loading down the oscillator circuit in any way. I haven't found a single crystal yet that has been spot on frequency. Even some very high quality crystals can vary by a couple hundred Hertz.

Unless you have some compelling reasons that would convince me that your 9.8304 MHz crystal is more accurate at keeping track of 1 second periods than my 4, 8, or 16 MHz crystal, I have to stick with my "hogwash" statement Bill.

Btw, I'm still getting accuracy of plus or minus 1/2 second per month on my "software trimmer" clock with its 16 MHz crystal. That kind of accuracy is just about what you can expect from crystal aging and temperature drift and way beyond what Maxim says you can expect from a 32.768 KHz crystal timebase.

Mike
 
Use something like a DS1307 Real Time Clock chip (**broken link removed**)

hi geko,
Have you seen this version.?

Claims +/-1min/pa, 0 thru +40C
 

Attachments

  • DS32kHz.pdf
    397.1 KB · Views: 390
That looks like 1 cool chip Eric :rolleyes: Time to go hunt some samples
 
Just check **broken link removed**

They make small RTC chips that have the crystal built in and also have pins for connecting a backup battery so you only have to set your clock once. Also they will give you free samples if you cant get the chips locally.
 
What I was pointing out is a free running timer firing off interrupts will not introduce jitter. After all crystals cost about the same and there are plenty of common frequencies available. This also allows the use of the simple TIMER0 and relatively simple jiffy clock.
I also see no reason to use a DS1307 if you don't need a battery backup clock.
 
Last edited:
What I was pointing out is a free running timer firing off interrupts will not introduce jitter. After all crystals cost about the same and there are plenty of common frequencies available. This also allows the use of the simple TIMER0 and relatively simple jiffy clock.
I also see no reason to use a DS1307 if you don't need a battery backup clock.

I suppose I thought you might have another misconception about RTC timing. Remember throwing me for a loop last year when you suggested a 20-ppm 20 MHz crystal was less accurate than a 20-ppm 4 Mhz crystal (grin)?

So you're saying that it's easier to just count Timer0 8-bit or 16-bit rollovers on one of those powers-of-2 type crystals compared to presetting Timer registers? I suppose that's true but unless you're designing a dedicated RTC it hardly seems worth the trouble of being stuck with a non-standard crystal frequency.

As for using a 32.768 KHz crystal on the Timer1 oscillator... In my opinion this is really only an advantage when using sleep mode to conserve power on a battery powered system because the oscillator will continue to run during sleep mode. Otherwise, the 32.768 KHz oscillator isn't really any more accurate than an HS crystal.

Mike

<added>

I agree with you on the use of RTC DS1307 circuit. The only advantage is the battery backup capability.

<added>

Bill, have you sampled any one-wire RTC devices?
 
Last edited:
Yes I've used the 1 wire RTC, I've got a watch with one on it. I can't recall the part number but dalsemi has a DIP package RTC with a 1wire interface. DS1305 or something like that.
**broken link removed**
 
Well the RTC chips with internal oscillators will have a temperature compensated crystal oscillator inside.So it will be more accurate and battery backup will sure make things easyer.Because a pic will need its clock set agen evrytime its reset.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top