You are on page 1of 25

School of Engineering

Department of Electrical and Computer Engineering


14:332:223 Principles of Electrical Engineering I Laboratory
Lab Experiment #5

Laboratory objectives:
1. Learn how to work with an oscilloscope
2. Implement a digital-to-analog converter (DAC) based on R-2R resistor ladder, with and
without a buffer.
3. Integrating Arduino with electric circuits
4. Simulate circuits using TinkerCAD

PART A: Tutorials
A.1 Mixed Domain Oscilloscope:
An oscilloscope is an instrument used to display and analyze waveforms of electronic
signals. The device displays a graph of the instantaneous signal voltage (y-axis) as a
function of time (x-axis). Tektronix MDO3024 is the model used in the lab.

Controls dials allow you to adjust the scale of the graph, both vertically and horizontally
and zoom in and out on a signal. An oscilloscope (or scope) is useful for troubleshooting
circuit design, including:
- Determining frequency and amplitude of signals (circuit’s input and output).
- Identifying the shape of a waveform (sine, square, triangle, sawtooth, etc.)
- Quantifying phase differences between two different signals.
1
Scopes help to quickly quantify frequency, amplitude, and other waveform
characteristics. In general, a scope can measure both time-based and voltage-based
characteristics:
- Frequency (f) and period (T): – frequency is defined as the number of times per
second a waveform repeat. And the period is the reciprocal of that (number of
seconds each repeating waveform takes). The maximum frequency a scope can
measure varies, for the model mentioned it is 200 MHz.
- Duty cycle: the percentage of a period that a wave is positive or negative. It is a ratio
that determines how long a signal is “on” versus how long it is “off” during one
period.
- Rise and fall time: the duration it takes a wave to go from a low value to a high
value. Fall time measures reverse direction. These characteristics are important when
considering how fast a circuit can respond to signals.
- Amplitude: a measure of the magnitude of a signal. Can be a peak-to-peak amplitude
(absolute difference between a high and low voltage) or peak amplitude (measures
how high or low a signal is with respect to 0V).
- Maximum/minimum voltage: determine how high and low a circuit voltage gets.
- Average voltage: can calculate the average or mean of a signal.
The Tektronix MDO3024 model includes 4 analog channels, 16 digital channels and can
analyze a frequency range of 9kHz to 200 MHz (spectrum analyzer).
Detail information can be found at: https://www.tek.com/oscilloscope/mdo3000-mixed-
domain-oscilloscope-manual/mdo3000-series-3

2
3
4
5
PART B: Op-Amps and Implementation of Electric Circuit

B.1 Digital-to-Analog Converters (DAC)


A N-bit Digital-to-Analog converter (DAC) is a device that map a set of N-bits binary
number to 2 voltage levels between vmin to vmax based on the following relationship:
𝑣 = ∆𝑣 ∙ 𝑥 (1.1)
( )
where x is a number between 0 and 2 − 1 and ∆𝑣 = ( )
.

In other words, a 4-bit DAC with an output voltage between 0V to 4.5V will have a
( )
∆𝑣 = = 0.3125𝑉 . It will map 16=2 levels {0, 1, 2, 3, …, 14, 15} to voltage
levels {0V,0.3125V,0.625V, …, 4.375V,4.6875V}. Table 1 demonstrates the mapping
for this DAC.
Table 1: 4-bit DAC
Binary Level
MSB LSB Decimal Analog
𝟐𝟑 =8 𝟐𝟐 =4 𝟐𝟏 =2 𝟐𝟎 = 𝟏 Level Output
𝒃𝒊𝒕𝟑 𝒃𝒊𝒕𝟐 𝒃𝒊𝒕𝟏 𝒃𝒊𝒕𝟎 (volts)
0 0 0 0 0 0V
0 0 0 1 1 0.3125 V
0 0 1 0 2 0.625 V
0 0 1 1 3 0.9375 V
0 1 0 0 4 1.25 V
0 1 0 1 5 1.5625 V
0 1 1 0 6 1.875 V
0 1 1 1 7 2.1875 V
1 0 0 0 8 2.5 V
1 0 0 1 9 2.8125 V
1 0 1 0 10 3.125 V
1 0 1 1 11 3.4375 V
1 1 0 0 12 3.75 V
1 1 0 1 13 4.0625 V
1 1 1 0 14 4.375 V
1 1 1 1 15 4.6875 V

