SlideShare a Scribd company logo
Introduction to Verilog HDL
Jyun-Kai HuSeptember 11, 2020
Outline
 Verilog Semantic Introduction
 Continuous assignment
 Nonblocking assignment
 Simulation by VCS
 Code Coverage
2
Language Relationship
Verilog
SystemVerilog
UVM
class librarySynthesizable
SystemVerilog
Synthesizable
Verilog
3
Basic Syntax
4
1 module Top;
2 initial $display(“hello, world");
3 endmodule
this will be executed at program startup
like C’s printf, but automatically append newline character
uninstantiated module as top-level module
Value Set
5
 0 – logic zero
 1 – logic one
 x – unknown value
 both true & false, don’t care (in some condition)
 z – high impedance state
 neither true or false, open circuit
Event Control
6
 blocked until event occurs
 @a $display(a);
 call display by any value change in a
 @(posedge clk) $display(a);
 call display by positive edge on clk
to
from 0 1 x z
0 no pos pos pos
1 neg no neg neg
x neg pos no no
z neg pos no no
Always Construct
7
Basically, a, b, c have the same behavior
But assignment at time zero is unspecified
1 initial while (1) @u a = u;
2
3 initial forever @u b = u;
4
5 always @u c = u;
6
7 always d = u;
unintentional looping
Non-Constant Data Type
8
 Variable
 reg, integer, real, time…
 assigned only in procedure block or declaration
 initial, always, task, function block
 Net
 wire, tri, supply1…
 continuous assigned only
 net declaration assignment, port connection…
 have drive strength
Multiple Assignment
9
0 1 x z
0 0 x x 0
1 x 1 x 1
x x x x x
z 0 1 x z
1 reg a;
2 wire b;
3
4 wire #1 u = 0;
5 wire #1 v = 1;
6
7 always @u a = u;
8 always @v a = v;
9
10 assign b = u;
11 assign b = v;
1 unit delay, which is specified by timescale
result in 0 or 1 after 1 unit delay
(race condition)
result in unknown x after 1 unit delay
(multiple driven)
multiple driven on wire
Registers
10
 Typically composed of D flip-flops
 capture signal at the rising edge of the clock
 Not confused with the data type “reg“
1 module DFFR (
2 input CLK,
3 input D,
4 input R,
5 output reg Q
6 );
7 always @ (posedge CLK, negedge R)
8 if (!R)
9 Q = 0;
10 else
11 Q = D;
12 endmodule
D Flip-Flop
11
same as “or”
does that describe D flip-flop correctly?
implicit type wire
Shift Registers
12
1 module DFFR (
2 input CLK,
3 input D,
4 input R,
5 output reg Q
6 );
7 always @ (posedge CLK, negedge R)
8 if (!R)
9 Q = 0;
10 else
11 Q = D;
12 endmodule
1 module Testbench;
2 reg clk = 0,
3 d1 = 0;
4
5 DFFR dffr1 (
6 .CLK(clk),
7 .R(1'b1),
8 .D(d1),
9 .Q(q1)
10 );
11
12 DFFR dffr2 (
13 .CLK(clk),
14 .R(1'b1),
15 .D(q1),
16 .Q(q2)
17 );
18
19 always #1 clk = !clk;
20 initial #10 $finish;
21 endmodule
1 module DFFR (
2 input CLK,
3 input D,
4 input R,
5 output reg Q
6 );
7 always @ (posedge CLK, negedge R)
8 if (!R)
9 Q = 0;
10 else
11 Q = D;
12 endmodule
race condition!
Nonblocking Assignment
13
1 module DFFR (
2 input CLK,
3 input D,
4 input R,
5 output reg Q
6 );
7 always @ (posedge CLK, negedge R)
8 if (!R)
9 Q <= 0;
10 else
11 Q <= D;
12 endmodule
1 module Testbench;
2 reg clk = 0,
3 d1 = 0;
4
5 DFFR dffr1 (
6 .CLK(clk),
7 .R(1'b1),
8 .D(d1),
9 .Q(q1)
10 );
11
12 DFFR dffr2 (
13 .CLK(clk),
14 .R(1'b1),
15 .D(q1),
16 .Q(q2)
17 );
18
19 always #1 clk = !clk;
20 initial #10 $finish;
21 endmodule
1 module DFFR (
2 input CLK,
3 input D,
4 input R,
5 output reg Q
6 );
7 always @ (posedge CLK, negedge R)
8 if (!R)
9 Q <= 0;
10 else
11 Q <= D;
12 endmodule
evaluate both hand side immediately
but assign at the end of the time step
Stratified Event Queue
 4 event queues at the current simulation time
 Active
 Inactive
 #0, tf_synchronize, vpi_register_cb
 Nonblocking assign update
 <=
 Monitor
 $monitor, $strobe
14
Scheduling Algorithm
15
Simulation by VCS
Synopsys VCS Tool Chain
17
Separate Compilation
18
compile
time
elaboration
time
run
time
1 module Module;
2 reg in;
3 wire out;
4
5 SubModule subModule (
6 .in(in),
7 .out(out)
8 );
9
10 initial in = some_function();
11 endmodule
module, task, function will be resolved in elaboration time
i.e. the prototype can be unavailable during compile time
this makes separate compilation possible
incremental compilation isn’t based on timestamp in VCS
Interact with Your Simulation
 Compile time
 `define FNAME “vec1”
 vcs +define+FNAME=“vec2” …
 Elaboration time
 parameter IDX_FNAME = 1
 vcs –pvalue+<hier>.FNAME=2 …
 Run time
 $value$plusargs(“FNAME=%s”, FNAME)
 ./simv +FNAME=vec2
 $fscanf(“%s”, FNAME)
19
VCS Code Coverage
 Line coverage
 100% coverage is required
 Toggle coverage
 Branch coverage
 Condition coverage
 FSM coverage
20
Toggle Coverage
 Monitor transition on each bit
 0 -> 1, 1 -> 0
 x & z are ignored
 0 -> x -> 1 equals 0 -> 1
21
Verilog Branch
22
1 reg v;
2 reg [2:0] m = 3'b010,
3 n = 3'b110,
4 a, b, c;
5
6
7 if (v)
8 a = m;
9 else
10 a = n;
11
12
13 case (v)
14 1'b0:
15 b = m;
16 1'b1:
17 b = n;
18 endcase
19
20
21 c = v ? m : n;
v a b c
0 3’b110
1 3’b010
x or z 3’b110 old value 3’bx10
Branch Coverage
 Monitor scenarios
 if, case, casex, casez, ?:
23
a b c
0 1 -
0 0/x/z -
1 - 0
1 - 1
default - -
only 5 cases need to be covered
1 reg a, b, c;
2
3 case (a)
4 0:
5 if (b)
6 // do something
7 1:
8 c = c ? a : b;
9 endcase
Condition Coverage
 Monitor boolean formula
 ==, !=
 &&, ||
 &, |, ^, ~^  scalar-only
 vector condition
24
a b C
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
a b C
0 1 1
1 0 1
1 1 0
1 1 1
a
0
1
b
0
1
c
0
1
basic std allvectors
a && b && c
FSM coverage
 Monitor finite-state machine
 transition
 S0->S0, S0->S1, S1->S0
25
1 module FSM #(
2 parameter S0 = 0,
3 S1 = 1
4 ) (
5 input clk,
6 rstN,
7 in,
8 output reg state
9 );
10 always @ (posedge clk, negedge rstN)
11 if (!rstN)
12 state <= S0;
13 else case (state)
14 S0:
15 if (in)
16 state <= S1;
17 S1:
18 state <= S0;
19 endcase
20 endmodule
Coverage Analysis
26
we need to add test case to cover the
condition SEN = 0 & SRST = 1 in the
instance tb.scmCEDS

More Related Content

What's hot (20)

PDF
Verilog VHDL code Decoder and Encoder
Bharti Airtel Ltd.
 
PDF
Session 9 advance_verification_features
Nirav Desai
 
PDF
Assembly language 8086
John Cutajar
 
PPTX
System verilog coverage
Pushpa Yakkala
 
PPTX
Logical, Shift, and Rotate Instruction
Badrul Alam
 
PPTX
Verilog Test Bench
Dr.YNM
 
PPTX
FSM and ASM
Unsa Shakir
 
PPT
Counters
Bilal Mirza
 
PDF
VHDL- gate level modelling
VandanaPagar1
 
PDF
Coverage and Introduction to UVM
Dr. Shivananda Koteshwar
 
ODP
APB protocol v1.0
Azad Mishra
 
ODP
Apb
Azad Mishra
 
PPTX
SHIFT REGISTERS
kumari36
 
PDF
Session 6 sv_randomization
Nirav Desai
 
PPTX
1 Multiplexer
na491
 
PPT
Verilog hdl
dennis gookyi
 
PDF
UVM TUTORIAL;
Azad Mishra
 
PPTX
ATPG flow chart
Minh Anh Nguyen
 
PPTX
Octal to binary encoder
Ajay844
 
PDF
Loc, los and loes at speed testing methodologies for automatic test pattern g...
eSAT Journals
 
Verilog VHDL code Decoder and Encoder
Bharti Airtel Ltd.
 
Session 9 advance_verification_features
Nirav Desai
 
Assembly language 8086
John Cutajar
 
System verilog coverage
Pushpa Yakkala
 
Logical, Shift, and Rotate Instruction
Badrul Alam
 
Verilog Test Bench
Dr.YNM
 
FSM and ASM
Unsa Shakir
 
Counters
Bilal Mirza
 
VHDL- gate level modelling
VandanaPagar1
 
Coverage and Introduction to UVM
Dr. Shivananda Koteshwar
 
APB protocol v1.0
Azad Mishra
 
SHIFT REGISTERS
kumari36
 
Session 6 sv_randomization
Nirav Desai
 
1 Multiplexer
na491
 
Verilog hdl
dennis gookyi
 
UVM TUTORIAL;
Azad Mishra
 
ATPG flow chart
Minh Anh Nguyen
 
Octal to binary encoder
Ajay844
 
Loc, los and loes at speed testing methodologies for automatic test pattern g...
eSAT Journals
 

Similar to Introduction to Verilog & code coverage (20)

PDF
Lecture07(DHDNBK)-Behavior-Modelling.pdf
thanhfacebook123dn
 
PPT
Digital System Design-Synchronous Sequential Circuits
Indira Priyadarshini
 
PDF
Verilog_Examples (1).pdf
DrViswanathKalannaga1
 
PDF
Day4 順序控制的循序邏輯實現
Ron Liu
 
PPT
verilog2_Verilog Module&TEST_BENCH_SEQ.ppt
vizynq
 
PDF
verilog interview
Maitrik Shah
 
ODP
Fpga creating counter with internal clock
Politeknik Elektronika Negeri Surabaya
 
PPT
Sequential_Modelling Design Explainations
GoobeDGreat1
 
PDF
HDL PROGRAMMING-3.pdf
kaarthikK6
 
PPT
Verilog Lecture4 2014
Béo Tú
 
PPT
Verilog Lecture2 thhts
Béo Tú
 
PDF
VHdl lab report
Jinesh Kb
 
PDF
verilog ppt .pdf
RavinaBishnoi8
 
PPT
lecture8_Cuong.ppt
HongV34104
 
DOCX
Vhdl programs
Kirthika Natarajan
 
PPT
W8_2: Inside the UoS Educational Processor
Daniel Roggen
 
PDF
Short Notes on Verilog and SystemVerilog
Jason J Pulikkottil
 
DOCX
Uart
cs1090211
 
PPT
Verilogforlab
Shankar Bhukya
 
PDF
Verilog Cheat sheet-2 (1).pdf
DrViswanathKalannaga1
 
Lecture07(DHDNBK)-Behavior-Modelling.pdf
thanhfacebook123dn
 
Digital System Design-Synchronous Sequential Circuits
Indira Priyadarshini
 
Verilog_Examples (1).pdf
DrViswanathKalannaga1
 
Day4 順序控制的循序邏輯實現
Ron Liu
 
verilog2_Verilog Module&TEST_BENCH_SEQ.ppt
vizynq
 
verilog interview
Maitrik Shah
 
Fpga creating counter with internal clock
Politeknik Elektronika Negeri Surabaya
 
Sequential_Modelling Design Explainations
GoobeDGreat1
 
HDL PROGRAMMING-3.pdf
kaarthikK6
 
Verilog Lecture4 2014
Béo Tú
 
Verilog Lecture2 thhts
Béo Tú
 
VHdl lab report
Jinesh Kb
 
verilog ppt .pdf
RavinaBishnoi8
 
lecture8_Cuong.ppt
HongV34104
 
Vhdl programs
Kirthika Natarajan
 
W8_2: Inside the UoS Educational Processor
Daniel Roggen
 
Short Notes on Verilog and SystemVerilog
Jason J Pulikkottil
 
Uart
cs1090211
 
Verilogforlab
Shankar Bhukya
 
Verilog Cheat sheet-2 (1).pdf
DrViswanathKalannaga1
 
Ad

Recently uploaded (20)

PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
July Patch Tuesday
Ivanti
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Ad

Introduction to Verilog & code coverage

  • 1. Introduction to Verilog HDL Jyun-Kai HuSeptember 11, 2020
  • 2. Outline  Verilog Semantic Introduction  Continuous assignment  Nonblocking assignment  Simulation by VCS  Code Coverage 2
  • 4. Basic Syntax 4 1 module Top; 2 initial $display(“hello, world"); 3 endmodule this will be executed at program startup like C’s printf, but automatically append newline character uninstantiated module as top-level module
  • 5. Value Set 5  0 – logic zero  1 – logic one  x – unknown value  both true & false, don’t care (in some condition)  z – high impedance state  neither true or false, open circuit
  • 6. Event Control 6  blocked until event occurs  @a $display(a);  call display by any value change in a  @(posedge clk) $display(a);  call display by positive edge on clk to from 0 1 x z 0 no pos pos pos 1 neg no neg neg x neg pos no no z neg pos no no
  • 7. Always Construct 7 Basically, a, b, c have the same behavior But assignment at time zero is unspecified 1 initial while (1) @u a = u; 2 3 initial forever @u b = u; 4 5 always @u c = u; 6 7 always d = u; unintentional looping
  • 8. Non-Constant Data Type 8  Variable  reg, integer, real, time…  assigned only in procedure block or declaration  initial, always, task, function block  Net  wire, tri, supply1…  continuous assigned only  net declaration assignment, port connection…  have drive strength
  • 9. Multiple Assignment 9 0 1 x z 0 0 x x 0 1 x 1 x 1 x x x x x z 0 1 x z 1 reg a; 2 wire b; 3 4 wire #1 u = 0; 5 wire #1 v = 1; 6 7 always @u a = u; 8 always @v a = v; 9 10 assign b = u; 11 assign b = v; 1 unit delay, which is specified by timescale result in 0 or 1 after 1 unit delay (race condition) result in unknown x after 1 unit delay (multiple driven) multiple driven on wire
  • 10. Registers 10  Typically composed of D flip-flops  capture signal at the rising edge of the clock  Not confused with the data type “reg“
  • 11. 1 module DFFR ( 2 input CLK, 3 input D, 4 input R, 5 output reg Q 6 ); 7 always @ (posedge CLK, negedge R) 8 if (!R) 9 Q = 0; 10 else 11 Q = D; 12 endmodule D Flip-Flop 11 same as “or” does that describe D flip-flop correctly? implicit type wire
  • 12. Shift Registers 12 1 module DFFR ( 2 input CLK, 3 input D, 4 input R, 5 output reg Q 6 ); 7 always @ (posedge CLK, negedge R) 8 if (!R) 9 Q = 0; 10 else 11 Q = D; 12 endmodule 1 module Testbench; 2 reg clk = 0, 3 d1 = 0; 4 5 DFFR dffr1 ( 6 .CLK(clk), 7 .R(1'b1), 8 .D(d1), 9 .Q(q1) 10 ); 11 12 DFFR dffr2 ( 13 .CLK(clk), 14 .R(1'b1), 15 .D(q1), 16 .Q(q2) 17 ); 18 19 always #1 clk = !clk; 20 initial #10 $finish; 21 endmodule 1 module DFFR ( 2 input CLK, 3 input D, 4 input R, 5 output reg Q 6 ); 7 always @ (posedge CLK, negedge R) 8 if (!R) 9 Q = 0; 10 else 11 Q = D; 12 endmodule race condition!
  • 13. Nonblocking Assignment 13 1 module DFFR ( 2 input CLK, 3 input D, 4 input R, 5 output reg Q 6 ); 7 always @ (posedge CLK, negedge R) 8 if (!R) 9 Q <= 0; 10 else 11 Q <= D; 12 endmodule 1 module Testbench; 2 reg clk = 0, 3 d1 = 0; 4 5 DFFR dffr1 ( 6 .CLK(clk), 7 .R(1'b1), 8 .D(d1), 9 .Q(q1) 10 ); 11 12 DFFR dffr2 ( 13 .CLK(clk), 14 .R(1'b1), 15 .D(q1), 16 .Q(q2) 17 ); 18 19 always #1 clk = !clk; 20 initial #10 $finish; 21 endmodule 1 module DFFR ( 2 input CLK, 3 input D, 4 input R, 5 output reg Q 6 ); 7 always @ (posedge CLK, negedge R) 8 if (!R) 9 Q <= 0; 10 else 11 Q <= D; 12 endmodule evaluate both hand side immediately but assign at the end of the time step
  • 14. Stratified Event Queue  4 event queues at the current simulation time  Active  Inactive  #0, tf_synchronize, vpi_register_cb  Nonblocking assign update  <=  Monitor  $monitor, $strobe 14
  • 17. Synopsys VCS Tool Chain 17
  • 18. Separate Compilation 18 compile time elaboration time run time 1 module Module; 2 reg in; 3 wire out; 4 5 SubModule subModule ( 6 .in(in), 7 .out(out) 8 ); 9 10 initial in = some_function(); 11 endmodule module, task, function will be resolved in elaboration time i.e. the prototype can be unavailable during compile time this makes separate compilation possible incremental compilation isn’t based on timestamp in VCS
  • 19. Interact with Your Simulation  Compile time  `define FNAME “vec1”  vcs +define+FNAME=“vec2” …  Elaboration time  parameter IDX_FNAME = 1  vcs –pvalue+<hier>.FNAME=2 …  Run time  $value$plusargs(“FNAME=%s”, FNAME)  ./simv +FNAME=vec2  $fscanf(“%s”, FNAME) 19
  • 20. VCS Code Coverage  Line coverage  100% coverage is required  Toggle coverage  Branch coverage  Condition coverage  FSM coverage 20
  • 21. Toggle Coverage  Monitor transition on each bit  0 -> 1, 1 -> 0  x & z are ignored  0 -> x -> 1 equals 0 -> 1 21
  • 22. Verilog Branch 22 1 reg v; 2 reg [2:0] m = 3'b010, 3 n = 3'b110, 4 a, b, c; 5 6 7 if (v) 8 a = m; 9 else 10 a = n; 11 12 13 case (v) 14 1'b0: 15 b = m; 16 1'b1: 17 b = n; 18 endcase 19 20 21 c = v ? m : n; v a b c 0 3’b110 1 3’b010 x or z 3’b110 old value 3’bx10
  • 23. Branch Coverage  Monitor scenarios  if, case, casex, casez, ?: 23 a b c 0 1 - 0 0/x/z - 1 - 0 1 - 1 default - - only 5 cases need to be covered 1 reg a, b, c; 2 3 case (a) 4 0: 5 if (b) 6 // do something 7 1: 8 c = c ? a : b; 9 endcase
  • 24. Condition Coverage  Monitor boolean formula  ==, !=  &&, ||  &, |, ^, ~^  scalar-only  vector condition 24 a b C 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 a b C 0 1 1 1 0 1 1 1 0 1 1 1 a 0 1 b 0 1 c 0 1 basic std allvectors a && b && c
  • 25. FSM coverage  Monitor finite-state machine  transition  S0->S0, S0->S1, S1->S0 25 1 module FSM #( 2 parameter S0 = 0, 3 S1 = 1 4 ) ( 5 input clk, 6 rstN, 7 in, 8 output reg state 9 ); 10 always @ (posedge clk, negedge rstN) 11 if (!rstN) 12 state <= S0; 13 else case (state) 14 S0: 15 if (in) 16 state <= S1; 17 S1: 18 state <= S0; 19 endcase 20 endmodule
  • 26. Coverage Analysis 26 we need to add test case to cover the condition SEN = 0 & SRST = 1 in the instance tb.scmCEDS