Introduction to Digital Design with...

72
1 Korea Aerospace University Introduction to Digital Design with Verilog HDL Modeling Styles

Transcript of Introduction to Digital Design with...

Page 1: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

1Korea Aerospace University

Introduction to Digital Design with Verilog HDL

Modeling Styles

Page 2: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

2Korea Aerospace University

Levels of Abstraction

n Behavioral– The highest level of abstraction provided by Verilog HDL. A

module is implemented in terms of the desired design algorithm n Data Flow

– At this level the module is designed by specifying the data flow n Gate Level

– The module is implemented in terms of logic gates and interconnections between these gates

n Switch Level– This is the lowest level of abstraction provided by Verilog. A

module can be implemented in terms of switches, storage nodes and the interconnections between them

Page 3: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

3Korea Aerospace University

Behavioral Modeling

n Behavioral modelingn Data flow modelingn Gate level modelingn Switch level modelingn Others

Page 4: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

4Korea Aerospace University

Behavioral Modeling

n Blocks– always– Event-based timing control– Branch– case, casex, casez

Page 5: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

5Korea Aerospace University

Behavioral Modeling: always Block

Syntax Examplealways operation_name module pulse;

reg clock;

// start the clock at 0 initial clock = 1'b0;

/* toggle every 10 time units*/always #10 clock = ~clock;

endmodule

Page 6: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

6Korea Aerospace University

Behavioral Modeling:Event-based Timing Control

Syntax Example@(event) op_name @ (clock) a = b;

when the clock changes value, execute a = b @ (negedge clock) a = b;

when the clock change to a 0, execute a=b a = @(posedge clock) b;

evaluate b immediately and assign to a on a positive clock edge.

Page 7: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

7Korea Aerospace University

Behavioral Modeling:Branch Statements

Syntax Exampleif (conditional_expression) statement1else statement2

if (x!=1) a=2; else a=5;

Page 8: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

8Korea Aerospace University

Behavioral Modeling: Case

Syntax Examplecase(op)op1:operation1op2:operation2op3:operation3op4:operation4

default:operation5endcase

case(S3)00:A=0001:A=0110:A=1011:A=11

default:operation5endcase

Page 9: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

9Korea Aerospace University

Behavioral Modeling: casex, casez

n Two variations of the case statement– casez

• Treats all z values in the case alternatives or the case expression as don't cares, all bit positions with z can also be represented by ? in that position

– casex• Treats all x and z values in

the case item or the case expression as don't cares

– An input encoding = 4'b10xz would cause next_state = 3 to be executed

reg [3:0] encoding; integer state; casex (encoding)

4'b1xxx : next_state = 3; 4'bx1xx : next_state = 2; 4'bxx1x : next_state = 1; 4'bxxx1 : next_state = 0; default : next_state = 0;

endcase

Page 10: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

10Korea Aerospace University

Behavioral Modeling

n Definition of blocking and non-blocking procedural assignmentsn Delay-based timing control mechanism in behavioral modelingn The significance of structured procedures always and initial in

behavioral modelingn Event-based timing control mechanism in behavioral modelingn Level-sensitive timing control mechanism in behavioral modelingn Conditional statements using if and else n Multiway branching, using case, casex, and casez statementsn Looping statements while, for, repeat, and forevern Sequential and parallel blocks

Page 11: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

11Korea Aerospace University

Procedural Assignments

n Update values of reg, integer, real, or time variables– Blocking– Non-blocking

Page 12: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

12Korea Aerospace University

reg x, y, z; reg [15:0] reg_a, reg_b; integer count;initial begin

x = 0; y = 1; z = 1; // time 0count = 0; // time 0reg_a = 16'b0; // time 0reg_b = reg_a; // time 0#15 reg_a[2] = 1'b1; // time 15#10 reg_b[15:13] = {x, y, z}; // time 25count = count + 1; // time 25

end

Procedural Assignments: Blocking

n Blocking assignment statements are executed in the order they are specified in a sequential block

n A blocking assignment will not block execution of statements that follow in a parallel block

n The = operator is used to specify blocking assignments

Page 13: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

13Korea Aerospace University

Procedural Assignments: Non-Blocking

n Non-blocking assignments allow scheduling of assignments without blocking execution of the statements that follow in a sequential block

