1

How to produce 6 PWM signals with 60 degrees phase shift using Arduino Uno 6 PWM pins like in the image below?

enter image description here

2
  • What duty cycle? 50%?
    – Gerben
    Dec 16, 2017 at 20:02
  • You could also use a timer interrupt, that will bitbang PWM. Kind of similarly to how the servo library send "PWM" signals to multiple servos.
    – Gerben
    Dec 16, 2017 at 20:06

3 Answers 3

2

Using hardware it's not possible. Simply because you effectively only have three PWM timer units, each with two compare outputs.

That means you have three timebases, which are each compared with two values for two PWM signals each.

You would need a single master timebase with six independent offsettable counters with comparison for your needs.

It would be possible to (roughly) do it in software, though, depending on your needs. You get jitter from software generated PWM, due to interrupts getting in the way of your smooth execution. However you have complete control over how the waveform is generated. Instead of a 0-X duty cycle you could program it to have an X-Y duty cycle. And with all of them taken from the same counter value it's then all synchronised 100%.

5
  • Can I make the 3 timers begin counting at the same time? Dec 16, 2017 at 20:00
  • Not precisely, no. There is no way of starting them in the same instance. You could do it close together though. It wouldn't give you different phases then though.
    – Majenko
    Dec 16, 2017 at 20:02
  • 2
    You can invert one of the two PWM outputs.
    – Gerben
    Dec 16, 2017 at 20:03
  • You'd have to setup the timers with appropriate TCNTx values before starting them at the same time.
    – Gerben
    Dec 16, 2017 at 20:04
  • 1
    You can start the three timers at the same time by using the “Timer/Counter Synchronization Mode”. See the description of the GTCCR (General Timer/Counter Control Register) in the datasheet. Dec 16, 2017 at 22:35
3

I found the correct method for 6-phase PWM as the OP requested. And it can have any duty-cycle you want. My erroneous findings for 50% only duty we're because I used Fast-PWM mode. When I switched to Phase-PWM (mode-10-PWM in a 2560 ARduino), I got the correct waveforms, the same as the OP wanted.

Below is a link to a logic-analyzer snapshot showing the 6-phases from a 2560. The frequency is 500 Hz but that's easy to change. 4 Timers in all used to realize this outcome. 3 Timers used mode-10-PWM, 1 mode-14-PWM at the same frequency.

The full project is documented at Runtime Micro.

enter image description here

EDIT: I can now do this using an Uno. But there are limitations to duty-cycle and some other concerns. Provides usable N-channel (2, 3, 4, 5, and 6) phase-shift PWM from a single Uno board.

EDIT: A full 6-channel PSPWM solution using only an Uno is now published at Runtime Micro under Projects Menu. You'll find details, images, code and diagram. There are limitations such as no channel-to-channel overlap in pulse-width.

FWIW

1
  • Are you able to share your code so others can follow your method?
    – RowanP
    Sep 11, 2022 at 12:40
0

Use a timer to trigger an interrupt. Set the timer to 1/6 of the overall pwm cycle to get to 60degree phase. Each time the interrupt is triggered it turns on the next channel.

You could have a second timer and interrupt to turn them off working in the same manner.

Not the answer you're looking for? Browse other questions tagged or ask your own question.