Electronics > Microcontrollers

Timing differences between multiple micros

(1/2) > >>

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.

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.

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.

Use an out pin on one PIC that acts as a timing reference for the other PICs?

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.


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod