Title: EGR 277
1Lecture 7 EGR 262 Fundamental Circuits Lab
EGR 262 Fundamental Circuits Lab Presentation
for Lab 7 Analog-to-Digital Conversion - Software
Instructor Paul Gordy Office H-115 Phone
822-7175 Email PGordy_at_tcc.edu
2Lecture 7 EGR 262 Fundamental Circuits Lab
Lab 6 developed the hardware for an A/D
converter. Lab 7 will complete the A/D
converter 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 Lets try it (instructor writes a
number on the board behind the screen).
Guess Larger or smaller?
3Lecture 7 EGR 262 Fundamental Circuits Lab
Now lets 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. Example Try using the flowchart
for Value 3
Flowchart Guessing Game with Binary Values
Upper 2N
Lower 0
Guess (Upper Lower)/2
T
Upper Guess
F
Lower Guess
4Lecture 7 EGR 262 Fundamental Circuits Lab
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 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
5Lecture 7 EGR 262 Fundamental Circuits Lab
Binary output displayed
A/D Converter Schematic (discuss)
Note that the two button inputs from the last lab
are not needed.
Guess
Guess gt Vref?
b2
b1
b0
Vo fed back to input PA2 - 5V if True - 0V if
False
Analog input Vref
6Example Trace through the circuit for Vref
1.0V
Binary output displayed
A/D Converter Schematic (discuss)
Note that the two button inputs from the last lab
are not needed.
Guess
Guess gt Vref?
b2
b1
b0
Vo fed back to input PA2 - 5V if True - 0V if
False
Analog input Vref
7Example Trace through the circuit for Vref
3.5V
Binary output displayed
A/D Converter Schematic (discuss)
Note that the two button inputs from the last lab
are not needed.
Guess
Guess gt Vref?
b2
b1
b0
Vo fed back to input PA2 - 5V if True - 0V if
False
Analog input Vref
8Lecture 7 EGR 262 Fundamental Circuits Lab
4.1. Pre-lab Tasks (1) Write a C-language
MicroStamp11 program that implements the binary
search described above. Your program should run
within an in?nite while loop. Within that loop
your program should execute a for loop that
outputs a guess voltage, Vguess, then reads input
pin PA2 and ?nally generates a new guess voltage
according to the binary search algorithm. You can
assume that PA2 is a binary signal declaring
whether the guess was too high or too low. The
for loop should be executed until the algorithm
converges to the correct voltage level. Once the
for loop has been completed, your program should
display the guessed value on the 7-segment LED.
The basic structure of your program, therefore,
should be as outlined below include
"kernel.c" include "vector.c" void
main(void) init() disable_sci(
) while(1) for(i0 i lt N i) guess
(upper lower)/2 binary_output(guess) if(
(PORTA bit(2)) ! 0) upper guess else
lower guess display_digit(guess)
9Lecture 7 EGR 262 Fundamental Circuits Lab
4.1. Pre-lab Tasks (continued) (2) Explain how
the program works. (3) Include a schematic
diagram. (4) Plot a stair-step graph of
predicted digital outputs (to be displayed on the
7-segment display) as a function of applied
reference voltage. Use the data table of
threshold voltages from last lab.
10Lecture 7 EGR 262 Fundamental Circuits Lab
4.2. In-lab Tasks (1) Verify that the
circuit/program from Lab 6 is still functioning
correctly and that the clamper circuit produces
outputs between 0 and 5 volts (the potentiometer
should still be taped so that the 5V value does
not change). It is important that this voltage
be correct before feeding it back to the
MicroStamp11 as an input. (2) If the previous
step was correctly verified, close the loop
between the clamp circuit and the MicroStamp11 by
connecting the clamp circuits output to pin PA2.
(3) Compile and download your program to the
MicroStamp11. (4) Test your program to see if
it is working correctly. As you vary the
reference voltage (potentiometer) from 0 to 5V,
the 7-segment display should change from 0 to 7.
(5) Record the output value on your 7-segment
display as the reference voltage varies from 0 to
5V in 0.2V increments (see sample table
below). (6) Demonstrate the functionality of
your system to the instructor.
Vref (Analog) 7-segment display Binary Value (Digital)
0.0 0 000
0.2 0 000
0.4
5.0 7 111
11Lecture 7 EGR 262 Fundamental Circuits Lab
4.3. Post-Lab Tasks (1) Print a final program
listing. Highlight any changes made to the
original program listing and discuss the
changes. (2) Graph of digital output (shown on
7-segment display) versus applied reference
voltage (stair-step graph using the 26 measured
data points). (3) Comparison of graphs from
pre-lab and post-lab. (4) Assessment of how
well the ADC works.