# E15A Laboratory 2

## Combinational Logic in Verilog

Useful references for E15 labs

You might want to print out the Synthesizable Verilog Quick Reference (pdf

In this lab you will be doing some basic programming in Verilog, and then implementing your design in hardware on an FPGA (Field Programmable Gate Array).

### Quartus for Verilog tutorial

Go through the tutorial describing the writing, compiling, simulating and running of Verilog code using Quartus and the DE0 board.

### Working with 7 segment displays.

A BCD to 7 segmant decoder takes in a 4 bit BCD (Binary Coded Decimal) number and lights the digits of a seven segment display to represent a number from 0 to 9..

 Number (decimal) 0 1 2 3 4 5 6 7 8 9 Number (binary) 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 Display

The DE0 has several seven segment digits, HEX0 is the rightmost one. It is controlled by 7 bits.

So, for example, to display the number one, you want the LED's labelled b and c ( HEX0[1] and HEX0[2]) to be on, and all others off.

### Create a BCD to seven segment decoder

Write a verilog module that performs this conversion. It has a 4 bit (binary coded decimal) input called "i":and a 7 bit (for seven segment display) output called "o". Use Quartus and create a project called "lab2" with a file called "bcd2seven.v." This follows closely the section labelled "The Basics" in the tutorial. Use the following as a template.

```module bcd2seven(i, o);

// Input Port(s)
input [3:0]i;

// Output Port(s)
output [6:0]o;

// you fill in logical expressions here.

endmodule```

Note that the individual segments on the HEX0 display are lit when you apply a low signal, and are off when you apply a high signal. You need to account for this in your design somehow.

### Simulation

Simulate the code to verify that it works as expected (i.e., generate a timing diagram).  Present these results neatly.  You don't need to show that each digit is represented correctly, but pick two or three numbers and show that the simulated result is as expected. Follow the section labelled "Simulation" in the tutorial. Note in the simulator you can select all the bits of the input (the "i" vector) and set the variable to count (click on icon), instead of setting i[3], i[2], i[1] and i[0] separately. Remember when you are only simulating that you can just do an "Analysis and Synthesis" and needn't do a full compilation (Go to , or type ctrl-k)

### Run on hardware with switches

Connect inputs of the bcd2seven module to the switches SW[3:0], and the outputs to HEX0[6:0].Call the top level entity file "bcdSwitch.v." Follow the section labelled "Running on Hardware" in the tutorial. You'll need "E15DE0.qsf". You will need to do a full compilation. Verify that it works as expected.

### Run on hardware with counter

Connect a counter (0 to 9) to the inputs of the bcd2seven module and LEDR[3:0], and the display HEX0[6:0] to the outputs of your module. Call the top level entity file "bcdCount.v." Follow the section labelled "Using a counter" in the tutorial. You'll need "E15Counter1HzB.v". Verify that it works as expected.

### Extra (not required)

Build a "cylon" display with 6 eyes. Demonstrate your circuit for me (or send me a video, along with the names of the people in your group).

### To Turn in:

Each part of each task should be well labeled and in order. Each group should turn in one report as a single pdf on moodle.

• (20 pts) The Karnaugh maps and minimal sum-of-products expressions that you used to generate the logic in "bcd2seven".
• (15 pts) The file "bcd2seven.v". It should be well commented such that another student in the class can understand what the module does.
• (15 pts) The simulation results. You don't need show that all results are correct, but show that at least a few of the numbers are correct (e.g., the number 8 should have all seven segments lit).
• (15 pts) The file "bcdswitch.v". It should be well commented such that another student in the class can understand what the module does. Also include a block diagram showing all modules and the top level entity.
• (15 pts) The file "bcdCount.v". It should be well commented such that another student in the class can understand what the module does. Also include a block diagram showing all modules and the top level entity.
• (15 pts) Write one or two paragraphs describing what you would need to do to implement a 6 eye "cylon" circuit in which one LED is lit at a time and goes back and forth. Assume you have "E15Counter1HzB.v". Include a block diagram. You don't need to actually write any code.
• (5 pts) If you were told to make a 7 eye "cylon", would you rather use the individual logic gates (like last week), or Verilog? Why? A one paragraph description is fine.
• (5 pts) Extra: Describe what you did to actually get the 6 eye "cylon" circuit working, and include all the (well commented) files you wrote. Demonstrate your circuit for me (or send me a video, along with the names of the people in your group).

Please contact me if you find any errors or other problems (e.g., something is unclearly stated) in this web page