Two PWM Signals on pins 9 and 10 with input on A1. Signals Need to Be 180 degrees apart

Take a look at your figures in #1 -- there needs to be 4 transitions, all at different times. If you think of how to schedule those, it's relatively complicated, unless you are measuring outwards from the center of one of the pulses. Measuring outwards from the center is what you get from one of the phase-correct PWM modes. They count up and then back down so you need only set the distance from centers of the pulses.

The trick in this bit of the #17 code sets the duty cycle for one pin (e.g. HIGH for 60% of ICR1) , and the complimentary duty cycle for the inverted pin (100%-60%=40%) of the inverted pin makes the other pin LOW for the 40% around the center of the first pin (i.e. HIGH for 60%, 180° out of phase of the first pin.)

Keeping those edges coordinated with varying duty cycles across two timers using a non-phase-correct PWM mode would be awkward because you'd have to juggle three variables: OCR1A, OCR2A, to control the pulse widths, and the offset between the TCNT1 and TCNT2 counters to control the phase shift between the two pulse chains.

I have the code working.
Its running at 31.8kHz on pins 9 and 10. I used the code from post 8 and added the input for the pot on A0 from post 17. Also added an LCD display to show what the duty cycle is on the LCD. Have included screen shots from my scope for 30% and 60%.
Thanks for everyone’s help.


1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.