Two 20kHz phase shifted PWM

I wan to generate two PWM signals of 20kHz and 50 %duty cycle. There should be a controllable phase shift or delay between them.I am using arduino nano.
I am attaching a pic of the required signals for better explanation.
Any help is much appreciated.
Pwm.pdf (152.1 KB)

Use a timer in CTC mode. Perhaps the TimerOne library may be helpful, else direct timer register manipulation will be required.

I have used the timer but with that I am able to get two overlapping outputs. There is no phase difference between the two. However i require some delay between the two signals. Both delay(), and delayMicroseconds() functions are not working.

In CTC mode you can set OCRA/B to the turn points of the output signals. Use ICR to determine the signal frequency.

Set the CTC frequency to 40 kHz and set the Compare Output Mode to toggle on compare match. Then set the A and B Output Compare Registers (OCR1A and OCR1B) to different values. They will toggle at 50% duty cycle with a phase difference.

1 Like

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