LAB 3 Verilog for Combinational Circuits

Similar documents
LAB 3 Verilog for Combinatorial Circuits

CSCB58 - Lab 4. Prelab /3 Part I (in-lab) /1 Part II (in-lab) /1 Part III (in-lab) /2 TOTAL /8

Laboratory 1 - Introduction to Digital Electronics and Lab Equipment (Logic Analyzers, Digital Oscilloscope, and FPGA-based Labkit)

Digital Electronics II 2016 Imperial College London Page 1 of 8

Encoders and Decoders: Details and Design Issues

Design and implementation (in VHDL) of a VGA Display and Light Sensor to run on the Nexys4DDR board Report and Signoff due Week 6 (October 4)

ELEC 204 Digital System Design LABORATORY MANUAL

Digital Logic. ECE 206, Fall 2001: Lab 1. Learning Objectives. The Logic Simulator

Design of a Binary Number Lock (using schematic entry method) 1. Synopsis: 2. Description of the Circuit:

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science. EECS 150 Spring 2000

DIGITAL CIRCUIT LOGIC UNIT 9: MULTIPLEXERS, DECODERS, AND PROGRAMMABLE LOGIC DEVICES

Programmable Logic Design I

ENGG2410: Digital Design Lab 5: Modular Designs and Hierarchy Using VHDL

Step 1 - shaft decoder to generate clockwise/anticlockwise signals

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

Lab #10 Hexadecimal-to-Seven-Segment Decoder, 4-bit Adder-Subtractor and Shift Register. Fall 2017

EEM Digital Systems II

Laboratory Exercise 7

1. Convert the decimal number to binary, octal, and hexadecimal.

ECT 224: Digital Computer Fundamentals Digital Circuit Simulation & Timing Analysis

Switching Circuits & Logic Design, Fall Final Examination (1/13/2012, 3:30pm~5:20pm)

1. Synopsis: 2. Description of the Circuit:

Contents Circuits... 1

Modeling Latches and Flip-flops

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

Computer Systems Architecture

6.3 Sequential Circuits (plus a few Combinational)

COMPUTER ENGINEERING PROGRAM

Altera s Max+plus II Tutorial

Physics 217A LAB 4 Spring 2016 Shift Registers Tri-State Bus. Part I

Synchronous Sequential Logic

Experiment (6) 2- to 4 Decoder. Figure 8.1 Block Diagram of 2-to-4 Decoder 0 X X

ET398 LAB 4. Concurrent Statements, Selection and Process

Lab Assignment 5 I. THE 4-BIT CPU AND CONTROL

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Introductory Digital Systems Laboratory

FPGA Laboratory Assignment 4. Due Date: 06/11/2012

COE328 Course Outline. Fall 2007

University of Pennsylvania Department of Electrical and Systems Engineering. Digital Design Laboratory. Lab8 Calculator

Chapter 4: One-Shots, Counters, and Clocks

Main Design Project. The Counter. Introduction. Macros. Procedure

TSIU03: Lab 3 - VGA. Petter Källström, Mario Garrido. September 10, 2018

PHYSICS 5620 LAB 9 Basic Digital Circuits and Flip-Flops

Lab 13: FPGA Circuit Realization Ian Callahan

California State University, Bakersfield Computer & Electrical Engineering & Computer Science ECE 3220: Digital Design with VHDL Laboratory 7

Main Design Project. The Counter. Introduction. Macros. Procedure

UNIVERSITI TEKNOLOGI MALAYSIA

Logic Devices for Interfacing, The 8085 MPU Lecture 4

CprE 281: Digital Logic

ECE Lab 5. MSI Circuits - Four-Bit Adder/Subtractor with Decimal Output

Lab #6: Combinational Circuits Design

B2 Spice A/D Tutorial Author: B. Mealy revised: July 27, 2006

Laboratory 4. Figure 1: Serdes Transceiver

TSIU03, SYSTEM DESIGN. How to Describe a HW Circuit

Debugging of Verilog Hardware Designs on Altera s DE-Series Boards. 1 Introduction. For Quartus Prime 15.1

Modeling Digital Systems with Verilog

DALHOUSIE UNIVERSITY Department of Electrical & Computer Engineering Digital Circuits - ECED Experiment 2 - Arithmetic Elements

Chapter 3. Boolean Algebra and Digital Logic

LAB #6 State Machine, Decoder, Buffer/Driver and Seven Segment Display

Checkpoint 4. Waveform Generator