This device enables a microcontroller to set a required voltage level with a resolution of
∆𝑣 at 2 levels.

6
B.2 DAC implementation using R-2R resistor ladder
This can be implemented using several methods. One of them is using a R-2R resistor
ladder as shown in Figure 1.

Figure 1: DAC implementation using R-2R resistor ladder.

A microcontroller can use a DAC to generate a desired waveform and drive an external
device such as a speaker. Implementation of a DAC with an op-amp buffer is depicted
in Figure 2.

Figure 2: DAC implementation using R-2R resistor ladder with a buffer at the output.

The buffer stage is acting as a limiter on the current drawn from the microcontroller
digital IOs.

7
B.3 Thevenin Equivalent for DAC
Assuming each one of the digital IOs can be modeled using a voltage source that can be
either at 5V or 0V (GND), it can be shown that the Thevenin Equivalent for the DAC
will result with the circuit shown in Figure 3.

Figure 3: Thevenin equivalent for the DAC in Figure 1 without a buffer.

As digital IOs can be set to either LOW (0V) or HIGH (5V) the minimum for 𝑣 will
be with all bits at LOW and thus 𝑣 = 0𝑉 and the maximum will be when all bits are
at HIGH and thus 𝑣 = 4.6875𝑉. Without the use of an op-amp, the output voltage
will change based on the load while, with a buffer (as seen in Figure 4) the output
voltage, independent of the load, will always be:

𝑣 =𝑉

8
Figure 4: Thevenin equivalent for the DAC in Figure 3 with a buffer.

B.4 Periodic Waveforms


Electrical waveforms are commonly periodic waveforms. These include, among others,
sine waves (AC, Alternating Current, being one of them), square waves, Triangular
waves, and sawtooth wave (see Figure 5). They are all characterized by their:
 Periodic time 𝑇[𝑠𝑒𝑐; 𝑠]: length on time in second it takes a waveform to repeat
itself
 Frequency 𝑓 = [𝐻𝑒𝑟𝑡𝑧; 𝐻𝑧]: number of times a waveform repeats itself within
a time period of one second
 Bias: a biased waveform will have an average over a periodic time that is not
zero. An unbiased waveform will have an average of zero.
 Amplitude: the magnitude of the signal; for unbiased waveforms it |𝑣 |

9
Figure 5: Periodic waveforms.

10
PART C: Pre-Lab

C.1 If we wanted to generate an output:

𝟏 𝟏
Assuming an amplitude 𝑨 = 𝟐𝑽 and 𝑻 = 𝟐𝟎𝒎𝒔 or 𝒇 = = = 𝟎. 𝟎𝟓𝒌𝑯𝒛 = 𝟓𝟎𝑯𝒛
𝑻 𝟐𝟎𝒎𝒔

Find the function values for t between 0 to 19ms in steps of 1ms:

DAC data
t (msec) 𝒗𝑺𝑸𝑹(𝒃𝒊𝒂𝒔𝒆𝒅) Closest decimal Corresponding
value from Table 1 voltage level
[USE in LAB
experiment 2a]
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

11
C.2 If we wanted to generate a sinusoidal output:

𝟏 𝟏
Assuming an amplitude 𝑨 = 𝟐𝑽 and 𝑻 = 𝟐𝟎𝒎𝒔 or 𝒇 = = = 𝟎. 𝟎𝟓𝒌𝑯𝒛 = 𝟓𝟎𝑯𝒛
𝑻 𝟐𝟎𝒎𝒔

Find the function values for t between 0 to 19ms in steps of 1ms:

DAC data
t (msec) 𝒗𝑺𝒊𝒏(𝒃𝒊𝒂𝒔𝒆𝒅) Closest decimal Corresponding
value from Table 1 voltage level
[USE in LAB
experiment 2b]
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

