Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to sychronise multiple PICs running the same code?

Status
Not open for further replies.

sjb741

Junior Member level 2
Junior Member level 2
Joined
Aug 6, 2021
Messages
20
Helped
0
Reputation
0
Reaction score
1
Trophy points
3
Activity points
222
Suppose I have to synchronise multiple PWMs on separate PICs, how would I do that? Assume the two PICs share a common system clock.

Of course, one 'solution' is to side-step the question and find a PIC with enough independent PWM modules which can then somehow be sychroninised... However, I am still interested in techniques for synchronising across separate devices because I feel this could be a useful thing to understand - regardless of whether a single chip solution exists.


For instance: I designed a 'cheap as possible' 2-PWM wave generator using a PIC16F1825. For this particular PIC, I had to synchronise the 2 PWM by adding some assembly code into the C code. Whilst I realise other PICs have good ways to synchronise 2 (or maybe 4) PWM channels, I'd be interested in how to synchronise two 1825 devices.

That way, the two PWM can use independent master clock speeds. At present, the two on-chip PWM must share the same clock source, so I can't have one PWM going at MHz and the other running at a few Hz. Even though that range of PWM is possible, it involves 'clock switching' and that clock is common to both PWM.


BTW: In this particular example, I'm imagining the two PICs sharing one external system clock, like a crystal oscillator module - although I do wonder whether I can make use of a 'clock out' pin on one PIC to drive the other PIC's sytem clock.
 

Here is 32 PWM channels, all synched. Still lots of resources left for other
tasks. See right hand window. This is single chip solution.

1667656422768.png



Here are the resources onchip, in many cases multiple copies (as you see above) :

1667656516441.png


Note I set the PWMs all to the same clock. That can easily be changed to multiple clocks,
and use the reset input to perform the synch.

Regards, Dana.
 
Last edited:

Hi,

I don´t recommend to use several PIC and rely on the synchronisation of PWM signals.

But if you want to do so:
Use the PIC´s signal capture feature to "check" the phase shift to the other PIC´s PWM.

I don´t know how accurate you need ... so the "worst case" shift you allow.

I recommed one is the master. The slave tries to align. If aligned it sends out an "aligned" signal that enables all PWMs (using AND gates, for example)

Klaus
 

It is not clear if you need to control each PWM duty-cycle independently in a realtime loopback control. If so, you could delegate to one of both the task of creating a timer based output to be used as input for the period frequency for as much microcontrollers as you need.
 

Many thanks indeed for all the replies. My application is a user-configurable PWM source with 2 channels.

In the case where both PWM run at the same frequency, the user can choose to exactly align phase, use quandrature phase or arbitrarily choose any desired phase.

For fexibility though, I'd like to be able to allow the user to choose two very different PWM frequencies.
 

Hi,

We don't know the pwm frequency (range) nor the expected phase accuracy.
So we can not give more detailed help.

In case of different frequencies (and without additional information): sync is not needed at all.

Klaus
 

I wrote a "user guide" for the existing design which should explain things well.

I was about to attach the PDF file, but that option seems missing from this forum, so I'll add some images. I can't add the images either, the forum wants a URL.

Here it is on ebay - the specifications are there - I can't do that either my limit is "0 links per post"

OK, the ebay item id is this: 324215952908 :confused:
 

Hi,

The forum software provides buttons for
[Insert Image] (direct upoad is the preferred method)
[Attach files]
Just press them. Other members seem to have no problem with this.

*****

If there is a problem with the forum software you may contact me (or any other moderator) via PM.
Show us a screenshot including error description.

Klaus
 

    sjb741

    Points: 2
    Helpful Answer Positive Rating
Thank you Klaus

I missed the 'Attach Files' button as I was focusing on the row of icons at the top, wheras 'Attach Files' is a button at the bottom.

The range is 7.3Hz to 8MHz.

On the existing hardware, I believe the two PWMs are (in principle) 'perfectly' synchronised.