You will be first asked to demonstrate regular operation with default values. You will be asked to reprogram your time values and continue operation

CSE221- Logic Design, Spring 2003

Microprocessor Design

Digital. Digital. Revision: v0.19 Date: : / 76

Logic Design II (17.342) Spring Lecture Outline

Ryerson University Department of Electrical and Computer Engineering COE/BME 328 Digital Systems

WELCOME. ECE 2030: Introduction to Computer Engineering* Richard M. Dansereau Copyright by R.M. Dansereau,

DIGITAL SYSTEM DESIGN UNIT I (2 MARKS)

Chapter Contents. Appendix A: Digital Logic. Some Definitions

DIGITAL FUNDAMENTALS

Introduction to Digital Electronics

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Introductory Digital Systems Laboratory

CprE 281: Digital Logic

Experiment: FPGA Design with Verilog (Part 4)

Lab #12: 4-Bit Arithmetic Logic Unit (ALU)

CS302 Digital Logic Design Solved Objective Midterm Papers For Preparation of Midterm Exam

2.6 Reset Design Strategy

VeriLab. An introductory lab for using Verilog in digital design (first draft) VeriLab

1. a) For the circuit shown in figure 1.1, draw a truth table showing the output Q for all combinations of inputs A, B and C. [4] Figure 1.

The reduction in the number of flip-flops in a sequential circuit is referred to as the state-reduction problem.

Testing Results for a Video Poker System on a Chip

Half-Adders. Ch.5 Summary. Chapter 5. Thomas L. Floyd

Lab 17: Building a 4-Digit 7-Segment LED Decoder

Registers and Counters

Individual Project Report

WINTER 15 EXAMINATION Model Answer

EE 209 Lab 7 A Walk-Off

ECE 270 Lab Verification / Evaluation Form. Experiment 9

Programmable Logic Design Techniques II

EE 210. LOGIC DESIGN LAB.

Inside Digital Design Accompany Lab Manual

DE2-115/FGPA README. 1. Running the DE2-115 for basic operation. 2. The code/project files. Project Files

EECS 140 Laboratory Exercise 7 PLD Programming

NORTHWESTERN UNIVERSITY TECHNOLOGICAL INSTITUTE

Note 5. Digital Electronic Devices

Elwin Cabrera May 11, 2016 DIGITAL CLOCK. ECE271/CSC222 Final Project Report

FPGA Design. Part I - Hardware Components. Thomas Lenzi

Laboratory Sequential Circuits

S.K.P. Engineering College, Tiruvannamalai UNIT I

CPS311 Lecture: Sequential Circuits

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 151) Pass Marks: 24

Transcription:

Goals To Do LAB 3 Verilog for Combinational Circuits Learn how to implement combinational circuits using Verilog. Design and implement a simple circuit that controls the 7-segment display to show a 4-bit value in hexadecimal format. Design a circuit that gets a 4-bit binary value as an input and generates 7 control signals that drive the 7-segment display. Use the adder circuit from Lab2 and show its output on the 7-segment display. Follow the instructions. Paragraphs that have a gray background like the current paragraph denote descriptions that require you to do something. To complete the lab you have to show your work to an assistant before the deadline, there is nothing to hand in. The required tasks are clearly marked with gray background throughout this document. All other tasks are optional but highly recommended. You can ask the assistants for feedback on the optional tasks. Introduction In Lab 2 exercise, we used the LEDs to display the result of our adder. Instead of showing the result as a binary number, we could represent the number in a more human readable format using the 7-segment display on the Basys 3 board. A 7-segment display consists of seven separate LEDs in a single package (see Figure 1). Each of the seven segments is labeled using the letters a to g. We can use the 7-segment display to represent different characters or digits by making particular segments glow at the same time. In this lab, we will implement a circuit that could show the hexadecimal characters as shown in Figure 2. For example, if we want to display 0 on the 7- segment display, our circuit should make sure that all of the LEDs except g glow. Each one of the seven segments has a corresponding pin connected to the FPGA, just like the LEDs in Lab 2. In our circuit, we will need to convert a 4-bit binary input to drive the correct 7- bit signals. One thing to note is that, unlike the LEDs which glow when a logic-1 is applied, the segment in our FPGA board glow when a logic-0 is applied. As we have seen in the lecture, such signals are called active-low. Figure 2: 7-segment Figure 1: Hexadecimal characters represented in a 7-segment display display You will notice that there are a total of four 7-segment displays on the FPGA board. To save on the number of pins connecting to the FPGA chip, all four 7-segment displays share the same 1