12
PART D: In Lab Experiments

14:332:223 Principles of Electrical Engineering I Laboratory – Fall 2018


Lab Experiment #5
Date of lab experiment: ____________________
Lab section: __________ GROUP (A/B): ______

Team members: ___________________________________________________

Laboratory instruments:
 Power supply: Keithley 2231-30-3
 Digital Multimeter (DMM): Keysight (Agilent) 34461A
 Mixed Domain Oscilloscope: Tektronix MDO3024
 Breadboard/Arduino set
 1k and higher resistors by design
 LM741 op-amp

Experiment # 5.1: Basic DAC Design


Experiment # 5.1: PART A
Wiring Part 1a:
a. Use the circuit in Figure 1 for this experiment:

Note: in both experiment we will be using this basic R-2R resistor ladder-based DAC! In
the next steps we will only add to this basic circuit
b. Choose for all resistors a value of R=10k
13
c. Connect the Arduino and multimeter as follows:

d. Connect BIT0 through BIT3 to either ‘+’ (5V) for HIGH or ‘-‘ (0V) for LOW to measure the
output voltage for Table 2.
e. Measurement recording:
Table 2: implemented 4-bit DAC output voltage measurements
SET Binary Level to:
MSB LSB Decimal Measured
𝟐𝟑 =8 𝟐𝟏 =2 𝟐𝟎 = 𝟏 Level Output Voltage
𝒃𝒊𝒕𝟑 𝒃𝒊𝒕𝟏 𝒃𝒊𝒕𝟎 𝒗𝒐𝒖𝒕 (volts)
0 0 0 0 0
0 0 0 HIGH 1
0 0 HIGH 0 2
0 HIGH 0 0 4
0 HIGH HIGH 0 6
HIGH 0 0 0 8
HIGH 0 HIGH 0 10
HIGH HIGH 0 0 12
HIGH HIGH HIGH 0 14
HIGH HIGH HIGH HIGH 15

14
Experiment # 5.1: PART B
Wiring Part 1b:
 With the R-2R resistor ladder connected as before, connect the four inputs
(𝑏𝑖𝑡 , 𝑏𝑖𝑡 , 𝑏𝑖𝑡 , 𝑏𝑖𝑡 ) to the Arduino digital IOs as follows:
Arduino DAC
D0 𝑏𝑖𝑡
D1 𝑏𝑖𝑡
D2 𝑏𝑖𝑡
D3 𝑏𝑖𝑡

 Connect the DMM and the scope to the DAC output 𝑣 .


 Upload the following software to the Arduino.

Software for Part 1b: you may use the Arduino sketch ‘BareMinimum’ under
File>Examples>01.Basics’ as a starting point or upload the file from a memory stick.
------------------
void setup(){
// RUNs once: LAB 5-part 1a
// we first need to define D0 to D3 as digital outputs
// DDRD: command that sets Port D Data Direction Register-read/write
// its sets Arduino pins 0 to 7 as outputs

15
// equivalent to: pinMode(0,OUTPUT);pinMode(1,OUTPUT); …;pinMode(7,OUTPUT);

DDRD = B11111111;
}

void loop() {
// RUNs repeatedly:
// PORTD is the register for the state of the outputs
// ++ increments the value of a variable by 1

PORTD ++;
// Wait for 1000 millisecond(s)

delay(1000);
}
------------------

 Verify the code and upload it to the Arduino


 NOTE: before downloading the code, please disconnect D0 and D1. Once successful,
reconnect the two IOs.
 The output voltage will be a sawtooth waveform with values similar to the ones in Table 1.
 SCOPE: choose an appropriate time and voltage scales to display the sawtooth waveform.

TA Verification: _____________

 Save an image of the scope to be added later to the post lab report (use either the USB port
with a memory stick or take a picture of the screen).
 What is the period T of the sawtooth waveform?
o T = ______________

16
Experiment # 5.2: DAC with a buffer stage and more

Experiment # 5.2: PART A


Wiring Part 2a:
a. Building on experiment 5.1b, disconnect the Arduino digital IOs D0 and D1 and add the op-
amp buffer stage (marked by the green box) as shown in the schematic below:

