SlideShare a Scribd company logo
1 of 7
Download to read offline
VERILOG 4:
COMMON MISTAKES
© B. Baas 84
Common Mistake #1:
assign in an always block
• There is no “assign” keyword in always blocks!
• (Why is it so tempting to type it here?)
reg out;
always @(a or b) begin
out = a & b;
end
reg out2;
always @(a or b) begin
assign out2 = a ^ b;
end
module
endmodule
© B. Baas 85
Common Mistake #2:
Setting the same reg in multiple always blocks
• Simulators will typically do what
you tell them to do
• Synthesis tools and lint checkers
will typically give a warning
• Never do this in Hardware verilog
• You might be able to get away
with it in testing verilog but
normally don’t do it
always @(a or b) begin
x = a ^ b;
end
always @(reset) begin
x = 1’b0;
end
© B. Baas 86
Mistake #3: Inferring State In Combinational
Circuits By: An Incomplete Sensitivity List
• always @(a) begin // missing b
out = a & b;
end
• out updates when a changes as expected
• out does not update when b changes!
– Put another way, b can change all it wants
but out will not update—this requires a memory
element to remember the last value of out
• Synthesis tools and lint checkers will give
a warning
• Using the construct new in Verilog 1364-2001:
always @(*)
or
always @*
eliminates this type of bug, but it is not supported by all modern CAD tools
a out
b
edge
detector
G
// this "always" block does not
// instantiate combinational logic
always @(freq or xyz or abc) begin
if (xyz == 4’b0010) begin
freq_c = abc;
end
case (freq) begin
3’b000: freq_c = abc;
3’b001: freq_c = abc + 3’b001;
endcase
end
© B. Baas 87
• Example: attempted combinational circuit
– If xyz==4’b0010, freq_c is a function of the inputs
– If freq==3’b000 or 3’b001, freq_c is a function of the inputs
– Otherwise, freq_c keeps its old value—which implies memory is needed!
Which means our combinational circuit is broken.
– A failure occurs when the inputs of a statement are different from the
signals used for the if or case condition
Mistake #4: Inferring State In Combinational
Circuits By: Not Setting a reg In All Paths
freq_c
logic
abc
xyz
freq
// this "always" block does instantiate combinational logic
always @(freq or xyz or abc) begin
// “default” section of always block
freq_c = freq; // some default value
// main logic block
if (xyz==4’b0010) begin
freq_c = abc;
end
else begin // perhaps not always applicable
freq_c = ...;
end
case (freq) begin
3’b000: freq_c = abc;
3’b001: freq_c = abc+3’b001;
default: freq_c = ...; // perhaps you know freq should never be anything
endcase // other than 000 or 001, or perhaps you do want
end // freq_c equal to something in these six cases
© B. Baas 88
• Example: successful combinational circuit
– Solution: freq_c is set regardless of the values of all inputs
– One solution: always declare default values at beginning of always
blocks
– If helpful, declare default case in case statements
Mistake #4: Inferring State In Combinational
Circuits By: Not Setting a reg In All Paths
freq_c
logic
abc
xyz
freq
Fixes
all
Fixes
if
Fixes
only
case
© B. Baas 89
For Combinational Circuits:
Avoid Inferring State by:
1. Including all input variables in the sensitivity list!
2. Set the value of all regs in all paths through every
always block
• A nice solution is to set default values for all output
variables immediately after entering an always block
o You will eliminate the chance of this bug if you do

More Related Content

Similar to Handout14.verilog4.pdf

Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014Béo Tú
 
LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)Wang Hsiangkai
 
Lab3 testbench tutorial (1)
Lab3 testbench tutorial (1)Lab3 testbench tutorial (1)
Lab3 testbench tutorial (1)Abhishek Bose
 
Static analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systemsStatic analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systemsAndrey Karpov
 
