Difference between revisions of "CSC270 Lab 2 2011"

From dftwiki3
Jump to: navigation, search
(New page: Back to the weekly schedule ---- __TOC__ <br /> <br /> =LAB #2= © D. Thiebaut, 2009 ==Experiment #1: Python to the rescue== For this experiment, you need to b...)
 
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[CSC270_Class_Page | Back]] to the weekly schedule
+
--[[User:Thiebaut|D. Thiebaut]] 22:18, 30 January 2011 (EST)
 
----
 
----
 +
 +
  
 
__TOC__
 
__TOC__
 +
<br />
 +
<br />
 +
<bluebox>This lab deals with AND, OR, and NOT gates, as well as NAND-gate circuits.  There is a little bit of programming with Python as well.  Your report is due next week.
 +
</bluebox>
 
<br />
 
<br />
 
<br />
 
<br />
  
 
=LAB #2=
 
=LAB #2=
© D. Thiebaut, 2009
 
  
==Experiment #1: Python to the rescue==
+
==The Transisor==
For this experiment, you need to be working on a computer.  Choose which ever platform you like that supports '''Python'''.
+
 
 +
The transistor is a three-pole semiconductor. The poles are polarized and have well defined functions. They are called the '''collector''', the '''base''', and the '''emitter'''.
 +
 
 +
The transistor you will be using today is the 2N5772, and the manufacturer (fortunately) marked the poles on the package (E, B, and C).
 +
 
 +
Implement the circuit shown below.  Connect the input of the circuit to a switch, and its output to an Indicator. Observe how the output changes as a function of the input. Generate a truth table for this circuit. What logic function does it implement?
 +
 
 +
<br />
 +
<center>[[Image:TransitorCircuit.png|300px]]</center>
 +
<br />
 +
 
 +
===Resistor Color Chart===
 +
 
 +
* Use the resistor color chart on your bench to pick the resistors.
 +
* This nifty interactive color-chart can be useful.  It is located at http://www.smpspowersupply.com/resistor/resistorcolorcode.html
 +
 
 +
<br />
 +
<br />
 +
