Microchip dsPIC33 Start all PWMs at same time

371 views Asked by At

Using dsPIC33CK256MP508 on the Curiosity board.

Trying to run 4 PWM generators in high resolution mode.

I will run them in single cycle mode. Trying to figure out how to kick off all 4 signals at the exact same time, or trigger them from the same event, but I can't understand the rather complex triggering arrangement of this peripheral.

The data sheet shows diagrams that seem to indicate they all operate from the same time base, or at least they all seem to start at the exact same time, but in reality, as each PWM generator is enabled or a cycle is initiated with PGxSTATbits.TRSET, each cycle will kick off in sequence because they are started at different times by sequential commands.

Is there an easy way to do this? Ideally I'd like to write a bit or even drive a pin or something, so that each generator starts at the same time. There can be some latency between the trigger and when they actually start, as long as they start at the same time.

Thank you.

1

There are 1 answers

0
Michaël Roy On BEST ANSWER

You can initialize the values of the counter registers of the different PWM timer/counters so they will start in phase. The actual value depends on the number of instructions between setting the TRSET bits for each timer, and your prescaler options.

First, generate an assembly listing for your module/function, and count clock cycles between firing each PWM timer by hand. This will give you the exact phase difference between your PWM timers.

Once you know exactly the number of cycles of phase difference, adjust the phase of the PWM counters/timers by setting the value of each counter before firing them in sequence.

In other words, you have to count clock cycles and set initial counter values so they all reach ZERO or COMPARE at the same time, once started.