Go Down

Topic: Half-Bridge PWM (Read 2217 times) previous topic - next topic



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

Code: [Select]

#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,


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 http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.


Apr 02, 2013, 01:53 am Last Edit: Apr 02, 2013, 02:06 am by Erdin Reason: 1
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, http://www.righto.com/2009/07/secrets-of-arduino-pwm.html 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?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up