Half-Bridge PWM

Greetings,

I am trying, with an Arduino UNO, to generate two PWM signals of 50kHz, 25% of duty cycle and phase shifted at 90º degrees to control and Half-Bridge power converter. I tried to use the TimerOne library and I did successfully generate two PWM signals of 50kHz@25%duty. However, I was not successful in the 90 degrees phase shift. Both PWM generated signals had the same phase. Below are my code so far..

#include "TimerOne.h"

void setup()
{
  pinMode(9, OUTPUT);
  Timer1.initialize(20);         // initialize timer1, and set at 50kHz
  Timer1.pwm(9, 256);         // setup pwm on pin 9, 25% duty cycle
  Timer1.pwm(10, 256);       // setup pwm on pin 9, 25% duty cycle
}

void loop()
{
  // your program here...
}

How I can phase shift the second PWM signal in pin10 to look something like this in the screenshot below? I also tried to mess with the ATMega328 internal registers but nothing so far...

Best regards,
F.Borges

PWM50kHzShifted.png

I think you can get the effect you want by programming timer 1 in phase and frequency correct PWM mode, using register ICR1 to define TOP, and setting one of the outputs to give inverted PWM. See the atmega328p datasheet. Unfortunately, the TimerOne library doesn't give you that degree of control.

Or you could make the pulses in a software.
Have a timer running at 200kHz and make the pwm in a interrupt routine.
You might need some extra hardware, a few latches and gates and the Arduino to provide the 200kHz.
After looking that this, Secrets of Arduino PWM it can perhaps be done like dc42 wrote.

Perhaps set the timer MAX to 3 (use mode 14 and ICR1 = 3), and try OCR1A = 0, OCR1B = 2 and arrange for COM1A and COM1B bits to
be 11 and 10 respectively?