Advertisement

Creating an Interleaved PWM Generator With an Arduino

Pulse-width modulation (PWM) is the ground for control in power electronics. The vast majority of semiconductor power devices in power electronic circuits are controlled by pulse-width modulation signals of various forms. The fast rising and falling edges of the pulse-width modulation pulses ensure that the power semiconductor devices are turned on/off as quickly as possible to minimize the switching transition time and the associated switching losses. Pulse-width modulation can take different forms. Here is a practical introduction to the “Interleaved Pulse-width Modulation” technique widely used in power electronics!

 

Interleaved PWM

When multiple PWM converters are connected in series (or in parallel) in a power electronics circuit, it is appropriate to run all converters at the same frequency but with certain phase shift among their PWM signals. This “interleaved” trick is very useful in many different applications, such as charge pump gate drivers, buck/boost power converters, H-bridge controllers, etc. Because there is an abundance of authentic information on this topic, I didn’t dive too deep here.

 

Arduino PWM

As you may know, two PWM outputs of Arduino Uno are linked to the timers. For the “common” PWM, if we write a value from 0 to 255 on a PWM pin, the Arduino library will drive the assigned pin to output a PWM signal whose on time is in proportion to the written value. Because Arduino uses 8 bits to represent analog data, it can represent this data in decimal notation using any number between zero and 2^8 that is from 0 to 255, where 0 is zero volts and 255 is 5 volts. For example, if you write analogWrite(3, 255/2), the result is a square wave on pin 3 whose width was divided by 2. The full width will produce 5 volts, so this wave will produce 2.5 volts. Take note: Arduino has its own set default values of modulation frequency for its PWM pins. For pins 3, 9, 10, and 11, it is approximately 488 Hz, and for pins 5 and 6, it is about 977 Hz. Though these are for Arduino running at default 16 MHz, we can change it easily by writing new values to the appropriate timer register.

 

The Atmega 328P chip in the Arduino Uno has three PWM timers (known as Timer 0, Timer 1, and Timer 2) controlling six PWM outputs. Each of the timers has a prescaler that generates the timer clock by dividing the system clock with a prescale factor such as 1, 8, 64, 256, or 1024 (here, the system clock is 16 MHz; hence, the timer clock frequency will be the system clock frequency divided by the prescale factor). Another noteworthy fact is that Timer 1 is a 16-bit timer and has additional modes, and Timer 2 has a different set of prescale values from the other timers. Consult the Atmega 328P datasheet for more details.

 

Demo Project DIY

Recently, while preparing a hands-on review article, I needed an interleaved PWM signal for the road test of a test-and-measurement instrument and got hold of an Arduino Uno microcontroller for that purpose. But it wasn’t the quick fix that I thought it would be. After doing some search for a workable idea, I finally got a quick solution that’s just as brilliant. If we set up the initial value of Timer 1 counter register (TCNT1) to one-half of its full value (half of 2^16), it’s easy to get out of phase pulse-width modulation!

 

Because the main focus of this demo project is to have a clear perception of the system (and build up some experience for more innovative projects), the hardware setup consists of nothing other than an Arduino Uno loaded with the demo code (sketch). You can power it from USB or from an external 9-V DC adapter, as usual. In the code, pin 9 (D9) of Arduino is configured as the first output channel, and pin 11 (D11) is the second one. Here is the demo code (also see my code window):

 

 

/* Arduino-Based Interleaved PWM Generator

Demo Hardware: Arduino Uno R3

Prepared & Tested by: T.K.Hareendran

*/

 

int PWM1 = 0; // PWM channel 1 width

int PWM2 = 0; // PWM channel 2 width

void setup() {

TCNT1 = 0x7FFF; //Set Timer1 Counter Register to 32767 (1/2 of maximum value 2^16)

pinMode(9, OUTPUT); // Set Pin 9 to pwm channel 1 output

pinMode(11, OUTPUT); // Set Pin 11 to pwm channel 2 output

}

void loop() {

delay(500); //500ms delay

analogWrite(9, PWM1); // Write PWM1 value to channel 1

analogWrite(11, PWM2); // Write PWM2 value to channel 2

PWM1++; // Increment PWM1

PWM2++; // Increment PWM2

}

Code Download

Debug Hints

An oscilloscope is very handy for debugging PWM if you have access to one. Shown below is a random scope plot of the output, captured by the connected Xprotolab Plain breadboard oscilloscope. If you don’t have one, just for a basic test, you can connect two LEDs (with 1K current limiting resistors) to the output pins (D9 and D11). A quick video with a test LED connected to one output (D9) is also included here. Watch the video!

 

 

To sum it up, multiple PWM converters can be connected in parallel or in series to form a modular design with scalable current or voltage capacities. In such modular systems, interleaving pulse-width modulation techniques are efficient at minimizing the input/output ripples/harmonics and increasing the power output of boost converters operating in critical conduction mode. If you’re unfamiliar with interleaved pulse-width modulation, you can do only a few things in the power electronics world. So you should learn enough to make the art go, and there are many ways to improve your skills. I hope this little guide helps some of you out there!  Now that you have learned about this technique, what will you make with it?  Let us know in the comments below!

4 Comments

Join the conversation!

Error! Please fill all fields.
  • T.K.Hareendran

    Micro BLDC motor driver for submarine project; really interesting! Recently I looked up Micro-Beam’s page (http://www.microbeam.ch/index.php/products-services/3-brushless-dc-motor-driver), and glued to some design ideas.

  • Adam Carlson

    Thanks for posting this. T.K. do you happen to have any projects that you are planning on using this in?

    • Adam Carlson

      I have found some really great posts a while back on dynamic system response to an H-bridge. I will have to see if I can find them. I have been wanting to design a micro BLDC motor driver for quite a while for my submarine projects. I have a custom motor design that I am working right now that it would be useful for.

    • T.K.Hareendran

      Now I’m experimenting with an H-bridge controller based on the same concept. Hope I can share more details within 2 weeks (waiting for the arrival of some power semiconductors). Thank You!

Looking for the latest from TI?