inputs. To select which of the four display will act on the inputs, there are four additional activation inputs. If we activate all displays at the same time, all of them show the same number, i.e., the same segments glow on all displays. If we want to show different characters on each 7-segment display, then we need to activate the displays separately over multiple cycles. For example, our circuit should first activate the first display and drive the number to be displayed as an input. In the next cycle, our circuit can drive a different input by selecting another 7-segment display. Since the human eye can only notice changes slower than approximately 20ms, if you do this fast enough (more than 50 times per second) you will see a stable display. This is the same trick used in movies and television sets. In this exercise, we do not implement this trick as we do not implement sequential circuits in this lab. Instead, you could choose to show the same character on all of the 7-segment displays or turn three of them off (see the optional Part 4). In this lab, we will reuse our adder circuit from Lab 2. Our goal is to show the results of the adder on the 7-segment display. However, the output of the adder is 5 bits, we cannot show the results as a single hexadecimal character in all cases. Therefore, we will continue using an LED to represent addition results higher 15. Basically, in your design, the most significant bit of the addition should be connected to an LED and the rest of the bits should drive the 7-segment display. Part 1- Converting a Binary Number to 7-Segment Display Encoding As a first step, fill in the truth table below that converts a binary number to a 7-segment encoding. Note that a segment should glow when the corresponding output is logic-0. Display S3 S2 S1 S0 A B C D E F G 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 2 0 0 1 0 3 0 0 1 1 4 0 1 0 0 5 0 1 0 1 6 0 1 1 0 7 0 1 1 1 8 1 0 0 0 9 1 0 0 1 A 1 0 1 0 B 1 0 1 1 C 1 1 0 0 D 1 1 0 1 E 1 1 1 0 F 1 1 1 1 The truth table you have filled defines a circuit with 7 outputs. If you wanted, you could write the Boolean equations for all outputs separately, try to find out a (somewhat) optimized version of the equations, see if you can share portions of the gates among the different outputs (reducing the number of gates) and then draw the schematic for the resulting Boolean equations. 2

Part 2 - Implementing a Circuit to drive the 7-Segment Display This is not very difficult and can be done with some effort. However, since we have learned that we can also use Verilog to describe hardware, we can do the same with less effort. Before we continue, recall the bus concept that we know from the lectures and Lab 2. For the 7- segment display, we have seven outputs that we have named A to G. Instead of making seven separate connections, we can combine all of them together in a single bus. Assume that you call this bus D[6:0]. An important decision is how the bus signals should be connected to the individual outputs that drive the 7-segment display. Is A connected to D[0] or to D[6] (or to another signal)? You are free to choose what kind of assignment you want to make to the buses. Start with opening your Lab 2 project on Vivado. You may want to create a copy of the Lab 2 project if you would like to keep the current version of it. Inside Flow Navigator, under Project Manager, click on Add Sources. Select Add or Create Design Sources, and click next. Click Create File. A new dialog box will pop up. After you choose a name for the module (e.g., Decoder ) clicking on the Finish button will open a new window where you can easily add the connections. You can type in the name, select the direction (i.e., input or output), and you can specify the range of buses. You need to define 4-bit input and 7-bit output signals for your module that will convert a binary number to a 7-segment display encoding. Now you are ready to describe the functionality of your new module using Verilog. You can try different styles to see which one suits you well. It is important to realize that the length of the code is not proportional to the complexity of the hardware. Try to write well-structured code using simple statements and document them well. Once you have created the file, you can start writing Verilog code to implement the functionality of your new module. Basically, you need to implement a logic that will make the corresponding segment glow for each input number. Note that in case you have a procedural assignment to a wire (inside an always block) you should make sure that it is declared as reg. This is also the case for outputs that are defined in the module declaration. In general, all signals on the left-hand side of <= or = in an always statement must be declared as reg. In case there is any syntax error in your code, you can see a red underline along with a red marker on the scrollbar. Move your mouse to the scroll bar and you can see the cause of the error. Additionally, you can go to Window Messages which also shows all the errors (including the warnings) in your code. You may have to save the file before the messages are updated. Part 3 Showing the Addition Result on the 7-Segment Display Our goal is to show the result of our adder circuit from Lab 2 using the 7-segment display. To achieve that, we need to attach an instance of the new module that we just implemented (we will just call it Decoder from now on) to the output of the adder, i.e., the output of the adder should be an input to the instance of the Decoder. To do that, we need to create a new top module that will create an instance of each module and make appropriate connections between them. Create a new source file and instantiate the adder and the Decoder. In this module we will still have the two inputs A[3:0] and B[3:0] that go directly to the adder. The output of the adder is a bus that is 5-bits wide. 4 of these S[3:0] will go to the decoder, and the most significant bit S[4] should connect to a separate LED. An example schematic is given in Figure 3. 3