I would like the phase accuracy of a two-PIC solution to be 'essentially the same as' a one-PIC solution.

Regards
Stephen
 

Attachments

  • PWM-200 r01 User Guide.pdf
    387.4 KB · Views: 157

Hi,
The range is 7.3Hz to 8MHz.
This is huge dynamics. Does it make sense at all?

I would like the phase accuracy
This is "best case" whishful thinking. But I asked about "worst case" limit.

No comment about my recommended solution?

Klaus
 

@danadakk
which Infineon (Cypress) PsoC did you use? I didn't see / couldn't find it in your post.

@sjb741
what do you mean by synchronizing two (or more) PWM?
what is the purpose of synchronizing PWM?

in general, if the PWMs run at different frequencies, what does it mean to synchronize them?
 

The 5LP family,

1668085922955.png

If the PWMs integer multiples of reference PWM clock one could imagine
synchronization. Or just a bunch of Async running parts always starting
at a synch reset.....


Regards, Dana.
 

Hi,

This is huge dynamics. Does it make sense at all?


This is "best case" whishful thinking. But I asked about "worst case" limit.

No comment about my recommended solution?

Klaus
Hello Klaus

My understanding of the suggested solution is that
(a) The PWM duty is compared with the captured timer value.
(b) Because the same timer is used for PWM and capture, we know that the value captured is the time offset from the start of the PWM cycle
(c) We then want to see (time captured) = (PWM duty)

The 16F1825 DS shows that capture mode uses TMR1, wheras PWM mode uses of one of the 8-bit Timer2/4/6 timers.

Regards
Stephen
--- Updated ---

@danadakk
which Infineon (Cypress) PsoC did you use? I didn't see / couldn't find it in your post.

@sjb741
what do you mean by synchronizing two (or more) PWM?
what is the purpose of synchronizing PWM?

in general, if the PWMs run at different frequencies, what does it mean to synchronize them?
Hi

I am interested how in general in might be possible to synchronise 2 PICs sharing one clock. The PWM case is simply an example 'use case' for this.

In my example, the existing circuit is designed as a generic 2 channel PWM. As such, a user might find it useful to relate the phases of two PWM signals. Some examples
  • Quadrature
  • Experimenting with SMPS designs. Here the signals might well have different duty. We might want PWM 2 to 'fire' somewhere about the middle of PWM 1's mark (or space), and we might like to control 'somewhere about' to be a particular known value.
By 'synchronise' I mean a known time offset from the start of one duty to the start of another duty.
--- Updated ---

The 5LP family,

View attachment 179616
If the PWMs integer multiples of reference PWM clock one could imagine
synchronization. Or just a bunch of Async running parts always starting
at a synch reset.....


Regards, Dana.
Hi Dana

If I clock two PICs (running identical code) from one crystal oscillator module, and do a synchronous reset then is it guaranteed that both PICs execute their first instruction cycle on the same clock edge?

Regards
Stephen
 
Last edited:

Hello Klaus

My understanding of the suggested solution is that
(a) The PWM duty is compared with the captured timer value.
(b) Because the same timer is used for PWM and capture, we know that the value captured is the time offset from the start of the PWM cycle
(c) We then want to see (time captured) = (PWM duty)

The 16F1825 DS shows that capture mode uses TMR1, wheras PWM mode uses of one of the 8-bit Timer2/4/6 timers.

Regards
Stephen
--- Updated ---


Hi

I am interested how in general in might be possible to synchronise 2 PICs sharing one clock. The PWM case is simply an example 'use case' for this.

In my example, the existing circuit is designed as a generic 2 channel PWM. As such, a user might find it useful to relate the phases of two PWM signals. Some examples
  • Quadrature
  • Experimenting with SMPS designs. Here the signals might well have different duty. We might want PWM 2 to 'fire' somewhere about the middle of PWM 1's mark (or space), and we might like to control 'somewhere about' to be a particular known value.
By 'synchronise' I mean a known time offset from the start of one duty to the start of another duty.
--- Updated ---


Hi Dana

