Upload
caden
View
28
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Lab 5 EGR 262 – Fundamental Circuits Lab. EGR 262 Fundamental Circuits Lab Presentation for Lab #5 Pulse Width Modulation. Instructor: Paul Gordy Office: H-115 Phone: 822-7175 Email: [email protected]. Lab 5 EGR 262 – Fundamental Circuits Lab. v(t). V. t. 2T. 3T. T. - PowerPoint PPT Presentation
Citation preview
Instructor: Paul GordyOffice: H-115Phone: 822-7175Email: [email protected]
EGR 262Fundamental Circuits Lab
Presentation for Lab #5Pulse Width Modulation
1Lab 5 EGR 262 – Fundamental Circuits Lab
Pulse Width ModulationA periodic waveform can be described by v(t) = v(t + T) for some positive value of T, called the period of the waveform. The pulse waveform below is a periodic waveform with period T. The frequency, f, of the waveform is 1/T. T is measured in seconds and f is measured in Hertz.
0 TH T 2T 3T
V
v(t)
t
A pulse-width modulated (PWM) signal is one where TH can vary. The duty cycle, D, of the waveform is defined below. D is usually expressed as a percentage. VAVG or VDC is the average or DC value of the waveform.
TT D H
T1 f
2Lab 5 EGR 262 – Fundamental Circuits Lab
DV V V DCAVG
Examples: Determine the period, frequency, duty cycle, and average value of each waveform below.
T = ____________F = ____________D = ____________VDC = ____________0 2 4 8
5V
v(t)
t (ms)6 10
0 4 20 40
5V
v(t)
t (us)24 44
0 65 80 160
5V
v(t)
t (ns)145 205
3Lab 5 EGR 262 – Fundamental Circuits Lab
T = ____________F = ____________D = ____________VDC = ____________
T = ____________F = ____________D = ____________VDC = ____________
Applications: Pulse-width modulated signals are used in many applications. A few are listed below. Many devices essentially respond to the average value of the waveform.
Motor control. Motor speeds up or slows down as pulse width (or duty cycle) changes.
V
v(t)
t
Motor turns fast
V
v(t)
t
Motor turns slow
Microwave Oven. The microwave is essentially turned on and off as the power setting is changed.
4Lab 5 EGR 262 – Fundamental Circuits Lab
V
t
80% power setting
V
v(t)
t
20% power setting (defrost)
v(t)
Servo control. A servo is a combination motor & gear box where the motor position can turn 0 to 180 degrees (typically) as pulse width varies. Servos are used for steering RC cars.
V
v(t)
t
Turn Left
V
v(t)
t
Turn Right
V
t
Capacitor charges to larger analog voltage
V
v(t)
t
Capacitor charges to smaller analog voltage
v(t)
Digital-to-Analog Converter. In Lab 6 we will improve on the DAC built earlier using an R-2R ladder network by using the PWM signal to charge a capacitor to the desired analog voltage.
5Lab 5 EGR 262 – Fundamental Circuits Lab
Generating a PWM signal using the Arduino UNOPWM signals can be generated using the analogWrite( ) command:• form: analogWrite(pin, value)• Available on digital outputs 3,5,6,9,10,11 (note the ~ symbol on the UNO
below)• 0V to 5V square wave has duty cycle based on value• value varies from 0 (off) to 255 (on)• Uses set frequency of approximately 490 Hz• It is not necessary to use pinMode( ) to specify a pin as an output when it will
be used with analogWrite( )• PWM waveform will be maintained until the next occurrance of
analogWrite( ), digitalWrite( ), or digitalRead( ).• The analog value is the average
value or DC value of the waveform
6Lab 5 EGR 262 – Fundamental Circuits Lab
DCAVG V V valueanalog
Example: Create a PWM signal on D11 with a 25% duty cycle.
7Lab 5 EGR 262 – Fundamental Circuits Lab
ArduinoUNO
D11
0 0.51 2.04 4.08
5V
v(t)
t (ms)2.55 4.62
0VVDC = 1.255 V
V 1.255 (5V)(D) V Vms 0.512 ms) 04(0.251)(2. TD T so
, TT D
25.1%)(or 0.251 25564 D
ms 2.04 4901
f1 T
Hz 490 f
DCAVG
H
H
Example: (continued) The sketch on the previous slide was compiled and uploaded to an Arduino UNO in lab. The output on D11 was observed using an oscilloscope. The values shown are very close to the expected results.
8Lab 5 EGR 262 – Fundamental Circuits Lab
f = 489.234 Hz
VDC = 1.29 V
1V/div so waveform is 0V to 5V
5 V
0 V
T = 2.044 ms
Ground (0V) for CH1
Example: (continued) The duty cycle, D, can be measured on another oscilloscope screen using two cursors. The values shown are very close to the expected results.
9Lab 5 EGR 262 – Fundamental Circuits Lab
Input to program: value = 64D predicted by program: 25.1%D observed on oscilloscope:D = TH/T*100% D = 500us/2.044ms*100D = 24.46%
Cursor 1 Cursor 2
Delta = Cursor 2 – Cursor 1= TH = 800.0 us
f = 489.234 HzT = 1/f = 2.044 ms
Suppose that we wanted the user to enter the value for a PWM signal (from 0 to 255)? It is useful to begin with a little background on reading and writing using serial communication.
10Lab 5 EGR 262 – Fundamental Circuits Lab
Serial Communication using the Arduino UNOSerial communication is used by the Arduino UNO to communicate with the computer and other devices.• Serial communication uses pins D0 (RX or Receive)
and D1 (TX or Transmit).• Serial communication takes place at a rate of 9600
baud (bits per second). The following command should be included in setup( ):
Serial.begin(9600);• Serial communication takes place via the USB cable
and requires no additional wiring.• The Arduino software has a built-in monitor for
displaying information sent to or from the computer.• Serial communication is also used when you compile
and upload a sketch to the Arduino UNO.
11Lab 5 EGR 262 – Fundamental Circuits LabSerial Communication (continued)Data is transmitted one byte (8 bits) at a time using serial communication. When a key is pressed on a keyboard, an 8-bit ASCII code is transmitted. The ASCII code for letter A is 010000012 = 4116 = 6510
If you enter the characters ABC on the keyboard, 3 bytes of information are transmitted to the Arduino UNO as illustrated below.
01000011 01000010 01000001
C B A
USB cable
12Lab 5 EGR 262 – Fundamental Circuits LabSerial Communication (continued)Several useful functions that work with Serial are:• Serial.write(x); // writes character corresponding to the ASCII code so the
argument should be from 0 to 255• Serial.print(x); // displays the corresponding symbol(s) based on the ASCII
value• Serial.println(x); // similar to print( ) but advances to the next line• Serial.print(“Text”); // displays the exact text shown in double quotes• Serial.write(“Text\n”); // same as the line above• \n and \t can be used within text for tabs and newlines, respectively
Some of these functions may not work as you would expect, so examples are shown on the following slide.
Example using Serial.print( ) and Serial.write( ):13Lab 5 EGR 262 – Fundamental Circuits Lab
Notes:• Serial.write( ) only worked correctly when the argument was text or a value
between 0 and 255. Using a floating point argument yields a compiler error.• Serial.print( ) worked correctly for text or numerical values, but rounds off
floating point values to 2 digits after the decimal point.
14Lab 5 EGR 262 – Fundamental Circuits LabSerial Communication (continued)Additional useful functions that work with Serial are:• Serial.available( ); // Used to check for input values from keyboard• Serial.read( ); // used to read one byte of information. The function returns
this value.• Serial.parseInt( ); // used to read an integer number (1 or more digits)• Serial.parseFloat( ); // used to read a floating-point number (1 or more
digits)
Some of these functions may not work as you would expect, so examples are shown on the following slide.
Example using Serial.available( ), read( ), write( ) and print( ):15Lab 5 EGR 262 – Fundamental Circuits Lab
Note: When 3 was entered on the keyboard, the ASCII code (001100112 or 5110 ) was read.
Enter inputs here and then click Send or press Enter
Let’s repeat the last example using a multiple digit input:16Lab 5 EGR 262 – Fundamental Circuits Lab
Notes:• When 345 was entered on the keyboard, each digit was read separately, so 3
different integers were read. We could try to build the number 345 from these digits (for example, int N = 3*100 + 4*10 + 5), but this is a lot of work.
• A better solution: Use the parseInt( ) function•
Let’s repeat the last example using a multiple digit input:17Lab 5 EGR 262 – Fundamental Circuits Lab
Note:• Much better. Serial.parseInt( ) allows us to correctly read an integer input
from the keyboard.
Example: Create a PWM signal where the value (from 0 to 255) can be entered by the user to set the duty cycle.
18Lab 5 EGR 262 – Fundamental Circuits Lab
Now let’s return to our earlier topic of PWM. Recall that we wanted to enter the width of the pulse. We now know how to do it using parseInt( ).
If pin D11 was connected to an oscilloscope, we would see the waveform change every time a new value was entered.
Digital to Analog Conversion:Note that a PWM signal has a digital input (0 to 255) and has an analog output (or DC value), so it is essentially a Digital to Analog Converter (DAC).However, the output has a large ripple voltage, VR, which is not suitable for some applications.Example: An illustration is shown below for the last program (with value = 64):
19Lab 5 EGR 262 – Fundamental Circuits Lab
0 0.51 2.04 4.08
5V
v(t)
t (ms)2.55 4.62
0VVDC = 1.255 V
ArduinoUNO
D11Digital Input= 6410
= 010000002
Analog Output= 1.255 VDC
(with VR = 5V or 398% )398% 100
1.2555 V
100%VV Vor
5V 0V - 5V VV - V V
R
DC
RR
R
minmaxR
Looking ahead to Lab 6In Lab 6 we will add an RC circuit to a PWM output and will be able to reduce the ripple significantly (we will design it for 10% max ripple voltage).
20Lab 5 EGR 262 – Fundamental Circuits Lab Arduino
UNO
D12
D11
D13 V0 = analog output2R
2R
2R
R
R
2R
ArduinoUNO
D11
V0 = analog output (PWM)
t
ArduinoUNO
D11V0 = analog output (PWM)
t
R
C
Lab 4: 3-bit R-2R DAC – only 8 analog values, but VR = 0
Lab 5: 6-bit DAC – 256 analog values, but VR = 5V (or hundreds of percent in some cases)
Lab 6: 6-bit DAC – 256 analog values with VR = 10% max
Lab 4
Lab 5
Lab 6