<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2050962176404305705</id><updated>2026-05-10T15:50:47.893+05:30</updated><category term="examples"/><category term="vhdl tips"/><category term="useful codes"/><category term="Behavior level model"/><category term="Gate level model"/><category term="synthesisable"/><category term="xilinx tips"/><category term="state machine"/><category term="testbench"/><category term="block RAM"/><category term="file handling"/><category term="BCD"/><category term="Xilinx"/><category term="core generator"/><category term="fixed point package"/><category term="video tutorials"/><category term="adders"/><category term="arrays and records"/><category term="counters"/><category term="delay"/><category term="flipflops"/><category term="generic"/><category term="interview Q&#39;s"/><category term="port mapping"/><category term="real variable"/><category term="7 segment display"/><category term="coding style"/><category term="for loop"/><category term="functions"/><category term="generate"/><category term="gray code"/><category term="image processing"/><category term="modelsim"/><category term="multipliers"/><category term="random number generator"/><category term="resets"/><category term="vivado"/><category term="xilinx errors"/><category term="xilinx isim"/><category term="BCD converter"/><category term="Buffers"/><category term="C and VHDL"/><category term="CRC"/><category term="FFT"/><category term="FIFO"/><category term="FIR filter"/><category term="Frequency measurement"/><category term="LFSR"/><category term="QSD"/><category term="coe file"/><category term="comparator"/><category term="constants"/><category term="debouncing"/><category term="digital clock"/><category term="distributed RAM"/><category term="dual port ram"/><category term="error"/><category term="fast adder"/><category term="floating point"/><category term="hexadecimal"/><category term="ieee_proposed"/><category term="matrix multiplier"/><category term="memory"/><category term="numeric_std"/><category term="package"/><category term="pipelining"/><category term="polynomial equation"/><category term="power reduction"/><category term="procedure"/><category term="quaternary"/><category term="schematics"/><category term="sensitivity list"/><category term="sequence detector"/><category term="serial"/><category term="signals"/><category term="simulation tool"/><category term="square root"/><category term="stack"/><category term="std_logic"/><category term="synthesis"/><category term="textio"/><category term="unsigned"/><category term="variables"/><category term="vhdl beginners guide"/><category term="vhdl language"/><category term="wait for"/><title type='text'>VHDL coding tips and tricks</title><subtitle type='html'>First tip is &quot;Think Hardware, not software!&quot;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default?max-results=10&amp;redirect=false'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default?start-index=11&amp;max-results=10&amp;redirect=false'/><author><name>vipin</name><uri>http://www.blogger.com/profile/17675762038225600067</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>117</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>10</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-3086119139828881599</id><published>2022-04-05T13:22:00.003+05:30</published><updated>2022-04-05T13:22:57.470+05:30</updated><title type='text'>Extension of Digital Clock Project with 7 segment Decoder</title><content type='html'>&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; In the last post I shared a &lt;a href=&quot;https://vhdlguru.blogspot.com/2022/04/digital-clock-with-ability-to-set-time.html&quot; target=&quot;_blank&quot;&gt;Digital Clock VHDL code&lt;/a&gt; with you along with its testbench. Even though it was synthesizable, it would have been a bit cumbersome to test it on a FPGA board as it was. Because the timer outputs were of unsigned type, you would need to use LED&#39;s or something like that to see the time. But who would want a LED digital clock!?&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; Many FPGA boards have 7 segment displays in them. And this post is to take advantage of such boards. We will take the initial steps to display the time on 7 segment displays. Of course the codes here would need some additional modifications, based on the type of 7 segment displays available on the board and if they share a common bus etc.. But as I mentioned, this is just an initial step.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; Without further ado, let me share the codes with you. I have commented the codes plus have uploaded an YouTube video explaining the code. If its useful to you in some way please like and comment on the video. As this helps me with the future direction this blog/YouTube channel will take.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;iframe allowfullscreen=&quot;&quot; class=&quot;BLOG_video_class&quot; height=&quot;381&quot; src=&quot;https://www.youtube.com/embed/y26idaFJVS8&quot; width=&quot;458&quot; youtube-src-id=&quot;y26idaFJVS8&quot;&gt;&lt;/iframe&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span&gt;&lt;span&gt;&lt;br /&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;Digital Clock:&amp;nbsp;&lt;i&gt;digital_clock.vhd&lt;/i&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;You can get it from my last post:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;https://vhdlguru.blogspot.com/2022/04/digital-clock-with-ability-to-set-time.html&quot; target=&quot;_blank&quot;&gt;Digital Clock VHDL code&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;&lt;b&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Binary to BCD Converter:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;bin2bcd.vhd&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--Library declaration&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.STD_LOGIC_1164.ALL&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.NUMERIC_STD.ALL&lt;/span&gt;;

&lt;span style=&quot;color: #888888;&quot;&gt;--Binary to BCD Converter&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;bin2bcd&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt;(	binary_in : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
	bcd_out : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;)	&lt;span style=&quot;color: #888888;&quot;&gt;--8 bits(4 bits each for 2 digits)&lt;/span&gt;
	);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;bin2bcd&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Behavioral&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;bin2bcd&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;--actual value=0.0001100110011001101, so divide by 2^19.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;constant&lt;/span&gt; one_by_ten : unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;15&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;1100110011001101&quot;&lt;/span&gt;; 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; result_div_by_ten : unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;21&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; msb_digit : unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;--divide the input by 10. In VHDL, division by a constant is &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--easily done by multiplication by its inverse.&lt;/span&gt;
result_div_by_ten &amp;lt;=  binary_in*one_by_ten;	
&lt;span style=&quot;color: #888888;&quot;&gt;--get the decimal part of the result. Bits 18:0 are fractional part&lt;/span&gt;
msb_digit &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt; &amp;amp; result_div_by_ten(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;21&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;19&lt;/span&gt;);	
bcd_out(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;) &amp;lt;= msb_digit;	&lt;span style=&quot;color: #888888;&quot;&gt;--assign it to MSB part of output &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--subtract the product, 10*msb_digit, from the input binary number to get LSB digit.&lt;/span&gt;
bcd_out(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;) &amp;lt;= to_unsigned(to_integer(binary_in) - to_integer(msb_digit)*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;);  

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Behavioral&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;&lt;b&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Top Module:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;digital_clock_topmodule.vhd&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;

&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); overflow: auto; tab-size: 2; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--Libraries&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.STD_LOGIC_1164.ALL&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.NUMERIC_STD.ALL&lt;/span&gt;;

&lt;span style=&quot;color: #888888;&quot;&gt;--Top module which instantiates and connect together the 3 components:&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--Digital clock, Binary to BCD converter, BCD to 7 segment code converter&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock_topmodule&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
 &lt;span style=&quot;color: #888888;&quot;&gt;--frequency of the clock passed as a generic parameter.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;generic&lt;/span&gt;( 
		CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;50000000&lt;/span&gt;
		); 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt;(	
		Clock &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--system clock&lt;/span&gt;
		reset &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--resets the time&lt;/span&gt;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the seconds by 1.&lt;/span&gt;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the minutes by 1.&lt;/span&gt;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the hours by 1.&lt;/span&gt;
		secs_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--seconds LSB digit&lt;/span&gt;
		secs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--seconds MSB digit&lt;/span&gt;
		mins_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--minutes LSB digit&lt;/span&gt;
		mins_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--minutes MSB digit&lt;/span&gt;
		hrs_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--hours LSB digit&lt;/span&gt;
		hrs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;)  &lt;span style=&quot;color: #888888;&quot;&gt;--hours MSB digit&lt;/span&gt;
		);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock_topmodule&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Behavioral&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock_topmodule&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;

	&lt;span style=&quot;color: #888888;&quot;&gt;--Digital clock component&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;COMPONENT&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;GENERIC&lt;/span&gt;( CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;50000000&lt;/span&gt;);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;PORT&lt;/span&gt;(
		Clock &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
		reset &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
		seconds &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;OUT&lt;/span&gt;  unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
		minutes &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;OUT&lt;/span&gt;  unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
		hours &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;OUT&lt;/span&gt;  unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;)
		);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;COMPONENT&lt;/span&gt;;
	 
	&lt;span style=&quot;color: #888888;&quot;&gt;--Binary to BCD converter component&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;COMPONENT&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;bin2bcd&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;PORT&lt;/span&gt;(
		binary_in &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
		bcd_out &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;)
		);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;COMPONENT&lt;/span&gt;;
	
	&lt;span style=&quot;color: #888888;&quot;&gt;--Function to convert a BCD digit into a 7 segment code&lt;/span&gt;
	&lt;span style=&quot;color: #888888;&quot;&gt;--Source: https://vhdlguru.blogspot.com/2010/03/vhdl-code-for-bcd-to-7-segment-display.html&lt;/span&gt;
	&lt;span style=&quot;color: #888888;&quot;&gt;--The function is created by converting the code from the above link.&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt; bcd2seg7(bcd_in &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;)) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; unsigned &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;variable&lt;/span&gt; segment7 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;case&lt;/span&gt; bcd_in &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;0000&quot;=&amp;gt; segment7 :=&quot;0000001&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;0&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;0001&quot;=&amp;gt; segment7 :=&quot;1001111&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;1&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;0010&quot;=&amp;gt; segment7 :=&quot;0010010&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;2&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;0011&quot;=&amp;gt; segment7 :=&quot;0000110&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;3&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;0100&quot;=&amp;gt; segment7 :=&quot;1001100&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;4&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;0101&quot;=&amp;gt; segment7 :=&quot;0100100&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;5&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;0110&quot;=&amp;gt; segment7 :=&quot;0100000&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;6&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;0111&quot;=&amp;gt; segment7 :=&quot;0001111&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;7&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;1000&quot;=&amp;gt; segment7 :=&quot;0000000&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;8&#39;&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;1001&quot;=&amp;gt; segment7 :=&quot;0000100&quot;&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;-- &#39;9&#39;&lt;/span&gt;
			 &lt;span style=&quot;color: #888888;&quot;&gt;--nothing is displayed when a number more than 9 is given as input.&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; segment7 &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;1111111&quot;&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;case&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; segment7;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;bcd2seg7&lt;/span&gt;;
	
	
	&lt;span style=&quot;color: #888888;&quot;&gt;--Declare internal signals	&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; seconds &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; minutes &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; hours &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; bcd_secs,bcd_mins,bcd_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; hours_extended &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);

	
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;-- Instantiate the Digital Clock component&lt;/span&gt;
	uut&lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; digital_clock 
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;GENERIC&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;MAP&lt;/span&gt;(CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; CLOCK_FREQ)
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;PORT&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;MAP&lt;/span&gt; (
			Clock &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; Clock,
			reset &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; reset,
			inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_secs,
			inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_mins,
			inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_hrs,
			seconds &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; seconds,
			minutes &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; minutes,
			hours &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; hours
			);

	&lt;span style=&quot;color: #888888;&quot;&gt;--convert binary to BCD for seconds&lt;/span&gt;
	bin2bcd_secs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; bin2bcd 
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;map&lt;/span&gt;(
			binary_in &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; seconds,
			bcd_out &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; bcd_secs
			);

	&lt;span style=&quot;color: #888888;&quot;&gt;--convert binary to BCD for minutes&lt;/span&gt;
	bin2bcd_mins &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; bin2bcd 
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;map&lt;/span&gt;(
			binary_in &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; minutes,
			bcd_out &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; bcd_mins
			);

	hours_extended &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;&amp;amp;&lt;/span&gt; hours;	&lt;span style=&quot;color: #888888;&quot;&gt;--just make it the same size as seconds and minutes.&lt;/span&gt;
	&lt;span style=&quot;color: #888888;&quot;&gt;--convert binary to BCD for hours&lt;/span&gt;
	bin2bcd_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; bin2bcd 
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;map&lt;/span&gt;(
			binary_in &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; hours_extended,
			bcd_out &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; bcd_hrs
			);
			
	&lt;span style=&quot;color: #888888;&quot;&gt;--Call the bcd2seg7 function to convert each BCD digit into a &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;--&lt;/span&gt;format which can be used on the 7 segment display&lt;/span&gt;
	secs_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; bcd2seg7(bcd_secs(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;));
	secs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; bcd2seg7(bcd_secs(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;));
	mins_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; bcd2seg7(bcd_mins(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;));
	mins_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; bcd2seg7(bcd_mins(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;));
	hrs_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; bcd2seg7(bcd_hrs(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;));
	hrs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; bcd2seg7(bcd_hrs(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;));

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Behavioral&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;&lt;b&gt;&lt;span&gt;&lt;span&gt;Testbench for the top module:&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;tb_digitalClock_topModule.vhd&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; overflow: auto; tab-size: 2; width: auto;&quot;&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;LIBRARY&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;USE&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee.std_logic_1164.ALL&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;USE&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee.numeric_std.ALL&lt;/span&gt;;
&lt;span style=&quot;color: #888888;&quot;&gt;--the below library is used for finishing the simulation after we are done. &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--Otherwise it will run continously.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;std&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;std.env.finish&lt;/span&gt;;
 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;ENTITY&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_digitalClock_topModule&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IS&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_digitalClock_topModule&lt;/span&gt;;
 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;ARCHITECTURE&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;behavior&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;OF&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_digitalClock_topModule&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IS&lt;/span&gt; 
 
    &lt;span style=&quot;color: #888888;&quot;&gt;-- Component Declaration for the Unit Under Test (UUT)&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;COMPONENT&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock_topmodule&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
	 &lt;span style=&quot;color: #888888;&quot;&gt;--frequency of the clock passed as a generic parameter.&lt;/span&gt;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;generic&lt;/span&gt;( 
			CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;50000000&lt;/span&gt;
			); 
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt;(	
			Clock &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--system clock&lt;/span&gt;
			reset &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--resets the time&lt;/span&gt;
			inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the seconds by 1.&lt;/span&gt;
			inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the minutes by 1.&lt;/span&gt;
			inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the hours by 1.&lt;/span&gt;
			secs_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--seconds LSB digit&lt;/span&gt;
			secs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--seconds MSB digit&lt;/span&gt;
			mins_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--minutes LSB digit&lt;/span&gt;
			mins_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--minutes MSB digit&lt;/span&gt;
			hrs_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--hours LSB digit&lt;/span&gt;
			hrs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;)  &lt;span style=&quot;color: #888888;&quot;&gt;--hours MSB digit&lt;/span&gt;
			);
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;COMPONENT&lt;/span&gt;;    

   &lt;span style=&quot;color: #888888;&quot;&gt;--Inputs&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; Clock &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; reset &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;

 	&lt;span style=&quot;color: #888888;&quot;&gt;--Outputs&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; secs_7seg1,secs_7seg10 : unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; mins_7seg1,mins_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; hrs_7seg1,hrs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;   &lt;span style=&quot;color: #888888;&quot;&gt;-- Clock period definitions&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;constant&lt;/span&gt; Clock_period &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;time&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt; ns;
	
	&lt;span style=&quot;color: #888888;&quot;&gt;--Clock frequency in Hz. Use a smaller value for testbench. &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;--&lt;/span&gt;When testing on board it need to be set as 50 million, 100 million etc.&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;constant&lt;/span&gt; CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;;
 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;BEGIN&lt;/span&gt;
 
	&lt;span style=&quot;color: #888888;&quot;&gt;-- Instantiate the Unit Under Test (UUT)&lt;/span&gt;
   uut&lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; digital_clock_topmodule 
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;GENERIC&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;MAP&lt;/span&gt;(CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; CLOCK_FREQ)
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;PORT&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;MAP&lt;/span&gt; (
          Clock &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; Clock,
          reset &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; reset,
          inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_secs,
          inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_mins,
          inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_hrs,
          secs_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; secs_7seg1,
			 secs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; secs_7seg10,
			 mins_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; mins_7seg1,
			 mins_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; mins_7seg10,
			 hrs_7seg1 &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; hrs_7seg1,
			 hrs_7seg10 &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; hrs_7seg10
        );

   &lt;span style=&quot;color: #888888;&quot;&gt;-- Clock process definitions&lt;/span&gt;
   Clock_process &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
		Clock &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;;
		Clock &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;
 

   &lt;span style=&quot;color: #888888;&quot;&gt;-- Stimulus process&lt;/span&gt;
   stim_proc&lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;		
		reset &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
      &lt;span style=&quot;color: #888888;&quot;&gt;-- hold reset state for 100 ns.&lt;/span&gt;
      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt; ns;	
		reset &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;25&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--run the clock for 25 hours&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment seconds&lt;/span&gt;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 secs after incrementing seconds once.&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment seconds 60 times&lt;/span&gt;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 secs after incrementing seconds.&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment minutes&lt;/span&gt;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 mins after incrementing minutes once.&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment minutes 60 times&lt;/span&gt;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 mins after incrementing minutes.&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment hours&lt;/span&gt;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 hours after incrementing hours once.&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment hours 25 times&lt;/span&gt;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;25&lt;/span&gt;;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 hours after incrementing hours.&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--apply reset&lt;/span&gt;
		reset &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 100 Clock cycles and then finish the simulation.&lt;/span&gt;
		&lt;span style=&quot;color: #888888;&quot;&gt;--with the current settings it will run around 9 ms of simualtion time. &lt;/span&gt;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt;;
		finish;  
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;END&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;b&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;Top Level Block Diagrams:&lt;/span&gt;&lt;/b&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;The code was synthesized in Xilinx ISE 14.7. And the top level block diagram is shown below:&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg7gNz5IJ-lFN7xG2NzaXbLhySTty48QY2gMOyTeeaqO2AnXBclcbpKbsceIZoNvMj2-FmPyQsx44TgZ7tEEEdMwmEwh3i-ZqE7HjqFMU_pAQ5xIkcmMpIC3Jz7gYa7ltTBOa_0EjTFipQ1K0zX0AuVQ1GEJWfGgQgbPP-AW1UbIKV-ePk-qGVpDALfWg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;751&quot; data-original-width=&quot;744&quot; height=&quot;314&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg7gNz5IJ-lFN7xG2NzaXbLhySTty48QY2gMOyTeeaqO2AnXBclcbpKbsceIZoNvMj2-FmPyQsx44TgZ7tEEEdMwmEwh3i-ZqE7HjqFMU_pAQ5xIkcmMpIC3Jz7gYa7ltTBOa_0EjTFipQ1K0zX0AuVQ1GEJWfGgQgbPP-AW1UbIKV-ePk-qGVpDALfWg=w311-h314&quot; width=&quot;311&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;The inside view of the top module looks like this:&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg3GEafGNL9QwqdYUbjvgTp-Pn_w6MAvVk5U7Yc7FiQptjQYSu5nOv_J96KHDnHqPIh6Dw_DF4ONDnLoq2VtRe-HeE4jHiLCNnynyl9m4AY7TmqsPvJv23gxVWGoEsRdleOzTBfWUiBZ_SS-r0JnJrKM6NwiE_mdc3ZkXYjE1o5Spnp0NW_w1Qm-v_czA&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;1419&quot; data-original-width=&quot;1219&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg3GEafGNL9QwqdYUbjvgTp-Pn_w6MAvVk5U7Yc7FiQptjQYSu5nOv_J96KHDnHqPIh6Dw_DF4ONDnLoq2VtRe-HeE4jHiLCNnynyl9m4AY7TmqsPvJv23gxVWGoEsRdleOzTBfWUiBZ_SS-r0JnJrKM6NwiE_mdc3ZkXYjE1o5Spnp0NW_w1Qm-v_czA=w343-h400&quot; width=&quot;343&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;


