Go Down

Topic: Double PWM signals with High frequency (Read 367 times) previous topic - next topic

MFMFZY

Aug 18, 2017, 11:59 pm Last Edit: Aug 19, 2017, 12:43 am by MFMFZY
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

MFMFZY


Power_Broker

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.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

dougp

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.

MarkT

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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

MFMFZY

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.
 




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.

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

MFMFZY

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.

jbellavance

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

dougp

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.

MFMFZY

thanks dougp  :)

I will try it and tell you

Anarit

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.

MFMFZY

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

MorganS

#13
Aug 23, 2017, 01:03 pm Last Edit: Aug 25, 2017, 01:20 pm by MorganS
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.
"The problem is in the code you didn't post."

MFMFZY


Go Up