<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>VHDL: Convert a Fixed Module into a Generic Module for Reuse</title><link>/technologies/fpga-group/b/blog/posts/vhdl-convert-a-fixed-module-into-a-generic-module-for-reuse</link><description>The goal of this post is turn a fixed VHDL design into a configurable one. Change a fixed RAM IP into RAM that can be sized, without changing source or logic.
I use michaelkellett &amp;#39;s VHDL RAM Memory design before: use RAM...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: VHDL: Convert a Fixed Module into a Generic Module for Reuse</title><link>https://community.element14.com/technologies/fpga-group/b/blog/posts/vhdl-convert-a-fixed-module-into-a-generic-module-for-reuse</link><pubDate>Sun, 12 Dec 2021 22:26:21 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:a2a5c3fa-36d4-4e0e-9577-b441c4e6da8d</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;If you, like me, don&amp;#39;t have a particular writing style for VHDL, but you do like consistency, there&amp;#39;s a style checker available: &lt;a href="https://github.com/jeremiah-c-leary/vhdl-style-guide" rel="noopener noreferrer" target="_blank"&gt;vhdl style guide&lt;/a&gt;.&lt;br /&gt;I haven&amp;#39;t made up my mind about what&amp;#39;s best, but someone else has. I&amp;#39;m going to see what the effect is.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using this file as example:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:219de908-0147-4c64-aa44-a0d3ede80d15:type=text&amp;text=--%20from%20Micheal%20Kellett%3A%20https%3A%2F%2Fwww.element14.com%2Fcommunity%2Fgroups%2Ffpga-group%2Fblog%2F2021%2F07%2F31%2Fcheap-cyclone-10%0D%0A%0D%0Alibrary%20IEEE%3B%0D%0Ause%20IEEE.std_logic_1164.all%3B%20%20%20%0D%0Ause%20IEEE.NUMERIC_STD.all%3B%0D%0A%0D%0Apackage%20mem_inf%20is%0D%0Acomponent%20mem_inf_ram%20is%0D%0A%20%20%20%20%20generic%20%28%0D%0A%20%20%20%20%20%20%20data_width%20%3A%20integer%20%3A%3D%2012%3B%20--%20default%2012%20bits%20per%20element%0D%0A%20%20%20%20%20%20%20data_length%3A%20integer%20%3A%3D%2064%3B%20--%20default%2064%20addressable%20elements%20%0D%0A%20%20%20%20%20%20%20address_width%20%3A%20integer%20%3A%3D%206%20--%20default%20range%20fits%20in%206%20bits%0D%0A%20%20%20%20%20%29%3B%0D%0A%20%20%20%20%20port%28%0D%0A%20%20%20%20%20%20%20%20%20we%20%3A%20in%20STD_LOGIC%3B%0D%0A%20%20%20%20%20%20%20%20%20en%20%3A%20in%20STD_LOGIC%3B%0D%0A%20%20%20%20%20%20%20%20%20clk%20%3A%20in%20STD_LOGIC%3B%0D%0A%20%20%20%20%20%20%20%20%20address%20%3A%20in%20STD_LOGIC_VECTOR%28address_width%20-%201%20downto%200%29%3B%0D%0A%20%20%20%20%20%20%20%20%20data%20%3A%20in%20STD_LOGIC_VECTOR%28data_width%20-%201%20%20downto%200%29%3B%0D%0A%20%20%20%20%20%20%20%20%20q%20%3A%20out%20STD_LOGIC_VECTOR%28data_width%20-%201%20downto%200%29%0D%0A%20%20%20%20%20%20%20%20%20%29%3B%0D%0Aend%20component%3B%0D%0Aend%20package%3B%0D%0A%0D%0Alibrary%20IEEE%3B%0D%0Ause%20IEEE.std_logic_1164.all%3B%20%20%20%0D%0Ause%20IEEE.NUMERIC_STD.all%3B%0D%0A%0D%0Aentity%20mem_inf_ram%20is%0D%0A%20%20%20%20%20generic%20%28%0D%0A%20%20%20%20%20%20%20data_width%20%3A%20integer%3B%0D%0A%20%20%20%20%20%20%20data_length%3A%20integer%3B%20%0D%0A%20%20%20%20%20%20%20address_width%20%3A%20integer%0D%0A%20%20%20%20%20%29%3B%0D%0A%20%20%20%20%20port%28%0D%0A%20%20%20%20%20%20%20%20%20we%20%3A%20in%20STD_LOGIC%3B%0D%0A%20%20%20%20%20%20%20%20%20en%20%3A%20in%20STD_LOGIC%3B%0D%0A%20%20%20%20%20%20%20%20%20clk%20%3A%20in%20STD_LOGIC%3B%0D%0A%20%20%20%20%20%20%20%20%20address%20%3A%20in%20STD_LOGIC_VECTOR%28address_width%20-%201%20downto%200%29%3B%0D%0A%20%20%20%20%20%20%20%20%20data%20%3A%20in%20STD_LOGIC_VECTOR%28data_width%20-%201%20%20downto%200%29%3B%0D%0A%20%20%20%20%20%20%20%20%20q%20%3A%20out%20STD_LOGIC_VECTOR%28data_width%20-%201%20downto%200%29%0D%0A%20%20%20%20%20%20%20%20%20%29%3B%0D%0Aend%20mem_inf_ram%3B%0D%0A%0D%0Aarchitecture%20mem_inf_ram%20of%20mem_inf_ram%20is%20%20%20%0D%0A%0D%0A%20%20%20%20type%20ram_type%20is%20array%20%280%20to%20data_length%20-%201%29%20of%20std_logic_vector%28data_width%20-%201%20downto%200%29%3B%20%20%20--%20array%20must%20be%200%20-%20n%2C%20if%20declared%20the%20other%20way%20wit%20downto%20to%20match%20Xilinx%20example%20then%20Quartus%20fitter%20fails%0D%0A%20%20%20%20signal%20ram%20%3A%20ram_type%3B%0D%0A%0D%0Abegin%0D%0A%0D%0A%20%20%20%20process%28clk%29%0D%0A%20%20%20%20begin%0D%0A%20%20%20%20%20%20%20%20if%20rising_edge%28clk%29%20then%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20en%20%3D%20%271%27%20then%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20we%20%3D%20%271%27%20then%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ram%28to_integer%28unsigned%28%28address%29%29%29%29%20%3C%3D%20data%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20end%20if%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20q%20%3C%3D%20ram%28to_integer%28unsigned%28%28address%29%29%29%29%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20end%20if%3B%0D%0A%20%20%20%20%20%20%20%20end%20if%3B%0D%0A%20%20%20%20end%20process%3B%0D%0A%0D%0Aend%20mem_inf_ram%3B%0D%0A%0D%0A]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It uses different indents,&amp;nbsp;case, ... as my other posts. The style is even inconsistent inside the file itself.&lt;br /&gt;Let&amp;#39;s see what the style utility does.&lt;/p&gt;
&lt;p&gt;I first let it critique my style:&lt;/p&gt;
&lt;p&gt;&lt;img src="/resized-image/__size/1280x720/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-a2a5c3fa-36d4-4e0e-9577-b441c4e6da8d/pastedimage1639347465380v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then I let it format my code:&lt;/p&gt;
&lt;p&gt;&lt;img src="/resized-image/__size/1280x720/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-a2a5c3fa-36d4-4e0e-9577-b441c4e6da8d/pastedimage1639347714173v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Result:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:4789e902-3d58-4396-8d28-06dd282cb687:type=text&amp;text=--%20from%20Micheal%20Kellett%3A%20https%3A%2F%2Fwww.element14.com%2Fcommunity%2Fgroups%2Ffpga-group%2Fblog%2F2021%2F07%2F31%2Fcheap-cyclone-10%0D%0A%0D%0Alibrary%20IEEE%3B%0D%0A%20%20use%20IEEE.std_logic_1164.all%3B%0D%0A%20%20use%20IEEE.NUMERIC_STD.all%3B%0D%0A%0D%0Apackage%20mem_inf%20is%0D%0A%0D%0A%20%20component%20mem_inf_ram%20is%0D%0A%20%20%20%20generic%20%28%0D%0A%20%20%20%20%20%20data_width%20%20%20%20%3A%20integer%20%3A%3D%2012%3B%0D%0A%20%20%20%20%20%20data_length%20%20%20%3A%20integer%20%3A%3D%2064%3B%0D%0A%20%20%20%20%20%20address_width%20%3A%20integer%20%3A%3D%206%0D%0A%20%20%20%20%29%3B%0D%0A%20%20%20%20port%20%28%0D%0A%20%20%20%20%20%20we%20%20%20%20%20%20%3A%20in%20%20%20%20std_logic%3B%0D%0A%20%20%20%20%20%20en%20%20%20%20%20%20%3A%20in%20%20%20%20std_logic%3B%0D%0A%20%20%20%20%20%20clk%20%20%20%20%20%3A%20in%20%20%20%20std_logic%3B%0D%0A%20%20%20%20%20%20address%20%3A%20in%20%20%20%20std_logic_vector%28address_width%20-%201%20downto%200%29%3B%0D%0A%20%20%20%20%20%20data%20%20%20%20%3A%20in%20%20%20%20std_logic_vector%28data_width%20-%201%20%20downto%200%29%3B%0D%0A%20%20%20%20%20%20q%20%20%20%20%20%20%20%3A%20out%20%20%20std_logic_vector%28data_width%20-%201%20downto%200%29%0D%0A%20%20%20%20%29%3B%0D%0A%20%20end%20component%3B%0D%0A%0D%0Aend%20package%20mem_inf%3B%0D%0A%0D%0Alibrary%20IEEE%3B%0D%0A%20%20use%20IEEE.std_logic_1164.all%3B%0D%0A%20%20use%20IEEE.NUMERIC_STD.all%3B%0D%0A%0D%0Aentity%20mem_inf_ram%20is%0D%0A%20%20generic%20%28%0D%0A%20%20%20%20data_width%20%20%20%20%3A%20integer%3B%0D%0A%20%20%20%20data_length%20%20%20%3A%20integer%3B%0D%0A%20%20%20%20address_width%20%3A%20integer%0D%0A%20%20%29%3B%0D%0A%20%20port%20%28%0D%0A%20%20%20%20we%20%20%20%20%20%20%3A%20in%20%20%20%20std_logic%3B%0D%0A%20%20%20%20en%20%20%20%20%20%20%3A%20in%20%20%20%20std_logic%3B%0D%0A%20%20%20%20clk%20%20%20%20%20%3A%20in%20%20%20%20std_logic%3B%0D%0A%20%20%20%20address%20%3A%20in%20%20%20%20std_logic_vector%28address_width%20-%201%20downto%200%29%3B%0D%0A%20%20%20%20data%20%20%20%20%3A%20in%20%20%20%20std_logic_vector%28data_width%20-%201%20%20downto%200%29%3B%0D%0A%20%20%20%20q%20%20%20%20%20%20%20%3A%20out%20%20%20std_logic_vector%28data_width%20-%201%20downto%200%29%0D%0A%20%20%29%3B%0D%0Aend%20entity%20mem_inf_ram%3B%0D%0A%0D%0Aarchitecture%20mem_inf_ram%20of%20mem_inf_ram%20is%0D%0A%0D%0A%20%20type%20ram_type%20is%20array%20%280%20to%20data_length%20-%201%29%20of%20std_logic_vector%28data_width%20-%201%20downto%200%29%3B%20--%20array%20must%20be%200%20-%20n%2C%20if%20declared%20the%20other%20way%20wit%20downto%20to%20match%20Xilinx%20example%20then%20Quartus%20fitter%20fails%0D%0A%0D%0A%20%20signal%20ram%20%3A%20ram_type%3B%0D%0A%0D%0Abegin%0D%0A%0D%0A%20%20process%20%28clk%29%20is%0D%0A%20%20begin%0D%0A%0D%0A%20%20%20%20if%20clk%27event%20and%20clk%20%3D%20%271%27%20then%0D%0A%20%20%20%20%20%20if%20%28en%20%3D%20%271%27%29%20then%0D%0A%20%20%20%20%20%20%20%20if%20%28we%20%3D%20%271%27%29%20then%0D%0A%20%20%20%20%20%20%20%20%20%20ram%28to_integer%28unsigned%28%28address%29%29%29%29%20%3C%3D%20data%3B%0D%0A%20%20%20%20%20%20%20%20end%20if%3B%0D%0A%20%20%20%20%20%20%20%20q%20%3C%3D%20ram%28to_integer%28unsigned%28%28address%29%29%29%29%3B%0D%0A%20%20%20%20%20%20end%20if%3B%0D%0A%20%20%20%20end%20if%3B%0D%0A%0D%0A%20%20end%20process%3B%0D%0A%0D%0Aend%20architecture%20mem_inf_ram%3B%0D%0A]&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=22397&amp;AppID=19&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>