Transcript Lab #7

Lecture #7
EGR 262 – Fundamental Circuits Lab
EGR 262
Fundamental Circuits Lab
Presentation for Lab #7
Successive Approximation A/D Converter
Instructor: Paul Gordy
Office: H-115
Phone: 822-7175
Email: [email protected]
1
Lecture #7
EGR 262 – Fundamental Circuits Lab
2
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 (also referred to as a DAC or D/A converter).
Arduino UNO
D/A Converter
Digital Output from Arduino UNO
(or Digital Input to D/A Converter)
Analog
Output
Note: Labs 4 & 6
deal with digital-toanalog conversion.
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 (also referred to as a ADC or A/D converter).
Analog
Input
A/D Converter
Arduino UNO
Digital Output from A/D Converter
(or Digital Input to Arduino UNO
Note: Labs 7 & 8
deal with analog-todigital conversion.
Lecture #7
EGR 262 – Fundamental Circuits Lab
3
Analog-to-Digital Conversion
There are several methods of performing analog-to-digital conversion, including:
• Simultaneous A/D converter – this method uses 2N comparators and an N-bit priority
encoder to produce an N-bit output.
• Stairstep-ramp A/D converter – this method uses a D/A converter and a counter. As the
binary count advances, it is converted to an analog signal and compared to the analog
input.
• Tracking A/D converter – similar to the stairstep-ramp A/D converter, but uses an
UP/DOWN counter so that each successive conversion starts with the last digital value
and counts up or down until the new analog input value is detected.
• Single-slope A/D converter – instead of using D/A converter like the previous two
methods, this method uses a linear ramp generator to produce a constant-slope reference
voltage. A counter is synchronized with the slope of the ramp.
• Dual-slope A/D converter – similar to the single-slope A/D converter, but the input
charges a capacitor linearly, producing a negative, variable-slope ramp. The capacitor
then discharges linearly with a positive slope. A counter runs as the capacitor discharges,
yielding a count proportional to the voltage. This method is commonly used with
voltmeters and other test equipment.
• Successive-approximation A/D converter – this is perhaps the most widely used method
and is used in this lab. It has a much shorter conversion time than most other methods and
the conversion time is the same for any analog input. In the following lab we will also see
that the Arduino UNO has a built-in successive-approximation ADC.
Lecture #7
EGR 262 – Fundamental Circuits Lab
Successive-approximation ADC
The successive-approximation ADC consists of:
• DAC (such as the R-2R ladder network)
• Comparator
• Success-approximation register (or processing using the Arduino UNO)
Operation of the successive-approximation A/D converter:
• The bits of the DAC are enabled one at a time, starting with the MSB.
• As each bit is enabled, the comparator produces an output that indicates
whether the analog input voltage is greater or less than the output of the
DAC. If the analog input is greater than the DAC output, the comparator
output is HIGH and the bit is Reset (LOW). If the analog input is less than
the DAC output, the comparator output is LOW, and we will Keep the bit
(HIGH).
• This process is repeated for each bit.
• See the example on the following page.
4
Lecture #7
EGR 262 – Fundamental Circuits Lab
Example: 4-bit successive approximation A/D converter
Trace through Steps 1-4 below:
4.9V
4.9V
4.9V
4.9V
Step 1:
• Set the MSB, so SAR output = 1000
• DAC is 8V
• 8V > 4.9V input, so Reset the bit to 0
Step 2:
• Set the next bit, so SAR output = 0100
• DAC is 4V
• 4V < 4.9V input, so Keep the bit
Step 3:
• Set the next bit, so SAR output = 0110
• DAC is 6V
• 6V > 4.9V input, so Reset the bit to 0
Step 4:
• Set the next bit, so SAR output = 0101
• DAC is 5V
• 5V < 4.9V input, so Keep the bit
5
Note: A 4-bit DAC
is used where the
analog output is
0-15V for digital
inputs 0000 – 1111
Note: The SAR
makes the decision
when to Reset or
Keep a bit. In this
lab we will write a
program for the
Arduino UNO to
replace the SAR.
Result:
Analog input 4.9 V
was converted to
digital output 0101
Lecture #7
EGR 262 – Fundamental Circuits Lab
6
Generic 4-bit successiveapproximation ADC
4.9V
3-bit successive-approximation
ADC using the Arduino UNO
Arduino
UNO
Digital Output
(0 – 7 or 000 to 111)
DAC
(R-2R
ladder
network)
Analog
Input
(0-5V)
Comparator
+
_
Notes:
1) The SAR (successive-approximation
register) is replaced by the Arduino
UNO.
2) A comparator is added to compare the
output of the DAC to the analog input
(output will be 5V if the input is
greater than the DAC output and 0V if
not).
3) The Arduino UNO will read the
output of the comparator to decide
which bits to Reset or Keep as in the
previous example.
Lecture #7
EGR 262 – Fundamental Circuits Lab
Detailed ADC Schematic
7
Digital Output
(0 – 7, or 000 – 111 in binary)
Arduino
UNO
D2
D3
D9
D4
D5
D6
D7
D8
D10
D13
220 
+5V
a
b
c
d
e
f
g
a
f
g
b
e d c
DAC Output
4.4k
2.2k
+5V
+
_
D12
4.4k
2.2k
D11
+5V
4.4k
4.4k
10k
Analog
Input
(0-5V)
Comparator
Lecture #7
EGR 262 – Fundamental Circuits Lab
Operational Amplifiers
Operational amplifiers (or op amps) were covered in detail in EGR 271, but a
few points are reviewed here. Refer to Chapter 5 in Electric Circuits, 9th
Edition, by Nilsson for additional information.
Closed-loop versus open loop
Closed-loop configuration
• Includes nearly all op amp examples in EGR 271
• A feedback resistor is used
• Most common configuration with many applications
• ACL, closed-loop gain, is often calculated and is typically small (|ACL| <10)
Open-loop configuration
• No feedback resistor is used
• AOL, open-loop gain, is huge. Typical value: 100,000 (manufacturer spec)
• Op amp output is typically equal to one of the supply voltages (saturated)
• Key application: comparators or related circuits
8
Lecture #7
EGR 262 – Fundamental Circuits Lab
Open-loop configuration:
• Rarely used, but is useful for
comparators
• No feedback resistor used
• Open-loop gain, AOL, used (typical
value: AOL = 100,000)
Closed-loop configuration:
• Most commonly used
• Feedback resistor used
• Closed-loop gain, ACL, used
Rfeedback
Vin
_
Other
components
V
 o
