EECE6017C - Lab 0 Introduction to Altera tools and Basic ...

//input bits a,b; output bits sum, carry //designed by YOURNAME on THISDATE `timescale 1 ps/ 1 ps module halfadder_vlg_vec_tst(); // general purpose registers reg a; reg b; // wires wire carry; wire sum; // assign statements (if any) halfadder testunit ( // port map - connection between master ports and signals/registers .a(a), .b(b), .carry(carry), .sum(sum) ); initial begin #400 \$stop; end // a always begin

a = 1'b0; a = #200 1'b1; #200; end // b always begin b = 1'b0; b = #100 1'b1; #100; end endmodule 2. Full Adder Using the half adder example, Write the Verilog code for a Full Adder, that takes in three 1-bit inputs, a, b and carryin, and gives sum and carryout 1-bit outputs. Write the code for a test bench for the adder, and give appropriate inputs to test all possible combinations. Verilog Code: //module for fulladder //input bits a,b,cin; output bits sum, carry //designed by YOURNAME on THISDATE module fulladder(a,b,cin,sum,carry); input a,b,cin; output sum, carry; - Enter Code here

endmodule 3. D Flip Flop (Delay) The D type flip-flop has one data input 'D' and a clock input. The circuit edge triggers on the clock input. The flip-flop also has two outputs Q and Q' (where Q' is the reverse of Q). The operation of the D type flip-flop is as follows: Any input appearing (present state at t) at the input D, will be produced at the output Q in time t+1 (next state). e.g. if in the present state, we have D = 0 and Q = 1, the next state will be D = x and Q = 0 (previous state). The positive edge triggered D flip-flop can be modeled using behavioral modeling as shown below. Verilog Code: //module for D flipflop //input bits D,CLK (clock); output bits Q,Qi (Q-inverse) //designed by YOURNAME on THISDATE module dflipflop(D, Clk, Q, Qi); output Q,Qi; input D, Clk; reg Q,Qi; initial begin Q=1'b0; Qi=1'b1; end always @ (posedge Clk) begin

Q=D; Qi=~D; end endmodule 4. 2 to 1 MUX A 2-to-1 multiplexer has two inputs D0 and D1, one select input S and one output Y. Since there are two input signals only two ways are possible to connect the inputs to the outputs, so one select is needed to do these operations. Depending on the selector switching the inputs are produced at outputs , i.e., D0 , D1 and are switched to the output for S=0 and S=1 respectively . With the truth table for 2 to 1 multiplexer and write a test bench for the given mux Verilog module. Corresponding expression for mux output Y is given below The Verilog code can also be written using case statements or by simply using conditional operator (?: ) with assign statement. Verilog Code: //module for 2-to-1 mux //input bits D0,D1,S(select); output bit Y //designed by YOURNAME on THISDATE SELECT (S) IN1 (D0)

IN2 (D1) OUT (Y) 0 0 X 0 (D0) 0 1 X 1 (D0) 1

