Go Down

Topic: Double PWM with 180 degree phase shifting (Read 1 time) previous topic - next topic

Mowo

I designed  an interleaved boost converter. I could not achieve the dual pwm generation with 180 degree phase shifting.I need a pulse generator at rated frequency= 60kHz , duty cycle=0.58 . I want to use Arduino uno. Can anyone help me to solve this problem?
[I need that wawe form]

wvmarle

What's the problem?
Two output pins and a timer, utilising the two compare interrupts, should quite easily get these waveforms.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Mowo

What's the problem?
Two output pins and a timer, utilising the two compare interrupts, should quite easily get these waveforms.
I dont obtain an code working properly. Can u explain clearly or give code?

wvmarle

This will work best with timer2 (16-bit).

You'll have to calculate a suitable clock divide and the amount of timer ticks for each part of the clock cycle.

Each signal gets its own timer compare interrupt.

Start with low cycle: when interrupt is triggered, set signal high, set compare to last for the high cycle. Next interrupt: set to low, set compare to last for the low cycle.

The second goes the exact same, just time shifted, using the second compare register.

This requires some direct register manipulation; details of which register and so are all in the data sheet. Total sketch can be quite small. The same sketch should be able to run unchanged on an ATtiny (an x4 or x41 - for an x5 it's to be amended as those only have a 8-bit timer).

Otherwise, USD 50 will have it written/tested for you within a few hours.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Henry_Best

#4
Jul 26, 2018, 03:09 pm Last Edit: Jul 26, 2018, 03:10 pm by Henry_Best
This will work best with timer2 (16-bit).

You'll have to calculate a suitable clock divide and the amount of timer ticks for each part of the clock cycle.

Each signal gets its own timer compare interrupt.

Start with low cycle: when interrupt is triggered, set signal high, set compare to last for the high cycle. Next interrupt: set to low, set compare to last for the low cycle.

The second goes the exact same, just time shifted, using the second compare register.

This requires some direct register manipulation; details of which register and so are all in the data sheet. Total sketch can be quite small. The same sketch should be able to run unchanged on an ATtiny (an x4 or x41 - for an x5 it's to be amended as those only have a 8-bit timer).

Otherwise, USD 50 will have it written/tested for you within a few hours.
As the OP wants a 180o phase shift, why not just one output with a TTL inverter to give the second signal?

wvmarle

As the OP wants a 180o phase shift, why not just one output with a TTL inverter to give the second signal?
It's not symmetrical:


Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Mowo

It's not symmetrical:

As the OP wants a 180o phase shift, why not just one output with a TTL inverter to give the second signal?
How can I do it?

wvmarle

I don't see an easy way of doing this in hardware.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

cattledog

Quote
duty cycle=0.58
The image with non overlapping pulses has duty cycle of less than 50%. You can not get 58% with gaps and not overlap.

This code is for two 180 degree phased pulses with gaps between them. It is written for 200KHz with a 125 ns gap between pulses,(47.5% duty cycle) but it will give you the model for how to do this.

 
Code: [Select]

 //Timer1 Mode 10 PWM to ICR1
//Dual pin 200KHz PWM generator
//47.5% duty cycle 125ns dead band between pulses

void setup() {
  pinMode(9, OUTPUT); //output A
  pinMode(10, OUTPUT); //output B

  TCCR1A = 0; //clear timer registers
  TCCR1B = 0;
  TCNT1 = 0;

  //ICR1 and Prescaler sets frequency
  //no prescaler .0625 us per count @ 16Mh
  //80 counts x .0625 = 5 us = 200Khz

  TCCR1B |= _BV(CS10); //no prescaler
  ICR1 = 40;//PWM mode counts up and back down for 80 counts

  OCR1A = 21; //Pin 9 match
  //output A set rising/clear falling
  //Rise at TCNT 21 upslope, High 38 counts, Fall at TCNT 21 downslope
  //47,5% Duty Cycle Pulse centered on TCNT 40. High 38 Low 42
  TCCR1A |= _BV(COM1A1) | _BV(COM1A0); //output A set rising/clear falling

  OCR1B = 19; //Pin 10 match
  //output B clear rising/set falling
  //Fall at TCNT 19 upslope, Low 42, Rise at TCNT 19 downslope
  //47.5% Duty Cycle Pulse centered on TCNT 0. High 38 Low 42
  TCCR1A |= _BV(COM1B1); //output B clear rising/set falling

  TCCR1B |= _BV(WGM13); //PWM mode with ICR1 Mode 10
  TCCR1A |= _BV(WGM11); //WGM13:WGM10 set 1010

}

void loop() {}


wvmarle

I think OP means actually 42% duty cycle (58% low signal) based on the sketch.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up