Figure 3: An example top-level schematic Connect the output of the adder to the input of the Decoder as you see appropriate. Make sure that you do not have any errors. In case you would like to see the schematic representation of your code, go to Flow -> Elaborated Design. You can ignore the warning dialog. We also need to modify the constraints file (the.xdc file) that tells us how to map the outputs of our top module to the FPGA pins. Note that in your top module you should have seven bits going to the 7-segment display and one bit connecting to the LED. We assume that you call the output D[6:0] and A is D[0], B is D[1], C is D[2] etc. For the inputs, assume that we have a 4-bit bus called s[3:0]. Find and open the.xdc file that you created last week for Lab 2. Make necessary changes to select the pins connecting to the 7-segment display. We provide example constraints below assuming that you would like to connect D[0] to segment A, D[1], to segment B and so on. Also, make sure to update the constraints for the inputs if you use different input names in your new top module. Example connections for the 7-segment display are the following: set_property PACKAGE_PIN W7 [get_ports {D[0]}] set_property PACKAGE_PIN W6 [get_ports {D[1]}] set_property PACKAGE_PIN U8 [get_ports {D[2]}] set_property PACKAGE_PIN V8 [get_ports {D[3]}] set_property PACKAGE_PIN U5 [get_ports {D[4]}] set_property PACKAGE_PIN V5 [get_ports {D[5]}] set_property PACKAGE_PIN U7 [get_ports {D[6]}] set_property IOSTANDARD LVCMOS33 [get_ports {D}] Now we just have to generate the programming file of the entire project and download it to the FPGA. Then we can finally check the result using the 7-segment display. Using Lab 2 as a reference, generate the programming file and program the FPGA. Show the working circuit to an assistant. Part 4 Turning off the Redundant Displays (Optional) If you do not like seeing all 7-segment displays showing the same number four times you may want to turn off the three extra 7-segment displays. They can be disabled by connecting their activation input to logic-1 (note that the activation input is active-low). In order to achieve this, you can add a new 4-bit output AN[3:0] into your top module and assign logic-1 to AN[1], AN[2] and AN[3], and logic-0 to AN[0]. 4

At this point, you need to update the constraints file in order to map these new output signals to the activation pins on the board. Do this by adding the following lines to your constraints file: set_property PACKAGE_PIN U2 [get_ports {AN[0]}] set_property PACKAGE_PIN U4 [get_ports {AN[1]}] set_property PACKAGE_PIN V4 [get_ports {AN[2]}] set_property PACKAGE_PIN W4 [get_ports {AN[3]}] set_property IOSTANDARD LVCMOS33 [get_ports {AN}] You can name the new output as you prefer. Just be careful to be consistent with your choice when updating the constraints file. After this little tweak, generate the programming file again and reprogram the board. You should now see only the right-most 7-segment display on. Last Words In this exercise, we deliberately left some options (how to add the display decoder) up to you. There are frequently many ways a specific task can be completed, and it is not immediately clear which of the alternatives is the best choice. More often than not, there is not really a best option; all choices would work more or less equally well. While working on your implementation, you may come across various problems. Here are some tips to debug your circuit implementation. Isolate the problem. You can just map your new Decoder module to the FPGA board by connecting 4 inputs to the switches and the 7 outputs to the 7-segment display. This way, you can check if the Decoder works correctly. If this is the case, the problem could be in the adder circuit or in the interconnection between the two. If something is displayed on the 7-segment display, but it does not match the expectations, consider that all output LEDs are independent. Try to find out which LEDs function correctly (a, b, c, etc.) and which ones do not. You should then find the place in the Verilog code that determines the output of the LEDs that are not working correctly. Check your bit ordering. The given constraints for port D are only valid if you followed the example ordering of bits (i.e., D[0] corresponds to segment A, D[1] to segment B, etc.) Until now, we have designed combinational circuits. The outputs of these circuits were directly determined by their inputs. We use these circuits extensively, but they are not able to remember what has happened in the past: they have no memory, only the present time. Starting with the next exercise, we examine state holding circuits that can differentiate among different states and can move through different states depending on the input and the present state. These circuits are called finite state machines. 5