Author Topic: Timing differences between multiple micros  (Read 2420 times)

0 Members and 1 Guest are viewing this topic.

Offline wardenclyffe

  • Contributor
  • Posts: 30
Timing differences between multiple micros
« on: October 23, 2011, 09:13:26 pm »
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.
 

Offline sub

  • Regular Contributor
  • *
  • Posts: 107
  • Country: au
Re: Timing differences between multiple micros
« Reply #1 on: October 23, 2011, 09:44:23 pm »
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.
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2094
Re: Timing differences between multiple micros
« Reply #2 on: October 24, 2011, 03:08:47 am »
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.
 

Offline ToBeFrank

  • Regular Contributor
  • *
  • Posts: 234
  • Country: us
Re: Timing differences between multiple micros
« Reply #3 on: October 24, 2011, 05:51:31 am »
Use an out pin on one PIC that acts as a timing reference for the other PICs?
 

Offline sub

  • Regular Contributor
  • *
  • Posts: 107
  • Country: au
Re: Timing differences between multiple micros
« Reply #4 on: October 24, 2011, 06:50:08 am »
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.
 

Offline ChrisKiwi

  • Contributor
  • Posts: 41
  • Country: nz
Re: Timing differences between multiple micros
« Reply #5 on: November 09, 2011, 01:24:28 am »
I am working on a halloween display .... I did this for each of the micros individually, manually staggering the timing to make it fluid.

Now, 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf