SlideShare a Scribd company logo
VHDL 360©by: Mohamed Samy        Samer El-Saadany
CopyrightsCopyright © 2010/2011 to authors. All rights reservedAll 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
Module 4Synthesis Examples
ObjectiveGetting familiar with code changes' impact on synthesisSkills gained:Writing synthesis friendly codeVHDL 360 ©4
OutlineIntroductionSynthesize and LearnCombinational LogicLatch InferenceSequential LogicFlip-Flop InferenceVHDL 360 ©5
IntroductionVHDL 360 ©6VHDL is a H/W modeling language used to model digital circuitsDigital circuits can be either Combinational or SequentialCombinational Logic circuits: Implement Boolean functions whose output is only dependant on the present inputsSequential Logic circuits: Implement circuits whose output depends on the present inputs & the history of the inputs. i.e. Circuits having storage elements
IntroductionVHDL 360 ©7VHDL StandardSynthesizable VHDLSynthesis tools translate the VHDL code to a gate level netlist representing the actual H/W gates [and, or, not, Flip-Flops…etc]Only a subset of the language is synthesizableA model can be eitherSynthesizable: Used for both Simulation & SynthesisNon-Synthesizable:  Used for Simulation only
Synthesize And Learn8
Synthesize and LearnIn the next slides we will use examples from the previous modules to demonstrate synthesis and study the synthesized logicWe will also modify these examples and observe the impact on the synthesized logic9VHDL 360 ©
Combinational LogiclibraryIEEE;useIEEE.std_logic_1164.all;Entitymux_caseis Port(a, b, c, d:instd_logic;Sel:instd_logic_vector(1downto0);      F:outstd_logic);Endentity;Architecture rtl ofmux_caseisbegin  process(a,b,c,d,sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase;  Endprocess;Endarchitecture;VHDL 360 ©10Example 1: 4x1 Multiplexer
Skills CheckWhat is the impact of removing some signals from the sensitivity list as shown in example 2? Architecture rtl ofmux_caseisbegin  process(a,b,c,d,sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase;  Endprocess;Endarchitecture;VHDL 360 ©11Example 1: 4x1 MultiplexerExample 2: 4x1 Multiplexer Architecture rtl ofmux_caseisbegin  process(a, sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase;  Endprocess;Endarchitecture;
Skills Check (Soln.)Architecture rtl ofmux_caseisbegin  process(a,b,c,d,sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase;  Endprocess;Endarchitecture;VHDL 360 ©12No Impact on the synthesis results, however we will find that the simulation results differ
Synthesis tools don’t use the sensitivity list to determine the logic, but simulation tools depend on the sensitivity list to execute the process
Example 2 suffers a problem called “Simulation – Synthesis mismatch”Example 1: 4x1 MultiplexerExample 2: 4x1 MultiplexerArchitecture rtl ofmux_caseisbegin  process(a, sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase;  Endprocess;Endarchitecture;
Combinational LogicVHDL 2008* introduced the keyword "all" that implicitly adds all read signals to the sensitivity list to avoid “Simulation Synthesis mismatch”Architecture rtl ofmux_caseisbegin  process(all)is  beginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase;  Endprocess;Endarchitecture;VHDL 360 ©13Example 3Golden rule of thumbTo avoid “Simulation Synthesis mismatch” problems when modeling Combinational logic, add all read signals to the sensitivity list*Not yet supported by all tools in the market
Combinational Logic14VHDL 360 ©Example 4: Adder-SubtractorLIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITYadd_subISport(a, b :ininteger;        result :outinteger;operation:instd_logic);ENDENTITY;ARCHITECTURE behave OFadd_subISBEGINprocess(a, b, operation)beginif(operation = '1')thenresult <= a + b;else          result <= a - b;endif;endprocess;ENDARCHITECTURE;
Combinational Logic15VHDL 360 ©Consider that someone tries to re-use that code to implement an adder with an enable  He modifies the add_sub example; removes the else branch & renames the “operation” port to “enable” as shown below, How would these changes affect the logic?Example 5:LIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITY adder ISport(a, b :ininteger;        result :outinteger;enable:instd_logic);ENDENTITY adder;ARCHITECTURE behave OF adder ISBEGINprocess(a, b, enable)beginif(enable = '1')then result <= a + b;endif;endprocess;ENDARCHITECTURE;
Combinational Logic16VHDL 360 ©This will infer a latch, because we didn’t specify what should happen to “result” when “enable” isn’t equal to '1'Simulation & synthesis tools will just keep the value as is…i.e. It latches the last valueExample 5:LIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITY adder ISport(a, b :ininteger;        result :outinteger;enable:instd_logic);ENDENTITY adder;ARCHITECTURE behave OF adder ISBEGINprocess(a, b, enable)beginif(enable = '1')then result <= a + b;endif;endprocess;ENDARCHITECTURE;
Combinational LogicIn the below example, the "11" value of "sel" signal is not listed as a case choice, hence signal "F" is not assigned a value in this caseA Latch is inferred in this example  Probably that wasn’t neededExample 6:LIBRARYieee;USEieee.std_logic_1164.all;ENTITYincomplete_caseISport(sel:std_logic_vector(1downto0);       A, B:std_logic;       F   :outstd_logic);ENDENTITY;ARCHITECTURE rtl OFincomplete_caseISBEGIN  process(sel, A, B)  begin    case(sel)is    when"00"=>      F <= A;    when"01"=>      F <= B;    when"10"=>      F <= A xor B;    whenothers=>null;    endcase;  endprocess;ENDARCHITECTURE;17VHDL 360 ©
Skills CheckDo you think a Latch would be inferred in the below example?Example 7:LIBRARYieee;USEieee.std_logic_1164.all;ENTITYincomplete_assignmentIS  port(sel:instd_logic_vector(1downto0);       A, B  :instd_logic;       O1, O2:outstd_logic);ENDENTITY;ARCHITECTURE rtl OFincomplete_assignmentISBEGIN  process(sel, A, B)begin    case(sel)is    when"00"=>      O1 <= A;      O2 <= A and B;    when"01"=>      O1 <= B;      O2 <= A xor B;    when"10"=>      O1 <= A xor B;    when"11"=>      O2 <= A or B;    whenothers=>      O1 <= '0';      O2 <= '0';    endcase;  endprocess;ENDARCHITECTURE;18VHDL 360 ©
Skills Check (Soln.)Example 7:LIBRARYieee;USEieee.std_logic_1164.all;ENTITYincomplete_assignmentIS  port(sel:instd_logic_vector(1downto0);       A, B  :instd_logic;       O1, O2:outstd_logic);ENDENTITY;ARCHITECTURE rtl OFincomplete_assignmentISBEGIN  process(sel, A, B)begin    case(sel)is    when"00"=>      O1 <= A;      O2 <= A and B;    when"01"=>      O1 <= B;      O2 <= A xor B;    when"10"=>      O1 <= A xor B;    when"11"=>      O2 <= A or B;    whenothers=>      O1 <= '0';      O2 <= '0';    endcase;  endprocess;ENDARCHITECTURE;19VHDL 360 ©Do you think a Latch would be inferred in the below example?Latches are inferred for both signals "O1" & "O2"
Though the case is complete & no "null" statement is there, we find that "O1" & "O2" are not assigned in all case's branches  This is called “Incomplete signal assignment”Latch InferenceMost of the time latches are not desired in the design because they affect timing badlyTo remove unintended latches: Cover all branches of if-else and case statementsAvoid incomplete signal assignment by assigning a value to each signal in each branchif you don’t care about other conditional values then assign the output to '0' or '1'20VHDL 360 ©
Enough CombinationalLet's Go Sequential21
Sequential Logic22VHDL 360 ©Let's model the well known D-FF with outputs Q & nQ and see the synthesis resultsExample 8:Libraryieee;useieee.std_logic_1164.all;Entity d_ff isPort(d, clk, rst :instd_logic;Q, nQ :outstd_logic);endentity;Architecture behav of d_ff isBeginprocess(clk)beginIf(rising_edge(clk))thenIf(rst = '1')then         Q <= '0';         nQ <= '0';       else         Q <= d;         nQ <=not (d);       endif;     endif;endprocess;end behav;
Sequential Logic23VHDL 360 ©Let's model the well known D-FF with outputs Q & nQ and see the synthesis resultsExample 8:Libraryieee;useieee.std_logic_1164.all;Entity d_ff isPort(d, clk, rst :instd_logic;Q, nQ :outstd_logic);endentity;Architecture behav of d_ff isBeginprocess(clk)beginIf(rising_edge(clk))thenIf(rst = '1')then         Q <= '0';         nQ <='1';       else         Q <= d;         nQ <=not (d);       endif;     endif;endprocess;end behav;Two Flip-Flops ?!Change the code to have only one Flip-Flop
Sequential Logic24VHDL 360 ©Let's model the well known D-FF with outputs Q & nQ and see the synthesis resultsExample 9:Libraryieee;useieee.std_logic_1164.all;Entity d_ff isPort( d, clk, rst :instd_logic; Q, nQ :outstd_logic);endentity;Architecture behav of d_ff issignal Q_int:std_logic;Beginprocess(clk)beginIf(rising_edge(clk))thenIf(rst = '1')then         Q_int <= '0';       else        Q_int <= d;       endif;     endif;endprocess;Q <= Q_int;nQ <=not (Q_int);end behav;Yep…That's what we want!
Sequential Logic25VHDL 360 ©What about making an array of D-FFs?Example 10:Libraryieee;useieee.std_logic_1164.all;Entity d_ffs isPort(d: std_logic_vector(3downto0);clk, rst :instd_logic;Q, nQ :outstd_logic_vector(3downto0));endentity;Architecture behav of d_ffs issignal Q_int:std_logic_vector(3downto0);Beginprocess(clk)beginIf(rising_edge(clk))thenIf(rst = '1')then         Q_int <= (others => '0');       else        Q_int <= d;       endif;     endif;endprocess;Q <= Q_int;nQ <=not (Q_int);end behav;
Sequential LogicExample 11: 8-bit Shift Register (Shift right)Libraryieee;useieee.std_logic_1164.all;entity shift_register is  Port( clk, D, enable :inSTD_LOGIC;   Q :outSTD_LOGIC);endentity;architecture Behavioral of shift_register isbeginprocess(clk)variable reg:std_logic_vector(7downto0);beginifrising_edge(clk)thenif enable = '1' thenfor i in1to7loop          reg(i-1):= reg(i);endloop;        reg(7):= d;endif;endif;    Q <= reg(0);  endprocess;end Behavioral;7    6    5   4    3    2    1    0VHDL 360 ©26
Flip-Flop InferenceAssignments under clock edge where the object value needs to be remembered across multiple process invocations  Flip-FlopSignal assignment under clock edge will always infer a Flip-FlopVariable assignment under clock edge will infer Flip-Flop only when its value ought to be remembered across process invocations27VHDL 360 ©

More Related Content

PDF
Botafogo mas blues (g173)
PPTX
Reparacion de los circuitos inversores
PDF
16947169 cursotvchinas
PDF
địA ngục a_tỳ_du_ký
PDF
Giới Thiệu Tiên Thiên Đại Đạo
PDF
Kinh bát chánh_đạo
DOCX
Kinh- địa- tạng- bồ- tát- bổn- nguyện
PDF
Tam bảo tâm pháp
Botafogo mas blues (g173)
Reparacion de los circuitos inversores
16947169 cursotvchinas
địA ngục a_tỳ_du_ký
Giới Thiệu Tiên Thiên Đại Đạo
Kinh bát chánh_đạo
Kinh- địa- tạng- bồ- tát- bổn- nguyện
Tam bảo tâm pháp

Similar to Synthesis Examples (20)

PPTX
Create your first model for a simple logic circuit
PPTX
Writing more complex models
PPTX
Writing more complex models (continued)
PPTX
Building Hierarchy
PPTX
Introduction to VHDL
PPT
PPT
&lt;img src="xss.com">
PDF
Learning vhdl by examples
PPTX
Verilog overview
PPTX
Switch case and looping new
PPSX
Ds02 flow chart and pseudo code
PPT
Google mock training
PPTX
Switch case and looping kim
PPTX
Macasu, gerrell c.
PPT
Verilog Lecture5 hust 2014
PDF
learning vhdl by examples
PDF
Prepare a Verilog HDL code for the following register Positive Edge.pdf
PPTX
Basic Coding In VHDL COding
PPTX
My final requirement
Create your first model for a simple logic circuit
Writing more complex models
Writing more complex models (continued)
Building Hierarchy
Introduction to VHDL
&lt;img src="xss.com">
Learning vhdl by examples
Verilog overview
Switch case and looping new
Ds02 flow chart and pseudo code
Google mock training
Switch case and looping kim
Macasu, gerrell c.
Verilog Lecture5 hust 2014
learning vhdl by examples
Prepare a Verilog HDL code for the following register Positive Edge.pdf
Basic Coding In VHDL COding
My final requirement
Ad

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
master seminar digital applications in india
PDF
Computing-Curriculum for Schools in Ghana
PDF
Pre independence Education in Inndia.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Classroom Observation Tools for Teachers
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Types and Its function , kingdom of life
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Cell Structure & Organelles in detailed.
PPTX
Lesson notes of climatology university.
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial disease of the cardiovascular and lymphatic systems
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
master seminar digital applications in india
Computing-Curriculum for Schools in Ghana
Pre independence Education in Inndia.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Classroom Observation Tools for Teachers
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
TR - Agricultural Crops Production NC III.pdf
VCE English Exam - Section C Student Revision Booklet
Cell Types and Its function , kingdom of life
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Complications of Minimal Access Surgery at WLH
Cell Structure & Organelles in detailed.
Lesson notes of climatology university.
Ad

Synthesis Examples

  • 1. VHDL 360©by: Mohamed Samy Samer El-Saadany
  • 2. CopyrightsCopyright © 2010/2011 to authors. All rights reservedAll 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
  • 4. ObjectiveGetting familiar with code changes' impact on synthesisSkills gained:Writing synthesis friendly codeVHDL 360 ©4
  • 5. OutlineIntroductionSynthesize and LearnCombinational LogicLatch InferenceSequential LogicFlip-Flop InferenceVHDL 360 ©5
  • 6. IntroductionVHDL 360 ©6VHDL is a H/W modeling language used to model digital circuitsDigital circuits can be either Combinational or SequentialCombinational Logic circuits: Implement Boolean functions whose output is only dependant on the present inputsSequential Logic circuits: Implement circuits whose output depends on the present inputs & the history of the inputs. i.e. Circuits having storage elements
  • 7. IntroductionVHDL 360 ©7VHDL StandardSynthesizable VHDLSynthesis tools translate the VHDL code to a gate level netlist representing the actual H/W gates [and, or, not, Flip-Flops…etc]Only a subset of the language is synthesizableA model can be eitherSynthesizable: Used for both Simulation & SynthesisNon-Synthesizable: Used for Simulation only
  • 9. Synthesize and LearnIn the next slides we will use examples from the previous modules to demonstrate synthesis and study the synthesized logicWe will also modify these examples and observe the impact on the synthesized logic9VHDL 360 ©
  • 10. Combinational LogiclibraryIEEE;useIEEE.std_logic_1164.all;Entitymux_caseis Port(a, b, c, d:instd_logic;Sel:instd_logic_vector(1downto0); F:outstd_logic);Endentity;Architecture rtl ofmux_caseisbegin process(a,b,c,d,sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase; Endprocess;Endarchitecture;VHDL 360 ©10Example 1: 4x1 Multiplexer
  • 11. Skills CheckWhat is the impact of removing some signals from the sensitivity list as shown in example 2? Architecture rtl ofmux_caseisbegin process(a,b,c,d,sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase; Endprocess;Endarchitecture;VHDL 360 ©11Example 1: 4x1 MultiplexerExample 2: 4x1 Multiplexer Architecture rtl ofmux_caseisbegin process(a, sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase; Endprocess;Endarchitecture;
  • 12. Skills Check (Soln.)Architecture rtl ofmux_caseisbegin process(a,b,c,d,sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase; Endprocess;Endarchitecture;VHDL 360 ©12No Impact on the synthesis results, however we will find that the simulation results differ
  • 13. Synthesis tools don’t use the sensitivity list to determine the logic, but simulation tools depend on the sensitivity list to execute the process
  • 14. Example 2 suffers a problem called “Simulation – Synthesis mismatch”Example 1: 4x1 MultiplexerExample 2: 4x1 MultiplexerArchitecture rtl ofmux_caseisbegin process(a, sel)isbeginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase; Endprocess;Endarchitecture;
  • 15. Combinational LogicVHDL 2008* introduced the keyword "all" that implicitly adds all read signals to the sensitivity list to avoid “Simulation Synthesis mismatch”Architecture rtl ofmux_caseisbegin process(all)is beginCaseselisWhen"00"=> f <= a;When"01"=> f <= b;When"10"=> f <= c;When"11"=> f <= d;whenothers=> f <= a;Endcase; Endprocess;Endarchitecture;VHDL 360 ©13Example 3Golden rule of thumbTo avoid “Simulation Synthesis mismatch” problems when modeling Combinational logic, add all read signals to the sensitivity list*Not yet supported by all tools in the market
  • 16. Combinational Logic14VHDL 360 ©Example 4: Adder-SubtractorLIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITYadd_subISport(a, b :ininteger; result :outinteger;operation:instd_logic);ENDENTITY;ARCHITECTURE behave OFadd_subISBEGINprocess(a, b, operation)beginif(operation = '1')thenresult <= a + b;else result <= a - b;endif;endprocess;ENDARCHITECTURE;
  • 17. Combinational Logic15VHDL 360 ©Consider that someone tries to re-use that code to implement an adder with an enable  He modifies the add_sub example; removes the else branch & renames the “operation” port to “enable” as shown below, How would these changes affect the logic?Example 5:LIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITY adder ISport(a, b :ininteger; result :outinteger;enable:instd_logic);ENDENTITY adder;ARCHITECTURE behave OF adder ISBEGINprocess(a, b, enable)beginif(enable = '1')then result <= a + b;endif;endprocess;ENDARCHITECTURE;
  • 18. Combinational Logic16VHDL 360 ©This will infer a latch, because we didn’t specify what should happen to “result” when “enable” isn’t equal to '1'Simulation & synthesis tools will just keep the value as is…i.e. It latches the last valueExample 5:LIBRARYieee;USEieee.std_logic_1164.all;USEieee.std_logic_arith.all;ENTITY adder ISport(a, b :ininteger; result :outinteger;enable:instd_logic);ENDENTITY adder;ARCHITECTURE behave OF adder ISBEGINprocess(a, b, enable)beginif(enable = '1')then result <= a + b;endif;endprocess;ENDARCHITECTURE;
  • 19. Combinational LogicIn the below example, the "11" value of "sel" signal is not listed as a case choice, hence signal "F" is not assigned a value in this caseA Latch is inferred in this example  Probably that wasn’t neededExample 6:LIBRARYieee;USEieee.std_logic_1164.all;ENTITYincomplete_caseISport(sel:std_logic_vector(1downto0); A, B:std_logic; F :outstd_logic);ENDENTITY;ARCHITECTURE rtl OFincomplete_caseISBEGIN process(sel, A, B) begin case(sel)is when"00"=> F <= A; when"01"=> F <= B; when"10"=> F <= A xor B; whenothers=>null; endcase; endprocess;ENDARCHITECTURE;17VHDL 360 ©
  • 20. Skills CheckDo you think a Latch would be inferred in the below example?Example 7:LIBRARYieee;USEieee.std_logic_1164.all;ENTITYincomplete_assignmentIS port(sel:instd_logic_vector(1downto0); A, B :instd_logic; O1, O2:outstd_logic);ENDENTITY;ARCHITECTURE rtl OFincomplete_assignmentISBEGIN process(sel, A, B)begin case(sel)is when"00"=> O1 <= A; O2 <= A and B; when"01"=> O1 <= B; O2 <= A xor B; when"10"=> O1 <= A xor B; when"11"=> O2 <= A or B; whenothers=> O1 <= '0'; O2 <= '0'; endcase; endprocess;ENDARCHITECTURE;18VHDL 360 ©
  • 21. Skills Check (Soln.)Example 7:LIBRARYieee;USEieee.std_logic_1164.all;ENTITYincomplete_assignmentIS port(sel:instd_logic_vector(1downto0); A, B :instd_logic; O1, O2:outstd_logic);ENDENTITY;ARCHITECTURE rtl OFincomplete_assignmentISBEGIN process(sel, A, B)begin case(sel)is when"00"=> O1 <= A; O2 <= A and B; when"01"=> O1 <= B; O2 <= A xor B; when"10"=> O1 <= A xor B; when"11"=> O2 <= A or B; whenothers=> O1 <= '0'; O2 <= '0'; endcase; endprocess;ENDARCHITECTURE;19VHDL 360 ©Do you think a Latch would be inferred in the below example?Latches are inferred for both signals "O1" & "O2"
  • 22. Though the case is complete & no "null" statement is there, we find that "O1" & "O2" are not assigned in all case's branches  This is called “Incomplete signal assignment”Latch InferenceMost of the time latches are not desired in the design because they affect timing badlyTo remove unintended latches: Cover all branches of if-else and case statementsAvoid incomplete signal assignment by assigning a value to each signal in each branchif you don’t care about other conditional values then assign the output to '0' or '1'20VHDL 360 ©
  • 24. Sequential Logic22VHDL 360 ©Let's model the well known D-FF with outputs Q & nQ and see the synthesis resultsExample 8:Libraryieee;useieee.std_logic_1164.all;Entity d_ff isPort(d, clk, rst :instd_logic;Q, nQ :outstd_logic);endentity;Architecture behav of d_ff isBeginprocess(clk)beginIf(rising_edge(clk))thenIf(rst = '1')then Q <= '0'; nQ <= '0'; else Q <= d; nQ <=not (d); endif; endif;endprocess;end behav;
  • 25. Sequential Logic23VHDL 360 ©Let's model the well known D-FF with outputs Q & nQ and see the synthesis resultsExample 8:Libraryieee;useieee.std_logic_1164.all;Entity d_ff isPort(d, clk, rst :instd_logic;Q, nQ :outstd_logic);endentity;Architecture behav of d_ff isBeginprocess(clk)beginIf(rising_edge(clk))thenIf(rst = '1')then Q <= '0'; nQ <='1'; else Q <= d; nQ <=not (d); endif; endif;endprocess;end behav;Two Flip-Flops ?!Change the code to have only one Flip-Flop
  • 26. Sequential Logic24VHDL 360 ©Let's model the well known D-FF with outputs Q & nQ and see the synthesis resultsExample 9:Libraryieee;useieee.std_logic_1164.all;Entity d_ff isPort( d, clk, rst :instd_logic; Q, nQ :outstd_logic);endentity;Architecture behav of d_ff issignal Q_int:std_logic;Beginprocess(clk)beginIf(rising_edge(clk))thenIf(rst = '1')then Q_int <= '0'; else Q_int <= d; endif; endif;endprocess;Q <= Q_int;nQ <=not (Q_int);end behav;Yep…That's what we want!
  • 27. Sequential Logic25VHDL 360 ©What about making an array of D-FFs?Example 10:Libraryieee;useieee.std_logic_1164.all;Entity d_ffs isPort(d: std_logic_vector(3downto0);clk, rst :instd_logic;Q, nQ :outstd_logic_vector(3downto0));endentity;Architecture behav of d_ffs issignal Q_int:std_logic_vector(3downto0);Beginprocess(clk)beginIf(rising_edge(clk))thenIf(rst = '1')then Q_int <= (others => '0'); else Q_int <= d; endif; endif;endprocess;Q <= Q_int;nQ <=not (Q_int);end behav;
  • 28. Sequential LogicExample 11: 8-bit Shift Register (Shift right)Libraryieee;useieee.std_logic_1164.all;entity shift_register is Port( clk, D, enable :inSTD_LOGIC; Q :outSTD_LOGIC);endentity;architecture Behavioral of shift_register isbeginprocess(clk)variable reg:std_logic_vector(7downto0);beginifrising_edge(clk)thenif enable = '1' thenfor i in1to7loop reg(i-1):= reg(i);endloop; reg(7):= d;endif;endif; Q <= reg(0); endprocess;end Behavioral;7 6 5 4 3 2 1 0VHDL 360 ©26
  • 29. Flip-Flop InferenceAssignments under clock edge where the object value needs to be remembered across multiple process invocations  Flip-FlopSignal assignment under clock edge will always infer a Flip-FlopVariable assignment under clock edge will infer Flip-Flop only when its value ought to be remembered across process invocations27VHDL 360 ©
  • 30. Exercise 1LIBRARYieee;USEieee.std_logic_1164.all;Entity unknown isport(x:outstd_logic; y:instd_logic_vector(3downto0); c:ininteger);Endentity;Architecture behave of unknown isBegin x <= y(c);End behave;VHDL 360 ©28Deduce what the below code modelsUse synthesis tool to validate your answer
  • 31. ContactsYou can contact us at:http://www.embedded-tips.blogspot.com/VHDL 360 ©29