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

  • What duty cycle? 50%? – Gerben Dec 16 '17 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 '17 at 20:06

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%.

  • Can I make the 3 timers begin counting at the same time? – Ahmad Naoum Dec 16 '17 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 '17 at 20:02
  • 2
    You can invert one of the two PWM outputs. – Gerben Dec 16 '17 at 20:03
  • You'd have to setup the timers with appropriate TCNTx values before starting them at the same time. – Gerben Dec 16 '17 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. – Edgar Bonet Dec 16 '17 at 22:35

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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