Digital System Design-Switchlevel and Behavioural Modeling
Digital System Design-Switchlevel and Behavioural ModelingDigital System Design-Switchlevel and Behavioural Modeling
Digital System Design-Switchlevel and Behavioural ModelingIndira Priyadarshini
 
vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1MANDHASAIGOUD1
 
Demo4 code.docx
Demo4 code.docxDemo4 code.docx
Demo4 code.docxkalyank35
 
RailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsRailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsLourens Naudé
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++Mohammad Shaker
 
Random stability in systemVerilog and UVM based testbench
Random stability in systemVerilog and UVM based testbenchRandom stability in systemVerilog and UVM based testbench
Random stability in systemVerilog and UVM based testbenchKashyap Adodariya
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.pptsanjay
 
03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old daysAlexandre Moneger
 
PVS-Studio delved into the FreeBSD kernel
PVS-Studio delved into the FreeBSD kernelPVS-Studio delved into the FreeBSD kernel
PVS-Studio delved into the FreeBSD kernelPVS-Studio
 
SystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxSystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxNothing!
 

Similar to Handout14.verilog4.pdf (20)

Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014
 
LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)
 
Lab3 testbench tutorial (1)
Lab3 testbench tutorial (1)Lab3 testbench tutorial (1)
Lab3 testbench tutorial (1)
 
Static analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systemsStatic analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systems
 
Digital System Design-Switchlevel and Behavioural Modeling
Digital System Design-Switchlevel and Behavioural ModelingDigital System Design-Switchlevel and Behavioural Modeling
Digital System Design-Switchlevel and Behavioural Modeling
 
vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1
 
Demo4 code.docx
Demo4 code.docxDemo4 code.docx
Demo4 code.docx
 
bluespec talk
bluespec talkbluespec talk
bluespec talk
 
RailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsRailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMs
 
Ver1-iitkgp.ppt
Ver1-iitkgp.pptVer1-iitkgp.ppt
Ver1-iitkgp.ppt
 
PLSQL
PLSQLPLSQL
PLSQL
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
 
Random stability in systemVerilog and UVM based testbench
Random stability in systemVerilog and UVM based testbenchRandom stability in systemVerilog and UVM based testbench
Random stability in systemVerilog and UVM based testbench
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days
 
PVS-Studio delved into the FreeBSD kernel
PVS-Studio delved into the FreeBSD kernelPVS-Studio delved into the FreeBSD kernel
PVS-Studio delved into the FreeBSD kernel
 
Conditional branches
Conditional branchesConditional branches
Conditional branches
 
SystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxSystemVerilog Assertion.pptx
SystemVerilog Assertion.pptx
 
Cipher block modes
Cipher block modesCipher block modes
Cipher block modes
 
verilog_fsm.pdf
verilog_fsm.pdfverilog_fsm.pdf
verilog_fsm.pdf
 

More from DrViswanathKalannaga1

More from DrViswanathKalannaga1 (7)

Concept of datatype.pdf
Concept of datatype.pdfConcept of datatype.pdf
Concept of datatype.pdf
 
INTERVIEW QUESTIONS_Verilog_PART-3-5 (1).pdf
INTERVIEW QUESTIONS_Verilog_PART-3-5 (1).pdfINTERVIEW QUESTIONS_Verilog_PART-3-5 (1).pdf
INTERVIEW QUESTIONS_Verilog_PART-3-5 (1).pdf
 
TimesVLSI Notes-1.pdf
TimesVLSI Notes-1.pdfTimesVLSI Notes-1.pdf
TimesVLSI Notes-1.pdf
 
Verilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdfVerilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdf
 
Verilog_Examples (1).pdf
Verilog_Examples (1).pdfVerilog_Examples (1).pdf
Verilog_Examples (1).pdf
 
pci express system architecture.pdf
pci express system architecture.pdfpci express system architecture.pdf
pci express system architecture.pdf
 