If I clock two PICs (running identical code) from one crystal oscillator module, and do a synchronous reset then is it guaranteed that both PICs execute their first instruction cycle on the same clock edge?

Regards
Stephen


No to synch as I presume the PIC is not a fully static design, eg. its clock can go to DC.
In other words its clocks PLL derived ? If so there is no guarantee the PLLs acquire the
same state at the same time.

Try a quick experiment, toggle a GPIO on each, and set a scope to trigger on edge delay.


Regards, Dana.
 

Hi,

@danadakk:
The OP already knows/expects that the PWM are out of sync. So, no need to test this.

And this is the reason why the OP asks for a "synchronizer".

But also in post#1 the OP tells that both PICs share a common system clock.
So the system clock should be fairly aligned. I even expect this with a locked PLL.

And again: if the PLL loses it´s lock, then the synchronizer need do it´s job.

Klaus
--- Updated ---

Hi,

@OP:
In post#1 you ask about synchronizing the PWM of different PICs.
My answer: Yes, but with minor timing errors. I asked for the tolerance, but still no information.

Now you ask to synchronize two PICs.
Here I have to say: No. You won´t be able to "code synchronize" them.

Klaus
 

@KLAUS

The OP stated :

If I clock two PICs (running identical code) from one crystal oscillator module, and do a synchronous reset then is it guaranteed that both PICs execute their first instruction cycle on the same clock edge?

So I was suggesting a trial test method to confirm if it worked.

But also in post#1 the OP tells that both PICs share a common system clock.
So the system clock should be fairly aligned. I even expect this with a locked PLL.

I concur, once its locked, but when synch edge is issued until lock all bets are off.
PLL's are not totally deterministic in synch clocking circuits when acquiring.

And then there is the elephant in the suitcase problem, jitter......and the tradeoffs in
loop filter design versus acquisition versus jitter.....


Regards, Dana.
 
Last edited:

Depending on the task you could do as an interrupt so everthing triggers off the same event. And the event would be to toggle the line
 

Hi,

Yes.
That´s basically what I recommend. Just with two (minor) differences.
* I´d use the PWM of the other uC, so I don´t need an extra pin/signal/event.
* I´d use the capture periferal, because it is even more accurate than the interrupt method.

So for sure you could use an extra signal and the interrupt method as long as it meets your requirements.
Btw: Still missing the timing requirement.



Klaus
 

Hi,

@danadakk:
The OP already knows/expects that the PWM are out of sync. So, no need to test this.

And this is the reason why the OP asks for a "synchronizer".

But also in post#1 the OP tells that both PICs share a common system clock.
So the system clock should be fairly aligned. I even expect this with a locked PLL.

And again: if the PLL loses it´s lock, then the synchronizer need do it´s job.

Klaus
--- Updated ---

Hi,

@OP:
In post#1 you ask about synchronizing the PWM of different PICs.
My answer: Yes, but with minor timing errors. I asked for the tolerance, but still no information.

Now you ask to synchronize two PICs.
Here I have to say: No. You won´t be able to "code synchronize" them.

Klaus
Hi Klaus

The question I had in mind was simply "How do I synchronise PWMs on separate PICs ?".

Now, I look at the thread's title and it does not say that - I do not know why I typed a misleading title... apologies.


However, the wider question mentioned (actual code synchronisation) might have some use-cases. I can imagine some (perhaps assembler) generic routine sync_function(fn_ptr). What happens then, even if this is possible, is that sync is soon lost if outside conditions make the same code branch differently.


My understanding of Dana's post was that (assuming the PWMs never need their characteristics altering): One PIC has a PWM with duty A, the other has duty B, the period of both PWM match.

Therefore, (if) the PICs (somehow) execute instructions in 'lockstep', right from reset, the PWM will be in synch.
 

Hi,
It's post#20 now...
However, the wider question mentioned (actual code synchronisation) might have some use-cases
In post#15 I said "no" to code synchronisation. Please read through the posts/ideas of the others.

Klaus
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top