</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/3086119139828881599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2022/04/extension-of-digital-clock-project-with-7-segement-decoder.html.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/3086119139828881599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/3086119139828881599'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2022/04/extension-of-digital-clock-project-with-7-segement-decoder.html.html' title='Extension of Digital Clock Project with 7 segment Decoder'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/y26idaFJVS8/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-8697700710978511063</id><published>2022-04-03T11:58:00.000+05:30</published><updated>2022-04-03T11:58:29.824+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="digital clock"/><category scheme="http://www.blogger.com/atom/ns#" term="numeric_std"/><category scheme="http://www.blogger.com/atom/ns#" term="synthesisable"/><category scheme="http://www.blogger.com/atom/ns#" term="testbench"/><category scheme="http://www.blogger.com/atom/ns#" term="unsigned"/><title type='text'>Digital Clock (With ability to Set time) And Testbench in VHDL</title><content type='html'>&lt;span&gt;&amp;nbsp; &amp;nbsp; More than a decade back I had written a Digital Clock module in this blog, which was when I just started learning VHDL. Obviously&amp;nbsp;it had its own shortcomings and through this post, I wanted to rectify these shortcomings. Plus add the ability to set time.&lt;/span&gt;&lt;div&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;The codes are shared below. They are commented to help you understand the logic. For a detailed understanding watch the video. Also please make sure to like the video if it was helpful and subscribe to my YouTube channel for more such videos in the future.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; class=&quot;BLOG_video_class&quot; height=&quot;368&quot; src=&quot;https://www.youtube.com/embed/1PiqMRXQCAw&quot; width=&quot;443&quot; youtube-src-id=&quot;1PiqMRXQCAw&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;Digital Clock:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;

&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); overflow: auto; tab-size: 2; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--Declare the libraries&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.STD_LOGIC_1164.ALL&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.NUMERIC_STD.ALL&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--we need this one because we are using &quot;unsigned&quot; data type.&lt;/span&gt;


