SlideShare a Scribd company logo
1 of 25
VHDL 360© by: Mohamed Samy         Samer El-Saadany
Copyrights Copyright © 2010 to authors. All rights reserved All content in this presentation, including charts, data, artwork and logos (from here on, "the Content"), is the property of Mohamed Samy and Samer El-Saadany or the corresponding owners, depending on the circumstances of publication, and is protected by national and international copyright laws. Authors are not personally liable for your usage of the Content that entailed casual or indirect destruction of anything or actions entailed to information profit loss or other losses. Users are granted to access, display, download and print portions of this presentation, solely for their own personal non-commercial use, provided that all proprietary notices are kept intact.  Product names and trademarks mentioned in this presentation belong to their respective owners. VHDL 360 © 2
Objective Modeling more complicated logic using sequential statements Skills gained: Identify sequential environment in VHDL Model simple sequential logic VHDL 360 © 3
Outline Process Description  Data Objects Sequential Statements Case Statement IF Statement VHDL 360 © 4
Statements VHDL has concurrent statements and sequential statements Concurrent statements are executed in parallel with respect to each other, we explained some of them in Module 1* Sequential statements are executed in sequence with respect to each other. Sequential statements should be written inside a “process” VHDL 360 © 5 Module 1: Create your first model for a simple logic circuit
Process Description Process ( <sensitivity_list> ) -- process declarations  begin -- process body endprocess; 6 VHDL 360 © Syntax: Process declarations: defines variables, subprograms…etc to be used in process body Process body: defines implementation details of input/output relationship in a sequential manner <sensitivity_list>: List of signals/ports that cause the process to be executed whenever there is a change in their values Example 1: Architecture behave of example1 is Begin    process(x,y)-- Every time "x" or "y" value is changed, the process will be executed    begin myOutput<= x nand y;    endprocess; End behave ;
Sequential Assignments Statements inside a “process” are read sequentially and executed when the “process” suspends Signal assignment statement like “F <= A” causes a transaction to be scheduled This means; the current value of A is read and scheduled to drive F when the process suspends. “Process” suspends in two situations When “end process” is reached When a “wait” statement is reached 7 VHDL 360 © Example 2: process(...)-- Assume that initially A = '1' while G, F, Z and X = 'U'  Begin   Z <= A;-- Signal assignment, schedule a change/transaction,                  -- however the value of Z still equals 'U'   G <='1';   F <= G;-- G is not yet updated, so F is assigned the old value of G   X <= F;-- Similarly, X is assigned the old value of F   G <='0';-- overrides the previous scheduled transaction,                  -- however the value of G still equals 'U'     Z <= G; endprocess;-- Process suspends => Signals update with scheduled transactions                  -- G = '0', F = 'U', Z = 'U', X = 'U'
Sequential Assignments 8 VHDL 360 © Example 3: Architecture behave offulladderis 	signal temp :std_logic; Begin process(In1, In2, CarryIn) begin temp <= In1 XOR In2;     Sum  <= temp XORCarryIn; CarryOut<= (In1 AND In2) OR (CarryInAND temp); endprocess; End behave ; There’s a problem here!
Data Objects 9 VHDL 360 © VHDL offers different data objects: Constants Used to store values that can’t be changed during simulation time  Signals Used to model connections Signals can be  External  (Ports) used as an interface for the entity to the outside world (Declared in Entity) Internal  used inside the architecture to connect different logic parts (Usually declared in architecture) Assigned using “<=” Outside a process, its value is updated when their signal assignment is executed. Inside a process, its value is updated after the process suspends Variables Used for computations Variables are declared inside a process or sub-programs Assigned using “:=” Value is updated immediately Constant Declaration constant  <con_name>: <con_type>; Signal Declaration signal  <sig_name>:  <sig_type>; Variable Declaration variable <var_name>:  <var_type>;
Objects Scope 10 VHDL 360 © Each object in VHDL has a scope following the below rules: Objects declared in package are available to all units using that package Objects declared in an entity are available to all architectures of that entity Objects declared in an architecture are available to all statements in that architecture Objects declared in a process are available only within that process Entity architecture1 architecture2 process1 architecture3 process2
Data Objects Example 11 VHDL 360 © architecturebehavofmydutis -- Signals scope is the whole architecture signal x, y :std_logic:= 'U';-- Initialization (Not an assignment) signalsigbus:std_logic_vector(7downto0):="01011110";  begin    process()-- No sensitivity list, Is this a problem? -- Variables are declared inside a process 	  -- Variables scope is limited to the process variable z :std_logic:= '1'; variablevarbus:std_logic_vector(3downto0):="0001"; begin       x <= '1';-- Signal assignment, schedule a change,  						-- however the value of x still equals 'U' sigbus<="00110101";       z := '1';-- Variable assignment takes effect immediately varbus:="1101"; sigbus(3downto0)<=varbusand"1010";-- overrides the previous scheduled change,                                                       -- however sigbus still equals "01011110"       x <= z and '0';       z := '0';       y <= z xor '0'; endprocess;-- Process suspends => x = '0', y = '0' and sigbus = "00111000" endarchitecture;
Skills Check 12 VHDL 360 © ,[object Object],process(a,b) variablevar1: integer; begin var1:=a+b; temp<=var1; q<=temp; endprocess; Golden rules of thumb ,[object Object]
Signals are updated after the process suspends,[object Object]
Signals are updated after the process suspends,[object Object]
Signals are updated after the process suspends,[object Object]
Sequential Statements Now let’s introduce sequential statements Case statement If statement loop statements  Wait statement Think Hardware VHDL 360 © 16
17 VHDL 360 © a b F c d Sel(1:0) Case Statement ,[object Object],<expression> can be a signal or a variable <choice> constants representing one of possible <expression> values. “When others” is a must if not all values of <expression> are covered Each branch of a Case statement can have any number of sequential statements Syntax: case <expression> is  when <choice> =>   -- list of sequential statements when <choice> =>   -- list of sequential statements when others  =>  -- list of sequential statements   end case; Example 4: Architecturertlofmux_caseis begin   process(a,b,c,d,sel)isbegin Caseselis   When"00"=> 	f <= a;   When"01"=> 	f <= b;   When"10"=> 	f <= c;   When"11"=> 	f <= d;   whenothers=>-- is "when others" a must? 	f <= a; Endcase;   Endprocess; Endarchitecture;
18 VHDL 360 © a b F c d Sel(1:0) Case Statement ,[object Object],<expression> can be a signal or a variable <choice> constants representing one of possible <expression> values. “When others” is a must if not all values of <expression> are covered Each branch of a Case statement can have any number of sequential statements Syntax: case <expression> is  when <choice> =>   -- list of sequential statements when <choice> =>   -- list of sequential statements when others  =>  -- list of sequential statements   end case; Example 4: Architecturertlofmux_caseis begin   process(a,b,c,d,sel)isbegin Caseselis   When"00"=> 	f <= a;   When"01"=> 	f <= b;   When"10"=> 	f <= c;   When"11"=> 	f <= d;   whenothers=> 	f <= a; Endcase;   Endprocess; Endarchitecture; Do we need all these signals?
Exercise 1  19 VHDL 360 © a F 2 4 The below code is 2x4 Decoder; Complete it by doing the following: Declare F as an output port Add necessary signals to sensitivity list Add Case statement with all needed branches to create a 2x4 decoder libraryIEEE; useIEEE.std_logic_1164.all; entity decoder2x4 is 	port(a:instd_logic_vector(1downto0); -- Declare F as an output port <here> ); endentity; Architecture behave of decoder2x4 is Begin process(<here>)-- Add necessary signals to sensitivity list begin -- Add Case statement with all needed branches to create a 2x4 decoder <here> endprocess; EndArchitecture;
Sequential Statements Sequential Statements Case statement  If statement loop statements  Wait statement Think Hardware VHDL 360 © 20
IF Statement If <condition> then   -- list of sequential statements elsif<condition>then          -- list of sequential statements … else -- list of sequential statements end if; 21 VHDL 360 © ,[object Object],<condition> Boolean expression that evaluates to  either TRUE or FALSE The branches order is important as they imply a priority  Syntax: Example 5: Libraryieee; useieee.std_logic_1164.all; Entityd_ffis Port( d,clk,rst:instd_logic;  Q,nQ:outstd_logic); endentity; Architecturebehavofd_ffis signalQ_int:std_logic; Begin process(clk,rst) begin If(rst= '1')then Q_int<= '0'; elsifrising_edge(clk)then Q_int<= d;      endif; endprocess; Q <=Q_int; nQ<=not (Q_int); endbehav; Since rst has higher priority over the clk edge  D Flip Flop with asynchronous reset rising_edge() : defined for std_logic type
Exercise 2  The below code is D Flip-flop with synchronous reset; Complete it by doing the following: Add necessary signals to sensitivity list Add necessary condition to model the rising edge of the clock Add nested If statement to model the synchronous reset 22 VHDL 360 © Libraryieee; useieee.std_logic_1164.all; Entityd_ffis Port( d,clk,rst:instd_logic;  Q,nQ:outstd_logic); endentity; Architecturebehavofd_ffis signalQ_int:std_logic; Begin process(...) -- Add necessary signals to sensitivity list begin If(...)then-- Add necessary condition for a rising edge clock         ... -- Add a nested If statement to model the synchronous reset      endif; endprocess; Q <=Q_int; nQ<=not (Q_int); endbehav;
IF Statement 23 VHDL 360 © Example 6: LIBRARYieee; USEieee.std_logic_1164.all; USEieee.std_logic_arith.all; ENTITYadd_subIS port(a, b :ininteger;         result :outinteger; operation:instd_logic);-- add or subtract ENDENTITYadd_sub; ARCHITECTURE behave OFadd_subIS BEGIN process(a, b, operation) begin if(operation = '1')then   -- Add when operation = '1' result <= a + b; else-- Subtract otherwise           result <= a - b; endif; endprocess; ENDARCHITECTURE behave;
Exercise 3  The below code is a simple comparator; Complete it by doing the following: Declare 2 bits output port called “result” Add necessary conditions to model “equal to” and “greater than” Comparisons Add another “elsif” branch for “smaller than” comparison 24 VHDL 360 © LIBRARYieee; USEieee.std_logic_1164.all; USEieee.std_logic_unsigned.all; ENTITY comparator IS    port(a, b:instd_logic_vector(7downto0);          -- Declare a 2 bits output port called "result“ 	); ENDENTITY; ARCHITECTURE behave OF comparator IS BEGIN   process(a, b)   begin     if(...)then-- equality        result <="00"; elsif(...)then-- greater than        result <="01";     ...-- Add another "elsif" branch for "smaller than" comparison     else-- covers other cases        result <="11";     endif;   endprocess; ENDARCHITECTURE;
Contacts You can contact us at: http://www.embedded-tips.blogspot.com/ VHDL 360 © 25

More Related Content

What's hot

Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical fileArchita Misra
 
PVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 projectPVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 projectPVS-Studio
 
Checking the code of Valgrind dynamic analyzer by a static analyzer
Checking the code of Valgrind dynamic analyzer by a static analyzerChecking the code of Valgrind dynamic analyzer by a static analyzer
Checking the code of Valgrind dynamic analyzer by a static analyzerPVS-Studio
 
Exceptions and Exception Handling in C++
Exceptions and Exception Handling in C++Exceptions and Exception Handling in C++
Exceptions and Exception Handling in C++IRJET Journal
 
The Ring programming language version 1.6 book - Part 83 of 189
The Ring programming language version 1.6 book - Part 83 of 189The Ring programming language version 1.6 book - Part 83 of 189
The Ring programming language version 1.6 book - Part 83 of 189Mahmoud Samir Fayed
 
06 lcd slides 1 - PROCESS SYNCHRONIZATION POWERPOINT
06 lcd slides 1 - PROCESS SYNCHRONIZATION POWERPOINT06 lcd slides 1 - PROCESS SYNCHRONIZATION POWERPOINT
06 lcd slides 1 - PROCESS SYNCHRONIZATION POWERPOINTAnne Lee
 
Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations DVClub
 
Day2.Combinational Logic
Day2.Combinational LogicDay2.Combinational Logic
Day2.Combinational LogicRon Liu
 
radix_4 fft dif with mdc and mdf
radix_4 fft dif with mdc and mdfradix_4 fft dif with mdc and mdf
radix_4 fft dif with mdc and mdfsakthi1986
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xAndrey Karpov
 
Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphoresanandammca
 
Digital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDLDigital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDLOmkar Rane
 

What's hot (20)

VHDL Behavioral Description
VHDL Behavioral DescriptionVHDL Behavioral Description
VHDL Behavioral Description
 
Fpga creating counter with external clock
Fpga   creating counter with external clockFpga   creating counter with external clock
Fpga creating counter with external clock
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
 
Programs of VHDL
Programs of VHDLPrograms of VHDL
Programs of VHDL
 
Behavioral modeling
Behavioral modelingBehavioral modeling
Behavioral modeling
 
Reporte vhdl9
Reporte vhdl9Reporte vhdl9
Reporte vhdl9
 
Vhdl lab manual
Vhdl lab manualVhdl lab manual
Vhdl lab manual
 
Verifikation - Metoder og Libraries
Verifikation - Metoder og LibrariesVerifikation - Metoder og Libraries
Verifikation - Metoder og Libraries
 
PVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 projectPVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 project
 
Checking the code of Valgrind dynamic analyzer by a static analyzer
Checking the code of Valgrind dynamic analyzer by a static analyzerChecking the code of Valgrind dynamic analyzer by a static analyzer
Checking the code of Valgrind dynamic analyzer by a static analyzer
 
Direct analog
Direct analogDirect analog
Direct analog
 
Exceptions and Exception Handling in C++
Exceptions and Exception Handling in C++Exceptions and Exception Handling in C++
Exceptions and Exception Handling in C++
 
The Ring programming language version 1.6 book - Part 83 of 189
The Ring programming language version 1.6 book - Part 83 of 189The Ring programming language version 1.6 book - Part 83 of 189
The Ring programming language version 1.6 book - Part 83 of 189
 
06 lcd slides 1 - PROCESS SYNCHRONIZATION POWERPOINT
06 lcd slides 1 - PROCESS SYNCHRONIZATION POWERPOINT06 lcd slides 1 - PROCESS SYNCHRONIZATION POWERPOINT
06 lcd slides 1 - PROCESS SYNCHRONIZATION POWERPOINT
 
Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations
 
Day2.Combinational Logic
Day2.Combinational LogicDay2.Combinational Logic
Day2.Combinational Logic
 
radix_4 fft dif with mdc and mdf
radix_4 fft dif with mdc and mdfradix_4 fft dif with mdc and mdf
radix_4 fft dif with mdc and mdf
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-x
 
Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphores
 
Digital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDLDigital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDL
 

Similar to Writing more complex models

Similar to Writing more complex models (20)

Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
 
Introduction to-vhdl
Introduction to-vhdlIntroduction to-vhdl
Introduction to-vhdl
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
OSCh7
OSCh7OSCh7
OSCh7
 
OS_Ch7
OS_Ch7OS_Ch7
OS_Ch7
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
Lecture_6_Process.ppt
Lecture_6_Process.pptLecture_6_Process.ppt
Lecture_6_Process.ppt
 
DHow2 - L6 VHDL
DHow2 - L6 VHDLDHow2 - L6 VHDL
DHow2 - L6 VHDL
 
Unit v. HDL Synthesis Process
Unit v. HDL Synthesis ProcessUnit v. HDL Synthesis Process
Unit v. HDL Synthesis Process
 
Spdas2 vlsibput
Spdas2 vlsibputSpdas2 vlsibput
Spdas2 vlsibput
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Verilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdfVerilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).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
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
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
 
