200 likes | 505 Views
Lab 4 EGR 262 – Fundamental Circuits Lab. EGR 262 Fundamental Circuits Lab Presentation for Lab #4 Digital to Analog Conversion. Instructor: Paul Gordy Office: H-115 Phone: 822-7175 Email: PGordy@tcc.edu. Lab 4 EGR 262 – Fundamental Circuits Lab. Button switch.
E N D
Lab 4 EGR 262 – Fundamental Circuits Lab EGR 262 Fundamental Circuits Lab Presentation for Lab #4 Digital to Analog Conversion Instructor: Paul Gordy Office: H-115 Phone: 822-7175 Email: PGordy@tcc.edu
Lab 4 EGR 262 – Fundamental Circuits Lab Button switch • Communicating with Digital Devices • Labs performed in this class so far have only used digital inputs and outputs. This means that the microprocessor inputs and outputs are typically 0V and 5V, corresponding to the binary logic values 0 and 1. Working with digital inputs and outputs is relatively easy. • In Lab 3 the Arduino UNO used the following digital inputs and outputs: • Digital input: button switch (5V when pressed, 0V when not pressed) • Digital output: 7-segment display (0V - segment on, 5V - segment off). Arduino UNO +5V 220 +5V D2 D3 D4 D5 D6 D7 D8 D9 a a b c f b 10 k g d e Circuit for Lab 3 e c d f g Digital Input Digital Output
Lab 4 EGR 262 – Fundamental Circuits Lab Communicating with Analog Devices Microprocessors are also often used to communicate with analog devices. Analog devices might use any voltage level (not just 0V and 5V). • Examples of analog inputs: • Infrared sensor input – input voltage varies with the amount of reflected light • Dimmer switch input – the input voltage varies to indicate the desired output • Temperature sensor input – the input voltage is related to the temperature • Read the input voltage from any circuit • Examples of analog outputs: • Motor control – vary the motor speed gradually by changing output voltage • Light intensity control – vary output light intensity gradually by changing output voltage • Volume control – vary the volume of an alarm by gradually changing output voltage • Control the output voltage to any circuit
Lab 4 EGR 262 – Fundamental Circuits Lab Analog Output Microprocessor D/A Converter Digital Output from microprocessor (or Digital Input to D/A Converter) Analog Input A/D Converter Microprocessor Digital Output from A/D Converter (or Digital Input to microprocessor) Digital-to-Analog Conversion In order to control analog outputs, digital outputs must first be converted to analog form using a digital-to-analog converter(or DAC or D/A converter). Analog-to-Digital Conversion In order to read analog inputs, the analog inputs must first be converted to digital form using a an analog-to-digital converter(or ADC or A/D converter).
Lab 4 EGR 262 – Fundamental Circuits Lab ADC and DAC using the Arduino UNO Some microcontrollers, such as the Arduino UNO, have built-in ADCs and DACs. The DAC with the Arduino produces an analog output using Pulse Width Modulation (PWM). PWM is available on 6 of the digital I/O pins. Digital outputs and an external DAC circuit (Lab 4) Analog outputs using PWM (Lab 5) Arduino UNO D13D12 D11 . . . D0 ~D11~D10 ~D9 ~D6 ~D5 ~D3 Arduino UNO Analog Output DAC Circuit 6 available Analog Outputs using PWM Uses some of the 13 available Digital Outputs Similarly, ADC can be performed using external or internal circuits
Lab 4 EGR 262 – Fundamental Circuits Lab Digital-to-Analog Conversion Digital-to-analog converters do not produce all possible analog output voltages, but instead produce a discrete number of analog outputs based on the number of digital inputs. In general, if N = Number of analog levels M = Number of digital inputs (bits) Then N = 2M Examples: A 3-bit D/A converter has 23 = 8 analog levels A 4-bit D/A converter has 24 = 16 analog levels A 5-bit D/A converter has 25 = 32 analog levels A 10-bit D/A converter has 210 = 1024 analog levels Etc An output amplifier is often used with a D/A converter so that the output can be scaled to the desired analog level (such as 0-10V, 0-25V, etc).
Lab 4 EGR 262 – Fundamental Circuits Lab Example: Input = 0011 MSB 0 0 4-bit D/A Converter 6 V 1 1 Digital Input Analog Output Example: 4-bit D/A Converter A 4-bit D/A converter yields 16 analog output levels (or 15 increments between levels). If the output is scaled for the range 0-30V, then the increment between ranges is (30 V)/(15 increments) = 2V. So the resolution of the D/A converter is 2V. The relationship between the binary inputs and the analog output is shown below. The resolution of a D/A converter can also be expressed as a percentage (of the inverse of the number of increments). So for an 8-bit D/A converter: Note: Discuss binary numbers, MSB, LSB
Lab 4 EGR 262 – Fundamental Circuits Lab RF V1 _ R1 Vo V2 + “weighting factor” R2 V3 R3 V4 R4 D/A Converter Circuits There are several methods for performing D/A conversion. Three are listed below: Binary-weighted inputs R-2R ladder network - used in Lab 4 Charging a capacitor using pulse width modulation (PWM) – used in later lab Binary-weighted input D/A converter Recall the inverting summing amplifier introduced in EGR 260 shown below.
Lab 4 EGR 262 – Fundamental Circuits Lab 8R b _ 3 R V o b + 2 2R b 1 4R b 0 8R If binary weighting factorsare chosen corresponding to binary place values, then the desired analog output will be produced. Note that the value of the feedback resistor can be changed to scale the output and an extra op amp could be used to invert (negate) the output. (MSB) (LSB) • Limitations: • This circuit requires many different resistor values. An 8-bit D/A converter would require resistor values of R, 2R, 4R, 8R, 16R, 32R, 64R, and 128R. • The tolerances of the resistors many lead to some inaccuracy.
Lab 4 EGR 262 – Fundamental Circuits Lab 2R b3 _ 2R V o + R b2 2R R b1 2R R b0 2R 2R R-2R Ladder Network Another technique for performing D/A conversion is using an R-2R ladder network. This network only requires two values of resistors (R and 2R) for any number of bits. The R-2R network for a 4-bit D/A converter is shown below. Amplifier for scaling the output to the desired voltage range (optional). If omitted, the range will be 0 - 5V for 0V/5V binary inputs. Analysis of the R-2R Ladder Network The D/A converter can be analyzed using superposition. If we view the circuit as having 4 independent sources (b3, b2, b1, and b0) then we can determine the contribution to each source separately (with the others killed). For cases where multiple bits are high (5V), superposition tells us that we can simply add the contribution due to each bit (source). This technique is illustrated on the following pages.
Lab 4 EGR 262 – Fundamental Circuits Lab A VO 5V C B D A 2R R R 2R R R + 5V _ 2R 2R 2R 2R 0V B 2R R 2R||2R = R 0V C R+R = 2R 2R||2R = R 2R R+R = 2R R 2R||2R = R D 0V R+R = 2R 2R 2R A 2R + 5V _ 2R Case 1: b3 acting alone (short all other inputs) – so b3b2b1b0 = 1000 The circuit with b3 acting alone is shown below on the left. Also note the added node labeling. The circuit may be redrawn as (note the node labeling): Note the equivalent resistance that is seen at various points in the circuit. The circuit may now be redrawn as: Analog output due to b3 alone = 2.5V
Lab 4 EGR 262 – Fundamental Circuits Lab A VO 0V C B D 2R R 2R R R R 5V B + 5V _ 2R A 2R 2R 2R 2R R 0V C R+2R ||(R+ 2R||2R) = 2R 2R R D 0V 2R A B 2R R 2R + 5V _ 2R 2R A 2R + 2.5V _ 2R Case 2: b2 acting alone (short all other inputs) – so b3b2b1b0 = 0100 A) The circuit with b2 acting alone is shown below on the left. B) The circuit may be redrawn as (note the node labeling): C) After replacing the resistive network to the right of node B above with the equivalent resistance 2R, the circuit is redrawn as: D) After two source transformations (or by finding the TEC see by terminal A) the circuit is redrawn as: Analog output due to b2 alone = 1.25V
Lab 4 EGR 262 – Fundamental Circuits Lab Case 3: b1 acting alone (short all other inputs) – so b3b2b1b0 = 0010 Similarly it can be shown (and will be shown as a part of the Pre-Lab work) that: Analog output due to b1 alone = 0.625V Case 4: b0 acting alone (short all other inputs) – so b3b2b1b0 = 0001 Similarly it can be shown (and will be shown as a part of the Pre-Lab work) that: Analog output due to b0 alone = 0.3125V Final Result using Superposition: Superposition indicates that the total output Vo can be determined by the contribution of each input acting along. So if the input is b3b2b1b0 = 1101 then the analog output is 2.5 + 1.25 + 0 + 0.3125 = 4.0625V. The results for all 16 possible input combinations is shown in the following table.
Lab 4 EGR 262 – Fundamental Circuits Lab Results for 4-bit ADC Table of analog output for each digital input
Lab 4 EGR 262 – Fundamental Circuits Lab Analog Output 4.6875 4.3750 4.0625 3.7500 3.4375 3.1250 2.8125 2.5000 2.1875 1.8750 1.5625 1.2500 0.9375 0.6250 0.3125 Digital Input 0.0000 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 “Stair-step” graph illustrating analog outputs versus digital inputs A stairstep graph is commonly used with ADCs and DACs
Lab 4 EGR 262 – Fundamental Circuits Lab Creating a “Stair-step” graph in Excel Column Chart used in Excel – with Gap Width set to zero and columns filled
Lab 4 EGR 262 – Fundamental Circuits Lab b2 D13 b1 Analog Output Arduino UNO D12 D/A Converter b0 D11 Arduino UNO D13 V0= analog output 2R R D12 2R R D11 2R 2R Lab #4: Digital-to-Analog Conversion The primary goal of Lab #4 is to build a 3-bit D/A converter where the Arduino UNO produces the three bit binary (digital) outputs using D13, D12, and D11 (where D13 is the MSB). A block diagram is shown below. The D/A converter will be constructed using an R-2R ladder network. A more detailed diagram is shown below. Note: In lab we will use R = 2.2 k, so 2R = 4.4 k (which can be formed using two 2.2 k resistors in series). So a total of ten 2.2 k resistors will be required.
Lab 4 EGR 262 – Fundamental Circuits Lab Digital pins on the Arduino UNO Recall that the Arduino UNO has 14 digital I/O pins. This sounds like a lot, but we will use all 14 in this lab! The Arduino Mega and Arduino Due each have 54 digital I/O pins. D11-D13: DAC D9-10: Two button switches (increment and decrement) D2-D8: 7-segment display D0-D1: Serial communication with the computer
Lab 4 EGR 262 – Fundamental Circuits Lab 19 Decrement Button Increment Button Lab #4 Schematic Digital Input (Example: 6 = 110 in binary) Arduino UNO +5V 220 +5V D2 D3 D4 D5 D6 D7 D8 D13 D12 D11 D9 a a b 10 k c f b g d +5V e e c d f g D10 V0= Analog Output 4.4k 10 k 2.2k 4.4k 2.2k 4.4k 4.4k