EGR 277 Digital Logic - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

EGR 277 Digital Logic

Description:

... must first be converted to analog form using a digital-to-analog converter (also ... the output and an extra op amp could be used to invert (negate) the ... – PowerPoint PPT presentation

Number of Views:90
Avg rating:3.0/5.0
Slides: 26
Provided by: tcgo
Category:
Tags: egr | amp | digital | form | logic

less

Transcript and Presenter's Notes

Title: EGR 277 Digital Logic


1
Lecture 5 EGR 262 Fundamental Circuits Lab
EGR 262 Fundamental Circuits Lab Presentation
for Lab 5 Digital to Analog Conversion
Instructor Paul Gordy Office H-115 Phone
822-7175 Email PGordy_at_tcc.edu
2
Lecture 5 EGR 262 Fundamental Circuits Lab
  • Communicating with Digital Devices
  • The MicroStamp11 is a digital device. This means
    that its inputs and outputs are typically 0V and
    5V, corresponding to the binary logic values 0
    and 1. As a result, working with digital inputs
    and outputs is relatively easy.
  • In Labs 3-4 we used the MicroStamp11 to work
    with digital inputs/outputs
  • Digital input button switch (5V when pressed,
    0V when not pressed)
  • Digital output 7-segment display controlled
    (0V segment on, 5V segment off).

3
Lecture 5 EGR 262 Fundamental Circuits Lab
Communicating with Analog Devices Using the
MicroStamp11 to communicate with analog
inputs/outputs is much more difficult than using
digital inputs/outputs. Analog devices are
devices that can have any amplitude (any voltage
level).
  • Examples of analog inputs
  • Infrared sensor input the 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

4
Lecture 5 EGR 262 Fundamental Circuits Lab
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).
Note Labs 5 9 deal with digital-to-analog
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).
Note Labs 6 7 deal with analog-to-digital
conversion.
5
Lecture 5 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).
6
Lecture 5 EGR 262 Fundamental Circuits Lab
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-32V, then the increment
between ranges is (32 V)/(16 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
7
Lecture 5 EGR 262 Fundamental Circuits Lab
  • 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 5
  • Charging a capacitor using pulse width modulation
    (PWM) used in Lab 9
  • Binary-weighted input D/A converter
  • Recall the inverting summing amplifier introduced
    in EGR 260 shown below.

8
Lecture 5 EGR 262 Fundamental Circuits Lab
If binary weighting factors are 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.

9
Lecture 5 EGR 262 Fundamental Circuits Lab
R-2R Ladder Network Another technique for
performing D/A conversion is using a 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.
10
Lecture 5 EGR 262 Fundamental Circuits Lab
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
11
Lecture 5 EGR 262 Fundamental Circuits Lab
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
12
Lecture 5 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.
13
Lecture 5 EGR 262 Fundamental Circuits Lab
Results for 4-bit ADC
Table of analog output for each digital input
14
Lecture 5 EGR 262 Fundamental Circuits Lab
Stair-step graph illustrating analog outputs
versus digital inputs
15
Lecture 5 EGR 262 Fundamental Circuits Lab
Lab 5 Digital-to-Analog Conversion The primary
goal of Lab 5 is to build a 3-bit D/A converter
where the MicroStamp11 produces the three bit
binary output using PA3, PD0, and PD1 (where PA3
is the MSB and PD1 is the LSB). 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.
16
Lecture 5 EGR 262 Fundamental Circuits Lab
  • Programming Issues for Lab 5
  • First of all, why does the lab manual specify
    that PA3, PD0, and PD1 are to be used for the
    binary outputs b2b1b0 from the MicroStamp11?
  • The problem is that we need 10 outputs for this
    lab
  • seven for the 7-segment display
  • three for the binary outputs to the D/A
    converter
  • Recall from the presentation for Lab 3 that the
    easiest way to control outputs is to use the 8
    outputs (O0 O7) defined in kernel.c (as shown
    in the table below). The state of these 8
    outputs is easily easily controlled using kernel
    functions like set_pin(i) and clear_pin(i). But
    we need 10 outputs. Where do we get the other
    two?

17
Lecture 5 EGR 262 Fundamental Circuits Lab
Recall that we can also use other pins on PORTA
and PORTD as inputs and outputs as indicated in
the tables shown below.
Unused potential output
Unused potential output
Used for O2 (segment b)
Used for O3 (segment c)
Used for O4 (segment d)
Used for O5 (segment e)
Note that there are only three choices for
outputs in addition to O0-O7. The three choices
are PD0, PD1, and PA4. So the lab manual
reasonably specifies that PD0 and PD1 should be
used for b1 and b0 of the output to the ADC.
Used for O0 (b2 of ADC)
Unused potential output
Used for O6 (segment f)
Used for O7 (segment g)
Used for O1 (segment a)
18
Lecture 5 EGR 262 Fundamental Circuits Lab
Setting and clearing PA3, PD0, and PD1 (used for
b2b1b0). Setting and clearing PA3 is easy since
it corresponds to output O0. clear_pin(0)
//clear PA3 set_pin(0) //set PA3 Setting
and clearing PD0 requires more work as shown
below DDRD bit(0) // set the direction of
PD0 to 1 (output) PORTD bit(0) // set the
logical output of PD0 to 1 (logical DDRD
bit(0) // set the direction of PD0 to 1
(output) PORTD bit(0) // clear the logical
output of PD0 to 0 (logical LOW) Setting and
clearing PD0 is similar to setting and clearing
PD1. Use bit(1) instead of bit(0).
19
Lecture 5 EGR 262 Fundamental Circuits Lab
A problem with using PD0 and PD1 As we have seen,
pins 19-20 can be used for inputs/outputs (PD0
and PD1). However, pins 19-20 are also used for
asynchronous serial interfaces (SCI) one for
transmitting data (TxD) and one for receiving
data (RxD) as shown below.
Pins 19-20 can be used as I/O ports (PD1-PD0) or
for transmitting and receiving serial data
(TxD-RxD).
Asynchronous communication is used between
clocked devices, such as when the MicroStamp11
communicates with the computer (using
HyperTerminal, for example). When we execute the
function init( ) at the beginning of each main
program, it initializes some important items,
including establishing a transmission rate of
38400 baud and fixing values in control registers
to set up pins 19-20 for serial communication.
If we want to use pins 19-20 for inputs or
outputs, we can disable this feature using the
function disable_sci( )
Note that after executing this command, we can no
longer use HyperTerminal unless we re-enable the
pins for communication using enable_sci( )
20
Lecture 5 EGR 262 Fundamental Circuits Lab
  • Button switches
  • Lab 5 specifies that two button switches are to
    be used as follows
  • Button input to PA0 (I6) used to increment a
    counter
  • Button input to PA1 (I7) used to decrement a
    counter
  • Schematic
  • The complete schematic for Lab 5 (shown on the
    next page) includes
  • two button switch inputs on PA0 and PA1
  • three outputs to the ADC using PA3 (O0), PD0,
    and PD1
  • the R-2R ladder network to produce the analog
    output
  • the 7-segment display using outputs O1-O7

21
Lecture 5 EGR 262 Fundamental Circuits Lab
Lab 5 Schematic
22
Lecture 5 EGR 262 Fundamental Circuits Lab
  • Program Structure
  • The program for Lab 5 should have the following
    features
  • Main program
  • Initialize a counter .
  • Disable serial asynchronous communications by
    adding the disable_sci() function after the
    init() function.
  • Note that you will no longer be able to
    communicate with HyperTerminal after executing
    the instruction above.
  • Read the two button inputs (use the read_pin(i)
    kernel function).
  • Increment or decrement the counter based on the
    button inputs.
  • Call the function display_digit(count) to display
    the digit on the 7-segment display.
  • Call the function binary_output(count) to
    set/clear the appropriate pins for the binary
    value corresponding to the decimal digit.
  • Insure that the counter works as a mod-8 counter.
    Note that incrementing from 7 should yield 0
    (not 8) and decrementing from 0 should yield 7
    (not -1).
  • Additionally, advice from ODU instructors
    indicates that we should use the button(i)
    command after using read_pin(i), but kernel.c
    should be modified to comment out the instruction
    wait_pin(pin) in the button function (about line
    437). You might want to save the modified kernel
    function as kernel5.c (corresponding to Lab 5).

Note I experimented with read_pin(i),
button(i), and the modifications to kernel.c and
it seems that the recommended changes work well.
Using read_pin(i) without using button(i) or
without the changes to kernel.c resulted in
significant debounce problems or delayed
responses to button inputs.
23
Lecture 5 EGR 262 Fundamental Circuits Lab
So your main program might look something
like include kernel5.c // modify kernel.c
to comment out the instruction wait_pin(pin)
//in the button function (perhaps line
437) . . . void main(void) int count init(
) disable_sci( ) //disable serial comm so
that pins 19-20 can be used as outputs count
0 while(1) if (read_pin(6) 1
read_pin(7) 0) //increment button
pressed button(6) //use modified
button command in kernel5.c
count //increment counter if (read_pin(6)
0 read_pin(7) 1) //increment button
pressed button(7) //use modified
button command in kernel5.c
count-- //increment counter (call
function display_digit) (call function
binary_output) (add instructions for mod-8
operation)
24
Lecture 5 EGR 262 Fundamental Circuits Lab
  • Function display_digit(count)
  • Same function used in Lab 3 and Lab 4.
  • Function binary_output(count)
  • The input should be an integer with value 0 to 7.
  • Use a switch structure to distinguish between
    case 0, case 1, case 7. In each case, set or
    clear the appropriate outputs to produce the
    binary value of the count on PA3, PD0, and PD1.
    For example
  • if the count is 0, clear PA3, clear PD0, and
    clear PD1 (000)
  • If the count is 1, clear PA3, clear PD0, and set
    PD1 (001)
  • etc.
  • (Discuss in more detail in class.)

25
Lecture 5 EGR 262 Fundamental Circuits Lab
Changes to Pre-Lab Tasks
Write a Comment
User Comments (0)
About PowerShow.com