<?xml 
version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="https://www.alse-fr.com/spip.php?page=backend.xslt" ?>
<rss version="2.0" 
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:atom="http://www.w3.org/2005/Atom"
>

<channel xml:lang="en">
	<title>A.L.S.E the FPGA Experts</title>
	<link>https://www.alse-fr.com/</link>
	<description>A.L.S.E: Advanced Logic Synthesis for Electronics, offers a complete range of Services, IPs, Training courses and Boards to help you with the design of FPGA-based and EmbeddedSystems.</description>
	<language>en</language>
	<generator>SPIP - www.spip.net</generator>
	<atom:link href="https://www.alse-fr.com/spip.php?id_rubrique=35&amp;page=backend" rel="self" type="application/rss+xml" />

	<image>
		<title>A.L.S.E the FPGA Experts</title>
		<url>https://www.alse-fr.com/sites/alse-fr.com/local/cache-vignettes/L144xH42/siteon0-d414d.png?1782755771</url>
		<link>https://www.alse-fr.com/</link>
		<height>42</height>
		<width>144</width>
	</image>



<item xml:lang="en">
		<title>NUMERIC_STD Issues.</title>
		<link>https://www.alse-fr.com/20-NUMERIC_STD-Issue.html</link>
		<guid isPermaLink="true">https://www.alse-fr.com/20-NUMERIC_STD-Issue.html</guid>
		<dc:date>2017-03-01T13:28:56Z</dc:date>
		<dc:format>text/html</dc:format>
		<dc:language>en</dc:language>
		
		<enclosure url="https://www.alse-fr.com/sites/alse-fr.com/IMG/logo/numstd.png" length="79284" type="image/png" />



		<description>&lt;p&gt;This article describes two problems I found in NUMERIC_STD.&lt;br class='manualbr' /&gt;Conclusions : do not multiply signed or unsigned vectors by an integer, and be careful with with the resize function !&lt;/p&gt;

-
&lt;a href="https://www.alse-fr.com/-VHDL-helper-.html" rel="directory"&gt;VHDL helper&lt;/a&gt;


		</description>


 <content:encoded>&lt;img src='https://www.alse-fr.com/sites/alse-fr.com/local/cache-vignettes/L150xH31/numstd-90454.png?1782813971' class='spip_logo spip_logo_right' width='150' height='31' alt=&#034;&#034; /&gt;
		&lt;div class='rss_texte'&gt;&lt;h2 class=&#034;spip&#034;&gt;Description&lt;/h2&gt;
