8635Views19Replies

Author Options:

PIC Internal Clock -- How accurate? Answered

Can I trust a PIC's 4Mhz internal clock to keep accurate time over days of use? Or will I need an external crystal. I'm vary weary of that, as I'm going for a compact design. Thanks for the help.

Discussions

I just realized. I'm keeping 4 of these guys together, and they all have to be +/-0.0012% of each other, so they'll all be at the same temperature, so is temperature the only major factor? If it is I should be set.

I'm also thinking of using an Atiny (the number escapes me right now, but the 8-pin).

0
user
westfw

10 years ago

It's in the spec sheet; on the order of 2%, IIRC. Nowhere NEAR 0.0012% or 30s/month accurate, but (just barely) accurate enough to do serial comm, if you're lucky.

Hrm... Do resonators tend to be less accurate than crystals? I'm thinking about those since their size is what I need.

Traditionally, clocks use 32.768kHz "watch crystals", which are available in quite tiny packages (there is probably one inside your watch!)

PICs can use watch crystals, even though they are really slow compared to 4Mhz, they can be used to make a PIC clock, and may run over a year because PICs use very little power when they are run at 32768 hz. They probably would be just as accurate as a quartz watch then.

Speed doesn't matter, its for a clock, so I could technically use a 1Hz crystal -- if it existed.

Hey. I've done a few microcontroller clock projects too - accurate timing is always the hardest/most annoying part. The major problem I've found with using an internal clock is not the accuracy - it's easy to compute a correction factor, but the problem is that it is highly temperature dependant, so your correction factor goes out the window. Using a watch crystal is a good solution - it's a little bit of work to get it running, but it's a good cheap and low power solution. Another solution is a DS1307 chip - it can be used a 1Hz source without using it's complicated RTC funtions. You can therefore link the 1Hz output to an interrupt pin. Or if you are up for some i2c coding you can use the RTC clock function. Let us know how you go.

Most of the somewhat larger PICs have both the CPU oscillator, which can be internal at about 4MHz, AND a timer that can be set up to use an external 32kHz watch crystal, AND a sleep mode that lets the timer run along on its 32kHz crystal (at very low power) while the main CPU oscillator is turned off. This lets you have low average power with crystal timing accuracy, while still letting you do more complex CPU calculations when you need to. A bunch of other chips (TI's MSP430 comes to mind. Maybe some of the newer PICs?) derive the CPU clock from a 32kHz crystal using PLL clock multipliers, so you have the high accuracy timebase AND a high-speed CPU clock of reasonable accuracy. (Sometimes, however, relatively high "jitter." Our Network Time Protocol folk were cursing out the 68331 cpu that did this at one time...)

The 32.768K xtal value is easily dividable to obtain a precise 1Hz value, hence their use in clocks. I'm sure, as you say, the lower power consumption of the slow clock speed is a useful byproduct. With AVRs, no loading caps are needed with the clock xtals, also (maybe PICs, too?)

(and to answer your question, I think resonators tend to be about 100 times more accurate better than RC circuits (like the internal oscillator), and crystals about 100 times better than resonators.) Keep in mind that some of the accuracy of cheap digital watches comes from the fact that they're kept at a pretty constant temperature by body heat...

. Depends on how you define accurate. . While the clock may not be dead-on 4MHz, it should be fairly stable so that you can compute a correction factor.

Well, I'd like to make a clock, so it should be accurate to at least %0.0012 (thats 30 seconds a month) The problem, is its 4 clocks, all from separate PICs, but they need to all have the same time. (If I make them, it will defiantly be an instructable, and you will see the point)

. As others have pointed out, for that accuracy, an external timebase will be required.

Each PIC will have it's own accuracy ... As stated by gmoon, the internal clock accuracy is affected by temperature. So, the best solution is to use external crystals for each of your PICs.

0
user
HBF

10 years ago

WTF are you saying?

0
user
gmoon

10 years ago

If it's anything like the AVR's internal calibrated RC oscillator then it's probably not accurate enough (even after you calibrate it.) The internal oscillators are also effected by temp. Even an indoor clock would probably vary by > 30 sec. An xtal won't take up that much space. See if the PIC can use a watch xtal, which are tiny and don't need the two caps that are generally required (that's the case with the AVR.)

I found an accurate SMD crystal. I was going to go with a resonator, but it was only as accurate as the PIC (2%) although it could stand up to temp differences.

You're on the right track, don't forget the loading caps.

One more note: a 4.00 MHz xtal is NOT the same as a 4.00000000 MHz one. The first xtal might be 4.007392734 MHz....

Hmm... thanks. I'll look up how to use the crystal and stuff. I don't have much experience with crystal stuff.