Vin
V
+
Vo
+
A CL  closed- loopgain
A CL
_
_
+
9
_
VDC1
Vo
+
VDC2
V  V  - V Vo
 open- loopgain
V
 100,000(typical)
A OL 
A OL
Lecture #7
EGR 262 – Fundamental Circuits Lab
Example (closed-loop configuration)
Determine an expression for Vo for the inverting amplifier shown below.
Also find the closed-loop gain, ACL.
40 k
10 k
_
Vin = 2V
+
_
Vo
+
Solution :
 RF 
 40k 
Vin  - 
Vo  - 
 2V  - 8V
 10k 
 R1 
V
- 8V
A CL  o 
-4
Vin
2V
10
Lecture #7
EGR 262 – Fundamental Circuits Lab
11
Comparator
An op amp in the open-loop configuration can be easily used to determine which is the
larger of two inputs. Such a circuit is called a comparator.
To illustrate how a comparator works, suppose that V+ is slightly larger than V-:
V  V  - V -  2.500- 2.499 0.001V  1 mV
+12V
2.499 V
2.500 V
_
V
+
_
Vo  A OL V  (100000)(1
mV)  100 V,
Vo
+
but Vo cannotexceed theposit ivesupply voltage
so Vo   12V (theop amp is saturated)
-12V
Now suppose that V+ is slightly less than V-:
V  V  - V -  2.500- 2.501 - 0.001V  - 1 mV
+12V
2.501 V
2.500 V
_
V
+
_
Vo  A OL V  (100000)(1mV)  - 100 V,
Vo
+
-12V
So the comparator indicates
which input is larger:
but Vo cannotbe less than thenegativesupply voltage
so Vo   12V (theop amp is saturated)
 12V if V   V Vo  


12V
if
V

V

Lecture #7
EGR 262 – Fundamental Circuits Lab
12
Comparator - continued
For digital circuits, it is useful to use 0V and 5V for the supply voltages as shown
below:
5V
V+
V-
+
Vo
_
5V if V   V Vo  

0V if V  V
0V
We will use the LMC 660 op amp in lab. Recall that the successive-approximation
ADC compares the DAC output with the analog input.
5V
DAC Output
+
Vo
_
Analog Input
0V
5V if DAC Output  AnalogInput
Vo  
0V if DAC Output  AnalogInput
Pinout for the LMC660:
Lecture #7
EGR 262 – Fundamental Circuits Lab
13
Connecting a potentiometer as a voltage divider (review)
Vsource
R1
Vsource
+
_
R1
+
R2
 R2 
V2  Vsource 

R1  R 2 

_
Rotate knob on potentiometer
to adjust
Analog Input from 0V to 5V
R2
 R2 
V2  Vsource 

 R1  R 2 
