<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Muhammed Kocaoğlu on Medium]]></title>
        <description><![CDATA[Stories by Muhammed Kocaoğlu on Medium]]></description>
        <link>https://medium.com/@kocamuha?source=rss-ccca18be8a49------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Tp8lb9BZ7tirCcL1</url>
            <title>Stories by Muhammed Kocaoğlu on Medium</title>
            <link>https://medium.com/@kocamuha?source=rss-ccca18be8a49------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 09:04:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kocamuha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[PYUVM RAL(Register abstraction layer)]]></title>
            <link>https://medium.com/@kocamuha/pyuvm-ral-register-abstraction-layer-2bc844c0b01e?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bc844c0b01e</guid>
            <category><![CDATA[pyuvm]]></category>
            <category><![CDATA[uvm-training]]></category>
            <category><![CDATA[vmu]]></category>
            <category><![CDATA[rals]]></category>
            <category><![CDATA[uvm-register]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Sun, 19 May 2024 16:35:28 GMT</pubDate>
            <atom:updated>2024-05-19T16:46:57.946Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, pyuvm contributors added the UVM Register Abstraction Layer to pyuvm. So, I wanted to give it a try for fun. It is really good to see the community is bringing pyuvm to a better level.</p><p>Those who want to have an introductory level of knowledge of Cocotb may have a look at my <a href="https://medium.com/@kocamuha/synchronous-fifo-tester-using-cocotb-836008d35c36">previous post</a> where I made an example without utilizing pyuvm. I’ll utilize pyuvm this time and will make a demo on pyuvm RAL.</p><h3><strong>What is pyuvm and how to install the version with RAL?</strong></h3><p>Pyuvm is an open-source Python implementation of the Universal Verification Methodology(UVM). Pyuvm allows us to use the same verification concepts and methodologies using Python. However, it is not mature yet and I think has a long way to go.</p><p>To get the version with RAL support, we need to run the command below. Note that, this is not the latest but a pre-release.<br><a href="https://pypi.org/project/pyuvm/3.0.0.dev0/">https://pypi.org/project/pyuvm/3.0.0.dev0/</a></p><p>$ pip install pyuvm==3.0.0.dev0</p><p>After installing we are good to go.</p><h3>What is RAL (Register Abstraction Layer)</h3><p>RAL is a concept used in verification to abstract and manage register and memories of a hardware design. This demo will be on only register abstraction. Memory declaration is not supported yet. And we will use front-door access, back-door access is not supported either.</p><p><strong>Step 1: Abstracting the registers<br></strong>As a first step, we’ll define the registers to be abstracted. We’ll have 4 registers in this example with names reg0, reg1, reg2, and reg3. Only reg0 implementation is given. The others are added the same way. I gave the complete code on my <a href="https://github.com/muhammedkocaoglu/Cocotb-Examples/tree/main/pyuvm_ral_demo">GitHub </a>page for you to have a look at. Assuming that you have a basic knowledge of UVM implementation and skipping detailed explanation as it is quite similar.</p><pre>class REG0(uvm_reg):<br>  def __init__(self, name=&quot;REG0&quot;, reg_width=32):<br>    super().__init__(name, reg_width)<br>    self.f0 = uvm_reg_field(&#39;f0&#39;)<br>  def build(self):<br>    self.f0.configure(self, 32, 0, &#39;RW&#39;, 0, 0)<br>    self._set_lock()<br><br>class reg_block(uvm_reg_block):<br>  def __init__(self, name=&quot;reg_block&quot;):<br>    super().__init__(name)<br>    self.def_map = uvm_reg_map(&#39;map&#39;)<br>    self.def_map.configure(self, 0)<br><br>    # reg0<br>    self.reg0 = REG0(&#39;reg0&#39;)<br>    self.reg0.configure(self, &quot;0x0&quot;, &quot;&quot;, False, False)<br>    self.def_map.add_reg(self.reg0, &quot;0x0&quot;, &quot;RW&quot;)</pre><p><strong>Step 2: Adapter</strong><br>The responsibility of the adapter is to convert register transaction to its equivalent bus transaction and the bus transaction to its equivalent register transaction. In this demo, we are not using any specific bus model.</p><pre># ADAPATER<br>class bus_adapter(uvm_reg_adapter):<br>  def __init__(self, name=&quot;bus_adapter&quot;):<br>    super().__init__(name)<br>  def reg2bus(self, rw: uvm_reg_bus_op) -&gt; uvm_sequence_item:<br>    item = simple_bus_item(&quot;item&quot;)<br>    if (rw.kind == access_e.UVM_READ):<br>      item.rd = 1<br>      item.rdata = rw.data<br>    else:<br>      item.rd = 0<br>      item.wdata = rw.data<br>    item.addr = rw.addr<br>    return item<br>  def bus2reg(self, bus_item: uvm_sequence_item, rw: uvm_reg_bus_op):<br>    if bus_item.rd == 1:<br>      rw.kind = access_e.UVM_READ<br>      rw.data = bus_item.rdata<br>    else:<br>      rw.data = bus_item.wdata<br>      rw.kind = access_e.UVM_WRITE<br>    rw.addr = bus_item.addr</pre><p><strong>Step 3: Sequence item</strong><br>Required bus signals are defined in this class.</p><pre># SEQUENCE ITEM<br>class simple_bus_item(uvm_sequence_item):<br>  def __init__(self, name):<br>    super().__init__(name)<br>    self.rdata: int = 0<br>    self.rd: int = 0<br>    self.addr: int = 0<br>    self.wdata: int = 0</pre><p><strong>Step 4: Driver</strong><br>DUT is driven in this class.</p><pre>  async def run_phase(self):<br>    self.reset()<br>    while True:<br>      cmd = await self.seq_item_port.get_next_item()<br>      if (cmd.rd == 0):<br>        await self.write_reg(int(cmd.addr, 16), cmd.wdata)<br>      else:<br>        read_data = await self.read_reg(int(cmd.addr, 16))<br>        cmd.rdata = read_data<br>      self.seq_item_port.item_done()</pre><p><strong>Step 5: Agent</strong><br>In this class, driver and sequencer connections are made.</p><pre>class Agent(uvm_agent):<br>  def build_phase(self):<br>    self.seqr = uvm_sequencer(&quot;seqr&quot;, self)<br>    self.drv = Driver.create(&quot;drv&quot;, self)<br>  def connect_phase(self):<br>    self.drv.seq_item_port.connect(self.seqr.seq_item_export)</pre><p><strong>Step 6: Environment</strong><br>In this class, register block connections to the agent sequencer and adapter are made.</p><pre>class Env(uvm_env):<br>  def build_phase(self):<br>    self.agt         = Agent.create(&quot;agt&quot;, self)<br>    self.reg_adapter = bus_adapter(&quot;reg_adapter&quot;)<br>    self.reg_block   = reg_block(&quot;reg_block&quot;)<br>  def connect_phase(self):<br>    self.reg_block.def_map.set_sequencer(self.agt.seqr)<br>    self.reg_block.def_map.set_adapter(self.reg_adapter)</pre><p><strong>Step 7: Describe the hardware to test RAL front-door write and read</strong><br>A very simple RTL is described to test RAL. In the RTL, there are 4 registers, each has 32 bits length.</p><pre>module bus_slave (<br>  input  logic        clk,<br>  input  logic        rstn,<br>  input  logic        rd,<br>  input  logic        wr,<br>  input  logic [1:0]  addr,<br>  input  logic [31:0] din,<br>  output logic [31:0] dout<br>);<br><br>  logic [31:0] regs_array [0:3];<br><br>  always_ff @(posedge clk) begin<br>    if (!rstn)  begin<br>      dout &lt;= 0;<br>    end else begin<br>      if (wr) begin<br>        regs_array[addr] = din;<br>      end else if (rd) begin<br>        dout &lt;= regs_array[addr];<br>      end<br>    end<br>  end<br>endmodule</pre><p><strong>Step 8: Write to the hardware registers using RAL front-door access<br></strong>We will use built-in read and write methods in uvm_reg class.</p><pre>status = await self.env.reg_block.reg0.write(15,self.env.reg_block.def_map,path_t.FRONTDOOR,check_t.NO_CHECK)<br>(status, rdata) = await self.env.reg_block.reg0.read(self.env.reg_block.def_map,path_t.FRONTDOOR,check_t.NO_CHECK)<br>self.logger.info(f&quot;reg model rdata: {int(rdata)} @addr: {self.env.reg_block.reg0.get_address()}&quot;)<br><br>status = await self.env.reg_block.reg1.write(25,self.env.reg_block.def_map,path_t.FRONTDOOR,check_t.NO_CHECK)<br>(status, rdata) = await self.env.reg_block.reg1.read(self.env.reg_block.def_map,path_t.FRONTDOOR,check_t.NO_CHECK)<br>self.logger.info(f&quot;reg model rdata: {int(rdata)} @addr: {self.env.reg_block.reg1.get_address()}&quot;)<br><br>status = await self.env.reg_block.reg2.write(35,self.env.reg_block.def_map,path_t.FRONTDOOR,check_t.NO_CHECK)<br>(status, rdata) = await self.env.reg_block.reg2.read(self.env.reg_block.def_map,path_t.FRONTDOOR,check_t.NO_CHECK)<br>self.logger.info(f&quot;reg model rdata: {int(rdata)} @addr: {self.env.reg_block.reg2.get_address()}&quot;)<br><br>status = await self.env.reg_block.reg3.write(45,self.env.reg_block.def_map,path_t.FRONTDOOR,check_t.NO_CHECK)<br>(status, rdata) = await self.env.reg_block.reg3.read(self.env.reg_block.def_map,path_t.FRONTDOOR,check_t.NO_CHECK)<br>self.logger.info(f&quot;reg model rdata: {int(rdata)} @addr: {self.env.reg_block.reg3.get_address()}&quot;)</pre><p>In the test, we are writing reg0, reg1, reg2, reg3, and reading respectively. We expect to read 15, 25, 35, and 45 decimals and the log is given below.</p><pre>make</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*pu_PlhUEYplLsxPCaj5ZZA.png" /></figure><p>As you can see, we are reading 15, 25, 35, and 45 decimals respectively.</p><p>If you have any questions, feel free to ask on Linkedin.<br><a href="https://www.linkedin.com/in/muhammedkocaoglu/">https://www.linkedin.com/in/muhammedkocaoglu/</a></p><p>Github Repo: <a href="https://github.com/muhammedkocaoglu/Cocotb-Examples/tree/main/pyuvm_ral_demo">https://github.com/muhammedkocaoglu/Cocotb-Examples/tree/main/pyuvm_ral_demo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bc844c0b01e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Synchronous FIFO Tester Using Cocotb]]></title>
            <link>https://medium.com/@kocamuha/synchronous-fifo-tester-using-cocotb-836008d35c36?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/836008d35c36</guid>
            <category><![CDATA[fifo]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[verification]]></category>
            <category><![CDATA[verilog]]></category>
            <category><![CDATA[system-verilog]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 18:53:34 GMT</pubDate>
            <atom:updated>2022-11-19T20:08:33.639Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I installed <a href="https://github.com/cocotb/cocotb"><strong>cocotb </strong></a>on my computer and tried the examples provided in the cocotb package under <a href="https://github.com/cocotb/cocotb/tree/master/examples"><strong>examples folder</strong></a>. The examples include adder, matrix multiplier simple_dff, etc. These are very helpful in understanding the python code written to test the SystemVerilog or VHDL modules. Cocotb is free and open source. The good thing about Cocotb is the language we are using which is python. The community is growing and more libraries to verify HDL designs will be available. So I thought it would be helpful for me if I learn Cocotb.</p><p>If you want to install Cocotb on your computer there are a few prerequisites you must install. The prerequisites are given on the Cocotb <a href="https://github.com/cocotb/cocotb"><strong>Github</strong> </a>page. <a href="https://medium.com/u/bcb5840fe7b2">Adam Taylor</a> also has a <a href="https://www.adiuvoengineering.com/post/microzed-chronicles-getting-started-with-cocotb"><strong>blog</strong> </a>where you can learn the prerequisites and how to install them on your computer which is very helpful.</p><p>In this blog, we will be looking at the python code I have written to verify a synchronous FIFO. This is going to be a very basic test.</p><p>Firstly, we will be writing data to the FIFO until we see the full flag. Then we will read the data until we see the empty flag.</p><p>The data written to FIFO is also going to be written to Queue.</p><p>The FIFO ports are given below.</p><pre>module sync_fifo_rtl # (<br>    parameter DATA_WIDTH = 8,<br>    parameter DATA_ADDR = 4 // 2**4-1:0 15:0 depth is 16<br>)(<br>    input  logic                  clk,<br>    input  logic                  srstn,<br>    input  logic [DATA_WIDTH-1:0] din,<br>    input  logic                  wr_en,<br>    input  logic                  rd_en,<br>    output logic [DATA_WIDTH-1:0] dout,<br>    output logic                  full,<br>    output logic                  empty,<br>    output logic [DATA_ADDR:0]    data_count<br>);</pre><p>Let’s start writing the Python code. The libraries we need to import are given below.</p><pre>import queue<br>from cocotb.clock import Clock<br>import cocotb<br>from cocotb.triggers import Timer</pre><p>queue library is going to be used to store data which is also written to the FIFO HDL model. Then we will read it back when we read data from the FIFO and compare whether they match.</p><p>The clock is imported to generate the clock signal.</p><p>cocotb is imported to use <a href="https://docs.cocotb.org/en/stable/coroutines.html#concurrent-execution">start_soon </a>Coroutine.</p><p>timer is imported in order to wait in the tester code. We will see the usage below.</p><p>The function below is going to be used to test the FIFO. @cocotb.test() is used to access your HDL top-level design. You can access the port signals using dut.port_name syntax and its values using dut.port_name.value syntax.</p><pre>@cocotb.test()<br>async def test_fifo(dut):</pre><p>With the below code, I gave initial values to inputs and created a queue with the name q1.</p><pre>    q1 = queue.Queue()<br>    <br>    dut.wr_en.value = 0;<br>    dut.rd_en.value = 0;<br>    dut.din.value = 0;</pre><p>We can create the clock using the code below.</p><pre>cocotb.start_soon(Clock(dut.clk, 10, units=&quot;ns&quot;).start())   </pre><p>Apply active low reset to the system.</p><pre>    dut.srstn.value = 0<br>    await Timer(20, units=&quot;ns&quot;)<br>    dut.srstn.value = 1<br>    await Timer(20, units=&quot;ns&quot;)</pre><p>We generated the clock signal and applied reset to the system.</p><p>Let’s write data to the FIFO until it is full. We can do that using the code below.</p><pre>    i=0<br>    await Timer(5, units=&quot;ns&quot;)<br>    while dut.full.value == 0:<br>        q1.put(i) # this will additem from 0 to 20 to the queue<br>        dut.din.value = i;<br>        dut.wr_en.value = 1;<br>        await Timer(10, units=&quot;ns&quot;)<br>        i = i + 1;<br>        <br>    dut.wr_en.value = 0;<br>    <br>    await Timer(100, units=&quot;ns&quot;)</pre><p>The FIFO is now full. We expect that the data written to the FIFO HDL model is also written to the queue we defined.</p><p>We can now test whether the FIFO I wrote using SystemVerilog is working properly or not. We can do that using the code snippet below.</p><pre>    golden_dout=0<br>    <br>    while dut.empty.value == 0:<br>        dut.rd_en.value = 1<br>        golden_dout = q1.get()<br>        await Timer(10, units=&quot;ns&quot;)<br>        print(&quot;FIFO Dout Value=&quot;,int(dut.dout.value), &quot;Queue Value=&quot;,int(golden_dout))<br>        assert dut.dout.value == golden_dout, &quot;test failed&quot;<br>        <br>    dut.rd_en.value = 0<br><br>    await Timer(500, units=&quot;ns&quot;)</pre><p>The complete python code and Synchronous FIFO code are also given in my <a href="https://github.com/muhammedkocaoglu/Cocotb-Examples"><strong>Github </strong></a>account.</p><h3>Create Make File</h3><p>The make file is required in order to test the example. I gave the content of the make file below. This is a modified make file of examples in the Cocotb package.</p><pre>TOPLEVEL_LANG ?= verilog<br><br>PWD=$(shell pwd)<br><br>export PYTHONPATH := $(PWD)/../model:$(PYTHONPATH)<br><br>ifeq ($(TOPLEVEL_LANG),verilog)<br>    VERILOG_SOURCES = $(PWD)/sync_fifo_rtl.sv<br>else ifeq ($(TOPLEVEL_LANG),vhdl)<br>    VHDL_SOURCES = $(PWD)/sync_fifo_rtl.vhd<br>else<br>    $(error A valid value (verilog or vhdl) was not provided for TOPLEVEL_LANG=$(TOPLEVEL_LANG))<br>endif<br><br>TOPLEVEL := sync_fifo_rtl<br>MODULE   := test_fifo<br><br>include $(shell cocotb-config --makefiles)/Makefile.sim<br></pre><p>Lastly, open the anaconda terminal to run the example and see the result. First go to the directory where you put your make file, python code, and HDL file. You can change the directory from C to D disk using the command below.</p><pre>cd /d d:\    % change from C to D<br>cd D:\Desktop\cocotb\cocotb\examples\mixed_signal\tests % go to the directory you want</pre><p>Once you are in the directory of your project, now you can run the make command on the anaconda terminal.</p><p>I am using the ModelSim simulator, you can change it to the simulator you are using. I also want to see the Waveform so I made GUI=1.</p><p>In this example, we are using Verilog.</p><pre>make SIM=modelsim clean<br>make SIM=modelsim GUI=1 TOPLEVEL_LANG=verilog</pre><p>The Waveform is given below. The clock and reset signals are generated properly. Write and read operations are also successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*dOEaWG3hG2gOpft98f7BnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*4PJylYHphJyy7BJI0lOZqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*DSr0GMsxaSe8kSVupeKArw.png" /></figure><p>References:</p><p><a href="https://github.com/cocotb/cocotb">https://github.com/cocotb/cocotb</a></p><p><a href="https://www.adiuvoengineering.com/post/microzed-chronicles-getting-started-with-cocotb">https://www.adiuvoengineering.com/post/microzed-chronicles-getting-started-with-cocotb</a></p><p><a href="https://www.adiuvoengineering.com/post/microzed-chronicles-cocotb-and-axi">https://www.adiuvoengineering.com/post/microzed-chronicles-cocotb-and-axi</a></p><ul><li><a href="https://dornerworks.com/blog/install-cocotb-on-windows-10-to-boost-fpga-verification-productivity/">Install Cocotb on Windows 10 to Boost FPGA Verification Productivity - DornerWorks</a></li><li><a href="https://docs.cocotb.org/en/latest/library_reference.html#cocotb.clock.Clock">Library Reference - cocotb 1.7.2 documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=836008d35c36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dual Port (Asyncronuous) FIFO Design Part 1: Synchronizing asynchronous reset for write and read…]]></title>
            <link>https://medium.com/@kocamuha/dual-port-asyncronuous-fifo-design-part-1-synchronizing-asynchronous-reset-for-both-domains-6186f2896b1d?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/6186f2896b1d</guid>
            <category><![CDATA[vhdl]]></category>
            <category><![CDATA[fpga-design]]></category>
            <category><![CDATA[fpga]]></category>
            <category><![CDATA[clock-domain-crossing]]></category>
            <category><![CDATA[fifo]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Wed, 14 Sep 2022 20:31:40 GMT</pubDate>
            <atom:updated>2022-09-14T21:02:22.738Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dual Port (Asyncronuous) FIFO Design Part 1: Synchronizing asynchronous reset for write and read clock domains</h3><p>Clock domain crossing is one of the most challenging topics in digital design for me. It took me a while to really understand it.</p><p>One of the ways to handle clock domain crossing is Asyncronuous FIFO. In the following few blogs, I will show you how we can design an asynchronous FIFO using VHDL. The series will cover the following topics:</p><p>1- Synchronizing asynchronous reset</p><p>2- Crossing pointers from the write domain to the read domain and from the read domain to the write domain</p><p>3- Gray encoding and its advantages</p><p>4- Converting binary encoding to gray encoding to decrease the probability of metastability</p><p>5- Calculating the data count for the read and write domain</p><p>6- Determining empty and full signals</p><p>7- Writing testbench for dual port FIFO</p><p>7- Adding time constraints for the read and write domain clocks</p><p>8- Implementation step in Vivado to see the negative slack</p><p>9- Solving the negative slack problem in Vivado</p><p>10- Adding AXI interface to dual port FIFO</p><p>11- Using the FIFO with MicroBlaze</p><p>In the first part, I will show you how we can synchronize asynchronous reset. When I am working with multiple clock domains I prefer using asynchronous reset and synchronizing the reset for all domains separately.</p><p>When there is an asynchronous signal entering our domain, we should always synchronize and stabilize the signal before using it to decrease the probability of metastability. If we don’t stabilize the signal and the signal change occurs too close to the next clock trigger the flip-flop may go metastable.</p><p>I use active-low reset in my designs and recommend you be consistent in the use of active-high or active-low reset. Let’s see an example VHDL code of reset synchronizer for read and write domains.</p><p><strong>Write Clock Domain:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*_wrrGP3Mkcw2M1pWybx-zA.png" /><figcaption>Stabilize reset for write domain</figcaption></figure><p>wr_rstn_n is the signal that will be used to reset the write domain. When we apply reset, wr_rstn_n1, wr_rstn_n2, and wr_rstn_n go low, and once rst_n goes high, the system is reset and in the third clock, the system becomes active in the write clock domain. <strong>wr_rstn</strong> is now synchronized with <strong>wr_clk</strong> and can be used in the write clock domain safely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*frZ3uCPMTkDSE-FU6h8iLA.png" /><figcaption>Reset synchronization for write domain</figcaption></figure><p><strong>Read Clock Domain</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*hO1VBmjVzAMu4hG_OlFfQQ.png" /><figcaption>Stabilize reset for read domain</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*md_40aFliCCG2kHhLBw7IQ.png" /></figure><p>Note that the wr_rst_n and rd_rst_n signals go high at different times. Consequently, the write and the read domain become active at different times since the frequencies are different. I will not care about that in the dual port FIFO design but that is of course something we should consider.</p><p>The schematic of the synchronized reset is shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3anfTKRmHjZzauq2Tt1ZFw.png" /></figure><p>LinkedIn: <a href="https://www.linkedin.com/in/muhammedkocaoglu/"><strong>https://www.linkedin.com/in/muhammedkocaoglu/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6186f2896b1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Doubly Linked List in VHDL for testbenches]]></title>
            <link>https://medium.com/@kocamuha/doubly-linked-list-in-vhdl-for-testbenches-dcebd82dfd2e?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcebd82dfd2e</guid>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Wed, 03 Aug 2022 19:45:56 GMT</pubDate>
            <atom:updated>2022-08-03T19:47:16.962Z</atom:updated>
            <content:encoded><![CDATA[<p>Linked list is the second most-used data structure after array in software. Implementing it in VHDL requires a dynamic memory allocation concept that is access type. Thanks to OSVM/UVVM libraries, they are already implemented and can be found as open-source. They are easy to use and I used them to simulate a FIFO I designed.<br>It actually took me a while to really understand how allocating memory dynamically works and how linked lists are implemented in these libraries. I implemented a doubly linked list to really understand the concept. The doubly linked list I created supports these methods:</p><p>push_back,<br>push_front,<br>pop_back,<br>pop_front,<br>is_empty,<br>get_count,<br>print_count,<br>init_linked_list</p><p>In the design I used;</p><p>protected type,<br>record type,<br>access type for allocating memory dynamically,<br>procedure,<br>impure function,<br>procedure/function overloading,<br>package</p><p>I have also written a test bench to show how the type I created can be used in a test bench environment. Next time I may show how a simple synchronous FIFO can be simulated using the package I created.<br>You can see the codes I have written in my Github account.</p><p>LinkedIn</p><p><a href="https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/">https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcebd82dfd2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fully Pipelined Generic Edge Detector Algorithms Using VHDL]]></title>
            <link>https://medium.com/@kocamuha/fully-pipelined-generic-edge-detector-algorithms-using-vhdl-47bf4425c55b?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/47bf4425c55b</guid>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[fpga]]></category>
            <category><![CDATA[vhdl]]></category>
            <category><![CDATA[image-processing]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Sun, 16 Jan 2022 10:12:22 GMT</pubDate>
            <atom:updated>2022-01-16T18:03:30.162Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we will see different types of edge detector algorithms implemented in VHDL. As you can see in the figure below, these are Sobel, Prewitt, Scharr, and Roberts edge detector algorithms. The core I have designed is fully pipelined. The latency is 5. After 5 clocks, it produces output at each clock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*U63QhvXN87xV3i6TgaCG6A.png" /></figure><p>The basic thing in all edge detection algorithms is the same, convolution. In my previous post, I explained the convolution process. That’s why I will not go through it again in this post. You can see my previous post <a href="https://medium.com/@kocamuha/implementing-sobel-edge-detection-filter-using-vhdl-d852d5cd9440"><strong>here</strong></a>. I will only show you the coefficient I have used.</p><h4>Sobel Operator</h4><p>The kernel size of the Sobel operator is 3. There are 2 coefficients, one of them is in the x-direction, and the other one is in the y-direction. These are;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*6PJSqm_Sb0_W3ib5Rrk1Qw.png" /></figure><p>Note that these constant values will be cast to signed values in the state machine. The result of the Sobel operator is shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*3Ke5KuETQxnY9d1kaWs6Nw.png" /></figure><h4>Prewitt Operator</h4><p>The kernel size is 3 and the values are shown in the figure below. The coefficients will be cast to signed values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*ej65Igq9HiJJVqvBwZNF7Q.png" /></figure><p>The result of the Prewitt operator is shown in the figure below. It is very similar to Sobel&#39;s result but if you look carefully, you can see the differences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*d20p-s9w_rwGeliXSvoDIQ.png" /></figure><h4>Scharr Operator</h4><p>The Scharr operators are shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*6NdRI-VsE5DlXx_t4Jpjuw.png" /></figure><p>The result is shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*1B6vEU4CRqz6NUQQIaZIbQ.png" /></figure><h4>Roberts Operator</h4><p>Lastly, we will see Roberts edge detector. This is different from the previous edge detector algorithms. The kernel size in the previous operators was 3.</p><p>This time the kernel size is 2.</p><p>The coefficients are shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*vio0F50DP3TYC85r6OIDWQ.png" /></figure><p>The result is shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*LUfCIAFdvfUO0iXJEKzzLw.png" /></figure><h4>The case-generate statement in VHDL</h4><p>In this project, I have learned a new concept in VHDL that is the case-generate statement. Let me also explain it to you. The case-generate statement is very similar to the if-generate statement. These are equivalent to ifdef in C/C++.</p><p>In VHDL if you have many components and if you want to generate only the ones you want you can use the if-generate or the case-generate statements.</p><p>For example, in this project, I have 4 different components and I only want to generate the hardware of one of them according to selection in the top module. Let me further explain by showing you the code.</p><p>In the top module, you choose the edge detection type you want. In that case, it is Sobel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*HkFIXQf8a2J8pSLEa4OvIA.png" /></figure><p>Let’s see the remaining code. If “0” is selected only the hardware of the Sobel filter is generated. If we choose 1, only the hardware of the Prewitt filter is generated, and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*1MhFBYYJ8EsOwcNF0EmwRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*VQaYGO-Rj2s9rZd6B2i4uA.png" /></figure><h4>The resource utilization</h4><p>As you see, the core is lightweight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*a-gB7CzzK7Fi_ZKkC7HJyQ.png" /></figure><p>The complete code can be found at my <a href="https://github.com/muhammedkocaoglu/Fully-Pipelined-Edge-Detector-Algorithms-Using-VHDL"><strong>Github </strong></a>account or at <a href="https://opencores.org/projects/fully-pipelined-edge-detection-algorithms"><strong>opencores.org</strong></a></p><p>You can reach me via <a href="https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/"><strong>LinkedIn</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47bf4425c55b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generic FIR Filter Using Floating-Point IP in Vivado]]></title>
            <link>https://medium.com/@kocamuha/generic-fir-filter-using-floating-point-ip-in-vivado-82622a0e8f3?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/82622a0e8f3</guid>
            <category><![CDATA[xilinx]]></category>
            <category><![CDATA[ip]]></category>
            <category><![CDATA[vhdl]]></category>
            <category><![CDATA[filters]]></category>
            <category><![CDATA[floating-points]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Sun, 09 Jan 2022 15:25:47 GMT</pubDate>
            <atom:updated>2022-01-10T05:24:06.633Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will be showing you my FIR filter design using floating-point IP in Vivado.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*ahbXM55q8WzUb86BZ7STpw.png" /></figure><h4>Floating Point IP</h4><p>Xilinx provides us with floating-point IP. The IP offers addition, subtraction, accumulation, multiplication, fused multiply-add, division, etc. In this project, I will use fused multiply-add. That will be enough for FIR filter implementation.</p><p>With the IP, I can multiply a coefficient with the input signal and then add the previous result. Actually, this is all we need to do in order to implement the FIR filter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*lHLODmQ38r8q1sLqqhPOUQ.png" /></figure><p>In the figure below, you can see the operation I selected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*ssaqBvCQNY7LBXBURuXm-g.png" /></figure><p>I configure the IP as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_PV-aWauxx2ZfzgP2YuivQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*Eci948nq1QGHg4YiS2qCpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*8ZoUnq_FpNb_IPp_oIIFcg.png" /></figure><p>Then I instantiated the IP to my module as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*NYgk3Dw8DPRAittbcEKY8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*DFu9a8pCcroRxmdYv6-5tQ.png" /></figure><h4>Storing the Coefficients in Block RAM</h4><p>I stored the single-precision coefficients in block ram. I have written the module inferring block ram in Verilog HDL. I will also show you how you can instantiate the Verilog module to the VHDL module. With the Verilog code below, you can infer a block ram with an initialization file. In the file, we will store the coefficients and the RAM will be initialized with the coefficients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*f21XNCOkciSjeVdq_wojPQ.png" /></figure><h4>FIR Filter Implementation</h4><p>In the figure below, you can see the generic and port parameters. The file address where we initialize the BRAM from and the tab size must be given. The Addr_Width will be calculated from tab size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*cmxhEkM_MdsbpPzG3zumCg.png" /></figure><p>Then we instantiate the Verilog module. Normally, we can instantiate a module using the syntax below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*cxsH04dclNY9zcsJtAT7eg.png" /></figure><p>However, this is not possible with mixed-language. If you want to utilize mixed-language support, you need to declare it as a component first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*YBAxMRtNbHqnUYKprLJ_Eg.png" /></figure><p>Now, we can instantiate the Verilog module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*kURBqakDgErhh1Cj6msKHA.png" /></figure><p>After that, we are ready to write the state machine. There are 3 states. In the first state, we shift the incoming signal to the data buffer and initialize signals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*XaaqdOjQZ9XyW-dHeXXJmQ.png" /></figure><p>In the next state, we initialize fuse multiply-add operation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*kRaM0CkIkeSdUUmi5AzeZg.png" /></figure><p>In the last state, we wait for the operation to be completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*PaasEEwMY03KXTOck_u-zg.png" /></figure><p>The resource utilization for 63 tabs is shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*VUDNoOetZRsEKePom4_H7w.png" /></figure><p>The complete code can be found in my <a href="https://github.com/muhammedkocaoglu/User-Configurable-FIR-Filter-Using-VHDL">Github </a>account. I also added noisy signal, coefficients I used. The sampling frequency is 10k Hz. Fpass is 800 Hz. Fstop is 1.2k Hz. The order of the filter is 63.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35GUKeLdfflqXdJ-lrZlUA.png" /></figure><p>The noisy and the filtered signals are shown in the figure above.</p><p>You can configure the order of the FIR filter as you wish.</p><p><a href="https://github.com/muhammedkocaoglu/User-Configurable-FIR-Filter-Using-VHDL">Github</a></p><p><a href="https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/">Linkedin</a></p><p><a href="https://youtu.be/CV8-LRrnx5s">Youtube</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82622a0e8f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Operator Overloading in VHDL]]></title>
            <link>https://medium.com/@kocamuha/operator-overloading-in-vhdl-670e3d0c2b20?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/670e3d0c2b20</guid>
            <category><![CDATA[operator-overloading]]></category>
            <category><![CDATA[fpga]]></category>
            <category><![CDATA[vhdl]]></category>
            <category><![CDATA[multidimensional-arrays]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Sun, 02 Jan 2022 18:12:26 GMT</pubDate>
            <atom:updated>2022-01-02T18:12:26.373Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we are going to see how you can overload 2 multidimensional arrays in VHDL.</p><p>When I work with C++, I often use operator overloading. There are many built-in implementations, for example, commonly used I when I work with STL libraries. With the STL library, you can add 2 vectors with a simple plus sign.</p><p>During my implementation of a filter in VHDL, I needed to overload 2 arrays which I did with for loop. However, I thought there must be a way of overloading 2 arrays with a simple plus sign in VHDL. Then I came to realize that, there are also many operator overloading functions in VHDL that are commonly used. For example, we add 2 std_logic_vector, this is also operator overloading.</p><p>What I did at this point was to go to the libraries of Synopsis, and IEEE that are found in your Vivado installation directory. I analyzed them and learned how they are implemented.</p><p>First, I created a package with the name OperatorOverloading_pkg and defined function prototypes. In the figure below, you can see the functions I have implemented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*AAVDcYR_0zu_WqVjPMQF9g.png" /></figure><p>In the first function, I overload 2 2D arrays, and in the second 2 3D arrays. array2d and array3D are user-defined data types and can be seen in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*J6TGRMrFCCTtkT0JCaqdCg.png" /></figure><p>Now, let’s see the function implementation of some of the prototypes that are defined in the package.</p><p>In the figure below, there are 2 inputs with type array2D, and the addition is realized in for loop in a single clock cycle. Here we need to determine the depths of array elements and can be determined as shown in the figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*u-tp02efmJ9OJb55-KwK3w.png" /></figure><p>Now, let’s see how 3D arrays can be overloaded. Instead of 1 for-loop, we need 2 nested for loops to perform addition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*kmPVh01qcE52HCS_n8xcAg.png" /></figure><p>Let’s see multiplication. In multiplication, the length return values are different from the input length. If we are multiplying 2 1 bytes, the result becomes 2 bytes. In the figure below, we can see how I determined the length of the array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*5RFY_YUg8UrU0P4DYuFhwg.png" /></figure><p>Finally, I will show you concatenate operator where I concatenate 2 arrays in a single clock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*NTeis3nsgOthfvU0TibBJg.png" /></figure><p>After we have seen the function implementation, let me show you the simulation results. The inputs are shown in the figure below, I will perform my function implementation on them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*3y6gab8zfQN3h2005Epnog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*dpPL-cIIpmhLy1y53MAOFQ.png" /></figure><p>If we concatenate 2 arrays, the result becomes as shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*2Z0Rb70IoakqOhXyob4Fww.png" /></figure><p>Now, let’s add 2 arrays.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*9e8M0SLa1cN30vCJqma4zA.png" /></figure><p>The important point is here whether this property is synthesizable or not. Let me synthesize and see the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*BQQphoHQNM0isivneCEXeg.png" /></figure><p>Yes, it is synthesizable. The figure above is the resource utilization for the addition of 2 3D arrays.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*jaxtvMxLMETaJIK2OyVJXQ.png" /></figure><p>The complete package, an example application, and a test bench can be found <a href="https://github.com/muhammedkocaoglu/Operator-Overloading-in-VHDL">at this link</a>. You can add many more functions if you need them.</p><p>If you have any questions, you can ask me on Linkedin.</p><p><a href="https://github.com/muhammedkocaoglu/Operator-Overloading-in-VHDL">Github</a></p><p><a href="https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=670e3d0c2b20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Sobel Edge Detection Filter Using VHDL]]></title>
            <link>https://medium.com/@kocamuha/implementing-sobel-edge-detection-filter-using-vhdl-d852d5cd9440?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/d852d5cd9440</guid>
            <category><![CDATA[microblaze]]></category>
            <category><![CDATA[edge-detection]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[vhdl]]></category>
            <category><![CDATA[sobel-filter]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Sun, 26 Dec 2021 17:19:46 GMT</pubDate>
            <atom:updated>2021-12-27T05:25:52.648Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*igVLcqVXXmC9tPgCJgrv8g.png" /></figure><p>In this post, we will see the implementation of Sobel Filter using software and firmware.</p><p>I first implemented the algorithm using a software language. Then I implemented it using VHDL and compared the results with a self-checking test bench. After verifying my design, I created and packaged it as IP with an AXI-Lite interface in order to use it with a Microblaze processor.</p><p>I created a block design and added Microblaze, UART IP, DDR3 SDRAM IP, and lastly my Sobel Filter IP to the system. After validating the result, I generated bitstream and exported the hardware for further use in Vitis. You can see how the system looks like in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*9pvyjp39-V7FMlJbr4aOMg.png" /></figure><h4>Sobel Filter Algorithm</h4><p>In this title, I will explain the algorithm. The algorithm is very straightforward in software. Different from Gaussian Filter there are coefficients in the x and y-directions. The yellow part is first convolved with coeff_x and obtained a value. Then it is convolved with coeff_y and obtained a value. Lastly, the final value of the blue pixel is calculated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*XYzLzsiboNMdmx5-kgN1DA.png" /></figure><p>The blue pixel is calculated with the formula below. The advantage of using VHDL is parallelization. Since the multiplication is an independent operation, we can multiply all the yellow pixels with coefficients in a single clock cycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*w918wrV6IO6Q6u28p-X4vg.png" /></figure><h4><strong>VHDL Implementation</strong></h4><p>Let me now show you how I wrote RTL of the Sobel filter algorithm and how I added AXI Lite IP to my design.</p><p>In the figure below, you can see the input and output ports of the design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*fku2Kb8yG9Zu55yLxU1E5w.png" /></figure><p>In the entity, the filter start triggers the system to start filtering. Filter busy is 0x55 as long as the filtering is in progress. Otherwise, it is 0x44. Filter_data_o_x is the value of the filtered pixel in the x-direction and Filter_data_o_y is the filtered pixel in the y-direction. Even though I don’t need them in the final stage, I added them because I checked them in the verification step. Filtered_data_o is the filtered pixel value.</p><p>filter_data_i is the input image.</p><p>filteredPixelReady signal tells you that the filtering has been completed.</p><p>Let’s analyze the code in detail.</p><p>When it is in the IDLE stage, wait for filter_start input to be 0xab. Once it becomes 0xab, it shifts in the incoming data and starts filtering. Filtering starts by multiplying the coefficients with the 3x3 array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*Cgge2Kw4l2pqb2tA8gqnqg.png" /></figure><p>the coefficients in the x and y direction are given below. they have 1 byte signed values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*P9uHVG_UYQH8Wo2ealnOJA.png" /></figure><p>The multiplication is performed in a single cycle parallelly for the x-direction and y-direction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U4ua8K9fE03xHN_yCPQuXg.png" /></figure><p>After the multiplication step, the addition step comes. We add each element of the matrix and obtain the filtered value in the x and y-direction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zU3wv3l8FudqFZyJ1uyDKg.png" /></figure><p>Lastly, we calculate the filtered pixel value using the calculation below. In VHDL, the square root operation is difficult. That’s why I prefer to do it in Microblaze.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*w918wrV6IO6Q6u28p-X4vg.png" /></figure><h4>Adding AXI-Lite Interface to the design</h4><p>AXI-Lite interface lets us connect it to a processor. Since we use MicroBlaze, we need to add the AXI-Lite interface. From tools menu, we can create and package IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*-DBW1-1qE4GLTh9IGk5fzQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*bgov8OnQH5C229x1M0pY3Q.png" /></figure><p>In the figure below, you can see how I connected my inputs to the registers. In the least significant byte of slv_reg0, I store the trigger signal. In the least significant 3 bytes of slv_reg1, I store input image. In the filter_data_o_Reg, I store the output obtained using my RTL implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*91G0w_aJnblGqU60ShwPpQ.png" /></figure><p>After connecting the ports to AXI peripheral, we can package the IP and add it to the Microblaze processor.</p><p>Lastly, I created an HDL wrapper, generated bitstream, and exported the hardware for further use in Vitis.</p><h4>Creating a project in Vitis and writing C code</h4><p>In the processor part, I stored the image in DDR3 SDRAM and performed the convolution part in the PL part. I actually accelerated the algorithm using FPGA.</p><p>A gray image with size 640x480 is stored in DDR. The filtered pixels are transmitted to the host PC through the UART protocol.</p><p>In C language, we need to send the image to FPGA in order to filter. You can see how we can send it to FPGA. ipSobelAddr is the base address that stores the trigger signal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*12jhnA0kCUjvWL8As8qPLg.png" /></figure><p>We can now get the filtered value and transmit it to PC through UART. In the figure below, I show how we can do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*TM_LMfeHqJ9Fz5LuqjxGXg.png" /></figure><p>When we program the FPGA from Vitis and connect a serial terminal to the FPGA, the filtered data will be transmitted to the PC. <a href="https://youtu.be/uIkAXSV5x3g">In this link</a>, you can see how the filtered data is transmitted to PC.</p><h4>Reconstructing and Visualizing the Image</h4><p>We can do reconstruction and visualizing of the image in Matlab or Octave. The data transmitted to the PC is 32*640*478 bits and in 1D format. We need to convert it to a 2D format to see a meaningful image. When I do that, I obtain the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8b0CrRyhVVZvuxbxGZMZ-w.png" /></figure><p>Let me now do it for another image and see the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*lf6bSkh7h9_DcFAUSnYuOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*AjcCSH00vmnqyBI0Zi1bKQ.png" /></figure><p>Github: <a href="https://github.com/muhammedkocaoglu/Sobel-Edge-Detection-Using-VHDL-and-FPGA">https://github.com/muhammedkocaoglu/Sobel-Edge-Detection-Using-VHDL-and-FPGA</a></p><p>LinkedIn : <a href="https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/">https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/</a></p><p>Youtube : <a href="https://www.youtube.com/watch?v=uIkAXSV5x3g">https://www.youtube.com/watch?v=uIkAXSV5x3g</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d852d5cd9440" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gaussian Filter Using Vitis HLS]]></title>
            <link>https://medium.com/@kocamuha/gaussian-filter-using-vitis-hls-5ddac5159ef1?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ddac5159ef1</guid>
            <category><![CDATA[hls]]></category>
            <category><![CDATA[verification]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[high-level-synthesis]]></category>
            <category><![CDATA[vhdl]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Sat, 18 Dec 2021 12:53:39 GMT</pubDate>
            <atom:updated>2021-12-19T07:37:09.498Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*22DZlf8WSYWCprWla1Zhqg.png" /><figcaption>Venice, grayscale and filtered image</figcaption></figure><p>In my <a href="https://medium.com/@kocamuha/implementing-gaussian-filter-by-using-vhdl-to-blur-images-8bc40d95fff3">previous post</a>, I implemented the Gaussian filter by using VHDL with 2 different methods. In the first method, I used floating-point which was very slow. In the second method, I used integers where the coefficients were extended by 4096 and this process enabled me to use integer multiplication and addition in my module. This time, I used Vitis HLS to implement the Gaussian filter by using integers. I verified this design by writing a test bench in the Vitis HLS and in Vivado. The results came out to be better than I expected. In my previous work, latency was 8 cycles(shift, multiply, add). This time these steps took only 5 cycles. Let’s continue with the C++language implementation of the algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*V5oZeJ9c3cILvAUNmpPQqg.png" /></figure><h4>Synthesible C++ Implementation</h4><p>In the C++ implementation, I made the steps of the algorithm concurrent as much as I can. I achieved a faster module than RTL implementation with less LUT, FF, and more DSP resources.</p><p>I will explain software implementation briefly but you can analyze the source codes from <a href="https://github.com/muhammedkocaoglu/Gaussian-Filter-Implementation-Using-Vitis-HLS">this link</a> in detail. In the figure, you can see the inputs and output of the filter function. We will feed the function with 5 inputs in type ap_uint&lt;8&gt; as it was in RTL. The function will produce 4-byte output in type ap_uint32&gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*iYar58jMeP9SQJgOaS-63A.png" /></figure><p>And these are coefficients of the Gaussian filter. These are multiplied by 4096.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*8jsXTvcw2YCS76a4y6-FJg.png" /></figure><p>The inputs of the function will be placed in the first column of the static array and the array will be shifted to the right each time we receive data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*5pd0CsgPpVGi-mQy5QaLzg.png" /></figure><p>Then, the multiplication is performed concurrently. Here in the photo, you can see the concurrent implementation of multiplication. I used pragma UNROLL to implement it concurrently. this can be thought of as a for-generate or for-loop statement in VHDL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*gW7mxmZxYcH878bt5MUx9Q.png" /></figure><p>After the multiplication is performed, now it is time to add all elements of the array. I implemented addition concurrent as well and it took 6 stages to complete addition.</p><p>In the figure below, you can see the first stage of the addition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*eSnZgvpMaTozgVK_a2FOhg.png" /></figure><p>Let me explain what I have tried to achieve in the figure above. In stage 1, first and fourth row, second and third rows are added concurrently. We continue this process up to the point where only a single box remains. We expect that only the addition will be completed in 6 cycles. However, the complete filtering of a pixel (multiplication and addition) is completed in 5 cycles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*LTIqkWSLQKLX1GV9pNA-Iw.png" /></figure><p>The tool somehow optimized the process. I couldn&#39;t figure out how the complete filtering was completed in 5 cycles. If you can figure it out, let me know:)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*MW96Xx6iIzFZHK--Zq-K7Q.png" /><figcaption>Addition stages</figcaption></figure><p>After the sixth stage, we return the value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*hG8uuf1SvgImLLYK_96kVA.png" /></figure><h4>Resource Utilization</h4><p>In this project, I achieved a faster module with fewer LUT and FF resources but with more DSP sources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*-ns1Cr4Z-SHTPi9V54OSMg.png" /><figcaption>RTL implementation using floating-point</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*usNSCpYtspA1paAoP40c9A.png" /><figcaption>RTL implementation using integers</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*HEh65FBxjWe2EjVfwfxLCw.png" /><figcaption>Vitis HLS implementation with integers</figcaption></figure><p>Now let me synthesize and implement in Vivado to see the resource utilization of generated IP in Vitis HLS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*y1I65VJbza6dfvkAfGRQvA.png" /></figure><p>The resource utilization that Vivado shows us and Vitis HLS shows us is different. In Vivado, it uses even more DSP but fewer LUT and FF. We can conclude that what Vitis HLS tells us may differ in implementation in Vivado.</p><h4>Test bench in Vitis HLS for verification</h4><p>Now, it is time to write a test bench. If you remember from the previous post, by using software, I obtained raw data and filtered data. In the test bench, we will compare the results and determine whether the function is working as we want.</p><p>We first read the raw and golden data from a file. Failure is false by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*KxOdrZwdl48pVL8U8EXg0w.png" /></figure><p>As you can see, we calculate the filtered pixel with the written function and compare. If they do not match, failure becomes false and we break the loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W22R_onqwaE3clTpraDldQ.png" /></figure><p>At the last path, if the failure remains false, that means we detected no mismatch in the complete data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*Z2mIbBmUgWpsHW7m-In8GA.png" /></figure><p>After the verification step, we can now export the design so that we can use it as an IP in Vivado.</p><p>Here is the generated IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*JgWL8in0FhLAS4OtKKaqHg.png" /></figure><p>What I intend to do now is to write a top module for this IP by which I can feed this IP serially with the UART module so that I can run it on my Arty 7 FPGA Board.</p><h4>Transmit data serially to FPGA using UART</h4><p>The figure below shows me the input-output signals. The FPGA will receiver serial data and deserialize it. When it receives 5 bytes of data, will begin the filtering which will take 5 clock cycles. Then filtered data which is 4 bytes will be transmitted to PC back. The UART transmitter and receiver modules I used are verified and can be found <a href="https://github.com/mbaykenar/apis_anatolia/tree/main/VHDL_ile_FPGA_PROGRAMLAMA/ders22">in this link</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*kEw5GOk-wURpCVYJ_qUzZA.png" /></figure><p>Now, let me show you the processes that I have written to receive serial data, filter the received data, and lastly transmit the filtered data.</p><p>The figure below shows the receiver part of the code where we receive 5 bytes of data. When we receive 5 bytes of data we start the same process again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*nkIxm2RX1r4-PsqMx3bxbA.png" /></figure><p>Now let’s see the process that is working in parallel with the process above. We are using RS232 physical protocol and that allows full-duplex communication.</p><p>In the figure below, we wait for the filtering to be completed and then transmit the data to PC back. When the <strong>ap_ctrl_0_ready </strong>signal becomes 1, we understand that the filtering is completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*3Dsfzn4yFcBZW8xo6cJUoA.png" /></figure><p>You can see the complete code in <a href="https://github.com/muhammedkocaoglu/Gaussian-Filter-Implementation-Using-Vitis-HLS"><strong>this link</strong></a> as well.</p><p>After generating the bitstream, I will download the bit file to FPGA and test my codes on hardware.</p><p>In the figure below, I have transmitted 25 bytes of data. Once the FPGA receives 5 bytes of data, it filters and transmits the 4 bytes of filtered data. For 25 bytes I expect 5 filtered data(20 bytes).</p><p>In the figure below, we can see the results. I used Hterm serial terminal to transfer data between FPGA and my Host PC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*4MxuoH4W4ND9j-KdyRoRAA.png" /></figure><p>In the figure below, you can see the result obtained from hardware in FPGA and the result obtained in software. They match.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*WIitq_0-Y_l_Y6Ln1Bb1iw.png" /></figure><p>Now, let me filter another image different from the cameraman to see the result with generated IP in Vitis HLS as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNTkHU0ZKw8JJkJdqQKbOw.png" /><figcaption>Prague, 2019</figcaption></figure><p>This is a photo of me taken in Prague in 2019. As you see, it is blurred as we expect. The test bench of this filtering is also given in my Github account.</p><h4>Github:</h4><p><a href="https://github.com/muhammedkocaoglu/Gaussian-Filter-Implementation-Using-Vitis-HLS">https://github.com/muhammedkocaoglu/Gaussian-Filter-Implementation-Using-Vitis-HLS</a></p><h4>LinkedIn:</h4><p><a href="https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/">https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/</a></p><h3>References</h3><p>[1] <a href="https://github.com/mbaykenar/apis_anatolia">https://github.com/mbaykenar/apis_anatolia</a></p><p>[2]<a href="https://github.com/ATaylorCEngFIET/all_about_hls/blob/master/All%20About%20HLS.pdf">https://github.com/ATaylorCEngFIET/all_about_hls/blob/master/All%20About%20HLS.pdf</a></p><p>[3] <a href="https://highlevel-synthesis.com/">https://highlevel-synthesis.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ddac5159ef1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Gaussian Filter by Using VHDL to Blur Images]]></title>
            <link>https://medium.com/@kocamuha/implementing-gaussian-filter-by-using-vhdl-to-blur-images-8bc40d95fff3?source=rss-ccca18be8a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bc40d95fff3</guid>
            <category><![CDATA[vhdl]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[fpga]]></category>
            <category><![CDATA[verification]]></category>
            <dc:creator><![CDATA[Muhammed Kocaoğlu]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 23:06:38 GMT</pubDate>
            <atom:updated>2022-10-11T13:54:43.427Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will explain the steps I followed in order to implement Gaussian Filter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*hZRyCCurWJcR7HohSLY8sA.png" /></figure><p>In this project, I have used:</p><ul><li>VHDL as a language</li><li>Jidan floating-point unit[1]</li><li>Procedure</li><li>User-defined data types</li><li>2D and 3D arrays</li><li>Self-checking test bench (assertion-based verification)</li><li>Package</li><li>for generate</li><li>for loop</li><li>pipelining</li></ul><h3>What is a Gaussian Filter?</h3><p>Gaussian filter is used in image processing in order to reduce noise, remove details, and blur images which will be shown in my result. After introducing it briefly, let me continue with the steps I followed.</p><h3>Implementing the Algorithm in Software</h3><p>I determined the coefficients using Octave. fspecian function can be used to determine. In that case, cutoff and sigma values are both 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*pguzXOcvgFhzjwwPvBtwfQ.png" /></figure><p>Here are the coefficients I obtained. As you notice, the coefficients are floating-point. We can use a floating-point unit in VHDL or extend the coefficients. Let me first go on with floating points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*dKE_gxeMHu61TYOEiaZSPg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*VH3eX4ddLcasX3fnf5lmYg.png" /><figcaption>IEEE 754 floating-point single-precision representation of coefficients</figcaption></figure><p>After obtaining coefficients, we determine the image to be filtered. I chose a very popular cameraman image. The image is in 256x256 uint8 format which means there are 252*252 points to be filtered. In this case, I ignored the edges of the image which I will explain later. The image pixels are actually represented by integer where we do not need to represent them by IEEE 754 format. However, since we converted coefficients to IEEE 754 single-precision representation, we also convert integers to floating points. num2dec function can be utilized for this purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*EjZZ1m8iC0MNiUfw1nvdqQ.png" /></figure><p>After obtaining both coefficient and image, let me explain the algorithm.</p><p>In order to find the filtered values of small rectangles, we convolve big rectangles with coefficients. At this point, I can explain why I ignored the 2 pixels in the edges. If we try to filter a corner right-upper corner, for example, there are only 9 points to be convolved with coefficients and this is not enough. If you don’t want to ignore it, then you should apply some techniques to increase the pixel number to 25. One way is to pad just zeros.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*y1-MT4KC0h3Blt0N7ly7QA.png" /></figure><p>In the figure below, we can see the problem in the edges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*t8RIN9bRIs_hK9w4O6uQFA.png" /></figure><p>The coefficient is advanced to each point and convolved. The result of the convolution is the filtred values.</p><p>First I will show you the results I obtained using software implementation. The software implementation is very simple. This code snippet can be utilized to implement the gaussian filter. VHDL implementation will not be that easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*qHpAE0limDRrNUDgO4EVAQ.png" /></figure><p>If we convolve each point and store it in a new array, the result becomes as shown in the figure below. As you notice, the image is blurred.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*TxidAkuZfS8q7PmI2_z-4w.png" /></figure><blockquote>This result is our golden result and I will use it in the <strong><em>verification </em></strong>step.</blockquote><h3>Implementing the Algorithm in Hardware using Floating Point Unit</h3><p>Now, we can continue with hardware implementation. For hardware implementation, we need 25 multiplication. Each coefficient will be multiplied by the corresponding pixel. Then we will sum them up. I divided multiplication into 5 steps. 5 pixels are multiplied in parallel with 5 coefficients. After multiplying them, I add them up. As you can see, multiplication is completed in a single step. However, the addition is completed in 3 steps. This is repeated 5 times for each pixel. After 5 times of this process, 25 coefficients are multiplied with 25 pixels. Then we obtain the filtered pixel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*isiJY80-t8zOrF8raKEUBg.png" /></figure><p>The parallel multiplication is performed using<strong> for generate</strong> and <strong>for loop</strong> statements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*MLvREOf0BxMAA2v4AIgBPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*kDZNoPrXHdRlzb534djr4Q.png" /></figure><p>gaussian_coeff is a 3D array and is defined in the package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*HGSn8rx_lfNYHWIzN_NvQQ.png" /></figure><p>Now we can write the test bench to verify the code.</p><p>The complete VHDL source is shared in my Github account. You can see the complete code as well. The Jidan floating-point unit is downloaded from Opencores.</p><h3>Verification(Self-Checking test bench)</h3><p>Here, we read from a text file and compare the result. If the difference is small enough, the simulation continues, otherwise stops and gives failure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*xgdix8P340Es4v-gbN8GHg.png" /></figure><p>FILTERDATA in the above code is the procedure. In the <strong>procedure</strong>, we give the required stimulus and wait for the completion of 5 steps. After 5 steps, the pixel’s value is ready to compare with the <strong>golden result</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*UuOeV5kgmy3Wbhg6ReLlsA.png" /></figure><p>This is performed for each pixel (for 252*252 pixels).</p><p>The complete simulation result, Golden data, raw data, and filtered data are also shared in my <a href="https://github.com/muhammedkocaoglu/Gaussian-Filter-with-VHDL-to-Blur-Images">Github </a>account. You can analyze them in detail.</p><p>When I run the simulation, it goes up to end and does not give failure which means that we have verified our design with a <strong>self-checking test bench.</strong> The report says that it compared almost 63500 pixels and all of them have matched with golden data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*gIxQNx4WqgtpATcZvbcAzA.png" /></figure><p>If we reconstruct the filtered data the result becomes the same as in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*yssLYvMTmBaNzZWL2QvVmA.png" /></figure><p>The utilization is shown in the figure below. In that case, I chose Arty 7 35T FPGA board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*7Jtcj-47eHpReq3d4W81GQ.png" /></figure><h3>Implementing the Algorithm in Hardware using Integers</h3><p>After implementing the algorithm and experiencing difficulty with it, we can implement it now using simple integer multiplication and addition. In order to achieve this, we extend the coefficient with an integer. In this case, I entended it by 4096. When we reconstruct the image we divide it by 4096 to get the correct result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*aj0AioSSifXBxIUNZfIF5g.png" /></figure><p>The coefficients become as in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*6OM9tgLD6Vqci4si8lR4wA.png" /></figure><p>After that, we do not need to use floating-point arithmetic anymore because both the pixel values and coefficients are integer values. In this way, the algorithm runs much faster.</p><p>Since we use integer multiplication, we can also use DSP resources in our FPGA. However, there is not need for this because the coefficients are constant values and FPGA do not use DSP sources when the multiplication is performed with constant. If you still want to use DSP, you should use attribute and force FPGA to use DSP resources.</p><p>In this case, we are going to multiply coefficients with pixels altogether. The multiplication of 25 coefficients with pixels will take only one clock cycle. In the previous example, we divided it into 5 to reduce resource usage. In the previous example, the multiplication process takes 15 clock cycles since we use floating points. Totaly 15*5 = 75 cycles for only multiplication. In the second method, it takes only one cycle. Here is my implementation with for loop to multiply them all together. The results are kept in a <strong>3D array</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*Gnj01VLhg_GADMpnlXKQoQ.png" /></figure><p>After multiplication, the addition comes which also can be completed in a single cycle but is very bad for timing in FGPA. That’s why I will <strong>pipeline </strong>(put extra registers) the addition. As you can see, the addition takes 5 clock cycles to complete. After the addition is completed, the filtered pixel becomes ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*Se3B4kL7sAxR5zonV-uaIw.png" /></figure><p>With the second method, the filtering is completed in 6 clock cycles for each pixel. If we run in 100 MHZ, it takes only 60 ns and the complete image is filtered in 60 * 252 * 252 ns which corresponds to 630 us.</p><p>Here is the VHDL code for the addition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*emcPlbJS4JbZ9rOJNx7GeQ.png" /></figure><p>If we run the test bench for this HDL code, the simulation again is completed without any failure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*TYMTsErcIe1J481N1y8xSg.png" /></figure><p>Now, let’s reconstruct the image from the text file and see the result. As you can see, the image was reconstructed back successfully as blurred.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*hZRyCCurWJcR7HohSLY8sA.png" /></figure><p>The resource utilization in the second case is shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*Yf5ITY3lPhxYMjjr0R1XOg.png" /></figure><p>Next time, I will try to implement the algorithm with HLS.</p><p>I will also run this code on my FPGA board. I will communicate with FPGA via UART protocol.</p><p>The codes are available in my <a href="https://github.com/muhammedkocaoglu/Gaussian-Filter-with-VHDL-to-Blur-Images"><strong>Github</strong> </a>account. You can analyze them in detail.</p><p>You can reach me via <a href="https://www.linkedin.com/in/muhammed-kocao%C4%9Flu-2b661b178/"><strong>LinkedIn</strong></a><strong>.</strong></p><p>The References:</p><p>[1] <a href="https://opencores.org/projects/fpu100">https://opencores.org/projects/fpu100</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bc40d95fff3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>