&lt;p&gt;The IEEE numeric_std library issued (eg) in Nov 1994, and which (as of 2022) is still used in the latest versions of the Simulation and Synthesis tools, implements incorrectly the multiplications of signed/unsigned vectors by an integer. Moreover, the resize function it includes can produce incorrect results without warning.&lt;/p&gt;
&lt;p&gt;Fixing these functions is not difficult but my attempts to have the &lt;abbr title=&#034;VHSIC Hardware Description Language. _ A consequence of the US DOD's VHSIC program, this language (normalized as IEEE 1076) was created to describe accurately the behavior of High Speed Integrated Circuits.&#034;&gt;VHDL&lt;/abbr&gt; working group fix this library have been unsuccessful. As a consequence, you should understand and take into account these &#8220;features&#8221;. This is the purpose of this page.&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Multiplication issue : Functions affected&lt;/h2&gt;
&lt;p&gt;Here are the original prototypes (in IEEE.numeric_std) :&lt;/p&gt;
&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt; -- Id: A.17 function &#034;*&#034; ( L: UNSIGNED; R: NATURAL) return UNSIGNED; -- Result subtype: UNSIGNED((L'length+L'length-1) downto 0). -- Result: Multiplies an UNSIGNED vector, L, with a non-negative -- INTEGER, R. R is converted to an UNSIGNED vector of -- SIZE L'length before multiplication. -- Id: A.18 function &#034;*&#034; ( L: NATURAL; R: UNSIGNED) return UNSIGNED; -- Result subtype: UNSIGNED((R'length+R'length-1) downto 0). -- Result: Multiplies an UNSIGNED vector, R, with a non-negative -- INTEGER, L. L is converted to an UNSIGNED vector of -- SIZE R'length before multiplication. -- Id: A.19 function &#034;*&#034; ( L: SIGNED; R: INTEGER) return SIGNED; -- Result subtype: SIGNED((L'length+L'length-1) downto 0) -- Result: Multiplies a SIGNED vector, L, with an INTEGER, R. R is -- converted to a SIGNED vector of SIZE L'length before -- multiplication. -- Id: A.20 function &#034;*&#034; ( L: INTEGER; R: SIGNED) return SIGNED; -- Result subtype: SIGNED((R'length+R'length-1) downto 0) -- Result: Multiplies a SIGNED vector, R, with an INTEGER, L. L is -- converted to a SIGNED vector of SIZE R'length before -- multiplication.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Multiplication Issue&lt;/h2&gt;
&lt;p&gt;As we can see above (in the comments), when multiplying a vector by an integer, the integer is converted into a vector &lt;em class=&#034;spip&#034;&gt;of the same width as the other operand&lt;/em&gt; !!!&lt;/p&gt;
&lt;p&gt;As a consequence, the result's width is forced to two times the width of the signed/unsigned vector, just as if the vector was squared (multiplied by itself), which absolutely does NOT make sense.&lt;/p&gt;
&lt;p&gt;The result is either too short or too large.&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Consequences&lt;/h2&gt;&lt;ul class=&#034;spip&#034; role=&#034;list&#034;&gt;&lt;li&gt; Multiplying a vector by 1 (or a small integer) creates a vector twice as large. &lt;br class='manualbr' /&gt;Quite inefficient, a bit ridiculous, but relatively harmless.&lt;/li&gt;&lt;li&gt; Multiplying a 128-bits vector by 7 (eg) creates a 256-bits results.&lt;br class='manualbr' /&gt;Same remark as above.&lt;/li&gt;&lt;li&gt; The result of Multiplying an 8-bits unsigned vector by 256 is a 16-bits vector (okay by chance) but &lt;strong class=&#034;caractencadre-spip spip&#034;&gt;with a value of ZERO&lt;/strong&gt; ! See the test case included.&lt;br class='manualbr' /&gt;This is definitely VERY WRONG :-( and the multiplication result is not usable.&lt;/li&gt;&lt;li&gt; Multiplying a 8-bits signed vector by 1000 (decimal) produces an incorrect result (actually V * 232) and the result is limited to 16 bits anyway.&lt;br class='manualbr' /&gt;This is also very wrong.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Note that simulators will typically issue truncation warnings &lt;em class=&#034;spip&#034;&gt;during the simulation&lt;/em&gt; (run-time) in the most offending cases, or refuse to compile if the result width is not what the user believed (which is how I uncovered the issue).&lt;br class='manualbr' /&gt;But Synthesis tools will compile and generate hardware which can potentially produce incorrect results, and this is not acceptable.&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Are these functions useful ?&lt;/h2&gt;
&lt;p&gt;Certainly. They are required by the principle of numeric_std which is to extend arithmetic operators to vectors that represent numbers (signed and unsigned).&lt;/p&gt;
&lt;p&gt;Moreover, Synthesis tools are usually relatively smart when they see multiplications by constants, in which case they know how to replace the multiplication by adder(s).&lt;/p&gt;
&lt;p&gt;However, their use has been limited (which explains why the incorrect implementation hasn't been reported heavily before).
One can note that the older Synopsys library &#8220;std_logic_arith&#8221; did not provide the multiplication of signed/unsigned vector by integers, and therefore could not have the same problem.&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Repairing NUMERIC_STD ?&lt;/h2&gt;
&lt;p&gt;Fixing the affected functions is not complicated : it suffices to convert the natural or integer into a &lt;strong class=&#034;caractencadre-spip spip&#034;&gt;32-bits&lt;/strong&gt; vector !
The resulting width at least starts making some sense (=Operand width + 32) and no truncation / incorrect result can occur.
If the result is still too large for you (like when you multiply by an integer &lt;em class=&#034;spip&#034;&gt;range&lt;/em&gt;), you just have to resize the result. If you lose information in the resize (you resized into a too short vector), YOU WILL NOT GET A WARNING.&lt;/p&gt;
&lt;p&gt;&lt;strong class=&#034;caractencadre-spip spip&#034;&gt;BUT, the issue is that numeric_std will probably never be fixed !&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So you have to take care of your code and make sure you are not affected by the library errors, as explained below.&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In spite of the library clumsiness (shift operators, resize issue, and this bug in particular), I still keep recommending using numeric_std instead of other non-IEEE libraries.&lt;/p&gt;
&lt;p&gt;My &lt;a href='https://www.alse-fr.com/VHDL-Coding-Guide.html' class=&#034;spip_in&#034;&gt;&lt;strong&gt;VHDL Coding Style Guide&lt;/strong&gt;&lt;/a&gt; is updated :&lt;/p&gt;
&lt;ul class=&#034;spip&#034; role=&#034;list&#034;&gt;&lt;li&gt; Do not multiply signed/unsigned vectors by Integers.
&lt;ul class=&#034;spip&#034; role=&#034;list&#034;&gt;&lt;li&gt; Use slices and adders if you multiply by an integer constant&lt;/li&gt;&lt;li&gt; Convert the integer in a properly sized signed or unsigned vector before multiplying.&lt;/li&gt;&lt;li&gt; Keep in mind that if resize creates an incorrect value due to truncation, you will NOT be warned !&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;and the older recommendation remains :&lt;/p&gt;
&lt;ul class=&#034;spip&#034; role=&#034;list&#034;&gt;&lt;li&gt; Avoid using shift/rotate operators from numeric_std (use slices &amp; concatenation)&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;And finally : kudos to the brilliant Technical Support at Mentor / Model Technology !&lt;/p&gt;&lt;/div&gt;
		
		</content:encoded>


		

	</item>
<item xml:lang="en">
		<title>Utilities</title>
		<link>https://www.alse-fr.com/Utilities.html</link>
		<guid isPermaLink="true">https://www.alse-fr.com/Utilities.html</guid>
		<dc:date>2016-09-20T21:44:56Z</dc:date>
		<dc:format>text/html</dc:format>
		<dc:language>en</dc:language>
		
		



		<description>
&lt;p&gt;&#169; 2009 ALSE. All rights reserved. NOTICE OF DISCLAIMER about Free IPs and other information on the ALSE Web site. ALSE is providing design, code, or information &#8220;as is.&#8221; By providing the design, code, or information ALSE makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may require for your implementation. You are entirely responsible with any use you make of the provided information, code or design. (&#8230;)&lt;/p&gt;


-
&lt;a href="https://www.alse-fr.com/-VHDL-helper-.html" rel="directory"&gt;VHDL helper&lt;/a&gt;


		</description>


 <content:encoded>&lt;div class='rss_chapo'&gt;&lt;div class=&#034;texteencadre-spip spip&#034;&gt;&lt;em class=&#034;spip&#034;&gt;&#169; 2009 ALSE. All rights reserved.
NOTICE OF DISCLAIMER about Free IPs and other information on the ALSE Web site.
ALSE is providing design, code, or information &#8220;as is.&#8221; By providing the design, code, or information ALSE makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may require for your implementation. You are entirely responsible with any use you make of the provided information, code or design.
ALSE expressly disclaims any warranty whatsoever with respect to the adequacy of the information, or to the suitability to any use beyond education, including but not limited to any warranties or representations that this information is free from claims of infringement and any implied warranties of merchandability or fitness for a particular purpose.&lt;/em&gt;&lt;/div&gt;
&lt;p&gt;These utilities are free to use, with the usual disclaimer above: use this at your own risk.&lt;/p&gt;&lt;/div&gt;
		&lt;div class='rss_texte'&gt;&lt;p&gt;&lt;a href='https://www.alse-fr.com/sites/alse-fr.com/IMG/7z/crimson_sv.7z' class=&#034;spip_in&#034; title=&#034;SystemVerilog definition files for Crimson Editor. &#8211; 7 Zip (3.3 KiB)&#034; type='application/x-7z-compressed'&gt;SystemVerilog definition files for Crimson Editor.&lt;/a&gt;&lt;br class='manualbr' /&gt;unzip into Crimson's base installation directory.&lt;/p&gt;
&lt;p&gt;&lt;abbr title=&#034;The first (in order of appearance) Hardware Description Language (like VHDL which followed a few years later). Normalized as IEEE 1364.&#034;&gt;Verilog&lt;/abbr&gt; &lt;abbr title=&#034;Register Transfer Level. Simply put: it's HDL code that is suitable for synthesis. Which mean in practice describing what happens on rising edges of a Clock.&#034;&gt;RTL&lt;/abbr&gt; ROM Generator&lt;br class='manualbr' /&gt;This Tcl/Tk utility reads in a memory contents file in Intel-Hex format and produces synthesizable Verilog code for the ROM.&lt;/p&gt;
&lt;p&gt;&lt;abbr title=&#034;VHSIC Hardware Description Language. _ A consequence of the US DOD's VHSIC program, this language (normalized as IEEE 1076) was created to describe accurately the behavior of High Speed Integrated Circuits.&#034;&gt;VHDL&lt;/abbr&gt; Quick Reference sheet.&lt;br class='manualbr' /&gt;Standard RTL &amp; Test bench templates and Numeric_std reminder, all in one sheet.&lt;/p&gt;
&lt;p&gt;Numeric_std cheat sheet.&lt;/p&gt;
&lt;p&gt;CPU_Time.&lt;br class='manualbr' /&gt;Utility (Tcl) to capture the current Date &amp; Time information (&#8220;wall clock time&#8221;) from within a VHDL simulation. (c) ALSE, for use with ModelSim. Your batch simulation can record start and end time in the VHDL output. Great also for simulation run-time optimization.&lt;/p&gt;&lt;/div&gt;
		
		</content:encoded>


		
		<enclosure url="https://www.alse-fr.com/sites/alse-fr.com/IMG/7z/crimson_sv.7z" length="3346" type="application/x-7z-compressed" />
		

	</item>
<item xml:lang="en">
		<title>VHDL templates</title>
		<link>https://www.alse-fr.com/VHDL-Examples.html</link>
		<guid isPermaLink="true">https://www.alse-fr.com/VHDL-Examples.html</guid>
		<dc:date>2016-09-20T21:38:13Z</dc:date>
		<dc:format>text/html</dc:format>
		<dc:language>en</dc:language>
		
		



		<description>
&lt;p&gt;If you are looking for well-written code to analyze, or coding examples, please check also our Free IP section where you can find the source code of many IPs, which are reasonably simple to understand while implementing all the concepts needed for designing complex functions. We have dedicated this page to Code Templates, so beginners or more advanced designers can simply cut &amp; paste from the snippets. There is enough code here to be used in 90% of VHDL code (both RTL and Simulation). (&#8230;)&lt;/p&gt;


-
&lt;a href="https://www.alse-fr.com/-VHDL-helper-.html" rel="directory"&gt;VHDL helper&lt;/a&gt;


		</description>


 <content:encoded>&lt;div class='rss_chapo'&gt;&lt;p&gt;If you are looking for well-written code to analyze, or coding examples, please check also our &lt;a href='https://www.alse-fr.com/Free-IPs.html' class=&#034;spip_in&#034;&gt;Free IP section&lt;/a&gt; where you can find the source code of many IPs, which are reasonably simple to understand while implementing all the concepts needed for designing complex functions.&lt;/p&gt;
&lt;p&gt;We have dedicated this page to Code Templates, so beginners or more advanced designers can simply cut &amp; paste from the snippets.
There is enough code here to be used in 90% of &lt;abbr title=&#034;VHSIC Hardware Description Language. _ A consequence of the US DOD's VHSIC program, this language (normalized as IEEE 1076) was created to describe accurately the behavior of High Speed Integrated Circuits.&#034;&gt;VHDL&lt;/abbr&gt; code (both &lt;abbr title=&#034;Register Transfer Level. Simply put: it's HDL code that is suitable for synthesis. Which mean in practice describing what happens on rising edges of a Clock.&#034;&gt;RTL&lt;/abbr&gt; and Simulation).&lt;/p&gt;
&lt;p&gt;Beginners: don't miss some Application Notes especially &#8220;Writing Test benches&#8221;.&lt;/p&gt;
&lt;p&gt;Note : the code below is compatible with all (decent) synthesis tools (it does not use VHDL 2008 constructs).&lt;/p&gt;&lt;/div&gt;
		&lt;div class='rss_texte'&gt;&lt;h2 class=&#034;spip&#034;&gt;&lt;abbr title=&#034;Register Transfer Level. Simply put: it's HDL code that is suitable for synthesis. Which mean in practice describing what happens on rising edges of a Clock.&#034;&gt;RTL&lt;/abbr&gt; Libraries&lt;/h2&gt;&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;Library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Simulation Libraries&lt;/h2&gt;&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt; use STD.TEXTIO.all; Library IEEE; use IEEE.std_logic_TEXTIO.all; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Resynchronization Flip-Flop&lt;/h2&gt;
&lt;p&gt;&lt;code class='spip_code spip_code_inline' dir='ltr'&gt;Ar &lt;= A when rising_edge(Clk);&lt;/code&gt;&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Synchronous Process Template&lt;/h2&gt;&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;process (Rst,Clk) -- NOTHING ELSE in the sensitivity list ! -- variables (if any) go here begin if Rst='1' then -- EVERY signal assigned below must be reset here ! &lt;&lt;&lt;signals receive CONSTANT values at reset here &gt;&gt;&gt; elsif rising_edge(Clk) then &lt;&lt;&lt; Your code goes here (only) &gt;&gt;&gt; end if; end process;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Tri-state output&lt;/h2&gt;
&lt;p&gt;&lt;code class='spip_code spip_code_inline' dir='ltr'&gt;Qtri &lt;= Dout when OE='1' else 'Z';&lt;/code&gt;&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Multiplexer&lt;/h2&gt;
&lt;p&gt;&lt;code class='spip_code spip_code_inline' dir='ltr'&gt;Q &lt;= A0 when Sel='0' else A1;&lt;/code&gt;&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Direct Instantiation&lt;/h2&gt;
&lt;p&gt;Don't use &#8220;components&#8221; !&lt;/p&gt;
&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;QUAD_inst: {{Entity work.}}QUAD(RTL) port map ( Rst =&gt; Rst, Clk =&gt; Clk, A =&gt; Ar, B =&gt; Br, Cnt =&gt; Position, Dir =&gt; open );&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Cannot read outputs&lt;/h2&gt;
&lt;p&gt;We assume you don't use &lt;abbr title=&#034;VHSIC Hardware Description Language. _ A consequence of the US DOD's VHSIC program, this language (normalized as IEEE 1076) was created to describe accurately the behavior of High Speed Integrated Circuits.&#034;&gt;VHDL&lt;/abbr&gt; 2008 (for reasons found in our Coding Style Guide), so you will not be able to read an output signal.&lt;/p&gt;
&lt;p&gt;The workaround is to declare and work on an internal signal which can be of a different type as below.&lt;/p&gt;
&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt; signal iCount : unsigned(Count'range); -- unsigned better than SLV internally Begin -- architecture Count &lt;= std_logic_vector(iCount); -- SLV required at the interface (ports)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;7-Segments decimal Decoder&lt;/h2&gt;&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;process(Data) begin Seg &lt;= (others =&gt; '-'); -- optimize for A..F with don't care case Data is when x&#034;0&#034; =&gt; Seg &lt;= &#034;1111110&#034;; when x&#034;1&#034; =&gt; Seg &lt;= &#034;0110000&#034;; when x&#034;2&#034; =&gt; Seg &lt;= &#034;1101101&#034;; when x&#034;3&#034; =&gt; Seg &lt;= &#034;1111001&#034;; when x&#034;4&#034; =&gt; Seg &lt;= &#034;0110011&#034;; when x&#034;5&#034; =&gt; Seg &lt;= &#034;1011011&#034;; when x&#034;6&#034; =&gt; Seg &lt;= &#034;1011111&#034;; when x&#034;7&#034; =&gt; Seg &lt;= &#034;1110000&#034;; when x&#034;8&#034; =&gt; Seg &lt;= &#034;1111111&#034;; when x&#034;9&#034; =&gt; Seg &lt;= &#034;1111011&#034;; when others =&gt; null; -- required to cover the 6551 remaining cases end case; end process;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Demux / binary to one-hot&lt;/h2&gt;&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;Process (i) begin MyVect &lt;= (others=&gt;'0'); MyVect(i) &lt;= '1'; -- i is an integer (range) end process;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Optimal One-Hot to Binary&lt;/h2&gt;
&lt;p&gt;In VHDL, this represents a quite challenging problem if you want to infer an efficient hardware implementation. &lt;br class='manualbr' /&gt;In &lt;abbr title=&#034;The first (in order of appearance) Hardware Description Language (like VHDL which followed a few years later). Normalized as IEEE 1364.&#034;&gt;Verilog&lt;/abbr&gt;, the use of a synthesis pragma was common. &lt;br class='manualbr' /&gt;In &lt;abbr title=&#034;SystemVerilog (IEEE standard 1800) is an HDVL (Hardware Description &amp;#38; Verification Language). _ This is the Language that now supersedes both Verilog and VHDL, thus becoming the de facto Language of the next 20 years.&#034;&gt;SystemVerilog&lt;/abbr&gt;, the unique case statement is the answer.&lt;/p&gt;
&lt;p&gt;If you are not too concerned by the amount of logic generated, you can use an intuitive
solution (a case statement). The optimal solution is below.&lt;/p&gt;
&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;-- OneHotDecoder.vhd -- ---------------------------------------------------- -- Optimal One-Hot to Binary Decoder -- ---------------------------------------------------- -- (c) ALSE / Bertrand CUZEAU - FPGA.fr -- Library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; -- --------------------------- Entity OneHotDecoder is -- --------------------------- port( Din : in std_logic_vector(7 downto 0); Dout : out std_logic_vector(2 downto 0) ); End entity OneHotDecoder; -- -------------------------------------- Architecture RTL of OneHotDecoder is -- -------------------------------------- Begin process (Din) variable R : unsigned (Dout'range); begin R := (others=&gt;'0'); for i in Din'range loop if Din(i)='1' then R := R or to_unsigned(i,R'length); end if; end loop; Dout &lt;= std_logic_vector(R); end process; End architecture RTL;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Butterfly (bus order swap)&lt;/h2&gt;&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;-- Note that both vectors start/end at index 0 Process (MyVect) begin for i in MyVect'range loop SwappedVect(i) &lt;= MyVect(MyVect'high-i); end loop; end process;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Power On Reset (POR)&lt;/h2&gt;
&lt;p&gt;When there is no (reliable) external reset input, it is very recommended to generate a global and general Reset of the entire &lt;abbr title=&#034;Field Programmable Gate Array. Standard devices that are customized at power up by loading a Programming pattern (aka bitstream) contained in a non-volatile memory. Users can develop completely custom functions and applications with off-the-shelf FPGAs.&#034;&gt;FPGA&lt;/abbr&gt; at start up. This is the function of the simple module below. The &#8220;magic vector&#8221; 1010 (decimal value 10) is too small in cases of FPGA families in which Flip-Flops come up in an indetermined state (like several Actel families). It is however suitable for SRam FPGAs.&lt;/p&gt;
&lt;p&gt;The Reset output will have to be resynchronized to all the different clock domains, but it's another story&#8230;&lt;/p&gt;
&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;-- ------------------------------------ -- Power On Reset with NO reset input -- ------------------------------------ -- Author : Bert Cuzeau - ALSE -- 10 clock cycles reset pulse issued at start up -- Suitable for SRam FPGAs Library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; -- ---------------------------------------- Entity POR is -- ---------------------------------------- Port ( Clock : in std_logic; -- clock input Reset : out std_logic ); -- reset output end entity POR; -- ---------------------------------------- Architecture RTL of POR is -- ---------------------------------------- signal Cnt : unsigned (3 downto 0) := (others=&gt;'0'); -- init for simulation signal iRst_n : std_logic := '0'; -- init for simulation Begin Reset &lt;= not iRst_n; process (Clock) begin if rising_edge(Clock) then if Cnt /= 10 then -- If counter hasn't reached this value then Cnt &lt;= Cnt + 1; -- keep counting iRst_n &lt;= '0'; -- and force the Reset else iRst_n &lt;= '1'; -- release the Reset end if; end if; end process; end architecture RTL;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Synchronous Edge Detector&lt;/h2&gt;&lt;div class='spip_document_46 spip_document spip_documents spip_document_image spip_documents_center spip_document_center spip_document_avec_legende' data-legende-len=&#034;27&#034; data-legende-lenx=&#034;&#034;
&gt;
&lt;figure class=&#034;spip_doc_inner&#034;&gt; &lt;img src='https://www.alse-fr.com/sites/alse-fr.com/local/cache-vignettes/L500xH192/edgedet-0ed7f.jpg?1782813971' width='500' height='192' alt='' /&gt;
&lt;figcaption class='spip_doc_legende'&gt; &lt;div class='spip_doc_titre crayon document-titre-46 '&gt;&lt;strong&gt;Synchronous Edge Detector
&lt;/strong&gt;&lt;/div&gt; &lt;/figcaption&gt;&lt;/figure&gt;
&lt;/div&gt;
&lt;p&gt;The input D signal can be asynchronous.&lt;/p&gt;
&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;-- ------------------------------------------ Architecture RTL of EdgeDet is -- ------------------------------------------ signal Dr, Drr : std_logic; Begin Dr &lt;= D when rising_edge(Clk); Drr &lt;= Dr when rising_edge(Clk); Rose &lt;= Dr and not Drr; Fell &lt;= Drr and not Dr; Changed &lt;= Dr xor Drr; end architecture RTL;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&#034;spip&#034;&gt;Simple Memory Inference&lt;/h2&gt;
&lt;p&gt;Please refer to ALSE training course.&lt;/p&gt;
&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;-- RTL (synthesizable) Synchronous Single Port Memory -- ---------------------------------------------------------- -- (c) ALSE - http://www.alse-fr.com -- Author : Bert Cuzeau -- Contact : info@alse-fr.com -- Note : Uses unconstrained arrays in port Library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; -- ------------------------------------------ Entity RamTest is -- ------------------------------------------ port ( Clk : in std_logic; Din : in std_logic_vector; Dout : out std_logic_vector; WE : in std_logic; RdAddr : in std_logic_vector; WrAddr : in std_logic_vector ); end RamTest; -- ------------------------------------------ Architecture RTL of RamTest is -- ------------------------------------------ subtype Data_t is std_logic_vector (Dout'range); type Mem_t is array (0 to 2**RdAddr'length-1) of Data_t; signal Mem : Mem_t; Begin process (Clk) begin if rising_edge(Clk) then Dout &lt;= Mem (to_integer(unsigned(RdAddr))); -- Synchronous Read if (WE = '1') then Mem (to_integer(unsigned(WrAddr))) &lt;= Din; end if; end if; end process; end architecture RTL;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Inference vs Instantiation is an important topic which is explained in our Training courses. The code above is normally suitable to all synthesis tools and FPGAs (that embark embedded memory blocks).&lt;/p&gt;
&lt;p&gt;While it is possible to infer true &lt;strong&gt;Dual&lt;/strong&gt;-Port memories with modern synthesis tools, instantiation is usually more recommended.&lt;/p&gt;
&lt;h2 class=&#034;spip&#034;&gt;Simple RTL assertions&lt;/h2&gt;&lt;div class=&#034;precode&#034;&gt;&lt;pre class='spip_code spip_code_block' dir='ltr' style='text-align:left;'&gt;&lt;code&gt;assert not (rising_edge(Clk) and FifoWR='1' and Fifo_Full='1') report &#034;Fifo Write Violation !!!&#034; severity failure;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note : it is not a &lt;abbr title=&#034;Property Specification Language. _ Normalis&#233; as IEEE 1850 and now part of VHDL-2008, thus language allows describing Properties and Assertions, thus enabling the ABV (Assertion Based Verification) methodology. _ A (roughly) equivalent to PSL can be found in SystemVerilog as &#8220;SVA&#8221;.&#034;&gt;PSL&lt;/abbr&gt; assertion, it shows how to take advantage of the VHDL &#8220;assert&#8221; statement and it does not require any specific simulator or feature. &lt;br class='manualbr' /&gt;PSL Assertions are more versatile and powerful (especially for their temporal layer).&lt;/p&gt;&lt;/div&gt;
		
		</content:encoded>


		

	</item>



</channel>

</rss>