Beruflich Dokumente
Kultur Dokumente
General definition
Example module HalfAdder (A, B, Sum Carry); input A, B; output Sum, Carry; assign Sum = A ^ B; //^ denotes XOR assign Carry = A & B; // & denotes AND endmodule
module module_name ( port_list ); port declarations; variable declaration; description of behavior endmodule
Switch Level: Module implemented with switches and interconnects. Lowest level of Abstraction Gate Level: Module implemented in terms of logic gates like (and ,or) and interconnection between gates
Dataflow Level: Module designed by specifying dataflow. The designer is aware of how data flows between hardware registers and how the data is processed in the design Behavioral Level :Module can be implemented in terms of the desired design algorithm without concern for the hardware implementation details. Very similar to C programming
Blank space - \b
Tabs - \t
Newline - \n Comments
o One line comments - //
Identifiers
o Identifiers are names assigned to modules, signals, variables.. o They must begin with an alphabetic character or underscore o Example:
addbit, sum, a$b, _multi etc
Sized number
<size><base format> <number>
Base format
o Binary (b or B) o Octal (o or O) o Decimal ( d or D) o Hexa-decimal (h or H)
Exampl e 4b1010 //4-bit binary # 16d255 //16-bit decimal # 9o123 //9-bit Octal # 12habc //12-bit hexadecimal #
Number
o 0 - 9, a - f
Value set Nets Registers Vectors Integer, real & time register Arrays Memories Parameters Strings
May 31, 2011 Proprietary and Confidential
0 1 X
One, High, True, Logic High, Power, VDD, VCC, Positive Assertion
technology-specific functionality
Net Verilog Net Type Function Standard wire, tri Wired OR wor, trior Wired AND wand, triand Capacitive trireg Pullup tri1 Pulldown tri0 Power supply1 Ground supply0 nets that are not explicitly declared default to single-bit nets of type wire module test_fixture ; reg r_in, s_in; rs_ff d1(out, outnot, r_in, s_in); ... endmodule
Storage elements
o Variable that can hold value. (not HW Register)
Syntax
reg register_name;
Example
parameter port_id = 5;
A logic circuit can be designed by use of logic gates. Verilog supports basic logic gates as predefined primitives. These primitives are instantiated like modules except that they are predefined in Verilog and do not need a module definition.
Continuous Assignment
o Implicit Continuous Assignment
Delays
o Regular Assignment Delay
in 2
ou t
10 20 30 60 70 80 85
Relational
The left hand side of an assignment must always be a scalar or vector net It cannot be a scalar or vector register. Continuous assignments are always active. The assignment expression is evaluated as soon as one of the right-hand-side operands changes and the value is assigned to the lefthand-side net.
Structured Procedure
Procedural Assignment Timing Control Delay - Based Timing Control Event - Based Timing control
o Regular event control o Named event control o Event OR control o Regular Delay Control o Intra - assignment Delay control o Zero delay control o Initial Statement o Always Statement
Loop Statement
Sequential Blocks & Parallel
Blocks
module fulladd (Cin, x, y, s, Cout); input Cin, x, y; output s, Cout; reg s, Cout; always @(x or y or Cin) begin {Cout, s} = x + y + Cin; end endmodule
module dec2to4 (W, Y, En); input [1:0] W; input En; output [0:3] Y; reg [0:3] Y; always @(W or En) begin case ({En, W}) 3'b100: Y = 4'b1000; 3'b101: Y = 4'b0100; 3'b110: Y = 4'b0010; 3'b111: Y = 4'b0001; default: Y = 4'b0000; endcase end endmodule
module compare (A, B, AeqB, AgtB, AltB); input [3:0] A, B; output AeqB, AgtB, AltB; reg AeqB, AgtB, AltB; always @(A or B) begin AeqB = 0; AgtB = 0; AltB = 0; if(A == B) AeqB = 1; else if (A > B) AgtB = 1; else AltB = 1; end endmodule
module D_latch(D, Clk, Q); input D, Clk; output Q; reg Q=0; always @(D or Clk) begin if (Clk) Q = D; endmodule
module shift4(R, L, w, Clock, Q); input [3:0] R; input L, w, Clock; output [3:0] Q; reg [3:0] Q; always @(posedge Clock) if (L) Q <= R; else begin Q[0] <= Q[1]; Q[1] <= Q[2]; Q[2] <= Q[3]; Q[3] <= w; end endmodule
module updowncount(R, Clock, L, E, up_down, Q); parameter n=8; input [n-1:0] R; input Clock, L, E, up_down; output [n-1:0] Q; reg [n-1:0] Q; integer direction; always @(posedge Clock) begin if (up_down) direction = -1; else direction = 1; if (L) Q <= R; else if (E) Q <= Q + direction; end endmodule