Difference between revisions of "CSC270 Homework 5"

From dftwiki3
Jump to: navigation, search
(New page: This homework assignment is due on 3/11/09, at 7:00 pm. =Problem #1= Implement a GYR-light sequencer that is located on Elm St to allow students to cross. The setup is the following....)
 
(Problem #2)
Line 26: Line 26:
 
Note: there are several ways to simulate the 2 switches.  One way is to define ahead of time what their values will be at each step of the simulation.
 
Note: there are several ways to simulate the 2 switches.  One way is to define ahead of time what their values will be at each step of the simulation.
  
For example, here is a python program simulating the D-flipflop and XOR gate of a previous lab:
+
For example, below is a python program simulating the D-flipflop and XOR gate of a Lab 4:
 +
<br />
 +
<center>[[Image:CSC270 controllableOscillator.png]]</center>
 +
<br />
 +
 
 +
<code><pre>
 +
Q = 0
 +
cmdValues = [0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,]
 +
 
 +
for i in range( len( cmdValues ) ):
 +
    cmd = cmdValues[ i ]
 +
    D = Q ^ cmd
 +
   
 +
    print "cmd: %d  Q: %d" % ( cmd, Q )a
 +
 
 +
    # tick!
 +
    Q = D
 +
 
 +
</pre></code>
 +
 
 +
=Problem #3=
 +
 
 +
Implement a 3-bit counter that counts down with JK flip-flops.  By counting down I mean the output goes 111, 110, 101, 100, 011, 010, 001, 000, 111, etc.
 +
 
 +
=Problem #4=
 +
 
 +
Submit the python code that verifies that your answer for Problem #3 is correct.

Revision as of 13:58, 4 March 2009

This homework assignment is due on 3/11/09, at 7:00 pm.


Problem #1

Implement a GYR-light sequencer that is located on Elm St to allow students to cross.

The setup is the following.

On both sides of the street we have a switch that can be ON or OFF. When the two switches are OFF, the lights go GREEN, YELLOW, RED, GREEN, YELLOW, RED, etc at a regular frequency, one time unit for each state.

When a student wants to cross the street, she flips one of the switches OFF. So now we have one switch ON, one switch OFF. As soon as the lights reach the RED state, the sequencer keeps outputing RED as long as the switches are different.

The student crosses the street, safe that the traffic will stop at the red light.

When she reaches the other side of the street, she flips the other switch ON, and the sequencer resumes its GREEN, YELLOW, RED cycle.

In summary: when both switches are the same, the sequencer cycles through all 3 colors. When the switches are different, the sequencer stays in red as soon as it reaches that state.

Implement this circuit with D flipflops.

Problem #2

Code your solution for Problem #1 in Python. Submit the code and a sample of its output.

Note: there are several ways to simulate the 2 switches. One way is to define ahead of time what their values will be at each step of the simulation.

For example, below is a python program simulating the D-flipflop and XOR gate of a Lab 4:

CSC270 controllableOscillator.png


Q = 0
cmdValues = [0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,]

for i in range( len( cmdValues ) ):
    cmd = cmdValues[ i ]
    D = Q ^ cmd
    
    print "cmd: %d   Q: %d" % ( cmd, Q )a

    # tick!
    Q = D
  

Problem #3

Implement a 3-bit counter that counts down with JK flip-flops. By counting down I mean the output goes 111, 110, 101, 100, 011, 010, 001, 000, 111, etc.

Problem #4

Submit the python code that verifies that your answer for Problem #3 is correct.