vlsi training course of scc -...

23
Verilog Lab. Twos Complement Add/Sub Unit TA: Xin-Yu Shi [email protected]

Upload: buithu

Post on 06-May-2018

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Verilog Lab.Two’s Complement Add/Sub Unit

TA: Xin-Yu [email protected]

Page 2: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 2

Introduction

In previous lecture, what you have learned :Complete representation for binary negative numberArithmetic operation of binary numberSkills to deign combinational circuitsBasic concept and syntax in Verilog-HDL

In this lab, we’ll guide you to model a combinational add/sub unit with gate-level Verilog HDL

SILOS : Verilog design / debug / simulation IDE

Page 3: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 3

Guideline

1. Analyze specified function, divide problems into sub-problems and conquer them one by one

2. Figure the architecture

3. Coding

4. Simulation

Page 4: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 4

Block Diagram

4

4 4

Page 5: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 5

Input/Output Description

Input signalsoperand_a, operand_b: signed 4-bit integermode: select the operation

0: result = operand_a + operand_b1: result = operand_a – operand_b

Output signalsresult: signed 4-bit integer

Page 6: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 6

Two’s Complement (1/2)[N]2 = 2n – (N)2

EX:2’s complement of (N)2 = (01100101)2

[N]2 = [01100101]2= 28 – (01100101)2= (100000000)2 – (01100101)2= (10011011)2

EX:show that (N)2 + [N]2 = 0011001011001101100000000

(carry)

+1

[N]2 = - (N)2

Page 7: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 7

Two’s Complement (2/2)

Convert (N)2 to [N]2:

N = 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 0 complement each bit

1 add 11 0 0 1 1 0 1 1

⎩⎨⎧

→→

→1001

,kk aa then add 1

Page 8: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 8

Unsigned AdderUnsigned addition by carry ripple adder (CRA)Implement with 1-bit full addersFor N-bit addition, each bit:

Sumi = 1, if the number of 1 in {ai, bi, carryi-1} is oddCarryi = 1, if the number of 1 in{ai, bi, carryi-1} is equalto or more than 2

Page 9: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 9

Implement Add/Sub with Unsigned AdderDivide and conquer

add

subtractIdentical:‧signal connection ‧module instance

Page 10: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 10

Architecture DesignShare the 4-bit carry ripple adderFor subtract, inverse b3~b0 and add 1 from carry in

operand_bi = mode bi

FA0FA1FA2FA3

a3 b3 a2 b2 a1 b1 a0 b0

result1 result0result2result3

carry out

mode

Page 11: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 11

Lab Procedures

Please follow the steps to build the dual-mode adder hierarchically.

1. Download the Verilog source code files from:http://access.ee.ntu.edu.tw/course/logic_design_95first/VerilogLabSource.zip

2. Complete/modify the source code

3. Simulate by SILOS

Page 12: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 12

1. Full Adder Gate-Level Model

Please complete the Verilog code of 1-bit full adder. (FA_1bit.v)

Fill in the necessary code(Please only use AND/OR gate)

Page 13: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 13

2. Carry Ripple Adder Model

Debug the Verilog code of 4-bit carry ripple adder.(CRA_4bit.v)

Page 14: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 14

3. Add/Sub Unit ModelComplete the Verilog code of the add/sub unit (Add_Sub_Unit.v)

Fill in the necessary code

Fill in the necessary code

Page 15: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 15

4. TestbenchPlease complete the module instance in testbench. (tb_Add_Sub_Unit.v)

Fill in the necessary code

Page 16: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Simulation using SILOS

Page 17: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 17

Create new projectWrite your Verilog design codeCreate a new project:

Project -> New -> (enter your project name)Include your verilog file(s):

(choose your .v file) -> (click Add bottom) -> (click OK)Note that testbench should be included

Then run and debug

Page 18: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 18

Type project name

1. Select Verilog source file/testbanchfile

2. Add to project

3. Click OK

Page 19: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 19

Run and Debug

RunPress F5 or click the “GO” icon on toolbarAn output window is generated to show whether there exists errors.

DebugPress F6 then click the “Open explorer” icon on toolbar

Choose signals you want to watchClick right button and select “Add signal to analyzer”

Then you can debug with waveform

Page 20: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 20

Press Go (F5)

Note if there is any warning or error

Page 21: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 21

1. Drag the signal you want to observe

2. Drop here

3. Observe the waveform

Page 22: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 22

Questions (1/2)

Please write Verilog codes for dual-mode 8-bit Add/Sub circuit design. (Similar to the architecture on p.10)Download the needed Verilog codes (including test-bench & template files) from :http://access.ee.ntu.edu.tw/course/logic_design_95first/VerilogLabQuestion.zipPlease write your whole design in only one Verilog file.(You can concatenate all the modules in only one file.) Deadline : E-mail to [email protected] before 2:00 PM 12/08.

Page 23: VLSI Training Course of SCC - 國立臺灣大學access.ee.ntu.edu.tw/course/logic_design_95first/lecture/951... · 1 0 0 1 1 0 1 0 complement each bit 1 add 1 1 0 0 1 1 0 1 1 ⎩

Logic Design Xin-Yu Shi, 11/24/2006 pp. 23

Questions (2/2)

Naming rule : For the student with student number of B94901101, the hand-in file should be B94901101.v; otherwise, the grade will be empty.

Template Code for Top Module :