&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
 &lt;span style=&quot;color: #888888;&quot;&gt;--frequency of the clock passed as a generic parameter.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;generic&lt;/span&gt;( CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;50000000&lt;/span&gt;	); 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt;(	
		Clock &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--system clock&lt;/span&gt;
		reset &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--resets the time&lt;/span&gt;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the seconds by 1.&lt;/span&gt;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the minutes by 1.&lt;/span&gt;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--set a pulse here to increment the hours by 1.&lt;/span&gt;
		seconds &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--seconds output&lt;/span&gt;
		minutes &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);  &lt;span style=&quot;color: #888888;&quot;&gt;--minutes output&lt;/span&gt;
		hours &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;)  &lt;span style=&quot;color: #888888;&quot;&gt;--hours output&lt;/span&gt;
		);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Behavioral&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;pre style=&quot;line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--temperory signals as we cant directly perform arithmetic operations on outputs&lt;/span&gt;&lt;/pre&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; secs, mins, hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;  &lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;pre style=&quot;line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--counter used for getting the 1 sec duration from the system Clock.&lt;/span&gt;&lt;/pre&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; counter &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;  

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;(Clock, reset)
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(reset &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;	&lt;span style=&quot;color: #888888;&quot;&gt;--reset the time.&lt;/span&gt;
		secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
		mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
		hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
		counter &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elsif&lt;/span&gt;(rising_edge(Clock)) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment the seconds. also increment mins and hours if needed.&lt;/span&gt;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(secs &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;59&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
				secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(mins &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;59&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
					mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
					&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(hrs &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;23&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
						hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
					&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
						hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; hrs&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
					&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
					mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; mins&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
				secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; secs &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment the minutes. also increment hours if needed.&lt;/span&gt;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elsif&lt;/span&gt;(inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(mins &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;59&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
				mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(hrs &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;23&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
					hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
					hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; hrs&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
				mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; mins&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment the hours. &lt;/span&gt;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elsif&lt;/span&gt;(inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(hrs &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;23&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
				hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
				hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; hrs&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--regular operation of the clock&lt;/span&gt;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(counter &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;	&lt;span style=&quot;color: #888888;&quot;&gt;--counting CLOCK_FREQ times takes 1 second. &lt;/span&gt;
			counter &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
			&lt;span style=&quot;color: #888888;&quot;&gt;--check and change values of secs, mins and hours&lt;/span&gt;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(secs &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;59&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
				secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(mins &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;59&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
					mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
					&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(hrs &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;23&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
						hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
					&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
						hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; hrs&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
					&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
					mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; mins&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
				&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
				secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; secs &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
			counter &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; counter&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
	
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;

&lt;span style=&quot;color: #888888;&quot;&gt;--The internal integer signals are converted into unsigned format. &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--The size of the output unsigned signal is assigned via the 2nd parameter(5 or 6 bits)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;seconds &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; to_unsigned(secs, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt;);
minutes &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; to_unsigned(mins, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt;);
hours &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; to_unsigned(hrs, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;);

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Behavioral&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;


&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;Testbench:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;

&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; overflow: auto; tab-size: 2; width: auto;&quot;&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;LIBRARY&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;USE&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee.std_logic_1164.ALL&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;USE&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee.numeric_std.ALL&lt;/span&gt;;
&lt;span style=&quot;color: #888888;&quot;&gt;--the below library is used for finishing the simulation after we are done. &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--Otherwise it will run continuously.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;std&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;std.env.finish&lt;/span&gt;;
 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;ENTITY&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_digitalClock&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IS&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_digitalClock&lt;/span&gt;;
 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;ARCHITECTURE&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;behavior&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;OF&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_digitalClock&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IS&lt;/span&gt; 
 
    &lt;span style=&quot;color: #888888;&quot;&gt;-- Component Declaration for the Unit Under Test (UUT)&lt;/span&gt;
 
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;COMPONENT&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;digital_clock&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;generic&lt;/span&gt;( CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;50000000&lt;/span&gt;	); 
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;PORT&lt;/span&gt;(
         Clock &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
         reset &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
         inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
         inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
         inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;IN&lt;/span&gt;  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
         seconds &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;OUT&lt;/span&gt;  unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
         minutes &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;OUT&lt;/span&gt;  unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
         hours &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;OUT&lt;/span&gt;  unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;)
        );
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;COMPONENT&lt;/span&gt;;
    

   &lt;span style=&quot;color: #888888;&quot;&gt;--Inputs&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; Clock &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; reset &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;

 	&lt;span style=&quot;color: #888888;&quot;&gt;--Outputs&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; seconds &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; minutes &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; hours &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);

   &lt;span style=&quot;color: #888888;&quot;&gt;-- Clock period definitions&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;constant&lt;/span&gt; Clock_period &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;time&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt; ns;
	
	&lt;span style=&quot;color: #888888;&quot;&gt;--Clock frequency in Hz. Use a smaller value for testbench. &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;--&lt;/span&gt;When testing on board it need to be set as 50 million, 100 million etc.&lt;/span&gt;
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;constant&lt;/span&gt; CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;:=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;;
 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;BEGIN&lt;/span&gt;
 
	&lt;span style=&quot;color: #888888;&quot;&gt;-- Instantiate the Unit Under Test (UUT)&lt;/span&gt;
   uut&lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; digital_clock 
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;GENERIC&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;MAP&lt;/span&gt;(CLOCK_FREQ &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; CLOCK_FREQ)
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;PORT&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;MAP&lt;/span&gt; (
          Clock &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; Clock,
          reset &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; reset,
          inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_secs,
          inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_mins,
          inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; inc_hrs,
          seconds &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; seconds,
          minutes &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; minutes,
          hours &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; hours
        );

   &lt;span style=&quot;color: #888888;&quot;&gt;-- Clock process definitions&lt;/span&gt;
   Clock_process &lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
		Clock &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;;
		Clock &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;
 

   &lt;span style=&quot;color: #888888;&quot;&gt;-- Stimulus process&lt;/span&gt;
   stim_proc&lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;		
		reset &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
      &lt;span style=&quot;color: #888888;&quot;&gt;-- hold reset state for 100 ns.&lt;/span&gt;
      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt; ns;	
		reset &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;25&lt;/span&gt;;  &lt;span style=&quot;color: #888888;&quot;&gt;--run the clock for 25 hours&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment seconds&lt;/span&gt;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 secs after incrementing seconds once.&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment seconds 60 times&lt;/span&gt;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;;
		inc_secs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 secs after incrementing seconds.&lt;/span&gt;
		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment minutes&lt;/span&gt;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 secs after incrementing minutes once.&lt;br /&gt;&lt;/span&gt;		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment minutes 60 times&lt;/span&gt;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;;
		inc_mins &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 secs after incrementing minutes.&lt;br /&gt;&lt;/span&gt;		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment hours&lt;/span&gt;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;background-color: white; line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;CLOCK_FREQ&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;;	&lt;span style=&quot;color: #888888;&quot;&gt;--wait for 5 secs after incrementing hours once.&lt;br /&gt;&lt;/span&gt;		
		&lt;span style=&quot;color: #888888;&quot;&gt;--increment hours 25 times&lt;/span&gt;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; Clock_period&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;25&lt;/span&gt;;
		inc_hrs &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;	&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;background-color: white; color: #008800; font-weight: bold;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;wait&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; Clock_period&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;CLOCK_FREQ&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;;	&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #888888;&quot;&gt;--wait for 5 secs after incrementing hours.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;		
		&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #888888;&quot;&gt;--apply reset&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;
		reset &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333;&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;;
		
		&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #888888;&quot;&gt;--wait for 100 Clock cycles and then finish the simulation.&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;
		&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #888888;&quot;&gt;--with the current settings it will run around 9 ms of simualtion time. &lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;
		&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; Clock_period&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;;
		finish;  
   &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;;

&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #008800; font-weight: bold;&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: red; font-size: medium;&quot;&gt;So what next?&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;As an extension of this project I want to show you how you can convert the time into BCD format and then connect a BCD to 7 segment converter to it. This will be useful for those who want to try this clock on a real FPGA board. Look forward to it in the next post.&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; overflow: auto; tab-size: 2; width: auto;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; overflow: auto; tab-size: 2; width: auto;&quot;&gt;So until next time...&lt;/div&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; overflow: auto; tab-size: 2; width: auto;&quot;&gt;&lt;br /&gt;&lt;/div&gt;

</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/8697700710978511063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2022/04/digital-clock-with-ability-to-set-time.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/8697700710978511063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/8697700710978511063'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2022/04/digital-clock-with-ability-to-set-time.html' title='Digital Clock (With ability to Set time) And Testbench in VHDL'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/1PiqMRXQCAw/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-3172080007419832502</id><published>2020-12-20T17:57:00.003+05:30</published><updated>2020-12-20T18:28:33.666+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Behavior level model"/><category scheme="http://www.blogger.com/atom/ns#" term="examples"/><category scheme="http://www.blogger.com/atom/ns#" term="file handling"/><category scheme="http://www.blogger.com/atom/ns#" term="image processing"/><category scheme="http://www.blogger.com/atom/ns#" term="textio"/><title type='text'>Image Processsing: RGB to Gray scale Converter in VHDL</title><content type='html'>&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; Implementing image processing algorithms in VHDL is a scary thing for many. Though I agree that its much more difficult to do it in VHDL than in a high level programming language like C, Matlab etc, it needn&#39;t be that scary.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;In this post I am going to share the code for a simple image processing algorithm - A RGB to Gray scale image converter.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;There are many ways, from simple to complex, in which you can do this. I have done it in a way, which makes sense to me. Touching upon few topics related to this subject. For example reading the image data from a text file, storing it in RAM and accessing the data within the code and then manipulating them etc...&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; I have used the standard Matlab image Lenna.bmp for this. The original image was 512*512*3 pixels in size. This takes a long time to load and run in Modelsim. So I first reduced its size to 1/8th of its original size, making it a 64*64*3 pixel image. Each pixel ranges from 0 to 255 and the dimension &quot;3&quot; indicates the presence of Red, Green and Blue components.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; VHDL text file operations aren&#39;t ideal for reading multiple pixels from the same row. So I converted the 3 Dimensional image data into a 1 Dimensional matrix. And then used &lt;i&gt;dlmwrite&lt;/i&gt; Matlab command to write it to a text file named rgb.txt. This will be our input image.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; In Matlab, I manually converted the above RGB image into a gray scale image using the formula:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Verdana, Tahoma; font-size: 16px; text-align: justify;&quot;&gt;&amp;nbsp;Grayscale Image = ( (0.3 * R) + (0.59 * G) + (0.11 * B) ).&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;The above grayscale pixels were converted to a 1-D matrix and written to a text file called gray.txt. This text file would be read by our VHDL testbench to verify that the results from our VHDL design is the same as the ideal result obtained from Matlab.&lt;/p&gt;&lt;p&gt;The &lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Matlab program&lt;/b&gt;&lt;/span&gt; which I used for achieving all this is shared below:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;I=imread(&lt;/span&gt;&lt;span style=&quot;color: #aa04f9; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&#39;Lenna.bmp&#39;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;);&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #028009; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;%read the
image into memory&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;I=imresize(I,1/8);&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #028009; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;%reduce the
size by 8 times.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;color: #028009; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;%convert image to 1-D array and write it to a text file.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;dlmwrite(&lt;/span&gt;&lt;span style=&quot;color: #aa04f9; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&#39;rgb.txt&#39;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;,reshape(I,64*64*3,1,1)); &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;I4=double(I);&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #028009; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;%convert it to
double format&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;color: #028009; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;%convert rgb pixels to gray manually as per formula.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;color: #0e00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt; i=1:64&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0e00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt; j=1:64&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2(i,j) =
I4(i,j,1)*0.3 + I4(i,j,2)*0.59 + I4(i,j,3)*0.11;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0e00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;color: #0e00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;color: #028009; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;%the converted image is changed to 1-D and then written to a
text file.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;I3=reshape(I2,64*64,1);&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;

























&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;dlmwrite(&lt;/span&gt;&lt;span style=&quot;color: #aa04f9; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&#39;gray.txt&#39;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;,I3);&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-family: Mangal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; The standard RGB format Lenna image, the resized version of it and the converted Grayscale image are shared below:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMaIvGqat5OEnCLeXSjzDAR_h-dD0Yz5yRqg-jM72kAiwmffwuK6NgbvDnXl4RQ1p0JynlxzH2Dd0sr_Oh9iLvyvDH-HGqmXU5MCPz1iYKh_IL9TE9grvmW2Bs5PYJI7NKHvarQKLH9sfo/&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;588&quot; data-original-width=&quot;1142&quot; height=&quot;330&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMaIvGqat5OEnCLeXSjzDAR_h-dD0Yz5yRqg-jM72kAiwmffwuK6NgbvDnXl4RQ1p0JynlxzH2Dd0sr_Oh9iLvyvDH-HGqmXU5MCPz1iYKh_IL9TE9grvmW2Bs5PYJI7NKHvarQKLH9sfo/&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Now that we have prepared the above basic data to work with, we can go and explore the VHDL designs. There are three VHDL files in this project:&lt;/span&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;1) im_ram.vhd:&lt;/h3&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; The input RGB image is internally stored in a RAM. The RAM is declared and initialized with the pixel values from the text file &lt;i&gt;rgb.txt&lt;/i&gt;. The &lt;i&gt;std.texti&lt;/i&gt;o library is used, to do the file reading operations.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--RAM&amp;nbsp;entity&amp;nbsp;for&amp;nbsp;storing&amp;nbsp;the&amp;nbsp;image.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--the&amp;nbsp;below&amp;nbsp;libraries&amp;nbsp;are&amp;nbsp;needed&amp;nbsp;for&amp;nbsp;reading&amp;nbsp;text&amp;nbsp;file.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;std;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;std.textio.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;im_ram&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ADDR_WIDTH&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;16&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Address&amp;nbsp;bus&amp;nbsp;size&amp;nbsp;of&amp;nbsp;the&amp;nbsp;Image&amp;nbsp;Ram.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IM_SIZE_D1&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Size&amp;nbsp;along&amp;nbsp;Dimension&amp;nbsp;1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IM_SIZE_D2&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Size&amp;nbsp;along&amp;nbsp;Dimension&amp;nbsp;2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;addr_in&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(ADDR_WIDTH-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Address&amp;nbsp;bus&amp;nbsp;to&amp;nbsp;the&amp;nbsp;Image&amp;nbsp;Ram.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rgb_out&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;23&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--24&amp;nbsp;bit&amp;nbsp;RGB&amp;nbsp;pixel&amp;nbsp;output&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;im_ram&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Behav&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;im_ram&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--custom&amp;nbsp;array&amp;nbsp;declaration.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;type&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;im_ram_type&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;array&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;&amp;nbsp;IM_SIZE_D1*IM_SIZE_D2-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;23&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--function&amp;nbsp;for&amp;nbsp;reading&amp;nbsp;the&amp;nbsp;image&amp;nbsp;pixels&amp;nbsp;from&amp;nbsp;text&amp;nbsp;file&amp;nbsp;and&amp;nbsp;use&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--it&amp;nbsp;to&amp;nbsp;initialize&amp;nbsp;the&amp;nbsp;RAM.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;impure&amp;nbsp;function&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;im_ram_initialize&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;return&lt;/span&gt;&amp;nbsp;im_ram_type&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;line_var&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;line&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;file&lt;/span&gt;&amp;nbsp;text_var&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;text&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;pixel&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;image_pixels&amp;nbsp;:&amp;nbsp;im_ram_type;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Open&amp;nbsp;the&amp;nbsp;file&amp;nbsp;in&amp;nbsp;read&amp;nbsp;mode.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;file_open(text_var,&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;rgb.txt&quot;&lt;/span&gt;,read_mode);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;while&lt;/span&gt;(&lt;span style=&quot;color: #569cd6;&quot;&gt;NOT&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;ENDFILE&lt;/span&gt;(text_var))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--until&amp;nbsp;end&amp;nbsp;of&amp;nbsp;file&amp;nbsp;is&amp;nbsp;reached&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;k&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;3&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--through&amp;nbsp;R,&amp;nbsp;G&amp;nbsp;and&amp;nbsp;B.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;j&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;IM_SIZE_D2-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;IM_SIZE_D1-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;readline&lt;/span&gt;(text_var,line_var);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--read&amp;nbsp;one&amp;nbsp;row.&amp;nbsp;Each&amp;nbsp;row&amp;nbsp;contains&amp;nbsp;one&amp;nbsp;pixel.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;read&lt;/span&gt;(line_var,pixel);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--From&amp;nbsp;the&amp;nbsp;read&amp;nbsp;line,&amp;nbsp;read&amp;nbsp;the&amp;nbsp;integer&amp;nbsp;value.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--save&amp;nbsp;the&amp;nbsp;pixel&amp;nbsp;in&amp;nbsp;the&amp;nbsp;RAM.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image_pixels(i*IM_SIZE_D2+j)(k*&lt;span style=&quot;color: #b5cea8;&quot;&gt;8&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;k*&lt;span style=&quot;color: #b5cea8;&quot;&gt;8&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;8&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_unsigned&lt;/span&gt;(pixel,&lt;span style=&quot;color: #b5cea8;&quot;&gt;8&lt;/span&gt;));&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;file_close(text_var);&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--close&amp;nbsp;the&amp;nbsp;file&amp;nbsp;after&amp;nbsp;reading.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;return&lt;/span&gt;&amp;nbsp;image_pixels;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;function&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--declare&amp;nbsp;and&amp;nbsp;initialize&amp;nbsp;the&amp;nbsp;image&amp;nbsp;ram.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;ram&amp;nbsp;:&amp;nbsp;im_ram_type&amp;nbsp;:=&amp;nbsp;im_ram_initialize;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--read&amp;nbsp;the&amp;nbsp;R,G&amp;nbsp;and&amp;nbsp;B&amp;nbsp;pixels&amp;nbsp;from&amp;nbsp;RAM&amp;nbsp;with&amp;nbsp;the&amp;nbsp;addr_in&amp;nbsp;input.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;rgb_out&amp;nbsp;&amp;lt;=&amp;nbsp;ram(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_integer&lt;/span&gt;(addr_in));&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;2) rgb2gray.vhd:&lt;/h3&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; This is the top level entity which converts the image from RGB format to Grayscale. The RAM block is instantiated as a component inside this entity.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Convert&amp;nbsp;a&amp;nbsp;internally&amp;nbsp;stored&amp;nbsp;RGB&amp;nbsp;image&amp;nbsp;into&amp;nbsp;gray&amp;nbsp;image.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;rgb2gray&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ADDR_WIDTH&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;16&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Address&amp;nbsp;bus&amp;nbsp;size&amp;nbsp;of&amp;nbsp;the&amp;nbsp;Image&amp;nbsp;Ram.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IM_SIZE_D1&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Size&amp;nbsp;along&amp;nbsp;Dimension&amp;nbsp;1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IM_SIZE_D2&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Size&amp;nbsp;along&amp;nbsp;Dimension&amp;nbsp;2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--active&amp;nbsp;high&amp;nbsp;asynchronous&amp;nbsp;reset&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data_valid&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--High&amp;nbsp;when&amp;nbsp;gray_out&amp;nbsp;has&amp;nbsp;valid&amp;nbsp;output.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gray_out&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;7&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--8&amp;nbsp;bit&amp;nbsp;gray&amp;nbsp;pixel&amp;nbsp;output&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;rgb2gray&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Behav&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;rgb2gray&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;im_ram&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ADDR_WIDTH&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;16&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Address&amp;nbsp;bus&amp;nbsp;size&amp;nbsp;of&amp;nbsp;the&amp;nbsp;Image&amp;nbsp;Ram.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IM_SIZE_D1&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Size&amp;nbsp;along&amp;nbsp;Dimension&amp;nbsp;1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IM_SIZE_D2&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Size&amp;nbsp;along&amp;nbsp;Dimension&amp;nbsp;2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;addr_in&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(ADDR_WIDTH-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Address&amp;nbsp;bus&amp;nbsp;to&amp;nbsp;the&amp;nbsp;Image&amp;nbsp;Ram.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rgb_out&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;23&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--24&amp;nbsp;bit&amp;nbsp;RGB&amp;nbsp;pixel&amp;nbsp;output&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;rgb_out&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;23&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;addr_in&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(ADDR_WIDTH-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Instantiation&amp;nbsp;of&amp;nbsp;Image&amp;nbsp;RAM.&amp;nbsp;Internally&amp;nbsp;stored&amp;nbsp;image.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image_ram&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;im_ram&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(ADDR_WIDTH,&amp;nbsp;&amp;nbsp;IM_SIZE_D1&amp;nbsp;,IM_SIZE_D2)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(Clk,&amp;nbsp;addr_in,&amp;nbsp;rgb_out);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Process&amp;nbsp;to&amp;nbsp;convert&amp;nbsp;RGB&amp;nbsp;to&amp;nbsp;Gray&amp;nbsp;image.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CONVERTER_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;(Clk,reset)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--temperary&amp;nbsp;variables&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;temp1,temp2,temp3,temp4&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;15&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(reset&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--active&amp;nbsp;high&amp;nbsp;asynchronous&amp;nbsp;reset&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;addr_in&amp;nbsp;&amp;lt;=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data_valid&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;elsif&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;rising_edge&lt;/span&gt;(Clk)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--output&amp;nbsp;is&amp;nbsp;ready&amp;nbsp;when&amp;nbsp;the&amp;nbsp;last&amp;nbsp;address&amp;nbsp;in&amp;nbsp;the&amp;nbsp;ram&amp;nbsp;has&amp;nbsp;reached.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_integer&lt;/span&gt;(addr_in)&amp;nbsp;=&amp;nbsp;IM_SIZE_D1*IM_SIZE_D2-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;addr_in&amp;nbsp;&amp;lt;=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data_valid&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;else&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--otherwise&amp;nbsp;keep&amp;nbsp;incrementing&amp;nbsp;the&amp;nbsp;address&amp;nbsp;value.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;addr_in&amp;nbsp;&amp;lt;=&amp;nbsp;addr_in&amp;nbsp;+&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data_valid&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--indicates&amp;nbsp;output&amp;nbsp;is&amp;nbsp;ready&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Gray&amp;nbsp;pixel&amp;nbsp;=&amp;nbsp;0.3*Red&amp;nbsp;pixel&amp;nbsp;+&amp;nbsp;0.59*Green&amp;nbsp;pixel&amp;nbsp;+&amp;nbsp;0.11*Blue&amp;nbsp;pixel&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--the&amp;nbsp;24&amp;nbsp;bit&amp;nbsp;value&amp;nbsp;is&amp;nbsp;split&amp;nbsp;into&amp;nbsp;R,G&amp;nbsp;and&amp;nbsp;B&amp;nbsp;components&amp;nbsp;and&amp;nbsp;multiplied&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--with&amp;nbsp;their&amp;nbsp;respective&amp;nbsp;weights&amp;nbsp;and&amp;nbsp;then&amp;nbsp;added&amp;nbsp;together.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp1&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&quot;01001100&quot;&lt;/span&gt;&amp;nbsp;*&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(rgb_out(&lt;span style=&quot;color: #b5cea8;&quot;&gt;7&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;));&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--(0.3&amp;nbsp;*&amp;nbsp;R)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp2&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&quot;10010111&quot;&lt;/span&gt;&amp;nbsp;*&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(rgb_out(&lt;span style=&quot;color: #b5cea8;&quot;&gt;15&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;8&lt;/span&gt;));&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--(0.59&amp;nbsp;*&amp;nbsp;G)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp3&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&quot;00011100&quot;&lt;/span&gt;&amp;nbsp;*&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(rgb_out(&lt;span style=&quot;color: #b5cea8;&quot;&gt;23&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;16&lt;/span&gt;));&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--(0.11&amp;nbsp;*&amp;nbsp;B)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp4&amp;nbsp;:=&amp;nbsp;temp1&amp;nbsp;+&amp;nbsp;temp2&amp;nbsp;+&amp;nbsp;temp3;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Most&amp;nbsp;significant&amp;nbsp;bit&amp;nbsp;of&amp;nbsp;the&amp;nbsp;LSB&amp;nbsp;portion&amp;nbsp;is&amp;nbsp;added&amp;nbsp;to&amp;nbsp;the&amp;nbsp;MSB&amp;nbsp;portion.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--To&amp;nbsp;round&amp;nbsp;off&amp;nbsp;the&amp;nbsp;result.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gray_out&amp;nbsp;&amp;lt;=&amp;nbsp;temp4(&lt;span style=&quot;color: #b5cea8;&quot;&gt;15&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;8&lt;/span&gt;)&amp;nbsp;+&amp;nbsp;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;&quot;0000000&quot;&lt;/span&gt;&amp;nbsp;&amp;amp;&amp;nbsp;temp4(&lt;span style=&quot;color: #b5cea8;&quot;&gt;7&lt;/span&gt;));&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;3) tb.vhd:&lt;/h3&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; This is the testbench for testing our main designs. The output image is received from the main design and compared with the actual result. Previously&amp;nbsp;using Matlab, we have saved the actual result in a file called&amp;nbsp;&lt;i&gt;gray.txt&lt;/i&gt;&amp;nbsp;.&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Testbench&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--the&amp;nbsp;below&amp;nbsp;libraries&amp;nbsp;are&amp;nbsp;needed&amp;nbsp;for&amp;nbsp;reading&amp;nbsp;text&amp;nbsp;file.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;std;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;std.textio.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Testbench&amp;nbsp;entity&amp;nbsp;is&amp;nbsp;always&amp;nbsp;empty.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;sim&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--the&amp;nbsp;generic&amp;nbsp;parameters&amp;nbsp;are&amp;nbsp;declared&amp;nbsp;and&amp;nbsp;initialized&amp;nbsp;as&amp;nbsp;constants&amp;nbsp;here.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;IM_SIZE_D1:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;IM_SIZE_D2:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--we&amp;nbsp;have&amp;nbsp;a&amp;nbsp;64*64&amp;nbsp;image.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;ADDR_WIDTH:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;12&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--64*64=4096&amp;nbsp;which&amp;nbsp;needs&amp;nbsp;12&amp;nbsp;bits.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--this&amp;nbsp;array&amp;nbsp;is&amp;nbsp;used&amp;nbsp;to&amp;nbsp;store&amp;nbsp;the&amp;nbsp;output&amp;nbsp;gray&amp;nbsp;pixels.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;type&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;image_type&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;array&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;&amp;nbsp;IM_SIZE_D1,&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;&amp;nbsp;IM_SIZE_D2)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;image_pixels&amp;nbsp;:&amp;nbsp;image_type&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;));&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--component&amp;nbsp;declaration.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;rgb2gray&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ADDR_WIDTH&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;16&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IM_SIZE_D1&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IM_SIZE_D2&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;64&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data_valid&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gray_out&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;7&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--temperory&amp;nbsp;signal&amp;nbsp;declarations.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;Clk,reset,data_valid&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;gray_out&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;7&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;Clk_period&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;time&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;10&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;ns&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--clock&amp;nbsp;period.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--generate&amp;nbsp;the&amp;nbsp;clock&amp;nbsp;signal.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;not&lt;/span&gt;&amp;nbsp;Clk&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;after&lt;/span&gt;&amp;nbsp;Clk_period/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Instantiate&amp;nbsp;the&amp;nbsp;Unit&amp;nbsp;under&amp;nbsp;test.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UUT&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;rgb2gray&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(ADDR_WIDTH,&amp;nbsp;IM_SIZE_D1,&amp;nbsp;IM_SIZE_D2)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(Clk,&amp;nbsp;reset,&amp;nbsp;data_valid,&amp;nbsp;gray_out);&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Process&amp;nbsp;where&amp;nbsp;we&amp;nbsp;apply&amp;nbsp;inputs,&amp;nbsp;read&amp;nbsp;outputs&amp;nbsp;and&amp;nbsp;verify&amp;nbsp;the&amp;nbsp;result.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;STIMULUS_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;i,j&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--loop&amp;nbsp;indices.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;line_var&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;line&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;file&lt;/span&gt;&amp;nbsp;text_var&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;text&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;pixel&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--this&amp;nbsp;value&amp;nbsp;should&amp;nbsp;be&amp;nbsp;zero&amp;nbsp;at&amp;nbsp;the&amp;nbsp;end&amp;nbsp;of&amp;nbsp;simulation.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;diff&amp;nbsp;:&amp;nbsp;image_type&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;));&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;Clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--reset&amp;nbsp;is&amp;nbsp;applied&amp;nbsp;for&amp;nbsp;one&amp;nbsp;clock&amp;nbsp;cycle.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;data_valid&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--wait&amp;nbsp;for&amp;nbsp;valid&amp;nbsp;data&amp;nbsp;at&amp;nbsp;the&amp;nbsp;output&amp;nbsp;port.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;while&lt;/span&gt;(data_valid&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;falling_edge&lt;/span&gt;(Clk));&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--sample&amp;nbsp;outputs&amp;nbsp;at&amp;nbsp;the&amp;nbsp;falling&amp;nbsp;edge&amp;nbsp;of&amp;nbsp;clock&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image_pixels(i,j)&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_integer&lt;/span&gt;(gray_out);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--save&amp;nbsp;pixel&amp;nbsp;as&amp;nbsp;integer.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--generate&amp;nbsp;indices&amp;nbsp;to&amp;nbsp;save&amp;nbsp;the&amp;nbsp;pixels&amp;nbsp;in&amp;nbsp;the&amp;nbsp;correct&amp;nbsp;place.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(j&amp;nbsp;=&amp;nbsp;IM_SIZE_D2)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;j&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(i&amp;nbsp;=&amp;nbsp;IM_SIZE_D1)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i&amp;nbsp;:=&amp;nbsp;i+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;j&amp;nbsp;:=&amp;nbsp;j+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;rising_edge&lt;/span&gt;(Clk));&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--pause&amp;nbsp;until&amp;nbsp;rising&amp;nbsp;edge&amp;nbsp;of&amp;nbsp;the&amp;nbsp;clock&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--all&amp;nbsp;output&amp;nbsp;gray&amp;nbsp;pixels&amp;nbsp;are&amp;nbsp;read.&amp;nbsp;Activate&amp;nbsp;reset&amp;nbsp;again.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Now&amp;nbsp;check&amp;nbsp;if&amp;nbsp;the&amp;nbsp;results&amp;nbsp;are&amp;nbsp;the&amp;nbsp;same&amp;nbsp;as&amp;nbsp;in&amp;nbsp;Matlab&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Open&amp;nbsp;the&amp;nbsp;file&amp;nbsp;in&amp;nbsp;read&amp;nbsp;mode.&amp;nbsp;gray.txt&amp;nbsp;contains&amp;nbsp;pixels&amp;nbsp;calculated&amp;nbsp;using&amp;nbsp;Matlab.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;file_open(text_var,&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;gray.txt&quot;&lt;/span&gt;,read_mode);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;while&lt;/span&gt;(&lt;span style=&quot;color: #569cd6;&quot;&gt;NOT&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;ENDFILE&lt;/span&gt;(text_var))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--until&amp;nbsp;end&amp;nbsp;of&amp;nbsp;file&amp;nbsp;is&amp;nbsp;reached&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;j&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;IM_SIZE_D2&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;IM_SIZE_D1&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;readline&lt;/span&gt;(text_var,line_var);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--read&amp;nbsp;one&amp;nbsp;row.&amp;nbsp;Each&amp;nbsp;row&amp;nbsp;contains&amp;nbsp;one&amp;nbsp;pixel.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;read&lt;/span&gt;(line_var,pixel);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--calculate&amp;nbsp;the&amp;nbsp;difference&amp;nbsp;between&amp;nbsp;actual&amp;nbsp;gray&amp;nbsp;pixels&amp;nbsp;from&amp;nbsp;Matlab&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--and&amp;nbsp;pixel&amp;nbsp;values&amp;nbsp;from&amp;nbsp;our&amp;nbsp;rgb2gray&amp;nbsp;VHDL&amp;nbsp;design.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;diff(i,j)&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;abs&lt;/span&gt;(image_pixels(i,j)&amp;nbsp;-&amp;nbsp;pixel);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--If&amp;nbsp;the&amp;nbsp;difference&amp;nbsp;is&amp;nbsp;2&amp;nbsp;or&amp;nbsp;more&amp;nbsp;then,&amp;nbsp;we&amp;nbsp;take&amp;nbsp;it&amp;nbsp;as&amp;nbsp;an&amp;nbsp;error&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--and&amp;nbsp;increment&amp;nbsp;the&amp;nbsp;variable&amp;nbsp;&#39;error&#39;&amp;nbsp;by&amp;nbsp;1.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(diff(i,j)&amp;nbsp;&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;ns&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--pause&amp;nbsp;for&amp;nbsp;1&amp;nbsp;ns.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;file_close(text_var);&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--close&amp;nbsp;the&amp;nbsp;file&amp;nbsp;after&amp;nbsp;reading.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--wait&amp;nbsp;eternally&amp;nbsp;after&amp;nbsp;finishing&amp;nbsp;simulation.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--End&amp;nbsp;of&amp;nbsp;Testbench&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; Note that&amp;nbsp;&lt;/span&gt;IM_SIZE_D1 and&amp;nbsp;IM_SIZE_D2 are the number of rows and columns respectively of the image matrix. You can read it as a short form for &quot;Image size along dimension 1 (or) 2&quot;.&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp; &amp;nbsp; In the testbench we have a variable matrix called &quot;diff&quot;. This matrix contains the absolute value&amp;nbsp; of difference between gray image pixels, from Matlab and VHDL. A difference of &quot;1&quot; is considered okay, as binary multiplications can cause some loss of least significant bits. But more than a difference of &quot;1&quot; is considered as an error. We can see that at the end of simulation, we didn&#39;t get any &quot;error&quot;.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; There is no address output from the top level entity rgb2gray. In our design, I thought it was unnecessary, because the pixel outputs were coming out in a sequential manner. So the testbench &quot;knew&quot; where to place each output pixel.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; I hope this post was helpful for you and gave you some ideas on how to do image processing using VHDL.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; You can Download the VHDL codes, images etc from &lt;a href=&quot;https://drive.google.com/file/d/1bfN6kvQ3PahtgOKhv7-zcy20rz7GxJ28/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;Here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/3172080007419832502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2020/12/image-processsing-rgb-to-gray-scale.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/3172080007419832502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/3172080007419832502'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2020/12/image-processsing-rgb-to-gray-scale.html' title='Image Processsing: RGB to Gray scale Converter in VHDL'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMaIvGqat5OEnCLeXSjzDAR_h-dD0Yz5yRqg-jM72kAiwmffwuK6NgbvDnXl4RQ1p0JynlxzH2Dd0sr_Oh9iLvyvDH-HGqmXU5MCPz1iYKh_IL9TE9grvmW2Bs5PYJI7NKHvarQKLH9sfo/s72-c" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-3877873313447191659</id><published>2020-12-08T22:57:00.003+05:30</published><updated>2020-12-08T22:57:35.453+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="examples"/><category scheme="http://www.blogger.com/atom/ns#" term="square root"/><category scheme="http://www.blogger.com/atom/ns#" term="synthesisable"/><title type='text'>Synthesizable Clocked Square Root Calculator In VHDL</title><content type='html'>&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Long back I had shared&amp;nbsp;&lt;a href=&quot;https://vhdlguru.blogspot.com/2010/03/vhdl-function-for-finding-square-root.html&quot; target=&quot;_blank&quot;&gt;VHDL function for finding the square root of a number&lt;/a&gt;. This function too was synthesisable, but as it was a function, it was purely combinatorial. If you want to find the square root of a relatively larger number, then the resource usage was very high.&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; In such cases, it makes sense to use a clocked design. Such a clocked design enables us to reuse one set of resources over and over. The advantage of such a design is that it uses far less resources while the disadvantage being the low speed.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; For example, in the design I have shared in this post, to find the square root of a N-bit number, you need to wait N/2 clock cycles.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; The code is written based on Figure (8) from this paper:&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://drive.google.com/file/d/1bhOr-KdjjQjOQ13TKr4b6WiEq42trPQj/view&quot; target=&quot;_blank&quot;&gt;A New Non-Restoring Square Root Algorithm and Its VLSI Implementations&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;The codes are well commented, so I wont write much about how it works here. Please refer to the block diagram from the paper in case you have some doubts.&lt;/p&gt;&lt;p&gt;Let me share the codes now:&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;square_root.vhd:&lt;/h3&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Synthesisable&amp;nbsp;Design&amp;nbsp;for&amp;nbsp;Finding&amp;nbsp;Square&amp;nbsp;root&amp;nbsp;of&amp;nbsp;a&amp;nbsp;number.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;square_root&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Clock&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rst&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Asynchronous&amp;nbsp;active&amp;nbsp;high&amp;nbsp;reset.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;input&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--this&amp;nbsp;is&amp;nbsp;the&amp;nbsp;number&amp;nbsp;for&amp;nbsp;which&amp;nbsp;we&amp;nbsp;want&amp;nbsp;to&amp;nbsp;find&amp;nbsp;square&amp;nbsp;root.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--This&amp;nbsp;signal&amp;nbsp;goes&amp;nbsp;high&amp;nbsp;when&amp;nbsp;output&amp;nbsp;is&amp;nbsp;ready&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sq_root&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--square&amp;nbsp;root&amp;nbsp;of&amp;nbsp;&#39;input&#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;square_root&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Behav&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;square_root&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQROOT_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;(Clk,rst)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;a&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--original&amp;nbsp;input.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;left,right,r&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;):=(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--input&amp;nbsp;to&amp;nbsp;adder/sub.r-remainder.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;q&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--result.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;i&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--index&amp;nbsp;of&amp;nbsp;the&amp;nbsp;loop.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(rst&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--reset&amp;nbsp;the&amp;nbsp;variables.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sq_root&amp;nbsp;&amp;lt;=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;left&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;right&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;q&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;elsif&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;rising_edge&lt;/span&gt;(Clk))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Before&amp;nbsp;we&amp;nbsp;start&amp;nbsp;the&amp;nbsp;first&amp;nbsp;clock&amp;nbsp;cycle&amp;nbsp;get&amp;nbsp;the&amp;nbsp;&#39;input&#39;&amp;nbsp;to&amp;nbsp;the&amp;nbsp;variable&amp;nbsp;&#39;a&#39;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(i&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;input&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--reset&amp;nbsp;&#39;done&#39;&amp;nbsp;signal.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i&amp;nbsp;:=&amp;nbsp;i+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--increment&amp;nbsp;the&amp;nbsp;loop&amp;nbsp;index.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;elsif&lt;/span&gt;(i&amp;nbsp;&amp;lt;&amp;nbsp;N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--keep&amp;nbsp;incrementing&amp;nbsp;the&amp;nbsp;loop&amp;nbsp;index.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i&amp;nbsp;:=&amp;nbsp;i+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--These&amp;nbsp;statements&amp;nbsp;below&amp;nbsp;are&amp;nbsp;derived&amp;nbsp;from&amp;nbsp;the&amp;nbsp;block&amp;nbsp;diagram.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;right&amp;nbsp;:=&amp;nbsp;q&amp;nbsp;&amp;amp;&amp;nbsp;r(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&amp;amp;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;left&amp;nbsp;:=&amp;nbsp;r(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&amp;amp;&amp;nbsp;a(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a&amp;nbsp;:=&amp;nbsp;a(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;3&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&amp;amp;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&quot;00&quot;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--shifting&amp;nbsp;left&amp;nbsp;by&amp;nbsp;2&amp;nbsp;bit.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(&amp;nbsp;r(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--add&amp;nbsp;or&amp;nbsp;subtract&amp;nbsp;as&amp;nbsp;per&amp;nbsp;this&amp;nbsp;bit.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&amp;nbsp;:=&amp;nbsp;left&amp;nbsp;+&amp;nbsp;right;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&amp;nbsp;:=&amp;nbsp;left&amp;nbsp;-&amp;nbsp;right;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;q&amp;nbsp;:=&amp;nbsp;q(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&amp;amp;&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;not&lt;/span&gt;&amp;nbsp;r(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;));&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(i&amp;nbsp;=&amp;nbsp;N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--This&amp;nbsp;means&amp;nbsp;the&amp;nbsp;max&amp;nbsp;value&amp;nbsp;of&amp;nbsp;loop&amp;nbsp;index&amp;nbsp;has&amp;nbsp;reached.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--make&amp;nbsp;&#39;done&#39;&amp;nbsp;high&amp;nbsp;because&amp;nbsp;output&amp;nbsp;is&amp;nbsp;ready.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--reset&amp;nbsp;loop&amp;nbsp;index&amp;nbsp;for&amp;nbsp;beginning&amp;nbsp;the&amp;nbsp;next&amp;nbsp;cycle.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sq_root&amp;nbsp;&amp;lt;=&amp;nbsp;q;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--assign&amp;nbsp;&#39;q&#39;&amp;nbsp;to&amp;nbsp;the&amp;nbsp;output&amp;nbsp;port.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--reset&amp;nbsp;other&amp;nbsp;signals&amp;nbsp;for&amp;nbsp;using&amp;nbsp;in&amp;nbsp;the&amp;nbsp;next&amp;nbsp;cycle.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;left&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;right&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;q&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Testbench: tb.vhd&lt;/h3&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Testbench&amp;nbsp;for&amp;nbsp;out&amp;nbsp;square&amp;nbsp;root&amp;nbsp;calculator&amp;nbsp;design.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.math_real.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--empty&amp;nbsp;entity&amp;nbsp;as&amp;nbsp;its&amp;nbsp;a&amp;nbsp;testbench&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;sim&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Declare&amp;nbsp;the&amp;nbsp;component&amp;nbsp;which&amp;nbsp;we&amp;nbsp;want&amp;nbsp;to&amp;nbsp;test.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;square_root&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rst&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;input&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sq_root&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;clk_period&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;time&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;10&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;ns&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--set&amp;nbsp;the&amp;nbsp;clock&amp;nbsp;period&amp;nbsp;for&amp;nbsp;simulation.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;16&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--width&amp;nbsp;of&amp;nbsp;the&amp;nbsp;input.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;Clk,rst,done&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;input&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;sq_root&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;unsigned&lt;/span&gt;(N/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--this&amp;nbsp;indicates&amp;nbsp;the&amp;nbsp;number&amp;nbsp;of&amp;nbsp;errors&amp;nbsp;encountered&amp;nbsp;during&amp;nbsp;simulation.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;not&lt;/span&gt;&amp;nbsp;Clk&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;after&lt;/span&gt;&amp;nbsp;clk_period&amp;nbsp;/&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--generate&amp;nbsp;clock&amp;nbsp;by&amp;nbsp;toggling&amp;nbsp;&#39;Clk&#39;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--entity&amp;nbsp;instantiation.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DUT&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;work&lt;/span&gt;.&lt;span style=&quot;color: #569cd6;&quot;&gt;square_root&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(N&amp;nbsp;=&amp;gt;&amp;nbsp;N)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(Clk,rst,&lt;span style=&quot;color: #4ec9b0;&quot;&gt;input&lt;/span&gt;,done,sq_root);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Apply&amp;nbsp;the&amp;nbsp;inputs&amp;nbsp;to&amp;nbsp;the&amp;nbsp;design&amp;nbsp;and&amp;nbsp;check&amp;nbsp;if&amp;nbsp;the&amp;nbsp;results&amp;nbsp;are&amp;nbsp;correct.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;number&amp;nbsp;of&amp;nbsp;inputs&amp;nbsp;for&amp;nbsp;which&amp;nbsp;the&amp;nbsp;results&amp;nbsp;were&amp;nbsp;wrongly&amp;nbsp;calculated&amp;nbsp;are&amp;nbsp;counted&amp;nbsp;by&amp;nbsp;&#39;error&#39;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SEQUENCER_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;actual_result,i&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--First&amp;nbsp;we&amp;nbsp;apply&amp;nbsp;reset&amp;nbsp;input&amp;nbsp;for&amp;nbsp;one&amp;nbsp;clock&amp;nbsp;period.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rst&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rst&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Test&amp;nbsp;the&amp;nbsp;design&amp;nbsp;for&amp;nbsp;all&amp;nbsp;the&amp;nbsp;combination&amp;nbsp;of&amp;nbsp;inputs.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Since&amp;nbsp;we&amp;nbsp;have&amp;nbsp;(2^16)-1&amp;nbsp;inputs,&amp;nbsp;we&amp;nbsp;test&amp;nbsp;all&amp;nbsp;of&amp;nbsp;them&amp;nbsp;one&amp;nbsp;by&amp;nbsp;one.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;while&lt;/span&gt;(i&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;**N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;input&lt;/span&gt;&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_unsigned&lt;/span&gt;(i,N);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--convert&amp;nbsp;&#39;i&#39;&amp;nbsp;from&amp;nbsp;integer&amp;nbsp;to&amp;nbsp;unsigned&amp;nbsp;format.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;done=&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--wait&amp;nbsp;until&amp;nbsp;the&amp;nbsp;&#39;done&#39;&amp;nbsp;output&amp;nbsp;signal&amp;nbsp;goes&amp;nbsp;high.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;falling_edge&lt;/span&gt;(Clk);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--we&amp;nbsp;sample&amp;nbsp;the&amp;nbsp;output&amp;nbsp;at&amp;nbsp;the&amp;nbsp;falling&amp;nbsp;edge&amp;nbsp;of&amp;nbsp;the&amp;nbsp;clock.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;actual_result&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;floor&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;sqrt&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;real&lt;/span&gt;(i))));&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Calculate&amp;nbsp;the&amp;nbsp;actual&amp;nbsp;result.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--if&amp;nbsp;actual&amp;nbsp;result&amp;nbsp;and&amp;nbsp;calculated&amp;nbsp;result&amp;nbsp;are&amp;nbsp;different&amp;nbsp;increment&amp;nbsp;&#39;error&#39;&amp;nbsp;by&amp;nbsp;1.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(actual_result&amp;nbsp;/=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_integer&lt;/span&gt;(sq_root))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i&amp;nbsp;:=&amp;nbsp;i+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--increment&amp;nbsp;the&amp;nbsp;loop&amp;nbsp;index.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--all&amp;nbsp;inputs&amp;nbsp;are&amp;nbsp;tested.&amp;nbsp;Apply&amp;nbsp;reset&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;input&lt;/span&gt;&amp;nbsp;&amp;lt;=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--reset&amp;nbsp;the&amp;nbsp;&#39;input&#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Simulation Waveform from ModelSim:&lt;/h3&gt;&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB3Py48ZaqM9zUARyoPXn4dH0Kgm0cWAZhRfiP_9EceD04dHTm6KIGFXoFwucHmVP6mm1Gwu31N9AhjaSFIEmg_TDQT-ZJKG24ufxD4X918bA0OstX_ZFUxudIH4TexjD8Suu1mipfXebx/s1475/i1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;579&quot; data-original-width=&quot;1475&quot; height=&quot;252&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB3Py48ZaqM9zUARyoPXn4dH0Kgm0cWAZhRfiP_9EceD04dHTm6KIGFXoFwucHmVP6mm1Gwu31N9AhjaSFIEmg_TDQT-ZJKG24ufxD4X918bA0OstX_ZFUxudIH4TexjD8Suu1mipfXebx/w640-h252/i1.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;&amp;nbsp; &amp;nbsp; T&lt;/span&gt;&lt;/span&gt;o reach the end of the testbench, you need to simulate only for 5.5 msec of simulation time.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/3877873313447191659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2020/12/synthesizable-clocked-square-root.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/3877873313447191659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/3877873313447191659'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2020/12/synthesizable-clocked-square-root.html' title='Synthesizable Clocked Square Root Calculator In VHDL'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB3Py48ZaqM9zUARyoPXn4dH0Kgm0cWAZhRfiP_9EceD04dHTm6KIGFXoFwucHmVP6mm1Gwu31N9AhjaSFIEmg_TDQT-ZJKG24ufxD4X918bA0OstX_ZFUxudIH4TexjD8Suu1mipfXebx/s72-w640-h252-c/i1.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-2707059573416696226</id><published>2020-12-07T19:22:00.000+05:30</published><updated>2020-12-07T19:22:44.961+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="examples"/><category scheme="http://www.blogger.com/atom/ns#" term="generic"/><category scheme="http://www.blogger.com/atom/ns#" term="polynomial equation"/><title type='text'>Synthesizable Polynomial Equation Calculator in VHDL</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp; &amp;nbsp; A polynomial equation is an equation which is formed with variables, coefficients and exponents. They can be written in the following format:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;em style=&quot;background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Oxygen, Ubuntu, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; text-align: center;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;y =&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;n&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;x&lt;/span&gt;&lt;sup&gt;&lt;span style=&quot;color: black;&quot;&gt;n&lt;/span&gt;&lt;/sup&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;+&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;n-1&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;x&lt;/span&gt;&lt;sup&gt;&lt;span style=&quot;color: black;&quot;&gt;n-1&lt;/span&gt;&lt;/sup&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;+ ... +&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;x +&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;0&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;Here&amp;nbsp;&lt;/span&gt;&lt;em style=&quot;background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Oxygen, Ubuntu, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; text-align: center;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;n,&amp;nbsp;&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;n-1&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;... ,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;1 ,&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;0&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/sub&gt;&lt;/em&gt;are coefficients,&lt;/p&gt;&lt;p&gt;n, n-1, ... etc are exponents and x is the variable.&amp;nbsp;&lt;/p&gt;&lt;p&gt;In this post, I want to share, VHDL code for computing the value of &#39;y&#39; if you know the value of &#39;x&#39; and coefficients forming the polynomial.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Directly calculating the polynomial with the above equation is very inefficient. So, first we reformat the equation as per Horner&#39;s rule:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;em style=&quot;background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Oxygen, Ubuntu, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; text-align: center;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;y =(((&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;n&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;x +&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;n-1&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;+&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;n-2&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;+&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;n-3&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;+ ... )&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;+&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;sub&gt;&lt;span style=&quot;color: black;&quot;&gt;0&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;This modified equation can be represented by the following block diagram:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV4avnwLeChibuDsICBE8DDWDT5OYo-zHC9O-2tS6ewv3cVJRcODUmYA2_zbjN9H67xbBrZepo76dK8w_H6D8cConmq4mQTwP2ssXdSbqyaM2MCHaSxwZEN9cTqrZk0nn24VAG4zBEHtYJ/&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;584&quot; data-original-width=&quot;1123&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV4avnwLeChibuDsICBE8DDWDT5OYo-zHC9O-2tS6ewv3cVJRcODUmYA2_zbjN9H67xbBrZepo76dK8w_H6D8cConmq4mQTwP2ssXdSbqyaM2MCHaSxwZEN9cTqrZk0nn24VAG4zBEHtYJ/w400-h208/image.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;There are 3 sub-entities in the above block diagram.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;u&gt;1) Block number 1:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;This block keep generating successive powers of input x.&amp;nbsp;&lt;/p&gt;&lt;p&gt;In the first clock cycle it generates x^0 = 1.&lt;/p&gt;&lt;p&gt;In the 2ndclock cycle it generates x^1.&lt;/p&gt;&lt;p&gt;In the 3rd clock cycle it generates x^2.&lt;/p&gt;&lt;p&gt;In the nth clock cycle it generates x^(n-1).&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; Every clock cycle, the previous outputs are multiplied with &#39;x&#39; to get the next power of x.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;b&gt;&lt;u&gt;2)Block number 2:&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;The powers of x generated in the first block are multiplied with the corresponding coefficients&amp;nbsp;of the polynomial&amp;nbsp;in Block numbered 2. The&amp;nbsp;&lt;/span&gt;coefficients are declared and initialized in the top level entity and can be changed easily.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;u&gt;3)Block number 4:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; This block is basically an accumulative adder which accumulates all the products generated by the multiplier. Once it does &#39;n&#39; additions, we have the final result available in output &#39;y&#39;. An output &#39;done&#39; is set as high to indicate that the output is ready.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;Let me share the VHDL codes for these entities along with the testbench.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;1) power_module.vhd&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--This&amp;nbsp;module&amp;nbsp;generates&amp;nbsp;successive&amp;nbsp;powers&amp;nbsp;of&amp;nbsp;input&amp;nbsp;x&amp;nbsp;in&amp;nbsp;each&amp;nbsp;clock&amp;nbsp;cycle.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--For&amp;nbsp;example&amp;nbsp;1,x,x^2,x^3,x^4&amp;nbsp;etc.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;output&amp;nbsp;from&amp;nbsp;the&amp;nbsp;previous&amp;nbsp;cycle&amp;nbsp;is&amp;nbsp;multiplied&amp;nbsp;again&amp;nbsp;by&amp;nbsp;x&amp;nbsp;to&amp;nbsp;get&amp;nbsp;the&amp;nbsp;next&amp;nbsp;power.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;output&amp;nbsp;from&amp;nbsp;this&amp;nbsp;entity&amp;nbsp;is&amp;nbsp;passed&amp;nbsp;to&amp;nbsp;the&amp;nbsp;multiplier&amp;nbsp;module,&amp;nbsp;where&amp;nbsp;it&amp;nbsp;gets&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--multiplied&amp;nbsp;by&amp;nbsp;the&amp;nbsp;corresponding&amp;nbsp;coefficient.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;power_module&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clock&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x_powered&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;power_module&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Behav&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;power_module&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;x_pow&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;,N);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;POWER_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;(Clock,reset)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;temp_prod&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;*N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(reset=&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x_pow&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;,N);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;elsif&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;rising_edge&lt;/span&gt;(Clock))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp_prod&amp;nbsp;:=&amp;nbsp;x*x_pow;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;MSB&amp;nbsp;half&amp;nbsp;of&amp;nbsp;the&amp;nbsp;result&amp;nbsp;is&amp;nbsp;ignored.&amp;nbsp;We&amp;nbsp;assume&amp;nbsp;that&amp;nbsp;all&amp;nbsp;intermediate&amp;nbsp;powers&amp;nbsp;of&amp;nbsp;x&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--can&amp;nbsp;be&amp;nbsp;represented&amp;nbsp;by&amp;nbsp;a&amp;nbsp;max&amp;nbsp;of&amp;nbsp;N&amp;nbsp;bits.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x_pow&amp;nbsp;&amp;lt;=&amp;nbsp;temp_prod(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x_powered&amp;nbsp;&amp;lt;=&amp;nbsp;x_pow;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;2) multiplier.vhd&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;successive&amp;nbsp;powers&amp;nbsp;of&amp;nbsp;x&amp;nbsp;are&amp;nbsp;multiplied&amp;nbsp;by&amp;nbsp;the&amp;nbsp;corresponding&amp;nbsp;coeffcients&amp;nbsp;here.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;results&amp;nbsp;are&amp;nbsp;sent&amp;nbsp;to&amp;nbsp;the&amp;nbsp;adder&amp;nbsp;module&amp;nbsp;which&amp;nbsp;acts&amp;nbsp;as&amp;nbsp;an&amp;nbsp;&quot;accumulator&quot;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;multiplier&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clock&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x,y&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;prod&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;multiplier&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Behav&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;multiplier&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MULT_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;(Clock)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;temp_prod&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;*N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;rising_edge&lt;/span&gt;(Clock))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp_prod&amp;nbsp;:=&amp;nbsp;x*y;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;MSB&amp;nbsp;half&amp;nbsp;of&amp;nbsp;the&amp;nbsp;result&amp;nbsp;is&amp;nbsp;ignored.&amp;nbsp;We&amp;nbsp;assume&amp;nbsp;that&amp;nbsp;all&amp;nbsp;intermediate&amp;nbsp;numbers&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--be&amp;nbsp;represented&amp;nbsp;by&amp;nbsp;a&amp;nbsp;max&amp;nbsp;of&amp;nbsp;N&amp;nbsp;bits.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;prod&amp;nbsp;&amp;lt;=&amp;nbsp;temp_prod(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;3) adder.vhd&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;output&amp;nbsp;from&amp;nbsp;multiplier&amp;nbsp;module&amp;nbsp;is&amp;nbsp;received&amp;nbsp;by&amp;nbsp;this&amp;nbsp;module&amp;nbsp;and&amp;nbsp;accumulated&amp;nbsp;to&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--form&amp;nbsp;the&amp;nbsp;output.&amp;nbsp;If&amp;nbsp;the&amp;nbsp;polynomial&amp;nbsp;equation&amp;nbsp;has&amp;nbsp;a&amp;nbsp;degree&amp;nbsp;of&amp;nbsp;&#39;n&#39;&amp;nbsp;then&amp;nbsp;&#39;n&#39;&amp;nbsp;additions&amp;nbsp;has&amp;nbsp;to&amp;nbsp;take&amp;nbsp;place&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--to&amp;nbsp;get&amp;nbsp;the&amp;nbsp;final&amp;nbsp;result.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;adder&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clock&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;adder&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Behav&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;adder&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;temp_sum&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ADDER_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;(Clock,reset)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(reset&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp_sum&amp;nbsp;&amp;lt;=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;elsif&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;rising_edge&lt;/span&gt;(Clock))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp_sum&amp;nbsp;&amp;lt;=&amp;nbsp;temp_sum&amp;nbsp;+&amp;nbsp;x;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum&amp;nbsp;&amp;lt;=&amp;nbsp;temp_sum;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;4) Top Level Entity : poly_eq_calc.vhd&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--This&amp;nbsp;is&amp;nbsp;the&amp;nbsp;top&amp;nbsp;level&amp;nbsp;entity&amp;nbsp;for&amp;nbsp;the&amp;nbsp;polynomial&amp;nbsp;equation&amp;nbsp;calculator.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;power_module,&amp;nbsp;multiplier&amp;nbsp;and&amp;nbsp;adders&amp;nbsp;entities&amp;nbsp;are&amp;nbsp;instantiated&amp;nbsp;inside&amp;nbsp;this&amp;nbsp;top&amp;nbsp;level&amp;nbsp;block.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--When&amp;nbsp;the&amp;nbsp;output&amp;nbsp;signal&amp;nbsp;done&amp;nbsp;is&amp;nbsp;High,&amp;nbsp;the&amp;nbsp;output&amp;nbsp;available&amp;nbsp;at&amp;nbsp;the&amp;nbsp;&#39;y&#39;&amp;nbsp;output&amp;nbsp;is&amp;nbsp;the&amp;nbsp;result&amp;nbsp;we&amp;nbsp;want.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Ignore&amp;nbsp;all&amp;nbsp;other&amp;nbsp;values&amp;nbsp;of&amp;nbsp;&#39;y&#39;&amp;nbsp;when&amp;nbsp;done&amp;nbsp;is&amp;nbsp;Low.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--We&amp;nbsp;have&amp;nbsp;assumed&amp;nbsp;that&amp;nbsp;all&amp;nbsp;the&amp;nbsp;intermediate&amp;nbsp;numbers&amp;nbsp;calculated&amp;nbsp;to&amp;nbsp;reach&amp;nbsp;the&amp;nbsp;final&amp;nbsp;result,&amp;nbsp;can&amp;nbsp;be&amp;nbsp;represented&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--by&amp;nbsp;a&amp;nbsp;maximum&amp;nbsp;of&amp;nbsp;N&amp;nbsp;bits.&amp;nbsp;This&amp;nbsp;simplifies&amp;nbsp;the&amp;nbsp;design&amp;nbsp;very&amp;nbsp;much.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;poly_eq_calc&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clock&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;y&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;poly_eq_calc&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Behav&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;poly_eq_calc&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;power_module&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clock&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x_powered&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;multiplier&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clock&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x,y&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;prod&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;adder&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clock&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;x_powered,coeff,product_from_mult&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;NUM_COEFFS&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;4&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Change&amp;nbsp;here&amp;nbsp;to&amp;nbsp;change&amp;nbsp;the&amp;nbsp;degree&amp;nbsp;of&amp;nbsp;the&amp;nbsp;polynomial.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;type&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;arr_type&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;array&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;&amp;nbsp;NUM_COEFFS-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Eq&amp;nbsp;:&amp;nbsp;3*x^3&amp;nbsp;-&amp;nbsp;2*x^2&amp;nbsp;-&amp;nbsp;4*x&amp;nbsp;+&amp;nbsp;5;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;coefficients&amp;nbsp;belonging&amp;nbsp;to&amp;nbsp;higher&amp;nbsp;powers&amp;nbsp;of&amp;nbsp;x&amp;nbsp;are&amp;nbsp;stored&amp;nbsp;in&amp;nbsp;higher&amp;nbsp;addresses&amp;nbsp;in&amp;nbsp;Coeffs&amp;nbsp;array.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;Coeffs&amp;nbsp;:&amp;nbsp;arr_type&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;5&lt;/span&gt;,N),&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--change&amp;nbsp;coefficients&amp;nbsp;here.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(-&lt;span style=&quot;color: #b5cea8;&quot;&gt;4&lt;/span&gt;,N),&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(-&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;,N),&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;3&lt;/span&gt;,N));&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;reset_adder&amp;nbsp;:&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Instantiate&amp;nbsp;the&amp;nbsp;3&amp;nbsp;sub-entities.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;calc_power_of_x&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;power_module&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(N&amp;nbsp;=&amp;gt;&amp;nbsp;N)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(Clock,reset,x,x_powered);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;multiply&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;multiplier&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(N&amp;nbsp;=&amp;gt;&amp;nbsp;N)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(Clock,x_powered,coeff,product_from_mult);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;add&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;adder&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(N&amp;nbsp;=&amp;gt;&amp;nbsp;N)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(Clock,reset_adder,product_from_mult,y);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;process&amp;nbsp;controlling&amp;nbsp;the&amp;nbsp;3&amp;nbsp;sub-entities&amp;nbsp;and&amp;nbsp;also&amp;nbsp;supplying&amp;nbsp;them&amp;nbsp;with&amp;nbsp;coefficients.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MAIN_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;(Clock,reset)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;coeff_index&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(reset&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;coeff_index&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;coeff&amp;nbsp;&amp;lt;=&amp;nbsp;Coeffs(&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset_adder&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;elsif&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;rising_edge&lt;/span&gt;(Clock))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset_adder&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--the&amp;nbsp;disabling&amp;nbsp;of&amp;nbsp;&#39;reset&amp;nbsp;of&amp;nbsp;adder&#39;&amp;nbsp;gets&amp;nbsp;noticed&amp;nbsp;by&amp;nbsp;adder&amp;nbsp;entity&amp;nbsp;in&amp;nbsp;the&amp;nbsp;next&amp;nbsp;clock&amp;nbsp;cycle.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(coeff_index&amp;nbsp;&amp;lt;&amp;nbsp;NUM_COEFFS-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;coeff_index&amp;nbsp;:=&amp;nbsp;coeff_index+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;coeff&amp;nbsp;&amp;lt;=&amp;nbsp;Coeffs(coeff_index);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--send&amp;nbsp;the&amp;nbsp;coefficients&amp;nbsp;one&amp;nbsp;by&amp;nbsp;one&amp;nbsp;to&amp;nbsp;the&amp;nbsp;multiplier&amp;nbsp;entity.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;elsif&lt;/span&gt;(coeff_index&amp;nbsp;=&amp;nbsp;NUM_COEFFS-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;coeff_index&amp;nbsp;:=&amp;nbsp;coeff_index+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;final&amp;nbsp;result&amp;nbsp;is&amp;nbsp;available&amp;nbsp;in&amp;nbsp;&#39;y&#39;&amp;nbsp;now.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;5) Testbench : tb_poly_eq_calc.vhd&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Testbench&amp;nbsp;code.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--The&amp;nbsp;testbench&amp;nbsp;entity&amp;nbsp;is&amp;nbsp;always&amp;nbsp;empty.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb_poly_eq_calc&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb_poly_eq_calc&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;sim&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb_poly_eq_calc&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;clk_period&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;time&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;10&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;ns&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--set&amp;nbsp;the&amp;nbsp;clock&amp;nbsp;period&amp;nbsp;here.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;Clk&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;reset&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--change&amp;nbsp;the&amp;nbsp;width&amp;nbsp;of&amp;nbsp;input&amp;nbsp;and&amp;nbsp;output&amp;nbsp;here.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;x,y&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;signed&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;done&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Clk&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;not&lt;/span&gt;&amp;nbsp;Clk&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;after&lt;/span&gt;&amp;nbsp;clk_period&amp;nbsp;/&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--generate&amp;nbsp;clock&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Instantiating&amp;nbsp;Design&amp;nbsp;Under&amp;nbsp;Test.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DUT&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;work&lt;/span&gt;.&lt;span style=&quot;color: #569cd6;&quot;&gt;poly_eq_calc&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;(N&amp;nbsp;=&amp;gt;&amp;nbsp;N)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;&amp;nbsp;(Clk,&amp;nbsp;reset,&amp;nbsp;x,&amp;nbsp;y,&amp;nbsp;done);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Apply&amp;nbsp;inputs&amp;nbsp;here.&amp;nbsp;Only&amp;nbsp;&#39;x&#39;&amp;nbsp;can&amp;nbsp;be&amp;nbsp;changed&amp;nbsp;here.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--To&amp;nbsp;change&amp;nbsp;coefficients&amp;nbsp;and&amp;nbsp;degree&amp;nbsp;of&amp;nbsp;polynomial&amp;nbsp;edit&amp;nbsp;the&amp;nbsp;top&amp;nbsp;level&amp;nbsp;entity&amp;nbsp;directly.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SEQUENCER_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--first&amp;nbsp;input.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period&amp;nbsp;*&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2.5&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;4&lt;/span&gt;,&amp;nbsp;N);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;done=&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--wait&amp;nbsp;for&amp;nbsp;result&amp;nbsp;to&amp;nbsp;be&amp;nbsp;out.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--second&amp;nbsp;input.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;7&lt;/span&gt;,&amp;nbsp;N);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;done=&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--wait&amp;nbsp;for&amp;nbsp;result&amp;nbsp;to&amp;nbsp;be&amp;nbsp;out.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--third&amp;nbsp;input.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;15&lt;/span&gt;,&amp;nbsp;N);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;done=&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--wait&amp;nbsp;for&amp;nbsp;result&amp;nbsp;to&amp;nbsp;be&amp;nbsp;out.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--fourth&amp;nbsp;input.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_signed&lt;/span&gt;(-&lt;span style=&quot;color: #b5cea8;&quot;&gt;9&lt;/span&gt;,&amp;nbsp;N);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;until&lt;/span&gt;&amp;nbsp;done=&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--wait&amp;nbsp;for&amp;nbsp;result&amp;nbsp;to&amp;nbsp;be&amp;nbsp;out.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;clk_period;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Check&amp;nbsp;if&amp;nbsp;the&amp;nbsp;results&amp;nbsp;are&amp;nbsp;correct&amp;nbsp;and&amp;nbsp;report&amp;nbsp;the&amp;nbsp;result.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CHECK_RESULTS_PROC&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;(Clk)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;actual_res&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;variable&lt;/span&gt;&amp;nbsp;input_num,x_int&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;rising_edge&lt;/span&gt;(Clk))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(done&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;1&#39;&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x_int&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_integer&lt;/span&gt;(x);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Change&amp;nbsp;this&amp;nbsp;equation&amp;nbsp;if&amp;nbsp;you&amp;nbsp;change&amp;nbsp;the&amp;nbsp;polynomial&amp;nbsp;eq&amp;nbsp;inside&amp;nbsp;the&amp;nbsp;top&amp;nbsp;level&amp;nbsp;entity.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;actual_res&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;3&lt;/span&gt;*x_int*x_int*x_int&amp;nbsp;-&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;*x_int*x_int&amp;nbsp;-&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;4&lt;/span&gt;*x_int&amp;nbsp;+&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;5&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;input_num&amp;nbsp;:=&amp;nbsp;input_num+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(actual_res&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_integer&lt;/span&gt;(y))&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;report&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;Input&amp;nbsp;number&amp;nbsp;&quot;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;&#39;image&lt;/span&gt;(input_num)&amp;nbsp;&amp;amp;&amp;nbsp;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&amp;nbsp;Worked&amp;nbsp;Well&quot;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;report&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;Input&amp;nbsp;number&amp;nbsp;&quot;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;&#39;image&lt;/span&gt;(input_num)&amp;nbsp;&amp;amp;&amp;nbsp;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&amp;nbsp;Has&amp;nbsp;Error&quot;&lt;/span&gt;;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The code was simulated successfully using &lt;b&gt;Modelsim 10.4a&lt;/b&gt; version. The simulation waveform below shows the signals for the first two set of inputs:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMvXgqCZ8FzR9G-OC4mS4OJW4_-okryWOy2bP34M2dE8M-RDgR3MXFrbniRwsN0XDS1RnOJRmlp4XvC_-nHPQfhqb669Lv7ewqKBqnDqQGjEAauZG02DPKcEVbW7gTt-KJ7cXDF2jv6LrL/s1913/image1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;831&quot; data-original-width=&quot;1913&quot; height=&quot;278&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMvXgqCZ8FzR9G-OC4mS4OJW4_-okryWOy2bP34M2dE8M-RDgR3MXFrbniRwsN0XDS1RnOJRmlp4XvC_-nHPQfhqb669Lv7ewqKBqnDqQGjEAauZG02DPKcEVbW7gTt-KJ7cXDF2jv6LrL/w640-h278/image1.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;The design was synthesized successfully using Vivado 2020.2 version.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/2707059573416696226/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2020/12/synthesizable-polynomial-equation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/2707059573416696226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/2707059573416696226'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2020/12/synthesizable-polynomial-equation.html' title='Synthesizable Polynomial Equation Calculator in VHDL'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV4avnwLeChibuDsICBE8DDWDT5OYo-zHC9O-2tS6ewv3cVJRcODUmYA2_zbjN9H67xbBrZepo76dK8w_H6D8cConmq4mQTwP2ssXdSbqyaM2MCHaSxwZEN9cTqrZk0nn24VAG4zBEHtYJ/s72-w400-h208-c/image.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-648863864414036422</id><published>2020-12-05T13:08:00.002+05:30</published><updated>2020-12-05T13:08:51.232+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="examples"/><category scheme="http://www.blogger.com/atom/ns#" term="generate"/><category scheme="http://www.blogger.com/atom/ns#" term="generic"/><category scheme="http://www.blogger.com/atom/ns#" term="gray code"/><title type='text'>Generic VHDL Code for Binary to Gray and Gray to Binary converter</title><content type='html'>&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Few years back I had written a &lt;a href=&quot;https://vhdlguru.blogspot.com/2017/10/4-bit-binary-to-gray-code-and-gray-code.html&quot; target=&quot;_blank&quot;&gt;4 bit converter for conversion between Gray and Binary codes&lt;/a&gt;. After receiving much positive response I decided to write a generic version of the same.&lt;/p&gt;&lt;p&gt;Let me share the codes...&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Binary to Gray Code Converter:&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;LIBRARY&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;USE&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;ALL&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;bin2gray&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;4&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;(&amp;nbsp;&amp;nbsp;&amp;nbsp;bin&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--binary&amp;nbsp;input&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;G&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--gray&amp;nbsp;code&amp;nbsp;output&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;bin2gray&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;gate_level&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;bin2gray&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;G(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&amp;lt;=&amp;nbsp;bin(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--generate&amp;nbsp;xor&amp;nbsp;gates.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;xor_gates&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generate&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;G(i)&amp;nbsp;&amp;lt;=&amp;nbsp;bin(i+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;xor&lt;/span&gt;&amp;nbsp;bin(i);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generate&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/h3&gt;&lt;h3&gt;&lt;b&gt;Gray Code to Binary Converter:&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;LIBRARY&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;USE&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;ALL&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;gray2bin&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;4&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;(&amp;nbsp;&amp;nbsp;&amp;nbsp;G&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--gray&amp;nbsp;code&amp;nbsp;input&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bin&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--binary&amp;nbsp;output&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;gray2bin&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;gate_level&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;gray2bin&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;temp&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;temp(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&amp;lt;=&amp;nbsp;G(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;--generate&amp;nbsp;xor&amp;nbsp;gates.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;xor_gates&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generate&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp(i)&amp;nbsp;&amp;lt;=&amp;nbsp;temp(i+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;xor&lt;/span&gt;&amp;nbsp;G(i);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generate&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;bin&amp;nbsp;&amp;lt;=&amp;nbsp;temp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;h3&gt;&lt;b&gt;Testbench:&lt;/b&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;library&lt;/span&gt;&amp;nbsp;ieee;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.std_logic_1164.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;use&lt;/span&gt;&amp;nbsp;ieee.numeric_std.&lt;span style=&quot;color: #569cd6;&quot;&gt;all&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;entity&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;architecture&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;behavior&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;of&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;tb&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--&amp;nbsp;component&amp;nbsp;declaration&amp;nbsp;for&amp;nbsp;the&amp;nbsp;unit&amp;nbsp;under&amp;nbsp;test&#39;s&amp;nbsp;(uut)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;bin2gray&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;4&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;(&amp;nbsp;&amp;nbsp;&amp;nbsp;bin&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--binary&amp;nbsp;input&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;G&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--gray&amp;nbsp;code&amp;nbsp;output&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;gray2bin&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;is&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;(N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;4&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;(&amp;nbsp;&amp;nbsp;&amp;nbsp;G&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--gray&amp;nbsp;code&amp;nbsp;input&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bin&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;out&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--binary&amp;nbsp;output&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;component&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;constant&lt;/span&gt;&amp;nbsp;N&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;16&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Change&amp;nbsp;this&amp;nbsp;to&amp;nbsp;control&amp;nbsp;the&amp;nbsp;number&amp;nbsp;of&amp;nbsp;bits&amp;nbsp;in&amp;nbsp;the&amp;nbsp;input/output.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;bin,g,bin_out&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;downto&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;:=&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;others&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;&#39;0&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;signal&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;integer&lt;/span&gt;&amp;nbsp;:=&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--&amp;nbsp;Both&amp;nbsp;the&amp;nbsp;converters&amp;nbsp;are&amp;nbsp;connected&amp;nbsp;back&amp;nbsp;to&amp;nbsp;back&amp;nbsp;to&amp;nbsp;see&amp;nbsp;the&amp;nbsp;binary&amp;nbsp;input&amp;nbsp;going&amp;nbsp;to&amp;nbsp;the&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--first&amp;nbsp;entity&amp;nbsp;is&amp;nbsp;the&amp;nbsp;same&amp;nbsp;as&amp;nbsp;the&amp;nbsp;output&amp;nbsp;coming&amp;nbsp;out&amp;nbsp;of&amp;nbsp;the&amp;nbsp;second&amp;nbsp;entity.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uut1:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;bin2gray&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;&amp;nbsp;(N&amp;nbsp;=&amp;gt;&amp;nbsp;N)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bin&amp;nbsp;=&amp;gt;&amp;nbsp;bin,&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;g&amp;nbsp;=&amp;gt;&amp;nbsp;g&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uut2:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;gray2bin&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;generic&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;&amp;nbsp;(N&amp;nbsp;=&amp;gt;&amp;nbsp;N)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;port&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;map&lt;/span&gt;&amp;nbsp;(&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;g&amp;nbsp;=&amp;gt;&amp;nbsp;g,&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bin&amp;nbsp;=&amp;gt;&amp;nbsp;bin_out&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--&amp;nbsp;stimulus&amp;nbsp;process&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--this&amp;nbsp;tests&amp;nbsp;for&amp;nbsp;all&amp;nbsp;the&amp;nbsp;input&amp;nbsp;combinations.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;stim_proc:&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;begin&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;to&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;**N-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--loop&amp;nbsp;through&amp;nbsp;all&amp;nbsp;the&amp;nbsp;&amp;nbsp;available&amp;nbsp;inputs&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bin&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;std_logic_vector&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;to_unsigned&lt;/span&gt;(i,N));&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--convert&amp;nbsp;integer&amp;nbsp;to&amp;nbsp;std_logic_vector.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;5&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;ns&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;--Count&amp;nbsp;the&amp;nbsp;number&amp;nbsp;of&amp;nbsp;errors.&amp;nbsp;Should&amp;nbsp;be&amp;nbsp;zero&amp;nbsp;at&amp;nbsp;the&amp;nbsp;end&amp;nbsp;of&amp;nbsp;simulation.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;(bin&amp;nbsp;/=&amp;nbsp;bin_out)&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;&amp;nbsp;&amp;lt;=&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;error&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;5&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;ns&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;loop&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;wait&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;process&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;end&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The codes were tested using Modelsim 10.4a version. Simply change the value of the constant &#39;N&#39; in the testbench to test for different sized converters.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/648863864414036422/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2020/12/generic-vhdl-code-for-binary-to-gray.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/648863864414036422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/648863864414036422'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2020/12/generic-vhdl-code-for-binary-to-gray.html' title='Generic VHDL Code for Binary to Gray and Gray to Binary converter'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-8014056494072629624</id><published>2020-11-29T11:02:00.000+05:30</published><updated>2020-11-29T11:02:11.654+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="examples"/><category scheme="http://www.blogger.com/atom/ns#" term="testbench"/><category scheme="http://www.blogger.com/atom/ns#" term="vhdl beginners guide"/><category scheme="http://www.blogger.com/atom/ns#" term="vhdl tips"/><category scheme="http://www.blogger.com/atom/ns#" term="video tutorials"/><title type='text'>Writing a Gate Level VHDL design (and Testbench) from Scratch</title><content type='html'>&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;In this video I want to show you how you can take a logic circuit diagram and write the corresponding VHDL code along with its testbench.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; class=&quot;BLOG_video_class&quot; height=&quot;463&quot; src=&quot;https://www.youtube.com/embed/k4wku4yJ2JU&quot; width=&quot;557&quot; youtube-src-id=&quot;k4wku4yJ2JU&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;The VHDL codes presented in the video are given below:&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;xor_gate.vhd:&lt;/h3&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee.std_logic_1164.all&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;xor_gate&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; (
        A,B : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
        C : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;
    );
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt;;


&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;gate_level&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;xor_gate&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; An,Bn,t1,t2 : &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; := &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;

An &amp;lt;= &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;not&lt;/span&gt; A;
Bn &amp;lt;= &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;not&lt;/span&gt; B;
t1 &amp;lt;= An &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;and&lt;/span&gt; B;
t2 &amp;lt;= Bn &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;and&lt;/span&gt; A;

C &amp;lt;= t1 &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;or&lt;/span&gt; t2;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;tb_xor.vhd:&lt;/h3&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;ieee.std_logic_1164.all&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_xor&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;behav&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_xor&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;component&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;xor_gate&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; (
        A,B : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;
        C : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;
    );
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;component&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; A,B,C : &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; := &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;

UUT : xor_gate &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;map&lt;/span&gt; (A,B,C);

stimulus : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
    A &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
    B &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt; ns;
    A &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
    B &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt; ns;
    A &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
    B &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt; ns;
    A &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
    B &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;    

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;h3 style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px; text-align: left;&quot;&gt;&lt;br /&gt;The Logic circuit diagram is given below:&lt;/h3&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9Zq0oHLJDZbfJv59vpzeDA57D1CXKD9TaF5dxR8bvJfyWmTanL_Jf5WYOEdCKq_yrQsIYpbbVYF43VfkRX25pTh1A_j7tyRsGAoXz9VJrsmYoH78WgRXdDpuk6L3h7bvaMkAtaMaZ9rj3/s1450/image1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;818&quot; data-original-width=&quot;1450&quot; height=&quot;362&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9Zq0oHLJDZbfJv59vpzeDA57D1CXKD9TaF5dxR8bvJfyWmTanL_Jf5WYOEdCKq_yrQsIYpbbVYF43VfkRX25pTh1A_j7tyRsGAoXz9VJrsmYoH78WgRXdDpuk6L3h7bvaMkAtaMaZ9rj3/w640-h362/image1.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;h3 style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px; text-align: left;&quot;&gt;&lt;b&gt;Simulation Waveform from Modelsim:&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqWfsumESIZrNM108pwLsNeq8nG2fOFmBhuOHpwPrLGVe9MA-FSHf5kUEeVnOsvHO6ONVvN7UT0zqas9Ly_PNrCnYNNL4UM4n6HnOZnMJMQz5pmgcWWKUH3CFjYoJ8tIC0IBBeqZa-euFq/&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;182&quot; data-original-width=&quot;883&quot; height=&quot;66&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqWfsumESIZrNM108pwLsNeq8nG2fOFmBhuOHpwPrLGVe9MA-FSHf5kUEeVnOsvHO6ONVvN7UT0zqas9Ly_PNrCnYNNL4UM4n6HnOZnMJMQz5pmgcWWKUH3CFjYoJ8tIC0IBBeqZa-euFq/&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/8014056494072629624/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2020/11/writing-gate-level-vhdl-design-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/8014056494072629624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/8014056494072629624'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2020/11/writing-gate-level-vhdl-design-and.html' title='Writing a Gate Level VHDL design (and Testbench) from Scratch'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/k4wku4yJ2JU/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-6159821543131778748</id><published>2020-11-28T10:55:00.001+05:30</published><updated>2020-11-28T10:55:44.091+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Behavior level model"/><category scheme="http://www.blogger.com/atom/ns#" term="examples"/><category scheme="http://www.blogger.com/atom/ns#" term="matrix multiplier"/><category scheme="http://www.blogger.com/atom/ns#" term="state machine"/><title type='text'>Synthesizable Matrix Multiplier in VHDL</title><content type='html'>&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Long back I had posted a &lt;a href=&quot;https://vhdlguru.blogspot.com/2010/03/matrix-multiplication-in-vhdl.html&quot; target=&quot;_blank&quot;&gt;simple matrix multiplier&lt;/a&gt; which works well in simulation but couldn&#39;t be synthesized. But many people had requested for synthesizable version of this code. So here we go.&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;The design takes two matrices of 3 by 3 and outputs a matrix of 3 by 3. Each element is stored as unsigned 8 bits. This is not a generic multiplier, but if you watch the video explaining the code, you might be able to extend it to a different sized multiplier.&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; class=&quot;BLOG_video_class&quot; height=&quot;440&quot; src=&quot;https://www.youtube.com/embed/8bqYa9NcD2I&quot; width=&quot;530&quot; youtube-src-id=&quot;8bqYa9NcD2I&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; Each matrix has 9 elements, each of which is 8 bits in size. So I am passing the matrix as a 72 bit 1-Dimensional array in the design. The following table shows how the 2-D elements are mapped into the 1-D array.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;&quot;&gt;
 &lt;tbody&gt;&lt;tr&gt;
  &lt;td style=&quot;border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;Row&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;Column&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;Bit’s Position
  in 1-D array&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;7:0&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;15:8&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;2&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;23:16&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;31:24&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;39:32&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;2&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;47:40&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;2&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;55:48&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;2&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;63:56&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: 1pt solid windowtext; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.4pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;2&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 49.6pt;&quot; valign=&quot;top&quot; width=&quot;66&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;2&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 5cm;&quot; valign=&quot;top&quot; width=&quot;189&quot;&gt;
  &lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: center;&quot;&gt;71:64&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;Let me share the codes now...&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;u&gt;matrix_mult.vhd:&lt;/u&gt;&lt;/h3&gt;&lt;div&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/div&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--3 by 3 matrix multiplier. Each element of the matrix is 8 bit wide. &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--Inputs are called A and B and output is called C. &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--Each matrix has 9 elements each of which is 8 bit wide. So the inputs is 9*8=72 bit long.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.std_logic_1164.all&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.numeric_std.all&lt;/span&gt;; 

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;matrix_mult&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; (  Clock: &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;; 
            reset : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;   &lt;span style=&quot;color: #888888;&quot;&gt;--active high reset&lt;/span&gt;
            start : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;   &lt;span style=&quot;color: #888888;&quot;&gt;--A &#39;1&#39; starts the matrix multiplication process.&lt;/span&gt;
            A,B : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;71&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
            C : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;71&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
            done : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;--a &#39;1&#39; indicates that multiplication is done and result is availble at C.&lt;/span&gt;
            );
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Behav&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;matrix_mult&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;type&lt;/span&gt; matType &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;array&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; matA, matB, matC : matType := (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; X&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;00&quot;&lt;/span&gt;));
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;type&lt;/span&gt; state_type &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt; (init,do_mult,apply_outputs);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; state : state_type := init;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; i,j,k : &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;integer&lt;/span&gt; := &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt; 

sm : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt; (Clock,reset)    &lt;span style=&quot;color: #888888;&quot;&gt;--process implementing the state machine for multiplying the matrices.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;variable&lt;/span&gt; temp : unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;15&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;) := (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(reset = &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
        state &amp;lt;= init;
        i &amp;lt;= &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
        j &amp;lt;= &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
        k &amp;lt;= &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
        done &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
        matA &amp;lt;= (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; X&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;00&quot;&lt;/span&gt;));
        matB &amp;lt;= (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; X&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;00&quot;&lt;/span&gt;));
        matC &amp;lt;= (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; X&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;00&quot;&lt;/span&gt;));
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elsif&lt;/span&gt; rising_edge(Clock) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;case&lt;/span&gt; state &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; init =&amp;gt;    &lt;span style=&quot;color: #888888;&quot;&gt;--the matrices which are in a 1-D array are converted to 2-D matrices first.&lt;/span&gt;
                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(start = &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;--run through the rows&lt;/span&gt;
                        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; j &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;--run through the columns&lt;/span&gt;
                            matA(i,j) &amp;lt;= A((i*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;+j+&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;-&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; (i*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;+j)*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;);
                            matB(i,j) &amp;lt;= B((i*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;+j+&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;-&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; (i*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;+j)*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;);
                        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;;
                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;;
                    state &amp;lt;= do_mult;
                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; do_mult =&amp;gt;
                temp := matA(i,k)*matB(k,j);
                matC(i,j) &amp;lt;= matC(i,j) + temp(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(k = &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
                    k &amp;lt;= &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(j = &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
                        j &amp;lt;= &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
                        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; (i= &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
                            i &amp;lt;= &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
                            state &amp;lt;= apply_outputs;
                        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
                            i &amp;lt;= i + &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
                        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
                        j &amp;lt;= j+&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;        
                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
                    k &amp;lt;= k+&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;     
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;when&lt;/span&gt; apply_outputs =&amp;gt;   &lt;span style=&quot;color: #888888;&quot;&gt;--convert 3 by 3 matrix into a 1-D matrix.&lt;/span&gt;
                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;--run through the rows&lt;/span&gt;
                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; j &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;--run through the columnss&lt;/span&gt;
                        C((i*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;+j+&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;-&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; (i*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;+j)*&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;) &amp;lt;= matC(i,j);
                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;;
                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;;   
                done &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
                state &amp;lt;= init;  
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;case&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;
 
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt;;&lt;/pre&gt;&lt;h3&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/h3&gt;&lt;h3&gt;&lt;u&gt;tb_matrix_mult.vhd:&lt;/u&gt;&lt;/h3&gt;&lt;div&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/div&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;--Testbench for testing the 3 by 3 matrix multiplier.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.std_logic_1164.all&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;IEEE.numeric_std.all&lt;/span&gt;; 

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_matrix_mult&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;--testbench entity is always empty. No input or output ports.&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;entity&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;behav&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;tb_matrix_mult&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;component&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;matrix_mult&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; (  Clock: &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;; 
            reset : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;   &lt;span style=&quot;color: #888888;&quot;&gt;--active high reset&lt;/span&gt;
            start : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;;   &lt;span style=&quot;color: #888888;&quot;&gt;--A &#39;1&#39; starts the matrix multiplication process.&lt;/span&gt;
            A,B : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;71&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
            C : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;71&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
            done : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;out&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;--a &#39;1&#39; indicates that multiplication is done and result is availble at C.&lt;/span&gt;
            );
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;component&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; A,B,C : unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;71&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; Clock,reset, start, done : &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; := &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;type&lt;/span&gt; matType &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;array&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;of&lt;/span&gt; unsigned(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; matC : matType := (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; (&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;others&lt;/span&gt; =&amp;gt; X&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;00&quot;&lt;/span&gt;)); 

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;

matrix_multiplier : matrix_mult &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;port&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;map&lt;/span&gt; (Clock, reset, start, A,B, C,done);

&lt;span style=&quot;color: #888888;&quot;&gt;--generate a 50Mhz clock for testing the design.&lt;/span&gt;
Clk_generator : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt; ns;
    Clock &amp;lt;= &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;not&lt;/span&gt; Clock;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;

apply_inputs : &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
    reset &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt; ns;
    reset &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;20&lt;/span&gt; ns;
    A &amp;lt;= X&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;09&quot; &amp;amp; X&quot;08&quot; &amp;amp; X&quot;07&quot; &amp;amp; X&quot;06&quot; &amp;amp; X&quot;05&quot; &amp;amp; X&quot;04&quot; &amp;amp; X&quot;03&quot; &amp;amp; X&quot;02&quot; &amp;amp; X&quot;01&quot;&lt;/span&gt;;
    B &amp;lt;= X&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;01&quot; &amp;amp; X&quot;09&quot; &amp;amp; X&quot;08&quot; &amp;amp; X&quot;07&quot; &amp;amp; X&quot;06&quot; &amp;amp; X&quot;05&quot; &amp;amp; X&quot;04&quot; &amp;amp; X&quot;03&quot; &amp;amp; X&quot;02&quot;&lt;/span&gt;;
    start &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;20&lt;/span&gt; ns;
    start &amp;lt;= &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;0&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;until&lt;/span&gt; done = &lt;span style=&quot;color: #0044dd;&quot;&gt;&#39;1&#39;&lt;/span&gt;;
    &lt;span style=&quot;color: #888888;&quot;&gt;--The result C should be (93,150,126,57,96,81,21,42,36)&lt;/span&gt;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt; ns;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt; &lt;span style=&quot;color: #888888;&quot;&gt;--run through the rows&lt;/span&gt;
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; j &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt; &lt;span style=&quot;color: #888888;&quot;&gt;--run through the columnss&lt;/span&gt;
            matC(i, j) &amp;lt;= C((i * &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt; + j + &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;) * &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt; - &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;downto&lt;/span&gt; (i * &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt; + j) * &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;);
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;loop&lt;/span&gt;;
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;wait&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;behav&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;h3 style=&quot;color: black; font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;&lt;u&gt;Simulation Results:&lt;/u&gt;&lt;/h3&gt;&lt;/pre&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; The design was simulated successfully using Modelsim SE 10.4a version. Screenshots of the simulation waveform is shown below:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNo47nhS0GbKigL-WYXhVUgjGDb5OuWdiRhfn3s8dut-mYnHLeBUF4D863-dKmuUn7mMVQGQbOmx0pu5DsycekeAOF7655dN0z1zb76__12mb3QyPac88lK-64f6t7eNWqNAf0TZDbyw9K/&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;690&quot; data-original-width=&quot;1505&quot; height=&quot;294&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNo47nhS0GbKigL-WYXhVUgjGDb5OuWdiRhfn3s8dut-mYnHLeBUF4D863-dKmuUn7mMVQGQbOmx0pu5DsycekeAOF7655dN0z1zb76__12mb3QyPac88lK-64f6t7eNWqNAf0TZDbyw9K/w640-h294/image.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWEZio8_8YPGPoX8IIgQrVt9R_PpHM8l2H0-WlEyoCMwRi1OoAFYiIghFznVop-2xKC05Ln9-6z2TXlrZFLHDeG60DRs0KmTtu_gYIFOsGF3pe3Odp8FmtVA71jZqpc8rj8Y5LE7A4O0wx/&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;679&quot; data-original-width=&quot;1509&quot; height=&quot;288&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWEZio8_8YPGPoX8IIgQrVt9R_PpHM8l2H0-WlEyoCMwRi1OoAFYiIghFznVop-2xKC05Ln9-6z2TXlrZFLHDeG60DRs0KmTtu_gYIFOsGF3pe3Odp8FmtVA71jZqpc8rj8Y5LE7A4O0wx/w640-h288/image.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Please let me know if you are unable to get the code to work or if its not synthesisable. Good luck with your projects.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/6159821543131778748/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2020/11/synthesizable-matrix-multiplier-in-vhdl.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/6159821543131778748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/6159821543131778748'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2020/11/synthesizable-matrix-multiplier-in-vhdl.html' title='Synthesizable Matrix Multiplier in VHDL'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/8bqYa9NcD2I/default.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-4018480547799374203</id><published>2020-11-26T09:43:00.005+05:30</published><updated>2020-12-04T22:13:48.747+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="signals"/><category scheme="http://www.blogger.com/atom/ns#" term="variables"/><category scheme="http://www.blogger.com/atom/ns#" term="vhdl language"/><category scheme="http://www.blogger.com/atom/ns#" term="vhdl tips"/><title type='text'>Signals and Variables in VHDL</title><content type='html'>&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; Every programming language has objects for storing values. VHDL too have them. Two of these object types are called&amp;nbsp;&lt;/span&gt;Signals and Variables. They might look very similar for a beginner, but there are few fundamental differences between them.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Variables are assigned using the := operator. And signals are assigned with the &amp;lt;= operator.&lt;/li&gt;&lt;li&gt;Variables can be declared and used only within a process/function/procedure but Signals can be declared and used anywhere.&lt;/li&gt;&lt;/ul&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/h4&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;u&gt;A very fundamental difference:&lt;/u&gt;&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;In a block of statements, the statements with variables immediately take their values. Very similar to how it works in programming languages like C. But in a group of statements with Signals on the left hand side, the signals does not take it&#39;s new value until the process has suspended (either hit the bottom or hit a wait statement).&lt;/p&gt;&lt;p&gt;This can be further explained with the following example scenario.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Suppose I want to implement a swapping function in VHDL using Signals.&amp;nbsp;&lt;/p&gt;&lt;p&gt;I can simply write,&amp;nbsp;&lt;/p&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;pre style=&quot;line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;signal&lt;/span&gt; x,y : &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; := &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;(Clk)
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(rising_edge(Clk)) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
  x &amp;lt;= y;
  y &amp;lt;= x;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; What happens above is that, though the &#39;x&#39; is assigned the value of &#39;y&#39; sequentially first, the new value isn&#39;t updated to &#39;x&#39; until we &quot;exit&quot; the process. So from a practical point of looking at it, it looks like they happen in parallel.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Now if I have to use variables for implementing a swapping function, I need three statements. Like below:&lt;/p&gt;&lt;pre style=&quot;line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;(Clk)
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;variable&lt;/span&gt; x,y,temp : &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; := &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;begin&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(rising_edge(Clk)) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;then&lt;/span&gt;
  temp := x;
  x := y;
  y := x;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;process&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;color: #333333; line-height: 16.25px; margin-bottom: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;    &lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Since variables take the values assigned to them right away, we need a temporary variable to hold the value of &#39;x&#39; before assigning &#39;y&#39; to it.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/pre&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Variables declared in different processes cannot communicate with each other. They are local to the process. On the other hand signals declared in a VHDL entity can be used anywhere in the entity.&lt;/li&gt;&lt;li&gt;You cannot declare or use a Signal inside a VHDL Function. Functions are purely combinatorial in VHDL and thus you have to have use variables.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;If you want the code to be synthesised, then beware of the consequences of using a variable. Variables often create latches when implemented on a FPGA and synthesis tools often pass a warning to notify. If not needed its good to avoid latches in your design.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Though using variables might seem make the work easier, it might not pass the synthesis stage. For many, who come to VHDL from a C background, using variables is very tempting.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;u&gt;Be easy with the use of Variables:&lt;/u&gt;&lt;/span&gt;&lt;/h4&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Check this &lt;a href=&quot;https://vhdlguru.blogspot.com/2010/03/matrix-multiplication-in-vhdl.html&quot; target=&quot;_blank&quot;&gt;Matrix Multiplication code using Variables&lt;/a&gt; to see some of the dangers involved with them. Multiplication of two matrices requires a large number of multipliers and adders. In C, you would use some nested &quot;for&quot; loops to achieve this. And with the use of variables you can do the same thing in VHDL too like you can see from the link.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;But using this same piece of code in a real FPGA is impossible to achieve. Either the design wont pass the synthesis stage or it will take days to get it done.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;All those individual additions and multiplications gets done in &quot;one&quot; clock cycle. None of the adders and multipliers get reused and the loops get unfolded into a concatenated series of resources.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; In such a case its necessary to use signals and spilt the whole operation over many clock cycles. This reduces the resource usage and more importantly you have a chance to get your design synthesised.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/4018480547799374203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2020/11/signals-and-variables-in-vhdl.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/4018480547799374203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/4018480547799374203'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2020/11/signals-and-variables-in-vhdl.html' title='Signals and Variables in VHDL'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2050962176404305705.post-3587851352749225718</id><published>2020-11-22T21:23:00.002+05:30</published><updated>2020-11-22T21:23:30.146+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="modelsim"/><category scheme="http://www.blogger.com/atom/ns#" term="simulation tool"/><title type='text'>Simulating a VHDL/Verilog code using Modelsim SE</title><content type='html'>&lt;p&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13.2px;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;This is a simple How-To video for ModelSim SE 10.4a version. If you are already familiar with this software tool then you may not need to watch this video.&lt;/span&gt;&lt;/p&gt;&lt;br style=&quot;background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13.2px;&quot; /&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13.2px;&quot;&gt;In this video, I am trying to show you:&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13.2px;&quot; /&gt;&lt;ol style=&quot;background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13.2px;&quot;&gt;&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;How to create a new project in ModelSim SE.&lt;/li&gt;&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Add VHDL codes to this project.&lt;/li&gt;&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Compile and simulate the codes.&lt;/li&gt;&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Few tips on the simulation part of the tool.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 13.2px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; class=&quot;BLOG_video_class&quot; height=&quot;392&quot; src=&quot;https://www.youtube.com/embed/9uSWnVwk_vg&quot; width=&quot;472&quot; youtube-src-id=&quot;9uSWnVwk_vg&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 13.2px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 13.2px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vhdlguru.blogspot.com/feeds/3587851352749225718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vhdlguru.blogspot.com/2020/11/simulating-vhdlverilog-code-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/3587851352749225718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2050962176404305705/posts/default/3587851352749225718'/><link rel='alternate' type='text/html' href='http://vhdlguru.blogspot.com/2020/11/simulating-vhdlverilog-code-using.html' title='Simulating a VHDL/Verilog code using Modelsim SE'/><author><name>vipin</name><uri>http://www.blogger.com/profile/02146017720228354842</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/9uSWnVwk_vg/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry></feed>