X 1 1 (D1) 1 X 0 0 (D1) module mux2to1( D0 , D1 , S, Y); input D0, D1, S; output Y; reg Y; always @ (S or D0 or D1) begin if (S == 1'b0) begin Y = D0; end

else begin Y = D1; end end endmodule Example: an altera state machine design: what does the state diagram look like? Draw the transition diagram Verilog Code: //module for state machine //input bits clk (clock), in, reset; //output 4-bit value out //designed by YOURNAME on THISDATE module statem(clk, in, reset, out); input clk, in, reset; output [3:0] out; reg [3:0] out; reg [1:0] state; parameter zero=0, one=1, two=2, three=3; always @(state) begin case (state) zero: out = 4'b0000; one: out = 4'b0001; two: out = 4'b0010;

three: out = 4'b0100; default: out = 4'b0000; endcase end always @(posedge clk or posedge reset) begin if (reset) state = zero; else case (state) zero: state = one; one: if (in) state = zero; else state = two; two: state = three; three: state = zero; endcase end endmodule 8 Points to remember while implementing: When creating a new project, be sure to select the correct device under the Available device list in the Picture shown here. The Device you need to select is 5CSEMA4U23C6. Use the name filter to select the device you want To use RTL viewer

Goto Tool - > Netlist Viewers -> RTL Viewer Waveform Editor - Simulation The Quartus II software also allows you to generate the following types of output files for use in performing functional and timing simulation in EDA simulation tools: You can create Verilog Test Bench Files (.vt) and VHDL Test Bench Files (.vht) for use with EDA simulation tools from a Vector Waveform File (.vwf) in the Quartus II Waveform Editor, using Simulation menu Generate ModelSim Testbench and script. Verilog HDL and VHDL Test Bench Files are test bench template files that contain an instantiation of the top-level design file and test vectors from the Vector Waveform File. You can also generate self-checking test bench files if you specify the expected values in the Vector Waveform File. To open Waveform Editor File ->New. The New file wizard will appear as shown in the picture Select University Program VWF under the Verification/Debugging Files The Simulation Waveform Editor is shown in the right. Using Waveform Editor Picture below is Simulation Waveform editor in the Quartus and simulation results Refer to Simulation of Verilog Designs Using ModelSim Graphical Waveform Editor in the Additional materials Tips: 1. Set the simulation time using Edit->Set End time

2. Set Grid Size using Edit->Grid Size, In this example total simulation time is 400us and Grid Size is 100us. 3. Select the Input a or b and Edit->Radix->Binary 4. Select input a, and to configure the waveform for a, Edit->Value->Count Value. Set Count time, say 200 ms 5. Similarly for input b, Set the Count time, say 100 ms 6. Run Simulation and you can see the resulting waveform for all the possible outcomes 7. This tool will help to automatically generate the test bench script. See example\simulation\modelsim folder and Waveform.vwf.vt is the test vector file automatically generated. Homework Design and test the following combinational logic structures using behavioral modeling. 1. Using the example done in lab0, Write the Verilog code for a 4-bit Adder, that takes in three inputs, A[3:0], B[3:0] and 1-bit Carry-in, and gives Result[3:0] and Carryout 1-bit. Write the code for a test bench for the adder, and give appropriate inputs to test all possible combinations. This module will be a basic building block for next lab exercise. 2. Create a 4-bit Shifter with one 4 bit input, 2 bit Select value (00 Shift LEFT, 10 Shift Right, 11 Shift Right Arithmetic) and 4 bit Output value 3. (sequential logic) Give the state table and the transition diagram for the state machine on slide 8.

Recently Viewed Presentations

• personal narrative: dynamic true story can be read in one sitting has a central character which is "i" (first person point of view) contains vivid details (imagery) uses description, figurative language, an dialogue to tell a personal story contains clear...
• A country's balance of payments accounts keep track of both its payments to and its receipts from foreigners. Any transaction resulting in a . receipt from foreigners. is entered in the balance of payments accounts as a . credit. Any...
• Cooperation on Access The Research Support Libraries Programme Ronald Milne Director, Research Support Libraries Programme
• Ethernet Oakton Community College CIS 238 Ethernet Developed as Xerox Network System (XNS) by PARC Original form is "DIX", later Ethernet II Standardized by IEEE as 802.2, 802.3 (wired), 802.11 (wireless) 802.4 (Token Ring), 802.5 (Token Bus) no longer used...
• Earthworms Anterior / Head End Mouth Clitellum Posterior / Tail End Anus Seminal Receptacles Setae Seminal Receptacles Testes Seminal Vesicles Ovaries Sperm Duct Central Nerve Cord Ganglia Pharynx Hearts Esophagus Crop Gizzard Intestine Dorsal Blood Vessel Ventral Blood Vessel Setae...
• Laws of Indices. Keywords. Index (indices), power, order, root, square, cube, simplify, laws, fractional, negative, reciprocal. Lesson Objectives: Developing students will be able to apply basic laws of indices. Secure students will be able to apply negative laws of indices....
• Maternal admission to Intensive Care Unit. Maternal blood transfusions. Maternal length of stay. Operative vaginal delivery. Unexpected Newborn Complications measure . Process: Compliance with labor induction practices. Compliance with first stage labor practices. Compliance with second stage labor practices
• Designing a Web Page with Tables ... or tables that span several Web pages The browser will repeat those sections across multiple pages Not all browsers support this capability Creating a Table Caption HTML allows you to specify a caption...