Basic Pulse Width Modulation



Similar documents
Basic DC Motor Circuits. Living with the Lab Gerald Recktenwald Portland State University

Basic DC Motor Circuits

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

Arduino Lesson 13. DC Motors. Created by Simon Monk

Arduino Motor Shield (L298) Manual

Introduction to Arduino

Arduino project. Arduino board. Serial transmission

Lab 6 Introduction to Serial and Wireless Communication

Pulse Width Modulation (PWM) LED Dimmer Circuit. Using a 555 Timer Chip

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Microcontroller Programming Beginning with Arduino. Charlie Mooney

IR Communication a learn.sparkfun.com tutorial

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

V out. Figure 1: A voltage divider on the left, and potentiometer on the right.

Arduino Lesson 1. Blink

Transistor Characteristics and Single Transistor Amplifier Sept. 8, 1997

CHAPTER 11: Flip Flops

Basic Electronics Prof. Dr. Chitralekha Mahanta Department of Electronics and Communication Engineering Indian Institute of Technology, Guwahati

Transistor Amplifiers

APPLICATION NOTES: Dimming InGaN LED

DIODE CIRCUITS LABORATORY. Fig. 8.1a Fig 8.1b

Experiment 8 : Pulse Width Modulation

Arduino Lesson 14. Servo Motors

Programming Logic controllers

Fundamentals of Signature Analysis

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

DC Motor control Reversing

A Practical Guide to Free Energy Devices

Timer A (0 and 1) and PWM EE3376

Theory of Operation. Figure 1 illustrates a fan motor circuit used in an automobile application. The TPIC kω AREF.

Electronics. Discrete assembly of an operational amplifier as a transistor circuit. LD Physics Leaflets P

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

BJT Characteristics and Amplifiers

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

Pulse Width Modulation

FPAB20BH60B PFC SPM 3 Series for Single-Phase Boost PFC

Lecture 18: Common Emitter Amplifier. Maximum Efficiency of Class A Amplifiers. Transformer Coupled Loads.

13. Diode Rectifiers, Filters, and Power Supplies

Physics 623 Transistor Characteristics and Single Transistor Amplifier Sept. 13, 2006

Electronics 5: Arduino, PWM, Mosfetts and Motors

Lecture - 4 Diode Rectifier Circuits

LABORATORY 10 TIME AVERAGES, RMS VALUES AND THE BRIDGE RECTIFIER. Bridge Rectifier

LAB 7 MOSFET CHARACTERISTICS AND APPLICATIONS

The 2N3393 Bipolar Junction Transistor

Objectives. Electric Current

Pulse Width Modulated (PWM) Drives. AC Drives Using PWM Techniques

The full wave rectifier consists of two diodes and a resister as shown in Figure

Table 1 Comparison of DC, Uni-Polar and Bi-polar Stepper Motors

HIGH VOLTAGE POWER SUPPLY FOR ELECTRO-OPTICS APPLICATIONS

Line Reactors and AC Drives

Bipolar Transistor Amplifiers

Diode Applications. by Kenneth A. Kuhn Sept. 1, This note illustrates some common applications of diodes.

Switch Mode Power Supply Topologies

TRANSISTOR/DIODE TESTER

H-Bridge Motor Control

Application Note AN-1068 reva

Lecture 7: Programming for the Arduino

Pulse Width Modulated (PWM)

RGB LED Strips. Created by lady ada. Last updated on :00:18 PM EST

Adding Heart to Your Technology

Servo Motors (SensorDAQ only) Evaluation copy. Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply

Theory and Practice of Tangible User Interfaces. Thursday Week 2: Digital Input and Output. week. Digital Input and Output. RGB LEDs fade with PWM

Talon and Talon SR User Manual

Controlling a Dot Matrix LED Display with a Microcontroller

LM 358 Op Amp. If you have small signals and need a more useful reading we could amplify it using the op amp, this is commonly used in sensors.

AMZ-FX Guitar effects. (2007) Mosfet Body Diodes. Accessed 22/12/09.

C4DI Arduino tutorial 4 Things beginning with the letter i

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

Considerations When Specifying a DC Power Supply

High voltage power supply (1 to 20 KV)

Lab 5 Operational Amplifiers

ARRL Morse Code Oscillator, How It Works By: Mark Spencer, WA8SME

Arduino Lesson 4. Eight LEDs and a Shift Register

Harmonics and Noise in Photovoltaic (PV) Inverter and the Mitigation Strategies