<center>[[Image:ResistorColorChartInteractive.png|200px|link=http://www.smpspowersupply.com/resistor/resistorcolorcode.html]]
 +
</center>
 +
 
 +
==Experiment #2: Python to the rescue==
 +
For this experiment, you will use one of the lab laptops, boot it with Ubuntu (DVD provided), and write a Python program.
  
The program below is written in Python and generates the truth table of two functions f(a,b,c) and g(a,b,c) of three input variables.  f is defined as <tt>((not a) and b ) or c</tt> and g is defined as <tt>( not a) and (not b) and (not c)</tt>.
+
The program below, written in Python, generates the truth table of two functions f(a,b,c) and g(a,b,c) of three input variables.  f is defined as <tt>((not a) and b ) or c</tt> and g is defined as <tt>( not a) and (not b) and (not c)</tt>.
  
 
<code><pre>
 
<code><pre>
Line 27: Line 54:
  
 
def f( a, b, c ):
 
def f( a, b, c ):
     return ( a and not b ) or c
+
     return ( a & (not b) ) | c
  
 
def g( a, b, c ):
 
def g( a, b, c ):
    return not a or not b or not c
 
  
 +
    return (not a) | (not b) | (not c)
  
 
def main():
 
def main():
Line 40: Line 67:
 
             for c in [ 0, 1 ]:
 
             for c in [ 0, 1 ]:
 
                 print "%3d%3d%3d  |%3d%3d" % \
 
                 print "%3d%3d%3d  |%3d%3d" % \
                       ( a, b, c, f( a, b, c ), g( a, b, c ) )
+
                       ( a, b, c, f( a, b, c ), g( a, b, c ) )              
  
               
 
 
main()
 
main()
 +
 
</pre></code>
 
</pre></code>
  
Line 61: Line 88:
 
</pre></code>
 
</pre></code>
  
Go back to your notes from this morning's class, find the boolean expressions for the majority voter (Majority, Fault, Id0 and Id1), and make the program verify that the equations are correct by making it display the truth table for all four outputs.
+
;Experiment #1
 +
: Create and run the program above.  verify that you get the same truth table as shown here. You may want to mail the code and output to yourself to simplify the taks of writing your report later on.  If you are using one of the lab's laptops, you'll find Python 2.6 IDLE under '''Start''', '''All Programs''', '''Programming Tools'''.
  
Note: if you want to use an xor operator, you should write your own function:
+
;Experiment #2
 +
: Modify your program and make it output the truth table for a 2-bit binary adder.
  
  def xor( a, b ):
+
==Experiment #3: 2-bit adder==
    return ''the boolean expression equal to the exclusive or of a and b''
+
 
 +
* Implement the 2-bit adder with AND, OR, NOT and possibly XOR gates (the XOR is packaged in a 74LS86 circuit).
 +
 
 +
* Demonstrate that your circuit works!
 +
 
 +
==Experiment #3: 3-bit adder==
 +
 
 +
* Implement a 3-bit adder with similar gates.
 +
 
 +
==Experiment #4 (depending on time available)==
 +
 
 +
* Implement the 2-bit adder with NAND gates only. The figures below show the schematics of a NAND gate (and of a NOR gate, for completeness).
 +
 
 +
 
 +
 
 +
{|
 +
|width="50%"|
 +
[[Image:CS270Nand.png |200px]]
 +
<br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;74LS00 NAND
 +
|
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 +
 
 +
|width="50%"|
 +
[[Image:CS270Nor.png | 200px]]
 +
<br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;74LS02 NOR
 +
|}
 +
 
 +
 
 +
Note that the NOR circuit '''does not have the same pinout''' as the NAND circuit!!!
 +
 
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
[[Category:CSC270]][[Category:Labs]]

Latest revision as of 11:24, 6 February 2011

--D. Thiebaut 22:18, 30 January 2011 (EST)





This lab deals with AND, OR, and NOT gates, as well as NAND-gate circuits. There is a little bit of programming with Python as well. Your report is due next week.



LAB #2

The Transisor

The transistor is a three-pole semiconductor. The poles are polarized and have well defined functions. They are called the collector, the base, and the emitter.

The transistor you will be using today is the 2N5772, and the manufacturer (fortunately) marked the poles on the package (E, B, and C).

Implement the circuit shown below. Connect the input of the circuit to a switch, and its output to an Indicator. Observe how the output changes as a function of the input. Generate a truth table for this circuit. What logic function does it implement?


TransitorCircuit.png


Resistor Color Chart



ResistorColorChartInteractive.png

Experiment #2: Python to the rescue

For this experiment, you will use one of the lab laptops, boot it with Ubuntu (DVD provided), and write a Python program.

The program below, written in Python, generates the truth table of two functions f(a,b,c) and g(a,b,c) of three input variables. f is defined as ((not a) and b ) or c and g is defined as ( not a) and (not b) and (not c).

# truthtable.py
# D. Thiebaut
# how a simple python program can generate the
# truth table of a boolean function
#
# here f is a function of 3 variables
#       _
# f = a.b + c
#     _   _   _
# g = a + b + c

def f( a, b, c ):
    return ( a & (not b) ) | c

def g( a, b, c ):

    return (not a) | (not b) | (not c)

def main():
    print "  a  b  c  |  f  g  "
    print "-----------+--------"
    for a in [ 0, 1 ]:
        for b in [ 0, 1 ]:
            for c in [ 0, 1 ]:
                print "%3d%3d%3d  |%3d%3d" % \
                      ( a, b, c, f( a, b, c ), g( a, b, c ) )                

main()

The output is show below:

  a  b  c  |  f  g  
-----------+--------
  0  0  0  |  0  1
  0  0  1  |  1  1
  0  1  0  |  0  1
  0  1  1  |  1  1
  1  0  0  |  1  1
  1  0  1  |  1  1
  1  1  0  |  0  1
  1  1  1  |  1  0
Experiment #1
Create and run the program above. verify that you get the same truth table as shown here. You may want to mail the code and output to yourself to simplify the taks of writing your report later on. If you are using one of the lab's laptops, you'll find Python 2.6 IDLE under Start, All Programs, Programming Tools.
Experiment #2
Modify your program and make it output the truth table for a 2-bit binary adder.

Experiment #3: 2-bit adder

  • Implement the 2-bit adder with AND, OR, NOT and possibly XOR gates (the XOR is packaged in a 74LS86 circuit).
  • Demonstrate that your circuit works!

Experiment #3: 3-bit adder

  • Implement a 3-bit adder with similar gates.

Experiment #4 (depending on time available)

  • Implement the 2-bit adder with NAND gates only. The figures below show the schematics of a NAND gate (and of a NOR gate, for completeness).


CS270Nand.png
      74LS00 NAND

          

CS270Nor.png
       74LS02 NOR


Note that the NOR circuit does not have the same pinout as the NAND circuit!!!