INTERVIEW QUESTIONS_Verilog_PART-2.pdf
INTERVIEW QUESTIONS_Verilog_PART-2.pdfINTERVIEW QUESTIONS_Verilog_PART-2.pdf
INTERVIEW QUESTIONS_Verilog_PART-2.pdf
 

Recently uploaded

Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfKira Dess
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentationsj9399037128
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...archanaece3
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological universityMohd Saifudeen
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxMustafa Ahmed
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfssuser5c9d4b1
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsMathias Magdowski
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.benjamincojr
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfJNTUA
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxMANASINANDKISHORDEOR
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...Amil baba
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalSwarnaSLcse
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksIJECEIAES
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...josephjonse
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxCHAIRMAN M
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...IJECEIAES
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptjigup7320
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...IJECEIAES
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Toolssoginsider
 

Recently uploaded (20)

Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentation
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 

Handout14.verilog4.pdf

  • 2. © B. Baas 84 Common Mistake #1: assign in an always block • There is no “assign” keyword in always blocks! • (Why is it so tempting to type it here?) reg out; always @(a or b) begin out = a & b; end reg out2; always @(a or b) begin assign out2 = a ^ b; end
  • 3. module endmodule © B. Baas 85 Common Mistake #2: Setting the same reg in multiple always blocks • Simulators will typically do what you tell them to do • Synthesis tools and lint checkers will typically give a warning • Never do this in Hardware verilog • You might be able to get away with it in testing verilog but normally don’t do it always @(a or b) begin x = a ^ b; end always @(reset) begin x = 1’b0; end
  • 4. © B. Baas 86 Mistake #3: Inferring State In Combinational Circuits By: An Incomplete Sensitivity List • always @(a) begin // missing b out = a & b; end • out updates when a changes as expected • out does not update when b changes! – Put another way, b can change all it wants but out will not update—this requires a memory element to remember the last value of out • Synthesis tools and lint checkers will give a warning • Using the construct new in Verilog 1364-2001: always @(*) or always @* eliminates this type of bug, but it is not supported by all modern CAD tools a out b edge detector G
  • 5. // this "always" block does not // instantiate combinational logic always @(freq or xyz or abc) begin if (xyz == 4’b0010) begin freq_c = abc; end case (freq) begin 3’b000: freq_c = abc; 3’b001: freq_c = abc + 3’b001; endcase end © B. Baas 87 • Example: attempted combinational circuit – If xyz==4’b0010, freq_c is a function of the inputs – If freq==3’b000 or 3’b001, freq_c is a function of the inputs – Otherwise, freq_c keeps its old value—which implies memory is needed! Which means our combinational circuit is broken. – A failure occurs when the inputs of a statement are different from the signals used for the if or case condition Mistake #4: Inferring State In Combinational Circuits By: Not Setting a reg In All Paths freq_c logic abc xyz freq
  • 6. // this "always" block does instantiate combinational logic always @(freq or xyz or abc) begin // “default” section of always block freq_c = freq; // some default value // main logic block if (xyz==4’b0010) begin freq_c = abc; end else begin // perhaps not always applicable freq_c = ...; end case (freq) begin 3’b000: freq_c = abc; 3’b001: freq_c = abc+3’b001; default: freq_c = ...; // perhaps you know freq should never be anything endcase // other than 000 or 001, or perhaps you do want end // freq_c equal to something in these six cases © B. Baas 88 • Example: successful combinational circuit – Solution: freq_c is set regardless of the values of all inputs – One solution: always declare default values at beginning of always blocks – If helpful, declare default case in case statements Mistake #4: Inferring State In Combinational Circuits By: Not Setting a reg In All Paths freq_c logic abc xyz freq Fixes all Fixes if Fixes only case
  • 7. © B. Baas 89 For Combinational Circuits: Avoid Inferring State by: 1. Including all input variables in the sensitivity list! 2. Set the value of all regs in all paths through every always block • A nice solution is to set default values for all output variables immediately after entering an always block o You will eliminate the chance of this bug if you do