Timing differences between multiple micros - Page 1
Forum section: electronics / general

author: wardenclyffe
author_rank: Contributor
timestamp: October 23, 2011, 09:13:26 pm
content: I am working on a halloween display for some friends using four independent PIC 16F690s. The timing on each is staggered to light up some LEDs in a specific sequence. To get something working for a quick demo, I wrote a delay loop that would just turn on some LEDs for a period of time then shut them off. I did this for each of the micros individually, manually staggering the timing to make it fluid. When I first turned on the display it all seemed to work as expected, but over time the display started to drift out of sequence until eventually the timing was completely off. I am wondering if it has something to do with using the internal oscillators for the timing and whether using interrupts and a timer or an external xtal would help get things on track. Does anyone know what could be causing the problem?I am using MPLABX, the PicKit 2, and the HI-TECH C compiler.

author: sub
author_rank: Regular Contributor
timestamp: October 23, 2011, 09:44:23 pm
content: That will be the internal oscillators, yes---from memory they are calibrated to only 1%, so additional time sync will be needed. I would suggest using an external oscillator to run all of the micros on a common clock.

author: Rufus
author_rank: Super Contributor
timestamp: October 24, 2011, 03:08:47 am
content: The processors do not run at exactly the same speed so the generated sequences will not be at exactly the same speed.The only way to fix this is to use a synchronising signal between them.Using a crystal oscillator will make them run closer to the same speed but it will just take longer to become completely out of sync.An untrimmed crystal will be out by maybe 1 part in 10,000. If your sequence is 10 seconds long it would take about a day to get completely out of sync.

author: ToBeFrank
author_rank: Regular Contributor
timestamp: October 24, 2011, 05:51:31 am
content: Use an out pin on one PIC that acts as a timing reference for the other PICs?

author: sub
author_rank: Regular Contributor
timestamp: October 24, 2011, 06:50:08 am
content: Looking at the datasheet now, the CLKOUT pin gives you an Fosc/4 oscillator output. Perhaps then the simplest solution would be to keep the internal oscillator on one chip, and feed this signal to the other three micros in external clock mode. Obviously the slaves would need to have their delays reduced accordingly.Failing that, you can rewrite your delay routines to use some sort of synchronisation signal using GPIOs as others have said, or, if you are using timer interrupts, place them in counter mode and connect the appropriate input pin to CLKOUT on one of the chips. This has the advantage over clocking the micros on CLKOUT of allowing them all to operate at the internal oscillator frequency, and with the same time delays.

author: ChrisKiwi
author_rank: Contributor
timestamp: November 09, 2011, 01:24:28 am
content: Quote from: wardenclyffe on October 23, 2011, 09:13:26 pmNow, this doesn't answer your question as such (some good answers have already been given anyway) but my understanding of what you are doing is that there are several PIC's on one display controlling the LED's. So, why not use one PIC and some 74HC595's shift registrars and write how ever many bytes to the shift registrars is required to change the pattern.