SlideShare a Scribd company logo
SKEL 4273: CAD with HDL
Ab Al-Hadi Ab Rahman, PhD
Semester 2017/2018-2
Universiti Teknologi Malaysia
Topic 3: Verilog Modeling of
Basic Combinational Logic
Outline
• If-then-else, case, loop.
• Combinational logic units
• Multiplexers, decoders, adder, comparator
Introduction
• Rather than using gates or logic equations, the
circuits will be modelled in terms of their
behaviour, applying behavioural modelling.
• As the circuit models are described, some new
behavioural Verilog constructs are introduced.
• These constructs are similar to those found in
programming languages, including if-else-if, case
statements, and loops.
• They all control the activity of flow within the
behavioural description.
IF-ELSE Construct
module mux2_1 (in0, in1, sel, y) ;
input in0, in1, sel;
output y ;
reg y;
always @ (in0 or in1 or sel)
if (sel == 0) y = in0;
else y = in1;
endmodule
The conditional IF statement executes a
statement if a condition is true. There are
two other variants available: IF-ELSE and
IF-ELSE-IF statement
Multiplexers
module mux2_1 (in0, in1, sel, y) ;
input [3:0] in0, in1;
input sel ;
output [3,0] y ;
reg [3,0] y ;
always @ (in0 or in1 or sel)
if (sel == 0)
y = in0;
else
y = in1;
endmodule
4-bit 2x1 multiplexer
Multiplexers
module mux4_1 ( X, S, y) ;
input [3:0] X ;
input [1:0] S ;
output y ;
reg y ;
always @ (X or S)
if (S == 0) y = X[0] ;
else if (S == 1) y = X[1] ;
else if (S == 2) y = X[2] ;
else if (S == 3) y = X[3] ;
endmodule
A 4-bit 4-1 MUX using if-else-if
Case statements
• Similar to the switch statement in C.
• It searches from top to bottom to find a match
between the case expression and a case item.
• The case statement executes the statement
associated with the first match found
• It does not consider any remaining
possibilities.
Case statements
A 4-bit 4-1 MUX using case statement
module mux4_1 ( X, S, y) ;
input [3:0] X ;
input [1:0] S ;
output y ;
reg y ;
always @ (X or S)
case (S )
0 : y = X[0] ;
1 : y = X[1] ;
2 : y = X[2] ;
3 : y = X[3] ;
endcase
endmodule
Case statements
module dec2_4 ( A, en, W) ;
input [1:0] A ;
input en ;
output [0:3] W ;
reg [0:3] W ;
always @ (A or en)
case ( {en, A} )
3b’100 : W = 4’b1000 ;
3b’101 : W = 4’b0100 ;
3b’110 : W = 4’b0010 ;
3b’111 : W = 4’b0001 ;
default : W = ’b0 ;
endcase
endmodule
BCD-to-7 segment LED
BCD-to-7 segment LEDmodule SEG7 ( bcd, leds) ;
input [3:0] bcd ;
output [1:7] leds ;
reg [1:7] leds ;
always @ (bcd)
case ( bcd ) // abcdefg
0 : leds = 7’b1111110 ;
1 : leds = 7’b0110000;
2 : leds = 7’b1101101;
3 : leds = 7’b1111001;
4 : leds = 7’b0110011 ;
5 : leds = 7’b1011011;
6 : leds = 7’b1011111;
7 : leds = 7’b1110000;
8 : leds = 7’b1111111 ;
9 : leds = 7’b1111011;
default : leds = 7’bxxxxxxx ;
endcase
endmodule
If-else and Case
• The if-else and case statements are procedural
statements, and therefore must be contained in an
always block.
• The always construct infers an implied memory if there
are conditions under which the output of a
combinational circuit is not assigned a value.
• The output retains its old value, unwanted when
describing combinational logic.
• Important rules
– all inputs should be listed in the sensitivity list, and
– all combinational circuit outputs must have assigned
values.
Conditional operator
• Verilog also provides an alternative way to describe
these combinational logic circuits using continuous
assignment statements.
• Declared with the keyword assign
• LHS target of the assignment.
• RHS expression of an assign statement
• The conditional operator, denoted by “? :” symbol can
be used.
• E.g., “A ? B : C” reads as:
– If A is true, then the result of the expression is B, else the
result is C
Conditional operator
Example: Description of 2-to-1 MUX
with conditional operator
module mux2_1 (in0, in1, sel, y) ;
input in0, in1, sel;
output y ;
assign y = sel ? in1 : in0 ;
endmodule
Conditional operator
module mux_circuit (A, B, C, D, S, Y) ;
input [3:0] A, B, C, D;
input [1:0] S;
output [3:0] Y;
assign Y = S[1] ? (S[0] ? D : C) : (S[0] ?
B : A) ;
endmodule
Tristate buffer
module tristatebuffer (Din, oe, Dout) ;
input Din, oe;
output Dout ;
assign Dout = oe ? Din : 1‘bz ;
endmodule
Exercise: Write the Verilog code for the tristate buffer using sequential
statement, instead of the continuous statement construct.
Generate statements
• Useful when we want to instantiate a module
multiple times
Module adder_gen (output cout, output [2:0] sum, input Cin, input [2:0] a,b);
Wire [3:0] C;
assign C[0] = Cin;
assign cout = C[3];
genvar k;
generate
for (k=0; k<3; k=k+1)
begin: addbit
FA fa_gen(.Cin(C[k]), .x(b[k]), .y(a[k]), .sum(sum[k]), .cout(C[k+1]);
end
endgenerate
endmodule

More Related Content

What's hot

Principles of Electromechanical Energy Conversion
Principles of Electromechanical Energy ConversionPrinciples of Electromechanical Energy Conversion
Principles of Electromechanical Energy Conversion
Yimam Alemu
 
3phase circuits
3phase circuits3phase circuits
3phase circuits
Pradeepa M
 
Sumpner Test on Transformers
Sumpner Test on TransformersSumpner Test on Transformers
Sumpner Test on Transformers
Soham Gajjar
 
Load flow study Part-II
Load flow study Part-IILoad flow study Part-II
Load flow study Part-II
Asif Jamadar
 
Power Quality Issues and Mitigation Techniques
Power Quality Issues and Mitigation TechniquesPower Quality Issues and Mitigation Techniques
Power Quality Issues and Mitigation Techniques
Chaitra Panat
 
Electronic Measurement - Power Factor Meter
Electronic Measurement - Power Factor MeterElectronic Measurement - Power Factor Meter
Electronic Measurement - Power Factor Meter
Burdwan University
 
Turn ON-OFF Methods of SCR.pptx
Turn ON-OFF Methods of SCR.pptxTurn ON-OFF Methods of SCR.pptx
Turn ON-OFF Methods of SCR.pptx
SaiKenekar
 
load frequency control of two area
load frequency control of two areaload frequency control of two area
load frequency control of two area
Sumit Patel
 
fdocuments.in_chapter-2-the-per-unit-system-new.ppt
fdocuments.in_chapter-2-the-per-unit-system-new.pptfdocuments.in_chapter-2-the-per-unit-system-new.ppt
fdocuments.in_chapter-2-the-per-unit-system-new.ppt
vMty
 
Fault analysis using z bus
Fault analysis using z busFault analysis using z bus
Fault analysis using z bus
Revathi Subramaniam
 
Electrical Circuit Analysis Ch 01 basic concepts
Electrical Circuit Analysis Ch 01 basic conceptsElectrical Circuit Analysis Ch 01 basic concepts
Electrical Circuit Analysis Ch 01 basic concepts
Ali Farooq
 
V/F control of Induction Motor - Variable voltage and Variable frequency
V/F control of Induction Motor - Variable voltage and Variable frequencyV/F control of Induction Motor - Variable voltage and Variable frequency
V/F control of Induction Motor - Variable voltage and Variable frequency
Citharthan Durairaj
 
Eece 259 dc motor
Eece 259 dc motorEece 259 dc motor
Eece 259 dc motor
Md. Imtiaz Pathan
 
Three phase ac voltage controllers
Three phase ac voltage controllersThree phase ac voltage controllers
Three phase ac voltage controllers
Josin Hippolitus
 
POWER HARMONICS- SOURCES, ISSUES AND MITIGATION
POWER HARMONICS- SOURCES, ISSUES AND MITIGATIONPOWER HARMONICS- SOURCES, ISSUES AND MITIGATION
POWER HARMONICS- SOURCES, ISSUES AND MITIGATION
ASHIKS842
 
Current Source Inverter
Current Source InverterCurrent Source Inverter
Current Source Inverter
Rajendra Gharase
 
Three phase-circuits
Three phase-circuitsThree phase-circuits
Three phase-circuits
rsamurti
 
Performance of dc motors experiment 2
Performance of dc motors experiment 2Performance of dc motors experiment 2
Performance of dc motors experiment 2
Karimi LordRamza
 
180degree conduction mode of 3 phase inverter
180degree conduction mode of  3 phase inverter180degree conduction mode of  3 phase inverter
180degree conduction mode of 3 phase inverter
dineshanand810
 
Starting method for 3 phase induction motor
Starting method for 3 phase induction motorStarting method for 3 phase induction motor
Starting method for 3 phase induction motor
Ahmed A.Hassan
 

What's hot (20)

Principles of Electromechanical Energy Conversion
Principles of Electromechanical Energy ConversionPrinciples of Electromechanical Energy Conversion
Principles of Electromechanical Energy Conversion
 
3phase circuits
3phase circuits3phase circuits
3phase circuits
 
Sumpner Test on Transformers
Sumpner Test on TransformersSumpner Test on Transformers
Sumpner Test on Transformers
 
Load flow study Part-II
Load flow study Part-IILoad flow study Part-II
Load flow study Part-II
 
Power Quality Issues and Mitigation Techniques
Power Quality Issues and Mitigation TechniquesPower Quality Issues and Mitigation Techniques
Power Quality Issues and Mitigation Techniques
 
Electronic Measurement - Power Factor Meter
Electronic Measurement - Power Factor MeterElectronic Measurement - Power Factor Meter
Electronic Measurement - Power Factor Meter
 
Turn ON-OFF Methods of SCR.pptx
Turn ON-OFF Methods of SCR.pptxTurn ON-OFF Methods of SCR.pptx
Turn ON-OFF Methods of SCR.pptx
 
load frequency control of two area
load frequency control of two areaload frequency control of two area
load frequency control of two area
 
fdocuments.in_chapter-2-the-per-unit-system-new.ppt
fdocuments.in_chapter-2-the-per-unit-system-new.pptfdocuments.in_chapter-2-the-per-unit-system-new.ppt
fdocuments.in_chapter-2-the-per-unit-system-new.ppt
 
Fault analysis using z bus
Fault analysis using z busFault analysis using z bus
Fault analysis using z bus
 
Electrical Circuit Analysis Ch 01 basic concepts
Electrical Circuit Analysis Ch 01 basic conceptsElectrical Circuit Analysis Ch 01 basic concepts
Electrical Circuit Analysis Ch 01 basic concepts
 
V/F control of Induction Motor - Variable voltage and Variable frequency
V/F control of Induction Motor - Variable voltage and Variable frequencyV/F control of Induction Motor - Variable voltage and Variable frequency
V/F control of Induction Motor - Variable voltage and Variable frequency
 
Eece 259 dc motor
Eece 259 dc motorEece 259 dc motor
Eece 259 dc motor
 
Three phase ac voltage controllers
Three phase ac voltage controllersThree phase ac voltage controllers
Three phase ac voltage controllers
 
POWER HARMONICS- SOURCES, ISSUES AND MITIGATION
POWER HARMONICS- SOURCES, ISSUES AND MITIGATIONPOWER HARMONICS- SOURCES, ISSUES AND MITIGATION
POWER HARMONICS- SOURCES, ISSUES AND MITIGATION
 
Current Source Inverter
Current Source InverterCurrent Source Inverter
Current Source Inverter
 
Three phase-circuits
Three phase-circuitsThree phase-circuits
Three phase-circuits
 
Performance of dc motors experiment 2
Performance of dc motors experiment 2Performance of dc motors experiment 2
Performance of dc motors experiment 2
 
180degree conduction mode of 3 phase inverter
180degree conduction mode of  3 phase inverter180degree conduction mode of  3 phase inverter
180degree conduction mode of 3 phase inverter
 
Starting method for 3 phase induction motor
Starting method for 3 phase induction motorStarting method for 3 phase induction motor
Starting method for 3 phase induction motor
 

Similar to SKEL 4273 CAD with HDL Topic 3

SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2
alhadi81
 
VIT_Workshop.ppt
VIT_Workshop.pptVIT_Workshop.ppt
VIT_Workshop.ppt
VINOTHRAJR1
 
dokumen.tips_verilog-basic-ppt.pdf
dokumen.tips_verilog-basic-ppt.pdfdokumen.tips_verilog-basic-ppt.pdf
dokumen.tips_verilog-basic-ppt.pdf
Velmathi Saravanan
 
verilog ppt .pdf
verilog ppt .pdfverilog ppt .pdf
verilog ppt .pdf
RavinaBishnoi8
 
Verilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfVerilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdf
sagar414433
 
Verilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfVerilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdf
sagar414433
 
Verilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdfVerilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdf
DrViswanathKalannaga1
 
System Verilog (Tutorial -- 2X1 Multiplexer)
System Verilog (Tutorial -- 2X1 Multiplexer)System Verilog (Tutorial -- 2X1 Multiplexer)
System Verilog (Tutorial -- 2X1 Multiplexer)
Denise Wilson
 
Vhdl
VhdlVhdl
Block diagram
Block diagramBlock diagram
Block diagram
Sagar Kuntumal
 
CH3_Gate Level Minimization.pdf
CH3_Gate Level Minimization.pdfCH3_Gate Level Minimization.pdf
CH3_Gate Level Minimization.pdf
SanjoySana2
 
Hardware Description Language
Hardware Description Language Hardware Description Language
Hardware Description Language
Prachi Pandey
 
Advanced Digital Design With The Verilog HDL
Advanced Digital Design With The Verilog HDLAdvanced Digital Design With The Verilog HDL
Advanced Digital Design With The Verilog HDL
Tony Lisko
 
Verilogforlab
VerilogforlabVerilogforlab
Verilogforlab
Shankar Bhukya
 
slide8.ppt
slide8.pptslide8.ppt
slide8.ppt
ssuserd3cf02
 
Overview of verilog
Overview of verilogOverview of verilog
Overview of verilog
Raghu Veer
 
kalaivaanar_NSK_V3.ppt
kalaivaanar_NSK_V3.pptkalaivaanar_NSK_V3.ppt
kalaivaanar_NSK_V3.ppt
VINOTHRAJR1
 
Coding verilog
Coding verilogCoding verilog
Coding verilog
umarjamil10000
 
Vlsiexpt 11 12
Vlsiexpt 11 12Vlsiexpt 11 12
Vlsiexpt 11 12
JINCY Soju
 
Understanding High-dimensional Networks for Continuous Variables Using ECL
Understanding High-dimensional Networks for Continuous Variables Using ECLUnderstanding High-dimensional Networks for Continuous Variables Using ECL
Understanding High-dimensional Networks for Continuous Variables Using ECL
HPCC Systems
 

Similar to SKEL 4273 CAD with HDL Topic 3 (20)

SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2
 
VIT_Workshop.ppt
VIT_Workshop.pptVIT_Workshop.ppt
VIT_Workshop.ppt
 
dokumen.tips_verilog-basic-ppt.pdf
dokumen.tips_verilog-basic-ppt.pdfdokumen.tips_verilog-basic-ppt.pdf
dokumen.tips_verilog-basic-ppt.pdf
 
verilog ppt .pdf
verilog ppt .pdfverilog ppt .pdf
verilog ppt .pdf
 
Verilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfVerilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdf
 
Verilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfVerilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdf
 
Verilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdfVerilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdf
 
System Verilog (Tutorial -- 2X1 Multiplexer)
System Verilog (Tutorial -- 2X1 Multiplexer)System Verilog (Tutorial -- 2X1 Multiplexer)
System Verilog (Tutorial -- 2X1 Multiplexer)
 
Vhdl
VhdlVhdl
Vhdl
 
Block diagram
Block diagramBlock diagram
Block diagram
 
CH3_Gate Level Minimization.pdf
CH3_Gate Level Minimization.pdfCH3_Gate Level Minimization.pdf
CH3_Gate Level Minimization.pdf
 
Hardware Description Language
Hardware Description Language Hardware Description Language
Hardware Description Language
 
Advanced Digital Design With The Verilog HDL
Advanced Digital Design With The Verilog HDLAdvanced Digital Design With The Verilog HDL
Advanced Digital Design With The Verilog HDL
 
Verilogforlab
VerilogforlabVerilogforlab
Verilogforlab
 
slide8.ppt
slide8.pptslide8.ppt
slide8.ppt
 
Overview of verilog
Overview of verilogOverview of verilog
Overview of verilog
 
kalaivaanar_NSK_V3.ppt
kalaivaanar_NSK_V3.pptkalaivaanar_NSK_V3.ppt
kalaivaanar_NSK_V3.ppt
 
Coding verilog
Coding verilogCoding verilog
Coding verilog
 
Vlsiexpt 11 12
Vlsiexpt 11 12Vlsiexpt 11 12
Vlsiexpt 11 12
 
Understanding High-dimensional Networks for Continuous Variables Using ECL
Understanding High-dimensional Networks for Continuous Variables Using ECLUnderstanding High-dimensional Networks for Continuous Variables Using ECL
Understanding High-dimensional Networks for Continuous Variables Using ECL
 

Recently uploaded

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 

Recently uploaded (20)

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 

SKEL 4273 CAD with HDL Topic 3

  • 1. SKEL 4273: CAD with HDL Ab Al-Hadi Ab Rahman, PhD Semester 2017/2018-2 Universiti Teknologi Malaysia Topic 3: Verilog Modeling of Basic Combinational Logic
  • 2. Outline • If-then-else, case, loop. • Combinational logic units • Multiplexers, decoders, adder, comparator
  • 3. Introduction • Rather than using gates or logic equations, the circuits will be modelled in terms of their behaviour, applying behavioural modelling. • As the circuit models are described, some new behavioural Verilog constructs are introduced. • These constructs are similar to those found in programming languages, including if-else-if, case statements, and loops. • They all control the activity of flow within the behavioural description.
  • 4. IF-ELSE Construct module mux2_1 (in0, in1, sel, y) ; input in0, in1, sel; output y ; reg y; always @ (in0 or in1 or sel) if (sel == 0) y = in0; else y = in1; endmodule The conditional IF statement executes a statement if a condition is true. There are two other variants available: IF-ELSE and IF-ELSE-IF statement
  • 5. Multiplexers module mux2_1 (in0, in1, sel, y) ; input [3:0] in0, in1; input sel ; output [3,0] y ; reg [3,0] y ; always @ (in0 or in1 or sel) if (sel == 0) y = in0; else y = in1; endmodule 4-bit 2x1 multiplexer
  • 6. Multiplexers module mux4_1 ( X, S, y) ; input [3:0] X ; input [1:0] S ; output y ; reg y ; always @ (X or S) if (S == 0) y = X[0] ; else if (S == 1) y = X[1] ; else if (S == 2) y = X[2] ; else if (S == 3) y = X[3] ; endmodule A 4-bit 4-1 MUX using if-else-if
  • 7. Case statements • Similar to the switch statement in C. • It searches from top to bottom to find a match between the case expression and a case item. • The case statement executes the statement associated with the first match found • It does not consider any remaining possibilities.
  • 8. Case statements A 4-bit 4-1 MUX using case statement module mux4_1 ( X, S, y) ; input [3:0] X ; input [1:0] S ; output y ; reg y ; always @ (X or S) case (S ) 0 : y = X[0] ; 1 : y = X[1] ; 2 : y = X[2] ; 3 : y = X[3] ; endcase endmodule
  • 9. Case statements module dec2_4 ( A, en, W) ; input [1:0] A ; input en ; output [0:3] W ; reg [0:3] W ; always @ (A or en) case ( {en, A} ) 3b’100 : W = 4’b1000 ; 3b’101 : W = 4’b0100 ; 3b’110 : W = 4’b0010 ; 3b’111 : W = 4’b0001 ; default : W = ’b0 ; endcase endmodule
  • 11. BCD-to-7 segment LEDmodule SEG7 ( bcd, leds) ; input [3:0] bcd ; output [1:7] leds ; reg [1:7] leds ; always @ (bcd) case ( bcd ) // abcdefg 0 : leds = 7’b1111110 ; 1 : leds = 7’b0110000; 2 : leds = 7’b1101101; 3 : leds = 7’b1111001; 4 : leds = 7’b0110011 ; 5 : leds = 7’b1011011; 6 : leds = 7’b1011111; 7 : leds = 7’b1110000; 8 : leds = 7’b1111111 ; 9 : leds = 7’b1111011; default : leds = 7’bxxxxxxx ; endcase endmodule
  • 12. If-else and Case • The if-else and case statements are procedural statements, and therefore must be contained in an always block. • The always construct infers an implied memory if there are conditions under which the output of a combinational circuit is not assigned a value. • The output retains its old value, unwanted when describing combinational logic. • Important rules – all inputs should be listed in the sensitivity list, and – all combinational circuit outputs must have assigned values.
  • 13. Conditional operator • Verilog also provides an alternative way to describe these combinational logic circuits using continuous assignment statements. • Declared with the keyword assign • LHS target of the assignment. • RHS expression of an assign statement • The conditional operator, denoted by “? :” symbol can be used. • E.g., “A ? B : C” reads as: – If A is true, then the result of the expression is B, else the result is C
  • 14. Conditional operator Example: Description of 2-to-1 MUX with conditional operator module mux2_1 (in0, in1, sel, y) ; input in0, in1, sel; output y ; assign y = sel ? in1 : in0 ; endmodule
  • 15. Conditional operator module mux_circuit (A, B, C, D, S, Y) ; input [3:0] A, B, C, D; input [1:0] S; output [3:0] Y; assign Y = S[1] ? (S[0] ? D : C) : (S[0] ? B : A) ; endmodule
  • 16. Tristate buffer module tristatebuffer (Din, oe, Dout) ; input Din, oe; output Dout ; assign Dout = oe ? Din : 1‘bz ; endmodule Exercise: Write the Verilog code for the tristate buffer using sequential statement, instead of the continuous statement construct.
  • 17. Generate statements • Useful when we want to instantiate a module multiple times Module adder_gen (output cout, output [2:0] sum, input Cin, input [2:0] a,b); Wire [3:0] C; assign C[0] = Cin; assign cout = C[3]; genvar k; generate for (k=0; k<3; k=k+1) begin: addbit FA fa_gen(.Cin(C[k]), .x(b[k]), .y(a[k]), .sum(sum[k]), .cout(C[k+1]); end endgenerate endmodule