SlideShare a Scribd company logo
1 of 28
Digital Design Using Verilog
- For Absolute Beginners
LEC 8 :Verilog Blocking & Non-
Blocking Assignments
PROLOGUE
• In the earlier lecture , you have seen the basic
concepts of Verilog Behavioral modelling with
some examples.
• Before going further, let us recapitulate what we
have learnt in the earlier lecture .
• In the behaviour model,which is mainly based on
the Proedural block ,there are aminly two
importanr constructs.
• One is always block and the other is Initial Block.
Procedural assignments
• Always block is used to describe the circuit
functionality using behavioral statements.
• The Initial block is used to initialize behavioral
statements for simulation.
• Each ‘always’ and ‘Initial’ block represents a
separate process.
• These processes run in parallel(concurrently)and
start at time 0.
• Statements inside the process are execute
sequentially.
Always block
• Always block consists of behavioural statements
and keywords begin and end must be used if the
block contains more than one statements.
• Example:
module clk_gen
# (parameter period = 50)
(
output reg clk
)
initial
clk = 1’b0;
contd
23 June 2020 5yayavaram@yahoo.com
• always
# (period/2 ) clk = ~ clk;
initial
# 100 $ finish;
endmodule
Example -2
23 June 2020 6yayavaram@yahoo.com
• module clock _gen (output, reg, clock);//Initialize
clock at time zero
initial
clock = 1'b0;
//Toggle clock every half-cycle (time period = 20)
always
# 10 clock = ~clock;
initial
#1000 $finish;
endmodule
contd
23 June 2020 7yayavaram@yahoo.com
• In this example , the always statement starts at time
0 and executes the statement clock = ~clock at every
10 time units.
• If the initialization of clock is inside the always
block, clock will be initialized every time the
‘always’ is entered.
• Also, the simulation must be halted inside an initial
statement. If there is no $stop or $finish statement to
halt the simulation, the clock generator will run
forever.
Initial Block
23 June 2020 8yayavaram@yahoo.com
• All statements inside an ‘initial’ statement constitute
the initial block. This is executed only once by the
simulator.
• The multiple statements are grouped in a ‘begin ..
end’ structure.
• The statement inside an ‘initial’ block start at time 0.
• If there are multiple blocks all the blocks start
concurrently at time 0 only.
• The initial block is typically used to write test bench
for simulation.
Ex: Initial Block
23 June 2020 9yayavaram@yahoo.com
• module stimulus;
reg x,y, a, b, m;
initial
m = 1'b0; //single statement; need not be grouped
initial
begin
#5 a = 1'b1; //multiple statements ,so grouped
#25 b = 1'b0;
• end
ex contd
23 June 2020 10yayavaram@yahoo.com
initial
begin
#10 x = 1'b0;
#25 y = 1'b1;
end
Initial
#50 $ finish; // no grouping
endmodule
ex contd
23 June 2020 11yayavaram@yahoo.com
• Thus, the execution sequence of the statements
inside the initial blocks will be as follows.
time statement executed
0 m = 1'b0;
5 a = 1'b1;
10 x = 1'b0;
30 b = 1'b0;
35 y = 1'b1;
50 $finish;
• Procedural assignments update values of reg,
integer, real, or time variables.
• The value placed on a variable will remain
unchanged until another procedural assignment
updates the variable with a different value.
• There are two types of procedural assignment
statements .
(i).Blocking assignments &
(ii).Non-Blocking Assignments
23 June 2020 12yayavaram@yahoo.com
Procedural Assignment types
BLOCKING ASSIGNMENT
• It is the most commonly used assignment and
denoted by ‘equal to sign ‘ (=).
• The target of the assignment is gets updated before
the next sequential in the procedural block is
executed.
• That means, a statement using the blocking
assignment blocks the execution of the statements
following it,until it gets completed.
• This type of assignment is normally used for
combinational logic For ex: Y = A & B;
23 June 2020 13yayavaram@yahoo.com
Non-Blocking Assignment(<=)
• This assignment is denoted by ‘less than equal to’
symbol. It is normally used in Sequential logic.
• In this style , the assignment to the target gets
scheduled for the end of the simulation cycle.
• i.e normally occurs at the end of the sequential block
• The statements, subsequent to the instruction under
consideration are not blocked by the assignment.
• This non-blocking assignment uses several reg type
variables synchronously under the control of
common clock.
23 June 2020 14yayavaram@yahoo.com
Example-Blocking
• reg x, y, z;
reg [15:0] reg_a, reg_b;
integer count;
initial begin
x = 0; y = 1; z = 1; // Scalar assignments
count = 0; //Assignment to integer variables
reg_a = 16'b0; reg_b = reg_a; / initialize vectors
#15 reg_a[2] = 1'b1; delay
#10 reg_b[15:13] = {x, y, z}
count = count + 1;
end
23 June 2020 15yayavaram@yahoo.com
Example-Blocking
• reg x, y, z;
• reg [15:0] reg_a, reg_b;
• integer count;
• initial begin
• x = 0; y = 1; z = 1; // Scalar assignments
• count = 0; //Assignment to integer variables
• reg_a = 16'b0; reg_b = reg_a; / initialize vectors
• #15 reg_a[2] = 1'b1; delay
• #10 reg_b[15:13] = {x, y, z}
• count = count + 1;
• end
23 June 2020 16yayavaram@yahoo.com
contd
• All statements x = 0 through reg_b = reg_a are
executed at time 0.
• Statement reg_a[2] = 0 at time = 15
• Statement reg_b[15:13] = {x, y, z} at time = 25
• Statement count = count + 1 at time = 25
• Since there is a delay of 15 and 10 in the preceding
statements, count = count + 1 will be executed at
time = 25 units
23 June 2020 17yayavaram@yahoo.com
Ex: Blocking vs Non-Blocking
Lets take the following example. Assume that initially,
a= 1 and b =2
23 June 2020 18yayavaram@yahoo.com
contd
• After simulation the result is
• a = b = 2 ; a=c=2 --in the blocking assignment
• a = b = 2 ; a=c=1 --in non-blocking assignment
23 June 2020 19yayavaram@yahoo.com
Blocking & Non Blocking Examples
• begin -------//Blocking example
a = 1 ; // at time 0 , the variable a is 1
#10 a = 0; // at time 10 , the variable a = 0
# 5 a = 4; // at time 15 ,the variable a = 4;
end
• begin ………// non-blocking example
a <= 1 ; // at time 0 the variable a = 1.
#10 a <= 0 ; // at time 5 the variable a = 4
# 5 a<= 4 ; // at time 10 the variable a = 0
end
23 June 2020 20yayavaram@yahoo.com
Another example
• module block_nonblock();
reg a,b,c,d,e,f;
initial begin
a =#10 1’b1 ;//the variable a= 1 at time 10
b = #20 1’b0 ;// the variable a= 0 at time 30
c = # 40 1’b 1 ;// the variable a =1 at time 70
end
initial begin
d <= #10 1’b1 ; // the variable a = 1 at time 10
23 June 2020 21yayavaram@yahoo.com
contd
e <= # 20 1’b 0 ; // the variable a = 0 at time 20
f <= # 40 1’b 1 ; // the variable a = 1 at time 40
end
endmodule
23 June 2020 22yayavaram@yahoo.com
(i). always @(posedge clk) (ii).always@(posedge clk)
begin begin
x = next_x ; x <= next_x;
end end
23 June 2020 23yayavaram@yahoo.com
DESIGN EXAMPLES
Different Example
always@(posedge clk) always @(posedge clk)
begin begin
x = next_x ; x<= next_x;
y = x; y <= x;
end end
23 June 2020 24yayavaram@yahoo.com
Ex: fork and join
• fork This fork –join block has the same
a = 1 ; functionality as the block with
# 10 a = 0; non-blocking assignment.
# 5 a = 4;
join
23 June 2020 25yayavaram@yahoo.com
While loop
Initial begin
Count = 0;
While (count <101)
begin
$display (‘count = %d”,count);
count = count +1;
end
end
23 June 2020 26yayavaram@yahoo.com
If –else example
always @ * begin
if(sel1)
q = A:
else if(sel2)
q = B;
else q =C ;
end
23 June 2020 27yayavaram@yahoo.com
23 June 2020 28yayavaram@yahoo.com
THANQ FOR WATCHINIG
GOOD LUCK !!