Transformerless UPS systems and the 9900 By: John Steele, EIT Engineering Manager

GRADE 11A: Physics 5. UNIT 11AP.5 6 hours. Electronic devices. Resources. About this unit. Previous learning. Expectations

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

Theory of Transistors and Other Semiconductor Devices

= V peak 2 = 0.707V peak

mecotron Safety relay ESTOP-2 For emergency stop monitoring

1602 LCD adopts standard 14 pins(no backlight) or 16pins(with backlight) interface, Instruction of each pin interface is as follows:

Transistors. NPN Bipolar Junction Transistor

Arduino Lesson 9. Sensing Light

Programmable Single-/Dual-/Triple- Tone Gong SAE 800

Analog & Digital Electronics Course No: PH-218

Speed Control Methods of Various Types of Speed Control Motors. Kazuya SHIRAHATA

Single-Stage High Power Factor Flyback for LED Lighting

TEA1024/ TEA1124. Zero Voltage Switch with Fixed Ramp. Description. Features. Block Diagram

GENERATOR START CONTROL MODULE - MINI (2 Wire to 3 Wire)

Chapter 4 AC to AC Converters ( AC Controllers and Frequency Converters )

POWER SUPPLY MODEL XP-15. Instruction Manual ELENCO

Digital to Analog Converter. Raghu Tumati

Diode Circuits. Operating in the Reverse Breakdown region. (Zener Diode)

Chapter 4: Pulse Width Modulation

Work with Arduino Hardware

Series AMLDL-Z Up to 1000mA LED Driver

The basic cascode amplifier consists of an input common-emitter (CE) configuration driving an output common-base (CB), as shown above.

EET272 Worksheet Week 9

CONSTRUCTING A VARIABLE POWER SUPPLY UNIT

Transcription:

EAS 199 Fall 211 Basic Pulse Width Modulation Gerald Recktenwald v: September 16, 211 gerry@me.pdx.edu 1 Basic PWM Properties Pulse Width Modulation or PWM is a technique for supplying electrical power to a load that has a relatively slow response. The supply signal consists of a train of voltages pulses such that the width of individual pulses controls the effective voltage level to the load. Both AC and DC signals can be simulated with PWM. In these notes we will describe the use of PWM on an Arduino for controlling LEDs and DC motors. The PWM pulse train acts like a DC signal when devices that receive the signal have an electromechanical response time that is slower than the frequency of the pulses. For a DC motor, the energy storage in the motor windings effectively smooths out the energy bursts delivered by the input pulses so that the motor experiences a lesser or greater electrical power input depending on the widths of the pulses. For an LED, using PWM causes the light to be turned on and off at frequency than our eyes can detect. We simply perceive the light as brighter or dimmer depending on the widths of the pulses in the PWM output. Figure 1 shows a voltage signal comprised of pulses of duration τ o that repeat every units of time. The output of a PWM channel is either V s volts during the pulse or zero volts otherwise. If this signal is supplied as input to a device that has a response time much larger than, the device will experience the signal as an approximately DC input with an effective voltage of V eff = V s τ o (1) The ratio τ o / is called the duty cycle of the square wave pulses. The effective DC voltage supplied to the load is controlled by adjusting the duty cycle. 2 Using PWM on an Arduino An Arduino Uno has 14 digital input/output (I/O) pins 1. Conventional, i.e., not PWM, operation of the digital I/O pins is controlled with the pinmode, digitalread and digitalwrite functions. The pinmode function is used to configure a pin as an input or output. When a digital I/O pin is configured as an input, digitalread reads the state of the pin, which will be either HIGH or LOW. In an Arduino sketch, HIGH is a predefined constant that is evaluated as true in a conditional 1 http://arduino.cc/en/main/arduinoboarduno τ o V s... Figure 1: Nomenclature for definition of PWM duty cycle.

