Double PWM signals with High frequency

Dear all in arduino.cc
I want to make an interleaved dc/dc boost converter. The interleaved boost converter needs a square pulses each one have the same duty cycle but each one is shifted about half of the conduction period like this (check the attachments):

The used frequency is 20000 HZ . I used arduino to get the pulses but only single pulse as in the program below:

#include <PWM.h>
int32_t frequency = 20000; // frequency in hertz
void setup()
{
InitTimersSafe ();
bool success = SetPinFrequencySafe (9,frequency);
if (success) {
pinMode (9, OUTPUT); // connect the output pin at pin 10
digitalWrite (9, HIGH);
}
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead (A1);
pwmWrite (9, sensorValue/4);
delay (30);
}

The used library is gotten from the links:
http://forum.arduino.cc/index.php?topic=117425.0
and
https://code.google.com/archive/p/arduino-pwm-frequency-library/downloads

by changing potentiometer the pulse width is changed. I am using arduino UNO where the library is changing the frequency only for pins 9 and 10. Now I know how to change the frequency at pin 9 for signal No.1 as shown in the picture, but how to make another signal in pin 10 and shifted around half the frequency period of the first one. I hope that you can understand the matter and find a solutions to me. Thank you.

d

Capture.JPG

please see the attached picture

If you want multiple PWM outputs, you need multiple analogWrite() calls with each call addressed to different PWM pins. Is that what you are asking? You question/explanation is very difficult to follow.

If you could get the Arduino to output 40KHz you run the signal to a D flip-flop set up as a divide-by-2 which would bring it back down to a 20KHz square wave.

You need to program one of the counters to have one pin inverted, then you can do this trick
(setting analogWrite to the same value then gives you antiphase, to slightly different values gives
slight gaps or slight overlap depending on the sense of the difference). You have to use a phase
correct mode for this to work.

Time to read the timer section(s) of the datasheet.

Thanks for all replies...

I will extend the ideas from MarKT & Power_Broker theI will reply to you but I have made this code :

#include <PWM.h>
int32_t frequency = 25000; // frequency in hertz

void setup()
{
InitTimersSafe ();
bool success = SetPinFrequencySafe (9,frequency);
if (success) {
pinMode (9, OUTPUT); // connect the output pin at pin 10
digitalWrite (9, HIGH);
digitalWrite (10, HIGH);
}

}

void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead (A1);
pwmWrite (9, sensorValue/4);
int sensorValue1 = analogRead (A0);
pwmWrite (10, sensorValue1/6); // change the duty cycle ratio
delay (30);

}

I am still using one potentiometer and got 2 different duty cycles of 2 signals at same frequency. I did not get my aim but I will try . Please if any one can give good idea or nice code I will be thankful to him.

Hi,

Not only are you trying to change the duty cycles. You are also trying to change the width of the signal when it is high and low. I am not sure that PWM can do that.

Is 20KHz the the maximum frequency that you want to achieve?

If so, you could generate your pulses yourself (without PWM) using the Blink Without Delay technique.

Of course, if you are doing something else in the background, you might not fire the signal very acurately.

Jacques

Dear Sir , thanks for reply

By the used library the frequency can be changed more than 20 KHZ. I need the PWM because of regulation techniques later. I need to give fire signals to 2 transistors where each signal have the same frequency and duty cycles but shifted around half of the frequency period to each other.

Maybe you could fire PWM on pin 9, use delayMicroseconds(), and then fire PWM on pin 10.

At this point, I have no other idea.

Jacques

Have a look at Tone. You could set it for 40KHz and drive two divide-by-2 flip-flops. Drive one on the rising edge of 40KHz, the other on the falling edge of 40KHz.

thanks dougp :slight_smile:

I will try it and tell you

I have a same problem on arduino nano, i use PWM frequency library for 20Khz and use pwmWrite (9, val1), bute when use analogWrite(10, val2), both generate 20khz pwm and duty cycle is correct. But I'm not sure if it's reliable.

What do you mean about your correct pwm? Can you please show what is the modification that you have did?

You are going to have to search long and hard to find a library that does exactly what you want. I expect you will find something close but it will need deep modifications to do exactly what you want.

The reason is that the hardware is capable of doing what you want with only a few lines of code but it's such a rare requirement for Arduino experimenters that nobody has written the library to make it easy.

Read the section of the datasheet that talks about phase-correct PWM. It will take many re-readings to understand even 10% of what is there.

waw! you gave me weak hope!

jbellavance:
Hi,

Not only are you trying to change the duty cycles. You are also trying to change the width of the signal when it is high and low. I am not sure that PWM can do that.

That's the same thing. duty cycle controls the width of the high and low parts of the waveform (in concert
of course).

Read the datasheet of the IC if you want to find out what it can do, it can do a lot (there are 16 modes
for timer1, for instance).

I need to give fire signals to 2 transistors where each signal have the same frequency and duty cycles but shifted around half of the frequency period to each other.

the interleaved boost converter needs a square pulses each one have the same duty cycle but each one is shifted about half of the conduction period like this (check the attachments):

I am uncertain of your requirements given this image you postedceed47b013404f52377d8cd14c458910e24b6cff.jpg

Can you please attach a hand drawn sketch of what you want? Do you want a deadband between the two pulses?

Check out these two threads for non overlapping complementary pulses
https://forum.arduino.cc/index.php?topic=438667.0
https://forum.arduino.cc/index.php?topic=495249.0

The picture shows two pulse trains with DIFFERENT frequency and DIFFERENT duty-cycle. That is not what is being described. The descriptions seem to call for two identical PWM signals (SAME frequency and SAME duty cycle) that are 180° out of phase (offset by half the PWM period). To do that you will need to use TWO timers. Set them both up to generate the required PWM frequency. Use the GTTCR (General Timer/Counter Control Register) to start them with the required phase difference. They will then run at that phase offset and you can change the duty cycle as needed.