Pages: [1]   Go Down
Author Topic: Half-Bridge PWM  (Read 865 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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,

* PWM50kHzShifted.png (7.15 KB, 320x234 - viewed 29 times.)

United Kingdom
Offline Offline
Tesla Member
Karma: 227
Posts: 6637
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Edison Member
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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, it can perhaps be done like dc42 wrote.
« Last Edit: April 01, 2013, 07:06:55 pm by Erdin » Logged

Online Online
Shannon Member
Karma: 216
Posts: 12545
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: