PWM timing

With two switches being toggled on and off, there are 4 states in which they can be

State Buck Switch Boost Switch

With state 2 being invalid, as it winds up shorting out the inductor.

To prevent state 2 from occurring I am going to ensure the following 3 points

  • Keep both PWM frequencies the same
  • Ensure in software that the duty cycle of switch 1 is greater than switch 2
  • Center align the pwm streams

By maintaining the truth in these statements, it is impossible to enter state 2.

All of my previous PWM experience had been with edge aligned PWM, where all duty cycles start at t=0, however the OC module is capable of emitting pulse streams with any alignment you may desire, they simply turn on when the timer hits the value in one register, and off when it hits the value in another. So as long as those values are surrounding the middle of the cycle it is "center" aligned. Satisfying bullet point 3

When I tried this I had a problem as soon as the "turn off register" was hit, the cycle restarted. Which caused the frequency to be dependent on the duty cycle, breaking bullet point 1. Also when looking at the pulse stream on the scope, it didn't appear to grow and shrink evenly either side of the center.

After banging my head on the wall for about 4 hours, I decided that I needed to take a break and give the facts time to percolate. While writing an email to a friend I had an epiphany! The reason the PWM didn't grow evenly was because the scope was slope triggering on the wave form, and so the second pulse was being displayed some time after the first. I also reasoned that the problem with the varying frequency was maybe due to the OC module running with synchronization set to itself.

As I was not happy with the 'scope display I decided that I would "borrow" an output pin that comes out onto header, and use the 3rd OC module to output a low dutycycle edge aligned stream at the desired frequency (remember I already had this working on different OC modules). This could then be used to trigger the 'scope so that I could see the relevant waveforms.

Using the module like this really highlighted that the frequencies were all over the place. So I re-read the datasheet, the FRM and a bunch of other stuff, and realized that the "turn-off register" was also used as the "end of dutycycle register" in self-sync mode. So I decided that I would use the 3rd pwm as the synchronization for the first 2, and suddenly, I saw output that I wanted and I took the video attached. In the video there are 3 channels, the top one is OC 3, the trigger for the scope, it is not supposed to change. The lower 2 traces are the PWM trains for the 2 switches in the converter. You can hear the clicks from the knob as I turn it, and you can see that the peaks grow and shrink evenly around their center, and their centers stay in the same place relative to each other.

Success! and fortunatly for me, OC 3 can synchronize the other waveforms even when it does not have an output pin assigned so I can return the debugging pin to the serial port under normal circumstances.