Fig. 1 Test setup using a Microchip 12F683 to demonstrate pulse width modulation.
Pulse Width Modulation Power Control for Microcontrollers
Here we will explore the concept of pulse-width modulation in particular as used by Arduino and Microchip PIC controllers. Our main focus is power control - by varying the "duty cycle" we can control power transfer to any number loads.
Pulse-width modulation (PWM) is a commonly used technique for controlling power made practical by modern electronic power switches. The average value of voltage (and current) fed to the load is controlled by turning the (transistor) switch between supply and load on and off at a fast pace. The longer the (transistor) switch is on compared to the off periods, the higher the power supplied to the load is.
The PWM switching frequency has to be much faster than what would affect the load, which is to say the device that uses the power...
The term duty cycle describes the proportion of 'on' time to the regular interval or 'period' of time; a low duty cycle corresponds to low power, because the power is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.
The main advantage of PWM is that power loss in the switching devices is very low. When a switch is off there is practically no current, and when it is on, there is almost no voltage drop across the switch. Power loss, being the product of voltage and current, is thus in both cases close to zero. PWM works also well with digital controls, which ... can easily set the needed duty cycle.
Fig. 2 LM2674-5.0 switching power regulator schematic.
Switching power supplies for example use a voltage feedback loop to control the output duty cycle. the LM2674-5.0 uses only a few external parts and unlike older series-pass voltage regulators such as a LM7805 efficiency approaches 98 percent.
Fig. 3 Average voltage is proportional to duty cycle.
Pulse Width Modulation with Micro-Controllers
Micro-controllers such as Arduino have no concept of analog voltages - 1s and 0s or HIGH and LOW or GND and Vcc. While it's possible to use software loops to create a PWM output most of the time we employ hardware counters and dividers. Time is something a uPC does understand. Through a low-pass filter we can create an analog voltage from a pulse-width modulated output, other times we use duty to control the average voltage.
Fig. 4 Mircochip PIC PIC12F683 test setup.
This test circuit (Fig. 1) employs a Mircochip PIC PIC12F683 using its analog-to-digital converter (ADC) taking the analog value of a potentiometer converting the 0-5V reading into a 10-bit value from 0-1023. That 10-bit value is sent to pulse-width-modulation module at pin GP2.
That value sets the duty cycle (on time vs. period) of a 250Hz square wave generated by an internal timer. Period = 1/F = 1/250 = 4mSec.
For more on the PIC12F683 see Introduction to PIC12F683 Programming.
The test circuit uses the PIC12F683, to control a the average voltage through an opto-coupler NPN Darlington transistor combination to a 12-volt LED light and 12-volts battery. The opto-coupler serves to isolate the 12-volt circuit from the 5-volt micro-controller circuit.
At this let's look at the output waveform across a LED lamp starting from fully to fully off. The output frequency is 250Hz and the period is 4mSec.
Fig. 6 Pulse width duty cycle 100 percent.
Fig. 7 Pulse width duty cycle 75 percent.
Fig. 8 Pulse width duty cycle 50 percent.
Fig. 9 Pulse width duty cycle 25 percent.
Fig. 10 Pulse width duty cycle 0 percent or off.
That ends this brief introduction to pulse-width modulation. Be sure to see my You Tube video.
- Updated-Added Dec. 2014
- Constant Current Circuits with the LM334
- LM317 Constant Current Source Circuits
- Introduction Hall Effect Switches, Sensors, and Circuits
- Using Ratiometric Hall Effect Sensors
- Pulse Width Modulation Power Control for Microcontrollers
- Introduction to PIC12F683 Programming
- Basic Transistor Driver Circuits for Micro-Controllers
- Opto-Isolated Transistor Drivers for Micro-Controllers
- ULN2003A Darlington Transistor Array with Circuit Examples
- Tutorial Using TIP120 and TIP125 Power Darlington Transistors
- Driving 2N3055-MJ2955 Power Transistors with Darlington Transistors
- Understanding Bipolar Transistor Switches
- N-Channel Power MOSFET Switching Tutorial
- P-Channel Power MOSFET Switch Tutorial
- H-Bridge Motor Control with Power MOSFETS
- More Power MOSFET H-Bridge Circuit Examples
- Build a High Power Transistor H-Bridge Motor Control