User:Ashmanskas/p364/lab 10

From LaPET electronics

Jump to: navigation, search

Contents

Lab 10

Part 1: adder

  • Start from the files you used in lab 9: http://positron.hep.upenn.edu/wja/p364/lab9/
    • The adder is inside the file lab9.v
  • Remember that in one of last week's circuits, you used a bank of DIP switches to supply the inputs to a 4-bit adder, and you displayed the adder's output using a bank of 10 LEDs in a DIP package.
  • Your first task is to modify this adder so that its output is displayed on the 7-segment LED display as a hexadecimal digit, one of 0123456789AbCdEF. Probably you already have code from last week that does this. If not, feel free to modify the version I put in to the online Verilog notes --- note that the order of the 7 segments may differ between your hardware and the example in verilog_notes.v .

Part 2: counter

  • Inside the file lab9_synchronous.v is a 6-bit counter. (After some contemplation, I now prefer the counter implementation that I showed you in today's notes, since it keeps the Verilog always block hidden away inside the dffe_Nbit definition.) Use either the counter from the lecture notes (which are also online at http://positron.hep.upenn.edu/p364 ) or the counter from last week's lab9_synchronous.v . Modify the counter so that instead of adding 1 each clock cycle, it instead adds a 4-bit number STEP[3:0] which you read from four DIP switches.
  • Show that your counter works for counting up by 1. Now count up by 2. And by 3. Does it stop counting when you count up by zero?
  • What value do you set on the switches to make the counter count down by ones? To count down by twos?
  • Notice that the value that makes the counter count by -1 or by -2 is just the two's complement 4-bit representation of -1 or of -2. The beauty of two's complement representation is that adding negative numbers "just works."

Part 3: South Street Bridge!

  • The Chief Traffic Engineer for the brand new South Street Bridge has just resigned from his post on short notice to pursue an important reality TV opportunity in Alaska. You have been recruited to provide the digital logic to control a key traffic signal.
  • The traffic signal will have four useful states: NS_GREEN, NS_YELLOW, EW_GREEN, EW_YELLOW
  • Since Mayor Nutter is in a big hurry to open the new SSB to traffic, as a first step, let's just use the output of your existing 6-bit counter to represent states of the traffic signal:
    • Using a 1 Hz clock, the signal will cycle through its complete set of states in 64 seconds --- seems reasonable.
    • Let's make each of the two yellow phases two seconds long. That leaves 30 seconds each for the two green phases.
    • Write Verilog equations for four wires called NS_GREEN, NS_YELLOW, EW_GREEN, and EW_YELLOW, which are a function only of the counter output. For example, if the counter output is called ticks[5:0], then I could write wire NS_GREEN = (ticks<30);
    • Now write Verilog equations for additional wires called NS_RED and EW_RED, which are a function only of NS_GREEN, NS_YELLOW, EW_GREEN, and EW_YELLOW. Grab two red, two yellow, and two green LEDs and six 100Ω resistors. Arrange for the FPGA to drive the three north/south LEDs and the three east/west LEDs from the six corresponding Verilog wires. Be sure to use a resistor between each LED and ground to limit the current. (Note that the FPGA uses CMOS outputs, which are equally happy to source or to sink current, so there is no need to invert the signals to drive the LEDs. Just connect the positive side of each LED to an FPGA output and the negative side of the LED to a resistor whose other side goes to ground.)
  • Two weeks later, Mayor Nutter complains to you that your new traffic signal has bridge traffic flowing so efficiently that once a day some innocent pedestrian is picked off by one of Philadelphia's notoriously aggressive drivers. Now only you can make the bridge safe for pedestrians by implementing WALK states in your traffic light. Since Philadelphia pedestrians have a difficult time negotiating their way past cars making right turns, the intersection will be marked NO TURN ON RED and traffic will be stopped in all directions during the WALK states.
    • Notice that I already sketched out in the lecture notes a possible state diagram for a traffic signal that includes WALK states.
    • Without actually going to the trouble of implementing the logic, sketch out on a piece of paper how you would use familiar components (counters, N-bit-wide D-type flip-flops, gates, any Verilog assign statement you wish) to implement the new state diagram. You do not need to provide every detail --- just sketch out a plausible design. If your answer requires more than one sheet of paper, you are working too hard.

Part 4: vending machine

  • Let's go back to the early days of my childhood, when one might occasionally still find a vending machine that would charge only 25 cents for a can of soda.
  • Implement the soda machine whose state diagram (from HH figure 8.80) is reproduced in this week's lecture notes.
  • Use three push-button switches --- one for nickel, one for dime, and one for quarter.
  • Use a 1 Hz clock and send a copy of the clock to an LED (with a current-limiting resistor) so that you know when to expect state changes to occur.
  • Using two seven-segment LED displays, display the funds deposited: 0, 5, 10, 15, 20. Display the somewhat exciting value '88' to represent the successful purchase of a can of soda.
  • Make the "successful purchase" display even more interesting by adding a few states and wiring them up to display some sort of animated or otherwise interesting sequence. You might just have '88' blink once or twice. Or you might have one LED segment spin around the perimeter of the display. Whatever floats your soda can!
  • I doubt anyone will reach this point on Monday. So I will try by Thursday to have a skeletal solution implemented, into which you can fill in the details. You should also feel free to push ahead without my help!
  • Your state machine should be synchronous, meaning that transitions should only occur on the leading edge of the clock. Since your clock is fairly slow, there is the oddity that the button must be held down during the leading edge of the clock. That's why the blinking LED is helpful. Note that if you try to cure this limitation by making the clock faster, you will need to worry about debouncing the buttons --- i.e. ensuring that a single button press only causes a single coin to be counted. That is an interesting problem to work out, but I am guessing that you will not have enough lab time to make it worth doing. If you have extra time, you might consider how to do this.
  • Optional: sketch out (but don't bother implementing) a way to make the vending machine dispense change if, for instance, you insert three dimes, or a nickel or dime followed by a quarter.
Personal tools