Lec01 Verilog Combinational Circuits Design
Lec01 Verilog Combinational Circuits Design
✓ Profiling
– Profiling is a form of dynamic program analysis that measures the
space/time complexity of a program to aid program optimization.
– by doing profiling we can find the most time-consuming part of the
system
– designers can implement this part in hardware instead of software
Description of elements as a
transistor and parasitic elements
Circuit Level (Voltages; Currents)
Description of elements as a
transistor and parasitic elements
Physical Level (Voltages; Currents)
Synthesis
Synthesis
Timing Verificaiton
Design Specification
Algorithmic Model
Behavior
language
RTL Model
Verilog HDL
Gate-Level Model
Structural
language
Switch-Level Model
Physical Layout
endmodule
✓ Comments
– single line : //
– multiple line : /* … */
module MUX2_1(out,a,b,sel,clk,reset);
input sel,clk,reset; `include “mux.v”
input a,b; module test;
output out; reg out; //incorrect define
wire c; reg a,b;
reg a,b; //incorrect define reg clk,sel,reset;
reg out;
// 1. connect port by ordering
//Continuous assignment MUX2_1 mux(out,a,b,sel,clk,reset);
assign c = (sel==1’b0)?a:b;
// 2. connect port by name
//Procedural assignment, MUX2_1 mux(.clk(clk), .reset(reset),
//only reg data type can be assigned value .sel(sel), .a(a), .b(b), .out(out));
always@(posedge reset or posedge clk)
begin initial begin
if(reset==1’b1) out <= 0; ………
else out <= c; end
end endmodule
endmodule 【 sub module】 【test module】
-- can use without instance name i.e. and( out, in1, in2 ) ;
-- can use with multiple inputs i.e. xor( out, in1, in2, in3 ) ;
in1
in1
out in2 out
in2 in3
✓ Gate Delays
– Rise, Fall, and Turn-off Delays Why do we need these?
• Rise Delays
• Fall Delays
• Turn-off Delays enable
input
enable
1
output HiZ
in out 0
tpLH tpHL tpZ
notif1 ( out, in, enable ) ;
module MUX2_1(out,a,b,sel) ;
//declare ports
input a, b, sel ;
output out ; w0
//declare inside wire a
wire seln ;
wire w0, w1 ; out
//gate instances sel seln
not #(0.2:0.3:0.5, 0.2:0.3:0.5) n0( seln, sel ) ;
endmodule
✓ conditional assignment (? :)
– infers a mux with slower simulation performance
– better avoided
d 0 a 00
c 1 b 01
0
b 0 c 10
1 out
sel Sel=10
1 d 11
a
Sel=01
2
Sel=00 Sel
…
b[0]
……
• {} a = {b, c}; c[3]
…
a[0]
c[0]
a[7]
……
C[3]
• {{}} a = {2{c}};
…
a[0]
C[0]
Memory Vector
(Array) :
:
– Verilog-2001
• allows reg variables and all net data types to be declared
using the reserved keyword signed
endmodule
module MUX2_1(out,a,b,sel,clk,reset);
input sel,clk,reset;
input a,b;
output out;
wire c;
reg a,b; //incorrect define
reg out;
//Continuous assignment
assign c = (sel==1’b0)?a:b;
//Procedural assignment,
//only reg data type can be assigned valve
always@(posedge reset or posedge clk)
begin
if(reset==1’b1) out <= 0;
else out <= c;
end
endmodule
Combinational circuit
– always@*begin
– x = a & b;
– y = x | c | d;
– end
✓ Logic Assignments
– Ex: // b=5’b01110 c=5’b00101
– assign a = !b ; // a=1’b0
– assign a = ~b ; // a=5’b10001
✓ Arithmatic Assignments
– Ex: // b=5’b01110 c=5’b00101
– assign a = b * c ; // a=10’d 70
Better !!
always@* begin
case(MODE)
2'b00: OUT = A+B;
2'b01: OUT = A-B;
2'b10: OUT = A*B;
2'b11: OUT = A/B;
endcase
end
endmodule
TESTBED.v
DESIGN.v PATTERN.v
Port declaration
input
data type declaration
Applying simulation
output
Display results
`timescale 1ns/10ps
`include “MUX2_1.v”
`include “PATTERN.v”
module TESTBED;
wire out,a,b,sel,clk,reset;
enmodule
#cycle sel=1;
PATTERN.v for(i=0;i<=3;i=i+1)
begin
#cycle {a,b}=i;
module PATTERN(sel,out,a,b); #cycle $display( "sel=%b, a=%b, b=%b,
out=%b" , sel, a, b, out);
input out; end
output a,b,sel;
#cycle sel=0;
reg a,b,sel,clk,reset; for(i=0;i<=3;i=i+1)
integer i; begin
parameter cycle=10; #cycle {a,b}=i;
#cycle $display( "sel=%b, a=%b, b=%b,
always #(cycle/2) clk = ~clk; out=%b" , sel, a, b, out);
end
initial begin
a=0;b=0;sel=0;reset=0;clk=0; #cycle $finish;
#3 reset = 1; end
#10 reset = 0;
endmodule
✓ Simulation command
input waveforms
– Verilog compile
Your
• ncverilog test_file_name.v Verilog Verilog
• ncverilog test_file_name.v design Test pattern
output test data
+access+wr (dump the waveform)
– Debussy waveform generation
• nWave &
– Stop the simulation and continue the simulation
• Ctrl+z Suspend the simulation at anytime you want.(not terminate yet!)
• . Continue if you stop your simulation by $stop command
• jobs Here you can see the jobs which are processing with a index on
the left [JOB_INDEX]
• kill Use the command “kill %JOB_INDEX to terminate the job
ICLAB NCTU Institute of Electronics 54
Overview
✓ Verdi
– An HDL Debug & Analysis tool developed by NOVAS Software, Inc. It mainly
contains the following three parts.
– nTrace : A source code viewer and analyzer that can display the design hierarchy and source code
(Verilog, VHDL, SysmVerilog, SystemC, PSL, OVA, mixed) for selected design blocks.
– nWave : A state-of-the-art graphical waveform viewer and analyzer that is fully integrated with Verdi’s
source code, schematic, and flow views.
– nSchema : A schematic viewer and analyzer that generates interactive debug-specific logic diagrams
showing the structure of selected portions of a design.
✓ Invoke nWave
– By command : nWave &
Pull Down
Menu
Signal
Window
✓ Get signal
– Use Signal Get Signals... command
Default : Hexadecimal
✓ Reload nWave
– Update fsdb file in Debussy database
• File Reload
• Hot key L (shift + l)