More Related Content

What's hot

What's hot (20)

Delays in verilog
Delays in verilogDelays in verilog
Delays in verilog
 
Data types in verilog
Data types in verilogData types in verilog
Data types in verilog
 
Verilog Test Bench
Verilog Test BenchVerilog Test Bench
Verilog Test Bench
 
Sta by usha_mehta
Sta by usha_mehtaSta by usha_mehta
Sta by usha_mehta
 
Vlsi physical design-notes
Vlsi physical design-notesVlsi physical design-notes
Vlsi physical design-notes
 
Unit VI CPLD-FPGA Architecture
Unit VI CPLD-FPGA ArchitectureUnit VI CPLD-FPGA Architecture
Unit VI CPLD-FPGA Architecture
 
4.FPGA for dummies: Design Flow
4.FPGA for dummies: Design Flow4.FPGA for dummies: Design Flow
4.FPGA for dummies: Design Flow
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
 
Physical design
Physical design Physical design
Physical design
 
Clock divider by 3
Clock divider by 3Clock divider by 3
Clock divider by 3
 
Project Report Of SRAM Design
Project Report Of SRAM DesignProject Report Of SRAM Design
Project Report Of SRAM Design
 
UVM Methodology Tutorial
UVM Methodology TutorialUVM Methodology Tutorial
UVM Methodology Tutorial
 