b. Connect the DMM, scope and Arduino as follows:

17
 Connect the DMM and the scope to the op-amp output 𝑣 _ .
 Use ±𝟏𝟓𝑽 for the op-amp references. Make sure to connect ALL ground points on the
breadboard.
 Based on the pre-lab, use the values you found for the triangular waveform to set the DAC
output using the following sketch:

Software for Part 2a: you may use the Arduino sketch ‘BareMinimum’ under
File>Examples>01.Basics’ as a starting point or upload the file from a memory stick.
------------------
// Define a data array size= 20
const int size = 20;

// Declare types &


// set the array data: will be used to send data to digital IOs D3-D0
// PLEASE UPDATE the number highlighted in yellow based on pre-lab C.1
// Triangular waveform
// 20 decimal values from pre-lab C.1 will be set here to be sent to the DAC
int mBuffer[size] = {7,8,9,10,12,13,
12,10,9,8,7,5,
4,3,1,0,1,3,4,5};

// initial value for index variable: will be used to read info from mBuffer
int index = 0;

void setup(){
// RUNs once: LAB 5-part 1a
// we first need to define D0 to D3 as digital outputs
// DDRD: command that sets Port D Data Direction Register-read/write
// its sets Arduino pins 0 to 7 as outputs
// equivalent to: pinMode(0,OUTPUT);pinMode(1,OUTPUT); …;pinMode(7,OUTPUT);

DDRD = B11111111;
}

void loop() {
// RUNs repeatedly:
// increment index variable: read next value from mBuffer
index = index+1;

18
// read next value from mBuffer
unsigned char dvolt = mBuffer[index];

// send value (digital data) to PORT D


PORTD = dvolt;

// Wait for 1 millisecond(s)


delay(1);

// Once done going through mBuffer, start again


if (index == size) index=0;
}
------------------

 Verify the code and upload it to the Arduino


 NOTE: before downloading the code, please disconnect D0 and D1. Once successful,
reconnect the two IOs.
 Verify that the output voltage 𝑣 is a triangular waveform with values similar to the
design in pre-lab part C.1.

TA Verification: _____________

 Save an image of the scope to be later added to the post lab report (use either the USB port
with a memory stick or take a picture of the screen).
 What is the period T of the triangular waveform 𝑣 _ ?
o 𝑇 = ______________
 What is the minimum and maximum voltage of the triangular waveform 𝑣 _ ?
o 𝑣 (𝑚𝑎𝑥𝑖𝑚𝑢𝑚) = ______________
o 𝑣 (𝑚𝑖𝑛𝑖𝑚𝑢𝑚) = ______________
o Is it also a triangular waveform? _______________

19
Experiment # 5.2: PART B

Software for Part 2b: update the code in part 2a as follows


------------------
// PLEASE UPDATE the number highlighted in yellow based on pre-lab C.2
// Sinusoidal waveform
// 20 decimal values from pre-lab C.2 will be set here to be sent to the DAC
int mBuffer[size] = { , , , , , , , , , ,
, , , , , , , , , };

------------------

 Verify the code and upload it to the Arduino


 NOTE: before downloading the code, please disconnect D0 and D1. Once successful,
reconnect the two IOs.
 Verify that the output voltage 𝑣 is a sinusoidal waveform with values similar to the
design in pre-lab part C.2.
 Save an image of the scope to be added later to the post lab report (use either the USB port
with a memory stick or take a picture of the screen).
 What is the period T of the sinusoidal waveform 𝑣 _ ?
o 𝑇 = ______________
 What is the minimum and maximum voltage of the sinusoidal waveform 𝑣 _ ?
o 𝑣 (𝑚𝑎𝑥𝑖𝑚𝑢𝑚) = ______________
o 𝑣 (𝑚𝑖𝑛𝑖𝑚𝑢𝑚) = ______________
o Is it also a sinusoidal waveform? _______________