5V
Analog Input
Lecture #7
EGR 262 – Fundamental Circuits Lab
14
Using a potentiometer to adjust the Analog Input
We will use a potentiometer to simulate an Analog Input (to be converted to a digital
value) as shown below.
5V
DAC Output
+
LMC660
5V
_
0V
10 k pot
Analog
Input
Analog Input varies from 0V to 5V
as the potentiometer is adjusted
5V if DAC Output  AnalogInput
Vo  
0V if DAC Output  AnalogInput
Lecture #7
EGR 262 – Fundamental Circuits Lab
Detailed ADC Schematic
15
Digital Output
(0 – 7, or 000 – 111 in binary)
Arduino
UNO
D2
D3
D4
D5
D6
D7
D8
D10
D13
220 
+5V
a
b
c
d
e
f
g
a
f
g
b
e d c
DAC Output
4.4k
2.2k
+5V
+
_
D12
4.4k
2.2k
D11
+5V
4.4k
4.4k
10k
Analog
Input
(0-5V)
Comparator
Lecture #7
EGR 262 – Fundamental Circuits Lab
16
Writing a program to complete the ADC
The design for the ADC will be completed by adding software that will make a
series of guesses in order to determine the binary value that represents the
analog input.
Guessing Game
Consider the following game. The instructor will pick a number from 0 to 100.
You try to guess the number as quickly as possible.
Strategy: Each time guess as closely as possible to the midpoint of the
remaining range after each guess.
Example: Let’s try it (instructor writes a
number on the board behind the screen).
Guess
Larger or
smaller?
Lecture #7
EGR 262 – Fundamental Circuits Lab
Now let’s modify the
game to use binary
values. We can guess
an N-bit number using
N guesses. For
example, a 4-bit number
can be guessed using 4
guesses.
17
Upper = 2N
Flowchart – Guessing
Game with Binary Values
Lower = 0
Guess = (Upper + Lower)/2
Read Value
for I = 1 to N
T
Example: Try using the
flowchart for:
Value = 3
Guess > Value?
F
Upper = Guess
Lower = Guess
Guess = (Upper + Lower)/2
Display Guess
Lecture #7
EGR 262 – Fundamental Circuits Lab
18
Binary Search
The guessing game is an example of a binary search. A/D converters based on
a binary search are called successive approximation A/D converters.
We begin by assuming that some input analog voltage is applied and we would
like to convert it to a digital value. For our 3-bit A/D converter, we will assume
that the input is between 0V and 5V and we wish to convert it to a binary value
as shown below (using the table from the last lab):
Analog Input
(V)
Binary
Value
Decimal
Value
0.000 – 0.625
000
0
0.625 – 1.250
001
1
1.250 – 1.875
010
2
1.875 – 2.500
011
3
2.500 – 3.125
100
4
3.125 – 3.750
101
5
3.750 – 4.375
110
6
4.375 – 5.000
111
7
EGR 262 – Fundamental Circuits Lab
Lecture #7
Example:
Trace through the ADC schematic
for an analog input of 3.5V. Add
binary values and voltages to the
schematic.
I
1
2
3
Upper
8
8
6
Lower
0
4
4
Guess
4
6
5
DAC
Output
Test
2.5V
2.5 > 3.5?
(False)
3.75V
3.125
Digital Output
(0 – 7, or 000 – 111 in binary)
Arduino
UNO
220 
D10
+5V
a
b
c
d
e
f
g
D2
D3
D4
D5
D6
D7
D8
a
f
e
g
d
b
c
DAC Output
D13
4.4k
3.75 > 3.5?
(True)
3.125 > 3.5?
(False)
19
2.2k
+5V
+
_
D12
4.4k
2.2k
+5V
Result:
3.5V converted to 5 = 101
D11
4.4k
4.4k
10k
Analog
Input
(0-5V)
Comparator
Lecture #7
EGR 262 – Fundamental Circuits Lab
Example:
Trace through the ADC schematic
for an analog input of 0.8V. . Add
binary values and voltages to the
schematic.
I
Upper
Lower
Guess
DAC
Output
20
Digital Output
(0 – 7, or 000 – 111 in binary)
Arduino
UNO
220 
a
b
c
d
e
f
g
D2
D3
D4
D5
D6
D7
D8
Test
D10
+5V
a
f
e
g
d
b
c
DAC Output
D13
4.4k
2.2k
+5V
+
_
D12
4.4k
2.2k
+5V
Result:
0.8V converted to ________
D11
4.4k
4.4k
10k
Analog
Input
(0-5V)
Comparator
Lecture #7
EGR 262 – Fundamental Circuits Lab
21
Pre-lab Task:
Write a C++ program for the Arduino UNO to use a binary search to
implement a successive-approximation ADC where:
• The 3-bit binary guess will be output to an R-2R ladder network using the
function R2R( ) from Lab 4.
• The value of the binary guess will be displayed on a 7-segment display using
the function display_digit( ) from Labs 3-4.
• No buttons are required, so the functions for debouncing button inputs are not
needed.
• An outline of the program might look as follows (see next slide):
Lecture #7
EGR 262 – Fundamental Circuits Lab
void setup( )
{ // Define input and output pins
}
void loop( )
{
// Assign initial values to upper, lower and N
// guess = (upper + lower)/2
// for i = 1 to N
{ // Call R2R( ) to send guess to output pins
// Read comparatorInput on D10
if(comparatorInput == 1) // guess > analog input
upper = guess
else
lower = guess
// guess = (upper + lower)/2
}
// display guess on 7-segment display
}
void display_digit(int N)
{ // Use code from Lab #3 (do not make any changes)
}
void R2R(int N)
{ // Use code from Lab #4
22