View previous topic :: View next topic |
Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
Synching 2 PICs? |
Posted: Thu Aug 16, 2007 5:30 am |
|
|
Hi
I have one PIC that has a Xstal=6MHz, and is outputing a pulse of 25ms every 2seconds (or any other duration for that matter).
I would like to build a 2nd PIC (with any Xstal) that will lock on to this pulse and output its own 25ms pulse every 2seconds.
I can connect the two PICS for say 10seconds to achieve this synching, before I disconnect them.
The aim is to have these two PICs produce the same pulse in time.
Can someone please point me in the right direction of how to achieve this synching?
Thank you in advance.
a. |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Thu Aug 16, 2007 6:22 am |
|
|
If I understand your question correctly, I don't think this is possible, in the real world. Once the 2 pics are disconnected, the pulses will slowly drift. No matter how close the tolerances of the parts, they are different. Sorry.
Ken |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Aug 16, 2007 7:22 am |
|
|
There are three ways to go, none of which is perfect.
1) Buy the most stable crystal oscillator modules you can afford, and you will probably still want to tweak the timing with either a software count or hardware.
2) Use some external timing source such as GPS, WWV, or maybe the sync signal from a local TV broadcast station. It is possible to use the carrier of an AM radio station as well.
3) Have one PIC send some kind of signal to the other such as RF, IR, or a pulse over a wire or fiber. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Aug 16, 2007 7:35 am |
|
|
Hi
Thank you for your replies.
I understand that thigns will drift.
However, what I would like to know is the typical drift? My specs require that after 4 hours I have the two PICS different by no more than 0.5ms.
Is this possible? If I use a 40MHz clock on PIC #2 will that help?
What is a realistic drift that I should expect? (both PICS will be subjected to very similar temperatures).
Regards
a. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Aug 16, 2007 7:55 am |
|
|
There are several variables that will affect the drift; temperature, accuracy of the crystals, internal circuitry of the parts, to mention a few. The parts may be sycronized, initially, but will drift apart after being separated and this drift will continue to get larger until the signals start to approach sychronization again.
It's kind of like a clock that has stopped. It shows the correct time, twice a day. The pulses, of the parts, will slowly drift further apart until they start to come together again, like the clock. Once they pass each other, the time between the pulses, will get larger again.
Clear as mud?
Ronald |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Aug 16, 2007 8:05 am |
|
|
Hi Rnielsen
Thank you for your explanation- yes I think I understand what you write.
However, do you think that the drift can be as large as 0.1ms over 4hours if my 2nd PIC has a 40MHz clock? i.e. the time is 10ns for each instruction.
Perhaps I should look at *decreasing* the number of clock cycles in those 4 hours?
Regards
a. |
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Thu Aug 16, 2007 10:09 am |
|
|
+/-50 parts/million is an error spec for decent oscillators you can buy. The error is 10000 times worse than what you want (worst case, one pic +50 other -50). I think you need to stay synced with some external method in order to get to 0.1ms over 4 hours. |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Aug 16, 2007 10:19 am |
|
|
Hi
Surely I can start off by matching the oscilations with an Oscope of the two Xstals to be used with the 2 PICs?
Regards
a. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Aug 16, 2007 11:52 am |
|
|
For $15 from Digi-Key you can get an oscillator (10MHz) good to 2.5 ppm. In 4 hours that is 36mS each. Worst case would be 72mS but probably they would drift together so the difference would be much smaller. Still 0.1mS is an awful lot to ask for.
From Fox Oscillators (http://foxonline.com/pdfs/fts301ah.pdf) for a lot more money, 1 watt of power and a 2 minute warm-up you can get an ovenized oscillator that can be as good as +/-20ppb which is still +/-.288mS. But if these drift together they may work. The devil will be in the details. Maybe you should talk to an application engineer at an oscillator company. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 16, 2007 4:22 pm |
|
|
A GPS receiver is an extremely accurate time reference with no drift at all, you would never have to sync both units. In low quantities these modules can be bought for less than US$35.
Only problem is that you can't use them indoor (or add a long antenna cable to the outside world).
Before the GPS systems became popular here in Europe we used a radio transmitted timing signal, a German long wave radio station connected to an atomic clock. Cheap radio receivers are able to pick up this signal even inside most buildings. Search the internet for DCF77. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Aug 16, 2007 5:06 pm |
|
|
Are these two PIC's physically separated on different PCB's? If they are on the same board it might be easier to have an oscillator drive both PIC's. This way you would be sure they are running at the same frequency. If this is not possible, then you will definately need some way to get the same reference pulse to keep them in sync. Like I said, the different variables will affect each component differently.
Ronald |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Tue May 20, 2008 9:08 am |
|
|
The mains power could be a potential external signal to sync to. It's probably not too accurate in an absolute sense, but should be spot-on in relative terms.
I remember going on a power station tour many years ago, and being told that they go to some effort to get as close as possible to the correct number of cycles/day (i.e. 50/60 * 60 * 60 * 24) since there are many clocks that operate off the mains frequency for time keeping. _________________ Andrew |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Wed May 21, 2008 7:44 am |
|
|
Hi All
Thank you for your replies. Unfortunately I do not have the board space to use any external signal.
But let me understand this:
if the 10MHz Xstal reports a 50ppm accuracy, does that mean:
(a) it oscillates at 10e6+/-500 times per second which is fixed from second to second, or
(b) each second it oscillates a variable number of cycles per second
Thank you
a. |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
|
Posted: Wed May 21, 2008 8:39 am |
|
|
arrow wrote: | ...But let me understand this:
if the 10MHz Xstal reports a 50ppm accuracy, does that mean:
(a) it oscillates at 10e6+/-500 times per second which is fixed from second to second, or
(b) each second it oscillates a variable number of cycles per second...
|
The answer is closer to (a) than to (b), but (b) is partly right too. There is some drift in the frequency that is dependent mostly on temperature but also a little on the operating voltage of the circuit in which it is oscillating and on simple aging. (I doubt that the aging effect is going to be a concern for you over a 4-hour period). Over a reasonable temperature range, the frequency drift is much smaller han the 50ppm accuracy spec. And if both PICs are in the same temperature environment, that will help your cause too. Perhaps it is something like 1ppm over a 4 hour period. But check the temperature drift specs in the crystal manufacturer's datasheet to be sure. They will be in ppm/degree C.
If you intend to use this information to establish a ratio between the two PICs' oscillator frequencies to keep the outputs in sync, make sure you have a method that can measure this ratio with sufficient accuracy during the synchronization time. This might require keeping the two PICs connected for 30 seconds or more, depending on the method you use to make the measurement.
Robert Scott
Real-Time Specialties |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed May 21, 2008 8:47 am |
|
|
There is Accuracy and Stability. You really need to look at the data sheet of the crystal. The crystal will have some nominal frequency which is close to 10MHz but slightly different. That is the accuracy spec. The frequency will drift with temperature, power level, aging, and countless other minor factors. That is stability. Those two are usually combined in the simple 50ppm spec.
There is also jitter, which is the cycle by cycle difference in frequency. It does not sound like reasonable amounts of jitter will be a problem for you.
Get a data sheet that separates accuracy from stability, or talk to an application engineer at the crystal company. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|