CH05.pdf
CH05.pdfCH05.pdf
CH05.pdf
 
VHDL Subprograms and Packages
VHDL Subprograms and PackagesVHDL Subprograms and Packages
VHDL Subprograms and Packages
 

Recently uploaded

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 

Recently uploaded (20)

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 

Writing more complex models

  • 1. VHDL 360© by: Mohamed Samy Samer El-Saadany
  • 2. Copyrights Copyright © 2010 to authors. All rights reserved All content in this presentation, including charts, data, artwork and logos (from here on, "the Content"), is the property of Mohamed Samy and Samer El-Saadany or the corresponding owners, depending on the circumstances of publication, and is protected by national and international copyright laws. Authors are not personally liable for your usage of the Content that entailed casual or indirect destruction of anything or actions entailed to information profit loss or other losses. Users are granted to access, display, download and print portions of this presentation, solely for their own personal non-commercial use, provided that all proprietary notices are kept intact. Product names and trademarks mentioned in this presentation belong to their respective owners. VHDL 360 © 2
  • 3. Objective Modeling more complicated logic using sequential statements Skills gained: Identify sequential environment in VHDL Model simple sequential logic VHDL 360 © 3
  • 4. Outline Process Description Data Objects Sequential Statements Case Statement IF Statement VHDL 360 © 4
  • 5. Statements VHDL has concurrent statements and sequential statements Concurrent statements are executed in parallel with respect to each other, we explained some of them in Module 1* Sequential statements are executed in sequence with respect to each other. Sequential statements should be written inside a “process” VHDL 360 © 5 Module 1: Create your first model for a simple logic circuit
  • 6. Process Description Process ( <sensitivity_list> ) -- process declarations begin -- process body endprocess; 6 VHDL 360 © Syntax: Process declarations: defines variables, subprograms…etc to be used in process body Process body: defines implementation details of input/output relationship in a sequential manner <sensitivity_list>: List of signals/ports that cause the process to be executed whenever there is a change in their values Example 1: Architecture behave of example1 is Begin process(x,y)-- Every time "x" or "y" value is changed, the process will be executed begin myOutput<= x nand y; endprocess; End behave ;
  • 7. Sequential Assignments Statements inside a “process” are read sequentially and executed when the “process” suspends Signal assignment statement like “F <= A” causes a transaction to be scheduled This means; the current value of A is read and scheduled to drive F when the process suspends. “Process” suspends in two situations When “end process” is reached When a “wait” statement is reached 7 VHDL 360 © Example 2: process(...)-- Assume that initially A = '1' while G, F, Z and X = 'U' Begin Z <= A;-- Signal assignment, schedule a change/transaction, -- however the value of Z still equals 'U' G <='1'; F <= G;-- G is not yet updated, so F is assigned the old value of G X <= F;-- Similarly, X is assigned the old value of F G <='0';-- overrides the previous scheduled transaction, -- however the value of G still equals 'U' Z <= G; endprocess;-- Process suspends => Signals update with scheduled transactions -- G = '0', F = 'U', Z = 'U', X = 'U'
  • 8. Sequential Assignments 8 VHDL 360 © Example 3: Architecture behave offulladderis signal temp :std_logic; Begin process(In1, In2, CarryIn) begin temp <= In1 XOR In2; Sum <= temp XORCarryIn; CarryOut<= (In1 AND In2) OR (CarryInAND temp); endprocess; End behave ; There’s a problem here!
  • 9. Data Objects 9 VHDL 360 © VHDL offers different data objects: Constants Used to store values that can’t be changed during simulation time Signals Used to model connections Signals can be External (Ports) used as an interface for the entity to the outside world (Declared in Entity) Internal used inside the architecture to connect different logic parts (Usually declared in architecture) Assigned using “<=” Outside a process, its value is updated when their signal assignment is executed. Inside a process, its value is updated after the process suspends Variables Used for computations Variables are declared inside a process or sub-programs Assigned using “:=” Value is updated immediately Constant Declaration constant <con_name>: <con_type>; Signal Declaration signal <sig_name>: <sig_type>; Variable Declaration variable <var_name>: <var_type>;
  • 10. Objects Scope 10 VHDL 360 © Each object in VHDL has a scope following the below rules: Objects declared in package are available to all units using that package Objects declared in an entity are available to all architectures of that entity Objects declared in an architecture are available to all statements in that architecture Objects declared in a process are available only within that process Entity architecture1 architecture2 process1 architecture3 process2
  • 11. Data Objects Example 11 VHDL 360 © architecturebehavofmydutis -- Signals scope is the whole architecture signal x, y :std_logic:= 'U';-- Initialization (Not an assignment) signalsigbus:std_logic_vector(7downto0):="01011110"; begin process()-- No sensitivity list, Is this a problem? -- Variables are declared inside a process -- Variables scope is limited to the process variable z :std_logic:= '1'; variablevarbus:std_logic_vector(3downto0):="0001"; begin x <= '1';-- Signal assignment, schedule a change, -- however the value of x still equals 'U' sigbus<="00110101"; z := '1';-- Variable assignment takes effect immediately varbus:="1101"; sigbus(3downto0)<=varbusand"1010";-- overrides the previous scheduled change, -- however sigbus still equals "01011110" x <= z and '0'; z := '0'; y <= z xor '0'; endprocess;-- Process suspends => x = '0', y = '0' and sigbus = "00111000" endarchitecture;
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. Sequential Statements Now let’s introduce sequential statements Case statement If statement loop statements Wait statement Think Hardware VHDL 360 © 16
  • 17.
  • 18.
  • 19. Exercise 1 19 VHDL 360 © a F 2 4 The below code is 2x4 Decoder; Complete it by doing the following: Declare F as an output port Add necessary signals to sensitivity list Add Case statement with all needed branches to create a 2x4 decoder libraryIEEE; useIEEE.std_logic_1164.all; entity decoder2x4 is port(a:instd_logic_vector(1downto0); -- Declare F as an output port <here> ); endentity; Architecture behave of decoder2x4 is Begin process(<here>)-- Add necessary signals to sensitivity list begin -- Add Case statement with all needed branches to create a 2x4 decoder <here> endprocess; EndArchitecture;
  • 20. Sequential Statements Sequential Statements Case statement If statement loop statements Wait statement Think Hardware VHDL 360 © 20
  • 21.
  • 22. Exercise 2 The below code is D Flip-flop with synchronous reset; Complete it by doing the following: Add necessary signals to sensitivity list Add necessary condition to model the rising edge of the clock Add nested If statement to model the synchronous reset 22 VHDL 360 © Libraryieee; useieee.std_logic_1164.all; Entityd_ffis Port( d,clk,rst:instd_logic; Q,nQ:outstd_logic); endentity; Architecturebehavofd_ffis signalQ_int:std_logic; Begin process(...) -- Add necessary signals to sensitivity list begin If(...)then-- Add necessary condition for a rising edge clock ... -- Add a nested If statement to model the synchronous reset endif; endprocess; Q <=Q_int; nQ<=not (Q_int); endbehav;
  • 23. IF Statement 23 VHDL 360 © Example 6: LIBRARYieee; USEieee.std_logic_1164.all; USEieee.std_logic_arith.all; ENTITYadd_subIS port(a, b :ininteger; result :outinteger; operation:instd_logic);-- add or subtract ENDENTITYadd_sub; ARCHITECTURE behave OFadd_subIS BEGIN process(a, b, operation) begin if(operation = '1')then -- Add when operation = '1' result <= a + b; else-- Subtract otherwise result <= a - b; endif; endprocess; ENDARCHITECTURE behave;
  • 24. Exercise 3 The below code is a simple comparator; Complete it by doing the following: Declare 2 bits output port called “result” Add necessary conditions to model “equal to” and “greater than” Comparisons Add another “elsif” branch for “smaller than” comparison 24 VHDL 360 © LIBRARYieee; USEieee.std_logic_1164.all; USEieee.std_logic_unsigned.all; ENTITY comparator IS port(a, b:instd_logic_vector(7downto0); -- Declare a 2 bits output port called "result“ ); ENDENTITY; ARCHITECTURE behave OF comparator IS BEGIN process(a, b) begin if(...)then-- equality result <="00"; elsif(...)then-- greater than result <="01"; ...-- Add another "elsif" branch for "smaller than" comparison else-- covers other cases result <="11"; endif; endprocess; ENDARCHITECTURE;
  • 25. Contacts You can contact us at: http://www.embedded-tips.blogspot.com/ VHDL 360 © 25