EAS 199 :: Basic PWM Output 2 int PWM_out_pin = 9; // Must be one of 3, 5, 6, 9, 1, or 11 // for Arduino Uno void setup() { pinmode(pwm_out_pin, OUTPUT); void loop() { byte PWM_out_level; PWM_out_level =... // Code logic to set output level analogwrite( PWM_out_pin, PWM_out_level); Listing 1: Skeleton of an Arduino sketch to demonstrate the use of pinmode and analogwrite in controlling PWM output. expression, and is equivalent to a numerical value of 1. Electrically, a value of HIGH means the pin voltage is close to 5 V. Similarly, the constant LOW is interpreted as false in conditional expressions, it is numerically equivalent to, and electrically the pin voltage is. When a digital I/O pin is configured for output, digitalwrite is used to set the pin voltage to HIGH or LOW. On an Arduino Uno, PWM output is possible on digital I/O pins 3, 5, 6, 9, 1 and 11. On these pins the analogwrite function is used to set the duty cycle of a PWM pulse train that operates at approximately 5 Hz 2. Thus, with a frequency f c = 5 Hz, the period is = 1/f c 2 ms. As with conventional digital I/O, the pinmode function must be called first to configure the digital pin for output. The skeleton of a sketch in Listing 1 shows the basic code components for using PWM on an Arduino. Two integer variables, PWM_out_pin and PWM_out_level are used to indicate the pin number and output level respectively. In the setup function, the statement pinmode(pwm_out_pin, OUTPUT); configures the PWM_out_pin for output. The OUTPUT symbol is a constant defined by the Arduino programming tools (the IDE or Integrated Development Environment). The statement analogwrite( PWM_out_pin, PWM_out_level); sets the PWM_out_pin pin to the value of the PWM duty cycle and hence the effective voltage according to Equation (1). The parameter that sets the duty cycle is an 8-bit unsigned integer, i.e., a value in the range PWM_out_level 255. The digital output voltage of an Arduino Uno is either V or 5 V. Thus, in Equation (1), V s = 5 V. The PWM output level specified with the analogwrite is an 8-bit value that corresponds to an effective voltage range of to 5 V. Figure 2 depicts the relationships between the PWM output parameters. The quantities in Figure 2 are linearly related. Thus, PWM_out_level = 255 τ o = 255 V eff V s Remember that the second input to analogwrite is an unsigned 8-bit value, so PWM_out_level should be an byte variable type. Since V s = 5 V always, for routine calculations, we can use the simple formula PWM_out_level = 255 5 V eff (2) 2 See http://www.arduino.cc/en/tutorial/pwm and http://arduino.cc/en/tutorial/secretsofarduinopwm.

EAS 199 :: Basic PWM Output 3 1 1 5V 255 τ o V eff V s V eff PWM_out_level Figure 2: Scaling relationships for PWM parameters. PWM out level is the 8-bit value used as the second parameter to the analogwrite function. Therefore, to supply an effective voltage of 3 V use PWM_out_level = 255 5 3 = 153 3 Implementation Examples We now show how PWM can be applied to two practical situations: controlling the brightness of an LED, and controlling the speed of a DC motor. The Arduino code for both cases is the same. 3.1 Blinking an LED The very first program for most Arduino users is to blink an LED on and off. The wiring diagram for the LED is shown on the left side of Figure 3. The basic blink program is available as blink.pde, and is part of the standard installation of the Arduino Integrated Development Environment (IDE). Make the following menu selections from an open Arduino window File Examples Basics Blink Note that the blink.pde program does not use PWM. 3.2 LED Brightness Blinking an LED involves sending a signal to the LED that is either on or off, true or false, 5V or V. Adjusting the brightness of an LED requires the sending voltage values in the range between V and 5V using the PWM technique described earlier. Example 3.1 Modifying the Blink Program to use PWM Controlling the brightness of an LED with PWM is straightforward. The LED circuit is connected to one of the PWM output pins and the duty cycle for the PWM output is controlled with the analogwrite command. Listing 2 shows two programs for blinking an LED with an Arduino. The program on the left (blink.pde) is a slight variation on the Blink.pde program that comes as a standard part of the Arduino distribution. Blink.pde uses the digitalwrite command to turn an LED on and off. During the on state the digital output pin is supplied with 5V.