20
Experiment # 5.2: PART C
Using the amplitude values from Table 1 calculate a 10ms period waveform with 𝑨 = 𝟐𝑽 and
𝟏 𝟏
𝑻 = 𝟏𝟎𝒎𝒔 or 𝒇 = = = 𝟎. 𝟏𝒌𝑯𝒛 = 𝟏𝟎𝟎𝑯𝒛
𝑻 𝟏𝟎𝒎𝒔

Find the function values for t between 0 to 9ms in steps of 1ms:

DAC data
t (msec) 𝒗𝑺𝒊𝒏(𝒃𝒊𝒂𝒔𝒆𝒅) Closest decimal Corresponding
value from Table 1 voltage level
0
1
2
3
4
5
6
7
8
9

Wiring for Part 2c:


Add a speaker in series with the 240 resistor you used in part 2a:

21
Speaker supplied:
- A 8 with maximum power of 0.5W. We can limit it by either:
 setting the maximum allowable voltage drop across the speaker to:
𝑣 = 𝑃 ∙𝑅 = 2𝑉 or
 setting the maximum allowable current flowing through the speaker to:
𝑖 = 𝑃 /𝑅 = 0.25𝐴
- It works with sinusoidal signal with frequency in the range of 40Hz-20kHz.

Software for Part 2c: update the code in part 2b as follows


------------------
// PLEASE UPDATE the number highlighted in yellow
// 10 decimal values just calculated above
int size = 10;
int mBuffer[size] = { , , , , , , , , , , };

// at the end of the code try to replace


delay(1);
WITH
delayMicroseconds(50)
//or
delayMicroseconds(60)
------------------

 What is the minimum and maximum voltage of the sinusoidal waveform?


o 𝑣 _ (𝑚𝑎𝑥𝑖𝑚𝑢𝑚) = ______________
o 𝑣 _ (𝑚𝑖𝑛𝑖𝑚𝑢𝑚) = ______________
 Can you hear the speaker?

22
PART E: Post-Lab Report
The lab report should include a filled and signed copy of part D and analysis of the data based
on the following questions and required simulation.

1. Verifying theory:
a. Use superposition and source transformation to show that the Thevenin equivalent for
the DAC in Figure 1 is:

b. Using the Thevenin equivalent for the DAC in Figure 1, find the voltage drop across the
load connected to the DAC output, vload as a function of the D0-D3 voltage levels, R and
the load resistance

c. Using the Thevenin equivalent for the DAC with a buffer in Figure 2, find the voltage
drop across the load connected to the DAC output, vload as a function of the D0-D3
voltage levels, R and the load resistance

23
2. Analysis for experiment 5.1 (show all work for calculations and explain the experimental
results versus calculated ones in each of the relevant sections):
2.1 Compare the values measured for vout in Table 2 with the expected values in Table 1.
How do they compare? explain.
2.2 The digital IOs of an Arduino have an output current of 40mA. How much power can it
deliver at an output voltage of 5V?
2.3 For the DAC, connected to 4 IOs, what is the maximum power that the Arduino can
deliver to the DAC?
2.4 What will be the maximum current the DAC without a buffer can deliver at the output
(Hint: use the Thevenin equivalent) and how does it relate to the short circuit current for
the DAC?

3. Analysis for experiment 5.2 (show all work for calculations and explain the experimental
results versus calculated ones in each of the relevant sections):
3.1 Output short circuit current information for the LM 741 op-amp determines the
maximum current the op-amp can source or sink at the output pin (typically 25mA).

 Assuming we use the DAC with a buffer (as we did) to feed the speaker, what is
the maximum current that will be delivered to the speaker?
 Assuming we use the DAC without the buffer to feed the speaker, what would
be the maximum current delivered to the speaker?
 What will you need to change in the DAC design in order to deliver more current
to the speaker and how will the digital IOs output current limit this design?

24
3.2 Evaluate the output of the DAC with the op-amp (buffer) for the triangular and
sinusoidal signals. Include images of the actual waveforms
3.3 What is the period (T) and the frequency (f) for the periodic function in part 2a and 2b
when the delay command in the software was set to1ms?

4. Simulation:
Simulate the networks used for experiment 5.1 and experiment 5.2 using TinkerCAD.

25

You might also like