Your SlideShare is downloading. ×
0
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Synthesis Examples
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Synthesis Examples

20,377

Published on

Getting familiar with code changes' impact on synthesis …

Getting familiar with code changes' impact on synthesis
Skills gained:
1- Writing synthesis friendly code

This is part of VHDL 360 course

Published in: Education, Technology, Design
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
20,377
On Slideshare
0
From Embeds
0
Number of Embeds
56
Actions
Shares
0
Downloads
248
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. VHDL 360©<br />by: Mohamed Samy<br /> Samer El-Saadany<br />
  • 2. Copyrights<br />Copyright © 2010/2011 to authors. All rights reserved<br />All content in this presentation, including charts, data, artwork and logos (from here on, &quot;the Content&quot;), 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.<br />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.<br />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. <br />Product names and trademarks mentioned in this presentation belong to their respective owners.<br />VHDL 360 ©<br />2<br />
  • 3. Module 4<br />Synthesis Examples<br />
  • 4. Objective<br />Getting familiar with code changes&apos; impact on synthesis<br />Skills gained:<br />Writing synthesis friendly code<br />VHDL 360 ©<br />4<br />
  • 5. Outline<br />Introduction<br />Synthesize and Learn<br />Combinational Logic<br />Latch Inference<br />Sequential Logic<br />Flip-Flop Inference<br />VHDL 360 ©<br />5<br />
  • 6. Introduction<br />VHDL 360 ©<br />6<br />VHDL is a H/W modeling language used to model digital circuits<br />Digital circuits can be either Combinational or Sequential<br />Combinational Logic circuits: Implement Boolean functions whose output is only dependant on the present inputs<br />Sequential Logic circuits: Implement circuits whose output depends on the present inputs &amp; the history of the inputs. i.e. Circuits having storage elements<br />
  • 7. Introduction<br />VHDL 360 ©<br />7<br />VHDL Standard<br />Synthesizable VHDL<br />Synthesis tools translate the VHDL code to a gate level netlist representing the actual H/W gates [and, or, not, Flip-Flops…etc]<br />Only a subset of the language is synthesizable<br />A model can be either<br />Synthesizable: Used for both Simulation &amp; Synthesis<br />Non-Synthesizable: Used for Simulation only<br />
  • 8. Synthesize And Learn<br />8<br />
  • 9. Synthesize and Learn<br />In the next slides we will use examples from the previous modules to demonstrate synthesis and study the synthesized logic<br />We will also modify these examples and observe the impact on the synthesized logic<br />9<br />VHDL 360 ©<br />
  • 10. Combinational Logic<br />libraryIEEE;<br />useIEEE.std_logic_1164.all;<br />Entitymux_caseis<br /> Port(a, b, c, d:instd_logic;<br />Sel:instd_logic_vector(1downto0);<br /> F:outstd_logic);<br />Endentity;<br />Architecture rtl ofmux_caseis<br />begin<br /> process(a,b,c,d,sel)is<br />begin<br />Caseselis<br />When&quot;00&quot;=&gt; f &lt;= a;<br />When&quot;01&quot;=&gt; f &lt;= b;<br />When&quot;10&quot;=&gt; f &lt;= c;<br />When&quot;11&quot;=&gt; f &lt;= d;<br />whenothers=&gt; f &lt;= a;<br />Endcase;<br /> Endprocess;<br />Endarchitecture;<br />VHDL 360 ©<br />10<br />Example 1: 4x1 Multiplexer<br />
  • 11. Skills Check<br /><ul><li>What is the impact of removing some signals from the sensitivity list as shown in example 2? </li></ul>Architecture rtl ofmux_caseis<br />begin<br /> process(a,b,c,d,sel)is<br />begin<br />Caseselis<br />When&quot;00&quot;=&gt; f &lt;= a;<br />When&quot;01&quot;=&gt; f &lt;= b;<br />When&quot;10&quot;=&gt; f &lt;= c;<br />When&quot;11&quot;=&gt; f &lt;= d;<br />whenothers=&gt; f &lt;= a;<br />Endcase;<br /> Endprocess;<br />Endarchitecture;<br />VHDL 360 ©<br />11<br />Example 1: 4x1 Multiplexer<br />Example 2: 4x1 Multiplexer <br />Architecture rtl ofmux_caseis<br />begin<br /> process(a, sel)is<br />begin<br />Caseselis<br />When&quot;00&quot;=&gt; f &lt;= a;<br />When&quot;01&quot;=&gt; f &lt;= b;<br />When&quot;10&quot;=&gt; f &lt;= c;<br />When&quot;11&quot;=&gt; f &lt;= d;<br />whenothers=&gt; f &lt;= a;<br />Endcase;<br /> Endprocess;<br />Endarchitecture;<br />
  • 12. Skills Check (Soln.)<br />Architecture rtl ofmux_caseis<br />begin<br /> process(a,b,c,d,sel)is<br />begin<br />Caseselis<br />When&quot;00&quot;=&gt; f &lt;= a;<br />When&quot;01&quot;=&gt; f &lt;= b;<br />When&quot;10&quot;=&gt; f &lt;= c;<br />When&quot;11&quot;=&gt; f &lt;= d;<br />whenothers=&gt; f &lt;= a;<br />Endcase;<br /> Endprocess;<br />Endarchitecture;<br />VHDL 360 ©<br />12<br /><ul><li>No 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”</li></ul>Example 1: 4x1 Multiplexer<br />Example 2: 4x1 Multiplexer<br />Architecture rtl ofmux_caseis<br />begin<br /> process(a, sel)is<br />begin<br />Caseselis<br />When&quot;00&quot;=&gt; f &lt;= a;<br />When&quot;01&quot;=&gt; f &lt;= b;<br />When&quot;10&quot;=&gt; f &lt;= c;<br />When&quot;11&quot;=&gt; f &lt;= d;<br />whenothers=&gt; f &lt;= a;<br />Endcase;<br /> Endprocess;<br />Endarchitecture;<br />
  • 15. Combinational Logic<br /><ul><li>VHDL 2008* introduced the keyword &quot;all&quot; that implicitly adds all read signals to the sensitivity list to avoid “Simulation Synthesis mismatch”</li></ul>Architecture rtl ofmux_caseis<br />begin<br /> process(all)is<br /> begin<br />Caseselis<br />When&quot;00&quot;=&gt; f &lt;= a;<br />When&quot;01&quot;=&gt; f &lt;= b;<br />When&quot;10&quot;=&gt; f &lt;= c;<br />When&quot;11&quot;=&gt; f &lt;= d;<br />whenothers=&gt; f &lt;= a;<br />Endcase;<br /> Endprocess;<br />Endarchitecture;<br />VHDL 360 ©<br />13<br />Example 3<br />Golden rule of thumb<br /><ul><li>To avoid “Simulation Synthesis mismatch” problems when modeling Combinational logic, add all read signals to the sensitivity list</li></ul>*Not yet supported by all tools in the market<br />
  • 16. Combinational Logic<br />14<br />VHDL 360 ©<br />Example 4: Adder-Subtractor<br />LIBRARYieee;<br />USEieee.std_logic_1164.all;<br />USEieee.std_logic_arith.all;<br />ENTITYadd_subIS<br />port(a, b :ininteger;<br /> result :outinteger;<br />operation:instd_logic);<br />ENDENTITY;<br />ARCHITECTURE behave OFadd_subIS<br />BEGIN<br />process(a, b, operation)<br />begin<br />if(operation = &apos;1&apos;)then<br />result &lt;= a + b;<br />else<br /> result &lt;= a - b;<br />endif;<br />endprocess;<br />ENDARCHITECTURE;<br />
  • 17. Combinational Logic<br />15<br />VHDL 360 ©<br />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 &amp; renames the “operation” port to “enable” as shown below, How would these changes affect the logic?<br />Example 5:<br />LIBRARYieee;<br />USEieee.std_logic_1164.all;<br />USEieee.std_logic_arith.all;<br />ENTITY adder IS<br />port(a, b :ininteger;<br /> result :outinteger;<br />enable:instd_logic);<br />ENDENTITY adder;<br />ARCHITECTURE behave OF adder IS<br />BEGIN<br />process(a, b, enable)<br />begin<br />if(enable = &apos;1&apos;)then <br />result &lt;= a + b;<br />endif;<br />endprocess;<br />ENDARCHITECTURE;<br />
  • 18. Combinational Logic<br />16<br />VHDL 360 ©<br />This will infer a latch, because we didn’t specify what should happen to “result” when “enable” isn’t equal to &apos;1&apos;<br />Simulation &amp; synthesis tools will just keep the value as is…i.e. It latches the last value<br />Example 5:<br />LIBRARYieee;<br />USEieee.std_logic_1164.all;<br />USEieee.std_logic_arith.all;<br />ENTITY adder IS<br />port(a, b :ininteger;<br /> result :outinteger;<br />enable:instd_logic);<br />ENDENTITY adder;<br />ARCHITECTURE behave OF adder IS<br />BEGIN<br />process(a, b, enable)<br />begin<br />if(enable = &apos;1&apos;)then <br />result &lt;= a + b;<br />endif;<br />endprocess;<br />ENDARCHITECTURE;<br />
  • 19. Combinational Logic<br />In the below example, the &quot;11&quot; value of &quot;sel&quot; signal is not listed as a case choice, hence signal &quot;F&quot; is not assigned a value in this case<br />A Latch is inferred in this example  Probably that wasn’t needed<br />Example 6:<br />LIBRARYieee;<br />USEieee.std_logic_1164.all;<br />ENTITYincomplete_caseIS<br />port(sel:std_logic_vector(1downto0);<br /> A, B:std_logic;<br /> F :outstd_logic);<br />ENDENTITY;<br />ARCHITECTURE rtl OFincomplete_caseIS<br />BEGIN<br /> process(sel, A, B)<br /> begin<br /> case(sel)is<br /> when&quot;00&quot;=&gt;<br /> F &lt;= A;<br /> when&quot;01&quot;=&gt;<br /> F &lt;= B;<br /> when&quot;10&quot;=&gt;<br /> F &lt;= A xor B;<br /> whenothers=&gt;null;<br /> endcase;<br /> endprocess;<br />ENDARCHITECTURE;<br />17<br />VHDL 360 ©<br />
  • 20. Skills Check<br />Do you think a Latch would be inferred in the below example?<br />Example 7:<br />LIBRARYieee;<br />USEieee.std_logic_1164.all;<br />ENTITYincomplete_assignmentIS<br /> port(sel:instd_logic_vector(1downto0);<br /> A, B :instd_logic;<br /> O1, O2:outstd_logic);<br />ENDENTITY;<br />ARCHITECTURE rtl OFincomplete_assignmentIS<br />BEGIN<br /> process(sel, A, B)begin<br /> case(sel)is<br /> when&quot;00&quot;=&gt;<br /> O1 &lt;= A;<br /> O2 &lt;= A and B;<br /> when&quot;01&quot;=&gt;<br /> O1 &lt;= B;<br /> O2 &lt;= A xor B;<br /> when&quot;10&quot;=&gt;<br /> O1 &lt;= A xor B;<br /> when&quot;11&quot;=&gt;<br /> O2 &lt;= A or B;<br /> whenothers=&gt;<br /> O1 &lt;= &apos;0&apos;;<br /> O2 &lt;= &apos;0&apos;;<br /> endcase;<br /> endprocess;<br />ENDARCHITECTURE;<br />18<br />VHDL 360 ©<br />
  • 21. Skills Check (Soln.)<br />Example 7:<br />LIBRARYieee;<br />USEieee.std_logic_1164.all;<br />ENTITYincomplete_assignmentIS<br /> port(sel:instd_logic_vector(1downto0);<br /> A, B :instd_logic;<br /> O1, O2:outstd_logic);<br />ENDENTITY;<br />ARCHITECTURE rtl OFincomplete_assignmentIS<br />BEGIN<br /> process(sel, A, B)begin<br /> case(sel)is<br /> when&quot;00&quot;=&gt;<br /> O1 &lt;= A;<br /> O2 &lt;= A and B;<br /> when&quot;01&quot;=&gt;<br /> O1 &lt;= B;<br /> O2 &lt;= A xor B;<br /> when&quot;10&quot;=&gt;<br /> O1 &lt;= A xor B;<br /> when&quot;11&quot;=&gt;<br /> O2 &lt;= A or B;<br /> whenothers=&gt;<br /> O1 &lt;= &apos;0&apos;;<br /> O2 &lt;= &apos;0&apos;;<br /> endcase;<br /> endprocess;<br />ENDARCHITECTURE;<br />19<br />VHDL 360 ©<br />Do you think a Latch would be inferred in the below example?<br /><ul><li>Latches are inferred for both signals &quot;O1&quot; &amp; &quot;O2&quot;
  • 22. Though the case is complete &amp; no &quot;null&quot; statement is there, we find that &quot;O1&quot; &amp; &quot;O2&quot; are not assigned in all case&apos;s branches  This is called “Incomplete signal assignment”</li></li></ul><li>Latch Inference<br />Most of the time latches are not desired in the design because they affect timing badly<br />To remove unintended latches: <br />Cover all branches of if-else and case statements<br />Avoid incomplete signal assignment by assigning a value to each signal in each branch<br />if you don’t care about other conditional values then assign the output to &apos;0&apos; or &apos;1&apos;<br />20<br />VHDL 360 ©<br />
  • 23. Enough CombinationalLet&apos;s Go Sequential<br />21<br />
  • 24. Sequential Logic<br />22<br />VHDL 360 ©<br /><ul><li>Let&apos;s model the well known D-FF with outputs Q &amp; nQ and see the synthesis results</li></ul>Example 8:<br />Libraryieee;<br />useieee.std_logic_1164.all;<br />Entity d_ff is<br />Port(d, clk, rst :instd_logic;<br />Q, nQ :outstd_logic);<br />endentity;<br />Architecture behav of d_ff is<br />Begin<br />process(clk)<br />begin<br />If(rising_edge(clk))then<br />If(rst = &apos;1&apos;)then<br /> Q &lt;= &apos;0&apos;;<br /> nQ &lt;= &apos;0&apos;;<br /> else<br /> Q &lt;= d;<br /> nQ &lt;=not (d);<br /> endif;<br /> endif;<br />endprocess;<br />end behav;<br />
  • 25. Sequential Logic<br />23<br />VHDL 360 ©<br /><ul><li>Let&apos;s model the well known D-FF with outputs Q &amp; nQ and see the synthesis results</li></ul>Example 8:<br />Libraryieee;<br />useieee.std_logic_1164.all;<br />Entity d_ff is<br />Port(d, clk, rst :instd_logic;<br />Q, nQ :outstd_logic);<br />endentity;<br />Architecture behav of d_ff is<br />Begin<br />process(clk)<br />begin<br />If(rising_edge(clk))then<br />If(rst = &apos;1&apos;)then<br /> Q &lt;= &apos;0&apos;;<br /> nQ &lt;= &apos;0&apos;;<br /> else<br /> Q &lt;= d;<br /> nQ &lt;=not (d);<br /> endif;<br /> endif;<br />endprocess;<br />end behav;<br />Two Flip-Flops ?!<br />Change the code to have only one Flip-Flop<br />
  • 26. Sequential Logic<br />24<br />VHDL 360 ©<br /><ul><li>Let&apos;s model the well known D-FF with outputs Q &amp; nQ and see the synthesis results</li></ul>Example 9:<br />Libraryieee;<br />useieee.std_logic_1164.all;<br />Entity d_ff is<br />Port( d, clk, rst :instd_logic;<br /> Q, nQ :outstd_logic);<br />endentity;<br />Architecture behav of d_ff is<br />signal Q_int:std_logic;<br />Begin<br />process(clk)<br />begin<br />If(rising_edge(clk))then<br />If(rst = &apos;1&apos;)then<br /> Q_int &lt;= &apos;0&apos;;<br /> else<br /> Q_int &lt;= d;<br /> endif;<br /> endif;<br />endprocess;<br />Q &lt;= Q_int;<br />nQ &lt;=not (Q_int);<br />end behav;<br />Yep…That&apos;s what we want! <br />
  • 27. Sequential Logic<br />25<br />VHDL 360 ©<br /><ul><li>What about making an array of D-FFs?</li></ul>Example 10:<br />Libraryieee;<br />useieee.std_logic_1164.all;<br />Entity d_ffs is<br />Port(d: std_logic_vector(3downto0);<br />clk, rst :instd_logic;<br />Q, nQ :outstd_logic_vector(3downto0));<br />endentity;<br />Architecture behav of d_ffs is<br />signal Q_int:std_logic_vector(3downto0);<br />Begin<br />process(clk)<br />begin<br />If(rising_edge(clk))then<br />If(rst = &apos;1&apos;)then<br /> Q_int &lt;= (others =&gt; &apos;0&apos;);<br /> else<br /> Q_int &lt;= d;<br /> endif;<br /> endif;<br />endprocess;<br />Q &lt;= Q_int;<br />nQ &lt;=not (Q_int);<br />end behav;<br />
  • 28. Sequential Logic<br />Example 11: 8-bit Shift Register (Shift right)<br />Libraryieee;<br />useieee.std_logic_1164.all;<br />entity shift_register is<br /> Port( clk, D, enable :inSTD_LOGIC;<br /> Q :outSTD_LOGIC);<br />endentity;<br />architecture Behavioral of shift_register is<br />begin<br />process(clk)<br />variable reg:std_logic_vector(7downto0);<br />begin<br />ifrising_edge(clk)then<br />if enable = &apos;1&apos; then<br />for i in1to7loop<br /> reg(i-1):= reg(i);<br />endloop;<br /> reg(7):= d;<br />endif;<br />endif;<br /> Q &lt;= reg(0);<br /> endprocess;<br />end Behavioral;<br />7 6 5 4 3 2 1 0<br />VHDL 360 ©<br />26<br />
  • 29. Flip-Flop Inference<br />Assignments under clock edge where the object value needs to be remembered across multiple process invocations  Flip-Flop<br />Signal assignment under clock edge will always infer a Flip-Flop<br />Variable assignment under clock edge will infer Flip-Flop only when its value ought to be remembered across process invocations<br />27<br />VHDL 360 ©<br />
  • 30. Exercise 1<br />LIBRARYieee;<br />USEieee.std_logic_1164.all;<br />Entity unknown is<br />port(x:outstd_logic;<br /> y:instd_logic_vector(3downto0);<br /> c:ininteger);<br />Endentity;<br />Architecture behave of unknown is<br />Begin<br /> x &lt;= y(c);<br />End behave;<br />VHDL 360 ©<br />28<br />Deduce what the below code models<br />Use synthesis tool to validate your answer <br />
  • 31. Contacts<br />You can contact us at:<br />http://www.embedded-tips.blogspot.com/<br />VHDL 360 ©<br />29<br />

×