Programmable Logic Devices Plds
Programmable Logic Devices PldsProgrammable Logic Devices Plds
Programmable Logic Devices Plds
 
Inputs of physical design
Inputs of physical designInputs of physical design
Inputs of physical design
 
Verilog full adder in dataflow & gate level modelling style.
Verilog full adder in dataflow  & gate level modelling style.Verilog full adder in dataflow  & gate level modelling style.
Verilog full adder in dataflow & gate level modelling style.
 
FPGA
FPGAFPGA
FPGA
 
Verilog data types -For beginners
Verilog data types -For beginnersVerilog data types -For beginners
Verilog data types -For beginners
 
CPU Verification
CPU VerificationCPU Verification
CPU Verification
 
System verilog assertions
System verilog assertionsSystem verilog assertions
System verilog assertions
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4
 

Similar to VERILOG HDL :: Blocking & NON- Blocking assignments

Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machine
Malik Tauqir Hasan
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
Béo Tú
 

Similar to VERILOG HDL :: Blocking & NON- Blocking assignments (20)

Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machine
 
Lect 7: Verilog Behavioral model for Absolute Beginners
Lect 7: Verilog Behavioral model for Absolute BeginnersLect 7: Verilog Behavioral model for Absolute Beginners
Lect 7: Verilog Behavioral model for Absolute Beginners
 
Verilog Lecture4 2014
Verilog Lecture4 2014Verilog Lecture4 2014
Verilog Lecture4 2014
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONS
 
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
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
 
Operating System
Operating SystemOperating System
Operating System
 
Lecture1
Lecture1Lecture1
Lecture1
 
Python unit 3 part 1
Python unit 3 part 1Python unit 3 part 1
Python unit 3 part 1
 
Pro Java Fx – Developing Enterprise Applications
Pro Java Fx – Developing Enterprise ApplicationsPro Java Fx – Developing Enterprise Applications
Pro Java Fx – Developing Enterprise Applications
 
Synchronization in os.pptx
Synchronization in os.pptxSynchronization in os.pptx
Synchronization in os.pptx
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
MODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxMODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptx
 
lecture8_Cuong.ppt
lecture8_Cuong.pptlecture8_Cuong.ppt
lecture8_Cuong.ppt
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
 
UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
 
Functional Coverage Development Tips - Mentor Graphics
Functional Coverage Development Tips - Mentor GraphicsFunctional Coverage Development Tips - Mentor Graphics
Functional Coverage Development Tips - Mentor Graphics
 

More from Dr.YNM

More from Dr.YNM (20)

Introduction to DSP.ppt
Introduction to DSP.pptIntroduction to DSP.ppt
Introduction to DSP.ppt
 
Atmel.ppt
Atmel.pptAtmel.ppt
Atmel.ppt
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.ppt
 
Crystalstructure-.ppt
Crystalstructure-.pptCrystalstructure-.ppt
Crystalstructure-.ppt
 
Basics of OS & RTOS.ppt
Basics of OS & RTOS.pptBasics of OS & RTOS.ppt
Basics of OS & RTOS.ppt
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptx
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
Introduction to ASICs.pptx
Introduction to ASICs.pptxIntroduction to ASICs.pptx
Introduction to ASICs.pptx
 
VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.ppt
 
Basics of data communications.pptx
Basics of data communications.pptxBasics of data communications.pptx
Basics of data communications.pptx
 
CPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptxCPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptx
 
Transient response of RC , RL circuits with step input
Transient response of RC , RL circuits  with step inputTransient response of RC , RL circuits  with step input
Transient response of RC , RL circuits with step input
 
CISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURESCISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURES
 
Lect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURELect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURE
 
Lect 3 ARM PROCESSOR ARCHITECTURE
Lect 3  ARM PROCESSOR ARCHITECTURE Lect 3  ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE
 