EAS 199 :: Basic PWM Output 4 // File: Blink.pde // File: Blink_dim.pde // // // Turns on an LED on for one second, // Turns on an LED on for one second, // then off for one second, repeatedly. // then off for one second, repeatedly. // For digital I/O the brightness is set // Use PWM to control variable level of // to maximum during the "on" phase. // brightness of the "on" phase. // Use pins be, 1,..., 13 for digital I/O // Use pins 3, 5, 6, 9, 1 or 11 for PWM int LED_pin = 11; int LED_pin = 11; // must be in the range <= level <= 255 int level = 2; void setup() { void setup() { pinmode(led_pin, OUTPUT); pinmode(led_pin, OUTPUT); void loop() { void loop() { digitalwrite(led_pin, HIGH); analogwrite(led_pin, level); delay(1); delay(1); digitalwrite(led_pin, LOW); analogwrite(led_pin, ); delay(1); delay(1); Listing 2: Arduino using PWM to control the brightness of an LED. The Blink dim.pde program on the right hand side of Listing 2 uses the analogwrite function to supply a variable voltage level to the LED. Example 3.2 PWM Control of LED Brightness In this example, the brightness of the LED is set to three levels in an endlessly repeating sequence. This allows us to verify that the PWM control of brightness is working as it should. The LED circuit is the same. Digital output 5V Digital output Figure 3: Electrical circuit for the basic blink program on the left, and the transistor-controlled blink program. Note that the program to drive these two circuits can be identical as long as the same digital output pin is used for both circuits.

EAS 199 :: Basic PWM Output 5 // File: LED_three_levels.pde // // Use PWM to control the brightness of an LED // Repeat a pattern of three brightness levels int LED_pin = 11; // must be one of 3, 5, 6, 9, 1 or 11 for PWM void setup() { pinmode(led_pin, OUTPUT); // Initialize pin for output void loop() { int dtwait = 1; // Pause interval, milliseconds int V1=2, V2=22, V3=12; // 8-bit output values for PWM duty cycle analogwrite(led_pin, V1); delay(dtwait); analogwrite(led_pin, V2); delay(dtwait); analogwrite(led_pin, V3); delay(dtwait); Listing 3: Arduino using PWM to control the brightness of an LED. The LED three levels.pde sketch in Listing 3 causes an LED to glow at three different brightess levels specified by the variables V1, V2 and V3. Each level is held for a time interval specified by the dtwait variable. Example 3.3 Transistor-based PWM Control of LED Brightness The Arduino digital output pins can supply a maximum current of 4 ma. In many applications, higher current loads need to be switched. For modestly larger current loads, say up to 1A, simple NPN transistors can be used. For higher currents, MOSFETs or relays are necessary. In this example, the basic principle of using a transistor to switch a load is demonstrated. The load is an LED, which does not need a transistor for switching. The Arduino sketch is the same as in the preceding examples. The only difference is in the electrical circuit, where the PWM output pin is tied to the base of an NPN transistor, as shown in the right half of Figure 3. Continue Writing Here:

EAS 199 :: Basic PWM Output 6 Example 3.4 PWM Control of a DC Motor DC motor circuit: Transistor control; Diode snubber Sketch 3.3 Hardware Limits Each digital output pin of an Arduino Uno can supply no more than 4 ma. To drive modestly higher current loads, the PWM output can be used with a transistor that switches the load. That strategy works with small DC motors. For example, a P2N2222 transistor from ON Semiconductor has a current limit of 6 ma, a factor of 3 higher than a digital pin of an Arduino. Controlling higher power AC or DC loads introduces the potential for electrical hazards, and should not be attempted without substantial experience and abundant safety precautions. A MOSFET (Metal Oxide Field Effect Transistor) device can be used to control DC loads at higher currents. Arduino shields using MOSFET controls can be purchased from Sparkfun 3 or other vendors. One solution for controlling resistive AC loads such as heaters is a product called the Power- SwitchTail, which is available from the manufacturer (http://powerswitchtail.com/) or Adafruit (http://www.adafruit.com/products/268). 3.4 Further Reading The Secrets of Arduino PWM on the official Arduino web site 4 explains some of the low-level details of Arduino PWM, and how to take fine level control over the PWM outputs. 3 See, e.g., the Power Driver Shield http://www.sparkfun.com/products/1618 or the mini FET Shield http: //www.sparkfun.com/products/9627 4 http://arduino.cc/en/tutorial/secretsofarduinopwm +5V Orient the diode so + that the black stripe is at the same voltage as the positive motor motor terminal control pin 33Ω Collector. Connect to negative terminal of motor Base. Connect to motor control pin on Arduino Emitter: Connect to ground Figure 4: Electrical circuit for using PWM to control the speed control of a DC motor.

EAS 199 :: Basic PWM Output 7 3.5 Study Questions 1. What is the effective voltage V eff for V s = 5V and duty cycles of 25 percent, 38 percent, and 64 percent? 2. A small DC motor is connected to digital output pin 7 of an Arduino Uno. What are the Arduino commands to set the effective output voltage to 2V, 3V, and 4.5V? Only write the analogwrite( ) command.