n A <= operator is used to specify non-blocking assignments

reg x, y, z; reg [15:0] reg_a, reg_b; integer count;

initial begin x = 0; y = 1; z = 1; // time 0count = 0; // time 0reg_a = 16'b0; // time 0reg_b = reg_a; // time 0

reg_a[2] <= #15 1'b1; // time 0, but assigned at time 15reg_b[15:13] <= #10 {x, y, z}; // time 0, but assigned at time 10count <= count + 1; // time 0, assigned at time 0

end

Page 14: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

14Korea Aerospace University

Blocking vs. Nonblocking Assignments

Page 15: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

15Korea Aerospace University

Assignment Styles for Sequential Logic

Page 16: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

16Korea Aerospace University

Use Nonblocking for Sequential Logic

Page 17: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

17Korea Aerospace University

Simulation

Page 18: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

18Korea Aerospace University

Use Blocking for Combinational Logic

Page 19: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

19Korea Aerospace University

The Sequential always Block

Page 20: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

20Korea Aerospace University

Importance of the Sensitivity List

Page 21: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

21Korea Aerospace University

Simulation

Page 22: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

22Korea Aerospace University

Design a 4 to 1 MUX Using if Statement

module multiplexor4_1 (out, in1, in2, in3 ,in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2;

reg out; // Note that this is now a register

always @(in1 or in2 or in3 or in4 or cntrl1 or cntrl2) if (cntrl1==1)

if (cntrl2==1) out = in4;

else out = in3; else

if (cntrl2==1) out = in2;

else out = in1;

endmodule

Page 23: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

23Korea Aerospace University

Design a 4 to 1 MUX using case Statement

module multiplexor4_1 (out, in1, in2, in3, in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2;

reg out; // note must be a register

always @(in1 | in2 | in3 | in4 | cntrl1 | cntrl2) case ({cntrl2, cntrl1}) // concatenation

2'b00 : out = in1; 2'b01 : out = in2; 2'b10 : out = in3; 2'b11 : out = in4; default : $display("Please check control bits");

endcase

endmodule

module multiplexor4_1 (out, in1, in2, in3, in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2;

reg out; // note must be a register

always @(in1 | in2 | in3 | in4 | cntrl1 | cntrl2) case ({cntrl2, cntrl1}) // concatenation

2'b00 : out = in1; 2'b01 : out = in2; 2'b10 : out = in3; 2'b11 : out = in4; default : $display("Please check control bits");

endcase

endmodule

Page 24: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

24Korea Aerospace University

Data Flow Modeling

n Behavioral modelingn Data flow modelingn Gate level modelingn Switch level modelingn Others

Page 25: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

25Korea Aerospace University

Data Flow Modeling

n Describe the continuous assignment (assign) statementn Assignment delay, implicit assignment delay, net

declaration delayn Expressions, operators, operands (already mentioned)n Examples of digital circuits modeling in Verilog

Page 26: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

26Korea Aerospace University

assign Statement

n assign out = in1 & in2;– Continuous assign– Out is a net– i1 and i2 are nets

n assign addit[15:0] = addit1[15:0] ^ addit2[15:0];– Continuous assign for vector nets, addr is a 16 bit vector net– Addi1 and addit2 are 16-bit vector registers

n assign {cout, sum[3:0]} = a[3:0] + b[3:0] + cin; – Concatenation– Left-hand side is a concatenation of a scalar net and a vector net

Page 27: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

27Korea Aerospace University

Delays

n Delay values control the time between the change in a right-hand-side operand and when the new value is assigned to the left-hand side. – Regular assignment delay– Implicit continuous assignment delay– Net declaration delay

Page 28: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

28Korea Aerospace University

Implicit Net Declaration

n If a signal name is used to the left of the continuous assignment, an implicit net declaration will be inferred for that signal name.

n If the net is connected to a module port, the width of the inferred net is equal to the width of the module port.

Out was not declared as a wire, but an implicit wire declaration for out is done by the simulator

// Continuous assign. out is a net. wire i1, i2; assign out = i1 & i2;

Page 29: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

29Korea Aerospace University

Regular Assignment Delay

1. When signals in1 and in2 go high at time 20, out goes to a high 10 time units later (time = 30).

2. When in1 goes low at 60, out changes to low at 70.3. However, in1 changes to high at 80 but it goes down to low before 10 time units have

elapsed.4. Hence at the time of recomputation, 10 units after time 80, in1 is 0. Thus, out gets the

value 0. A pulse of width less than the specified assignment delay is not propagated to the output.

in1

in2

out

time

xxxxx

10 20 30 60 70 80 85

Page 30: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

30Korea Aerospace University

Implicit Continuous Assignment Delay

n An equivalent method is to use an implicit continuous assignment to specify both a delay and an assignment on the net

//implicit continuous assignment delay wire #10 out = in1 & in2;

//same as wire out; assign #10 out = in1 & in2

Page 31: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

31Korea Aerospace University

Net Declaration Delay

n A delay can be specified on a net when it is declared without putting a continuous assignment on the net.

n If a delay is specified on a net out, then any value change applied to the net out is delayed accordingly. Net declaration delays can also be used in gate-level modeling.

//The above statement has the same effect as the following. wire out; assign #10 out = in1 & in2;

//Net Delays wire # 10 out; assign out = in1 & in2;

Page 32: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

32Korea Aerospace University

Logic Statement Implementation

module multiplexor4_1 (out, in1, in2, in3 ,in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2;

assign out = (in1 & ~cntrl1 & ~cntrl2) | (in2 & ~cntrl1 & cntrl2) | (in3 & cntrl1 & ~cntrl2) | (in4 & cntrl1 & cntrl2);

endmodule

Page 33: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

33Korea Aerospace University

The Conditional Operator

Examplemodule multiplexor4_1 (out, in1, in2, in3, in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2;

assign out = cntrl1 ? (cntrl2 ? in4 : in3) :(cntrl2 ? in2 : in1);

endmodule

Syntaxconditional_expression ? true_expression : false_expression;

Page 34: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

34Korea Aerospace University

Gate Level Modeling

n Behavioral modelingn Data flow modelingn Gate level modelingn Switch level modelingn Others

Page 35: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

35Korea Aerospace University

Gate Level Modeling

n Identify logic gate primitives provided in Verilog n Truth tables for and/or, buf/not and bufif/notif type gatesn Examples of gate-level designsn Rise, fall and turn-off delays in the gate-level design

Page 36: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

36Korea Aerospace University

Gate Types

n and/orn buf/notn bufif/notifn User-Defined Primitive (UDP)

Page 37: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

37Korea Aerospace University

and/or gates buf/not gates

Gate Types: and/or, buf/not Gates

Page 38: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

38Korea Aerospace University

Gate Types: Examples

wire OUT, IN1, IN2, IN3;

// Basic gate instantiations and gate1(OUT, IN1, IN2);nand gate2(OUT, IN1, IN2);or gate3(OUT, IN1, IN2);nor gate4(OUT, IN1, IN2);xor gate5(OUT, IN1, IN2);xnor gate6(OUT, IN1, IN2);

// More than 2 inputs: 3 input and gate and gate7(OUT, IN1, IN2, IN3);// Gate instantiation without instance name

nand(OUT, IN1, IN2); // This is also a legal instantiation

Page 39: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

39Korea Aerospace University

Gate Types: bufif, notif

out in out

bufif1 notif1

bufif0 notif0

in

control control

in out out

controlcontrol

Page 40: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

40Korea Aerospace University

Gate Types: Examples (2)

n Examples of gate instantiations

wire OUT, IN, CONTROL;

// Basic instantiations of bufif gatesbufif1 b_1(OUT, IN, CONTROL);bufif0 b_0(OUT, IN, CONTROL);

// Basic instantiations of notif gatesnotif1 n_1(OUT, IN, CONTROL);notif0 n_0(OUT, IN, CONTROL);

Page 41: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

41Korea Aerospace University

Truth Tables for bufif/notif Gates

BUFIF1 0 1 x z

0 z 0 L L

1 z 1 H H

x z x x x

z z x x x

BUFIF0 0 1 x z

0 0 z L L

1 1 z H H

x x z x x

z x z x x

control control

in in

NOTIF1 0 1 x z

0 z 1 H H

1 z 0 L L

x z x x x

z z x x x

NOTIF0 0 1 x z

0 1 z H H

1 0 z L L

x x z x x

z x z x x

control control

in in

Page 42: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

42Korea Aerospace University

Gate Delays

n Rise delay is associated with a gate output transition to 1 from another value.

n Fall delay is associated with a gate output transition to 0 from another value.

n Turn-off delay is associated with a gate output transition to the high impedance value (z) from another value.

t_rise

t_fall

Page 43: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

43Korea Aerospace University

Gate Delays (2)

n Delay specifications – One delay is specified – its value is used for all transitions– Two delays are specified – they refer to rise and fall delay values

respectively– Three delays are specified – they refer to rise, fall and turn-off

delay values respectively– Default value is zero

Page 44: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

44Korea Aerospace University

// Delay is equal to trans_delay for all transitionsnand #(trans_delay) g1(out, in1, in2);

// Rise and Fall delays are specifiedand #(rise_delay, fall_delay) g2(out, in1, in2);

// Rise, Fall and Turn-off delays are specifiedbufif0 #(5,7,9) b1(out, in , control);

Gate Delays (3): Example

Page 45: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

45Korea Aerospace University

User-Defined Primitives (UDPs)

Symbol Interpretation Comments0 Logic 01 Logic 1x Unknown value Not permitted in output field.b Substitute for 0 and 1 Not permitted in output field.? Substitute for 0, 1, and x Not permitted in output field.- No change Permitted only in output field of sequential UDPs.

(vw) Transition from v to w value Permitted only in input field of sequential UDPs. v and w can be 0, 1, x, b, and ?

* Same as (??)All transitions

Any value change on input. Permitted only in input field of sequential UDPs.

r Same as (01) Rising edge on input. Permitted only in input field of sequential UDPs.

f Same as (10) Falling edge on input. Permitted only in input field of sequential UDPs.

p Same as (01), (0x), (x1) Positive edge on input. Permitted only in input field of sequential UDPs.

n Same as (10), (1x), (x0) Negative edge on input. Permitted only in input field of sequential UDPs.

Page 46: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

46Korea Aerospace University

User-Defined Primitives (UDPs) (2)

n Latch with asyncronous reset

primitive latch (q, clock, reset, data);input clock, reset, data;output q;reg q;initial q=1’b1; //initializationtable// clock reset data q q+

? 1 ? : ? : 1 ;0 0 0 : ? : 0 ;1 0 ? : ? : - ;0 0 1 : ? : 1 ;

endtableendprimitive

Page 47: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

47Korea Aerospace University

User-Defined Primitives (UDPs) (3)

primitive mux (o, i3, i2, i1, i0, a1, a0);output o;input i3, i2, i1, i0, a1, a0;table// i3 i2 i1 i0 a1 a0 : o;

0 ? ? ? 1 1 : 0;1 ? ? ? 1 1 : 1;? 0 ? ? 1 0 : 0;? 1 ? ? 1 0 : 1;? ? 0 ? 0 1 : 0;? ? 1 ? 0 1 : 1;? ? ? 0 0 0 : 0;? ? ? 1 0 0 : 1;

endtableendprimitive

Page 48: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

48Korea Aerospace University

Ports

n Descriptions– ports provide the interface by which a module can communicate with its environment

n Types– input, output or inout (implicitly all are declared as wire in Verilog)

n Port Data Types– input or inout ports cannot be of type reg, because reg variables store values– input ports should only reflect the changes of external signals they are connected to

module DFF (dout,din,clk,resetn);output dout; input din,clk,resetn;reg dout; // As the output of D FF holds value it is declared as reg

always @(posedge clk or negedge resetn)if (~resetn) dout<=0;else dout<=din;

endmodule

Page 49: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

49Korea Aerospace University

Port Connection Rules

n Ports– Inputs

• Internally, input ports must always be of the type net• Externally, the inputs can be connected to a variable which is reg or

net– Outputs

• Internally, output ports can be of the type reg or net• Externally, the outputs must always be connected to a net

– Inouts• Internally, inout ports must always be of the type net• Externally, inout ports must always be connected to a net

Page 50: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

50Korea Aerospace University

Port Connection Rules (3)

n Connections– By order– By name

Page 51: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

51Korea Aerospace University

Example

Port Connection Rules: By Order

module TOP;reg data_in,clock,resetn;wire data_out;

// In the following block DFF module is instantiated // and is called DFF_TEST// Signals are connected to ports in orderDFF DFF_TEST (data_out,data_in,clock,resetn);…<Stimulus>

endmodule

Page 52: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

52Korea Aerospace University

Port Connection Rules: By Name

n Connecting ports by name– In large designs where the number of ports is great it may seem

hard to use the ordered method of port connection– Verilog provides the capability to connect external signals to ports

by the port names– As long as the port name is not changed the order of ports in the

port list of a module can be rearranged without changing the port connections in module instantiations

DFF DFF_TEST(.din(data_in), .dout(data_out), .resetn(resetn), .clk(clock));

Page 53: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

53Korea Aerospace University

Gate Level Implementation of a 4 to 1 MUX

in1

in2

in3

in4

cntrl1

cntrl2

w

x

y

z

out

Page 54: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

54Korea Aerospace University

Gate Level Implementation of a 4 to 1 MUX : Verilog Description

module multiplexor4_1(out, in1, in2, in3, in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2;

wire notcntlr1, notcntrl2, w, x, y, z;

not (notcntrl1, cntrl1); not (notcntrl2, cntrl2); and (w, in1, notcntrl1, notcntrl2); and (x, in2, notcntrl1, cntrl2); and (y, in3, cntrl1, notcntrl2);and (z, in4, cntrl1, cntrl2); or (out, w, x, y, z);

endmodule

Page 55: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

55Korea Aerospace University

Switch Level Modeling

n Behavioral modelingn Data flow modelingn Gate level modelingn Switch level modelingn Others

Page 56: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

56Korea Aerospace University

Switch-level Primitives

n MOS switch– nmos, rnmos, pmos, rpmos, cmos, rcmos

n Bidirectional pass switch– tran, rtran, tranif1, rtranif1, tranif0, rtranif0

n Switch-level net– trireg

n Power sources– pullup, pulldown

Page 57: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

57Korea Aerospace University

Use of trireg: Example

pullup(vdd);trireg (small) #(3,3,10) TriS;trireg (medium) #(6,7,30) TriM;trireg (large) #(15,16,50) TriL;

// pass transistor network:tran (TriM, TriS); // left always winstran (TriM, TriL); // right always wins

// NMOS network:rnmos #1 (TriM, TriS, vdd); // input has no effectrnmos #1 (TriS, TriL, vdd); // input controls outputrnmos #1 (TriM, TriL, vdd); // connection on output

Page 58: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

58Korea Aerospace University

Others

n The Power of Verilog n Dangers of Verilogn Interconnecting Modules

Page 59: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

59Korea Aerospace University

The Power of Verilog: n-bit Signals

Page 60: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

60Korea Aerospace University

The Power of Verilog: Integer Arithmetic

Page 61: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

61Korea Aerospace University

Dangers of Verilog: Incomplete Specification

Page 62: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

62Korea Aerospace University

Incomplete Specification Infers Latches

Page 63: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

63Korea Aerospace University

Avoiding Incomplete Specification

Undefined in RHS is not good style, in fact.

Page 64: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

64Korea Aerospace University

Sensitivity List in Verilog 2001 Style

always @ (a or b or c)case({a, b})2’b00: d = c;2’b01: d = ~c;2’b10: d = {c[0], c[1]};2’b11: d = {~c[0], c[1]};

endcase

always @ *case({a, b})2’b00: d = c;2’b01: d = ~c;2’b10: d = {c[0], c[1]};2’b11: d = {~c[0], c[1]};

endcase

Page 65: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

65Korea Aerospace University

Dangers of Verilog : Priority Logic

Page 66: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

66Korea Aerospace University

Priority Logic

Page 67: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

67Korea Aerospace University

Avoiding (Unintended) Priority Logic

Page 68: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

68Korea Aerospace University

Interconnecting Modules

Page 69: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

69Korea Aerospace University

Module Definitions

Page 70: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

70Korea Aerospace University

Top-Level ALU Declaration

Page 71: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

71Korea Aerospace University

Simulation

Page 72: Introduction to Digital Design with VerilogHDLviscom.kau.ac.kr/wordpress/wp-content/uploads/2016/08/2016_DD_LN… · Introduction to Digital Design with VerilogHDL Modeling Styles.

72Korea Aerospace University

More on Module Interconnection