Microprocessor Architecture 4
Microprocessor Architecture  4Microprocessor Architecture  4
Microprocessor Architecture 4
 
Lect 2 ARM processor architecture
Lect 2 ARM processor architectureLect 2 ARM processor architecture
Lect 2 ARM processor architecture
 
Microprocessor Architecture-III
Microprocessor Architecture-IIIMicroprocessor Architecture-III
Microprocessor Architecture-III
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORS
 
Microprocessor architecture II
Microprocessor architecture   IIMicroprocessor architecture   II
Microprocessor architecture II
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 

VERILOG HDL :: Blocking & NON- Blocking assignments

  • 1. Digital Design Using Verilog - For Absolute Beginners LEC 8 :Verilog Blocking & Non- Blocking Assignments
  • 2. PROLOGUE • In the earlier lecture , you have seen the basic concepts of Verilog Behavioral modelling with some examples. • Before going further, let us recapitulate what we have learnt in the earlier lecture . • In the behaviour model,which is mainly based on the Proedural block ,there are aminly two importanr constructs. • One is always block and the other is Initial Block.
  • 3. Procedural assignments • Always block is used to describe the circuit functionality using behavioral statements. • The Initial block is used to initialize behavioral statements for simulation. • Each ‘always’ and ‘Initial’ block represents a separate process. • These processes run in parallel(concurrently)and start at time 0. • Statements inside the process are execute sequentially.
  • 4. Always block • Always block consists of behavioural statements and keywords begin and end must be used if the block contains more than one statements. • Example: module clk_gen # (parameter period = 50) ( output reg clk ) initial clk = 1’b0;
  • 5. contd 23 June 2020 5yayavaram@yahoo.com • always # (period/2 ) clk = ~ clk; initial # 100 $ finish; endmodule
  • 6. Example -2 23 June 2020 6yayavaram@yahoo.com • module clock _gen (output, reg, clock);//Initialize clock at time zero initial clock = 1'b0; //Toggle clock every half-cycle (time period = 20) always # 10 clock = ~clock; initial #1000 $finish; endmodule
  • 7. contd 23 June 2020 7yayavaram@yahoo.com • In this example , the always statement starts at time 0 and executes the statement clock = ~clock at every 10 time units. • If the initialization of clock is inside the always block, clock will be initialized every time the ‘always’ is entered. • Also, the simulation must be halted inside an initial statement. If there is no $stop or $finish statement to halt the simulation, the clock generator will run forever.
  • 8. Initial Block 23 June 2020 8yayavaram@yahoo.com • All statements inside an ‘initial’ statement constitute the initial block. This is executed only once by the simulator. • The multiple statements are grouped in a ‘begin .. end’ structure. • The statement inside an ‘initial’ block start at time 0. • If there are multiple blocks all the blocks start concurrently at time 0 only. • The initial block is typically used to write test bench for simulation.
  • 9. Ex: Initial Block 23 June 2020 9yayavaram@yahoo.com • module stimulus; reg x,y, a, b, m; initial m = 1'b0; //single statement; need not be grouped initial begin #5 a = 1'b1; //multiple statements ,so grouped #25 b = 1'b0; • end
  • 10. ex contd 23 June 2020 10yayavaram@yahoo.com initial begin #10 x = 1'b0; #25 y = 1'b1; end Initial #50 $ finish; // no grouping endmodule
  • 11. ex contd 23 June 2020 11yayavaram@yahoo.com • Thus, the execution sequence of the statements inside the initial blocks will be as follows. time statement executed 0 m = 1'b0; 5 a = 1'b1; 10 x = 1'b0; 30 b = 1'b0; 35 y = 1'b1; 50 $finish;
  • 12. • Procedural assignments update values of reg, integer, real, or time variables. • The value placed on a variable will remain unchanged until another procedural assignment updates the variable with a different value. • There are two types of procedural assignment statements . (i).Blocking assignments & (ii).Non-Blocking Assignments 23 June 2020 12yayavaram@yahoo.com Procedural Assignment types
  • 13. BLOCKING ASSIGNMENT • It is the most commonly used assignment and denoted by ‘equal to sign ‘ (=). • The target of the assignment is gets updated before the next sequential in the procedural block is executed. • That means, a statement using the blocking assignment blocks the execution of the statements following it,until it gets completed. • This type of assignment is normally used for combinational logic For ex: Y = A & B; 23 June 2020 13yayavaram@yahoo.com
  • 14. Non-Blocking Assignment(<=) • This assignment is denoted by ‘less than equal to’ symbol. It is normally used in Sequential logic. • In this style , the assignment to the target gets scheduled for the end of the simulation cycle. • i.e normally occurs at the end of the sequential block • The statements, subsequent to the instruction under consideration are not blocked by the assignment. • This non-blocking assignment uses several reg type variables synchronously under the control of common clock. 23 June 2020 14yayavaram@yahoo.com
  • 15. Example-Blocking • reg x, y, z; reg [15:0] reg_a, reg_b; integer count; initial begin x = 0; y = 1; z = 1; // Scalar assignments count = 0; //Assignment to integer variables reg_a = 16'b0; reg_b = reg_a; / initialize vectors #15 reg_a[2] = 1'b1; delay #10 reg_b[15:13] = {x, y, z} count = count + 1; end 23 June 2020 15yayavaram@yahoo.com
  • 16. Example-Blocking • reg x, y, z; • reg [15:0] reg_a, reg_b; • integer count; • initial begin • x = 0; y = 1; z = 1; // Scalar assignments • count = 0; //Assignment to integer variables • reg_a = 16'b0; reg_b = reg_a; / initialize vectors • #15 reg_a[2] = 1'b1; delay • #10 reg_b[15:13] = {x, y, z} • count = count + 1; • end 23 June 2020 16yayavaram@yahoo.com
  • 17. contd • All statements x = 0 through reg_b = reg_a are executed at time 0. • Statement reg_a[2] = 0 at time = 15 • Statement reg_b[15:13] = {x, y, z} at time = 25 • Statement count = count + 1 at time = 25 • Since there is a delay of 15 and 10 in the preceding statements, count = count + 1 will be executed at time = 25 units 23 June 2020 17yayavaram@yahoo.com
  • 18. Ex: Blocking vs Non-Blocking Lets take the following example. Assume that initially, a= 1 and b =2 23 June 2020 18yayavaram@yahoo.com
  • 19. contd • After simulation the result is • a = b = 2 ; a=c=2 --in the blocking assignment • a = b = 2 ; a=c=1 --in non-blocking assignment 23 June 2020 19yayavaram@yahoo.com
  • 20. Blocking & Non Blocking Examples • begin -------//Blocking example a = 1 ; // at time 0 , the variable a is 1 #10 a = 0; // at time 10 , the variable a = 0 # 5 a = 4; // at time 15 ,the variable a = 4; end • begin ………// non-blocking example a <= 1 ; // at time 0 the variable a = 1. #10 a <= 0 ; // at time 5 the variable a = 4 # 5 a<= 4 ; // at time 10 the variable a = 0 end 23 June 2020 20yayavaram@yahoo.com
  • 21. Another example • module block_nonblock(); reg a,b,c,d,e,f; initial begin a =#10 1’b1 ;//the variable a= 1 at time 10 b = #20 1’b0 ;// the variable a= 0 at time 30 c = # 40 1’b 1 ;// the variable a =1 at time 70 end initial begin d <= #10 1’b1 ; // the variable a = 1 at time 10 23 June 2020 21yayavaram@yahoo.com
  • 22. contd e <= # 20 1’b 0 ; // the variable a = 0 at time 20 f <= # 40 1’b 1 ; // the variable a = 1 at time 40 end endmodule 23 June 2020 22yayavaram@yahoo.com
  • 23. (i). always @(posedge clk) (ii).always@(posedge clk) begin begin x = next_x ; x <= next_x; end end 23 June 2020 23yayavaram@yahoo.com DESIGN EXAMPLES
  • 24. Different Example always@(posedge clk) always @(posedge clk) begin begin x = next_x ; x<= next_x; y = x; y <= x; end end 23 June 2020 24yayavaram@yahoo.com
  • 25. Ex: fork and join • fork This fork –join block has the same a = 1 ; functionality as the block with # 10 a = 0; non-blocking assignment. # 5 a = 4; join 23 June 2020 25yayavaram@yahoo.com
  • 26. While loop Initial begin Count = 0; While (count <101) begin $display (‘count = %d”,count); count = count +1; end end 23 June 2020 26yayavaram@yahoo.com
  • 27. If –else example always @ * begin if(sel1) q = A: else if(sel2) q = B; else q =C ; end 23 June 2020 27yayavaram@yahoo.com
  • 28. 23 June 2020 28yayavaram@yahoo.com THANQ FOR WATCHINIG GOOD LUCK !!

Editor's Notes

  1. If the value of S is 1 ,then Y= B other wise Y= A