How to generate 3 PWM signals

I have 2560 mega, and I Want to generate 3-phase PWM signal at 62.5khz, synced and shifted 120 degrees apart.

I need that for 3-phase split-coil boost converter (or even isolated flyback converter), with 3 phase transformer coupled inductor. So I dont need sine wave table like here, but actually, a direct square wave PWM output, from 3 synced digital pins, with chosen duty cycle. How can I do that?

• How accurate the phase difference has to be? Is (0°, ±119.53°) good enough? If not, would a frequency of 62.745 kHz be OK? What duty cycle do you want? Apr 29, 2020 at 15:43
• @EdgarBonet Hello. Probably, its better to stick with 2 phase or 4 phase, as it's easier to divide. Oh, and let's omit 2phase case, as it could be solved with h/w inverting (no software phase offset). All I want is a way to set up a phase offset in arduino, and question is about it. Everything other better fits as a topics for ee.se. Consider it is driving a transistors' gates, (no matter what is further), to focus only software question May 2, 2020 at 22:44

1 Answer

If you have any timers left, I would (regardless of the number of PWM signals and if you need different PWM frequencies) just dedicate a timer to do IRQs to manage them.

The frequency of the IRQs would then depend on how accurately you want to control the duty cycle, ref. also to the comment from Edgar Bonet .

• That seems to be nice solution. However, I am not very familiar with low level things of arduino. Can you extend your answer with simple small example, please? It could be as simple as if you given 4 pins: `pin[0,1,2,3]`, and 4 duty cycles: `dc[0,1,2,3]`. Frequency is fixed at 62.5khz (or 31khz, not matters), and pins must provide synced PWM signal, with given dutycycles, and phase offsets of 0, 90, 180 and 270 degrees respectively. Like `for(i=0; i<4; i++) { analogWrite(pin[i], dc[i]); }`, but for synced pins. Can you give such how to sync pins, with fixed phase offsets and frequency?? May 5, 2020 at 5:10
• Wow, hang on. Will try to write more later, but I mean that if e.g. 4 signals 90 degs apart all with 50% duty cycle, one would set a time at 8 times the frequency (not 4 since for a single 50% you need both the "LOW-to-HIGH" and "HIGH-to-LOW".Then depending on the duty cycle resolution/accuracy needs, one needs to increase the IRQ frequency (which above was the base frequency*8). Programming Arduino is like C, so operators like % (don't know the term in English, but I mean e.g. 107%100=7) come handy. May 8, 2020 at 14:34