If you are someone like me, who suddenly started using the Xilinx Vivado tool after using Xilinx ISE for a long time, then you might have noticed that Vivado currently doesn't support the Automatic testbench generation.
This is such a major disappointment for many of us. But luckily there are many online tools which does more or less the same. In this Video, I used the Doulos tool for creating testbenches for my VHDL designs. Once generated I tested the codes using the latest Vivado 2019.2 version.
This is a simple How-To video for Xilinx Vivado 2019.2 version. If you have been already using software tool then you may not need to watch this video.
Previously I had done the same for Xilinx ISE version 14.6. You can check that out here.
In this video, I am trying to show you:
How to create a new project.
Add VHDL codes to it.
Compile and simulate the codes.
Verify the code is working, after analyzing the waveform.
In there, I initialized the bram contents to zero on power up. But you can initialize it with non-zero values as well. How do we do that? It can be done with a special file, which has an extension coe.
Let me show you how this can be done with few screenshots. Note that you should first follow the instructions from the old article to set up a BRAM as per the settings given there, before proceeding with the rest of this article.
1. In the "Other options" tab in the IP settings, check the checkbox "Load Init File". To add the coe file, click on "Edit" option. Click on "Yes" when the following dialogue box opens up.
2. Type a filename. I gave the name as "bram_contents.coe". Click on "Save".
3. The following window shows up. Enter the radix of the values. Add the list of values as shown in the screenshot. Click on "Save" and then click on "Close".
4. Now click on "Ok" and then on "Generate" to generate the IP core.
5. Now we want to test whether the bram is correctly initialized. I have written the following testbench file for this.
libraryieee;
useieee.std_logic_1164.all;
--empty entity for testbenchentitytb_bramisendtb_bram;
architectureBehavioraloftb_bramis--copy paste the port declaration of the bram from the xilinx generated file.componentbram_testisPORT (
clka : INSTD_LOGIC;
ena : INSTD_LOGIC;
wea : INSTD_LOGIC_VECTOR(0DOWNTO0);
addra : INSTD_LOGIC_VECTOR(7DOWNTO0);
dina : INSTD_LOGIC_VECTOR(7DOWNTO0);
douta : OUTSTD_LOGIC_VECTOR(7DOWNTO0)
);
endcomponent;
--port signals for connecting with the bramsignal clka, ena : std_logic := '0';
signal wea : std_logic_vector(0downto0) := "0";
signal addra, dina, douta : std_logic_vector(7downto0) := (others => '0');
constant clk_period : time := 10 ns; --clock period.begin--componenent instantiation using named association.
bram : bram_test portmap(
clka => clka,
ena => ena,
wea => wea,
addra => addra,
dina => dina,
douta => douta);
--generate the clock for bram
clk_generation: processbeginwaitfor clk_period/2;
clka <= not clka;
endprocess;
--this is where we generate the inputs to apply to the bram
stimulus: processbeginwaitfor clk_period;
ena <= '1';
wea <= "0";
addra <= x"00"; waitfor clk_period;
addra <= x"01"; waitfor clk_period;
addra <= x"02"; waitfor clk_period;
addra <= x"03"; waitfor clk_period;
addra <= x"04"; waitfor clk_period;
addra <= x"05"; waitfor clk_period;
addra <= x"06"; waitfor clk_period;
wait;
endprocess;
endBehavioral;
6. Once we simulate it, we will get the following simulation waveform. You can see that the first 5 memory locations(addresses 0 to 5) are correctly initialized from 1 to 5, and the rest with zeros.
Note :- coe file has different uses. Here we used it to initialize the contents of a BRAM. For an FIR filter, we can use it to specify the filter coefficients.
I have used Xilinx Vivado 2023.2 tool for this article.
If you prefer to see this in action, watch this Youtube video I have created.
THIS ARTICLE WAS UPDATED on 18-04-2024. OLD ARTICLE USED XILINX ISE INSTEAD OF VIVADO.
BRAM(Block Random access memory) is an advanced memory constructor that generates area and performance-optimized memories using embedded block RAM resources in Xilinx FPGAs. I hope you have already gone through the Core generator introductory tutorial before. If you haven't please read those articles here.
We will be using Xilinx Vivado 2023.2 version for this. The steps should be the same in any version of Vivado, I believe. Let me guide you through the process with a series of screenshots.
1. Create a new project in Xilinx Vivado. 2. Click on IP Catalog, under flow navigator on the left pane of the software. You will see something like this on screen:
2. Type "BRAM" in the search bar and you will get a list of matching results as shown below:
3. Double click on Block Memory Generator, which is highlighted in the previous screenshot. A new window opens up where you can set the properties of the BRAM. You can check out the data sheet of the BRAM by clicking on Documentation. This is helpful in case you dont understand what these settings are. The component name can be changed as well.
4. Now we can start customizing the BRAM as per our requirements. Let me share the screenshots of the settings I have chosen.
We have customized our BRAM with the following settings:
It will be of 256 by 8 bits in size.
Algorithm will be chosen for "Low Power".
Read and write width will be of 8 bit.
You can initialize the memory with a coe file, but I have chosen them to be initialized with zeros.
5. Once done, you can click on the summary tab to verify that the settings are correctly chosen.
6. I have set the component name as "bram_test". Now click on the "OK" button at the bottom.
7. Click on "Generate".
8. The tool will generate the necessary files and will add bram_test as a new source to the project. You should be able to see the new component under "Design Sources".
9. Note that double clicking on the .xci file which is highlighted in the above image, will open the IP settings window once again. This means that anytime you can change the bram settings and regenerate the files if you want to.
10. To test the bram entity, we would need its port declaration. Meaning, we would need to know what are the input and output signals, their data type, size etc. To know this, we can click on the arrow, >, which shows the underlying vhdl file. This file contains the port definition which we can copy paste into our testbench code.
11. Next step would be to write a testbench code for testing the BRAM we just created. Create a new simulation source (tb_bram.vhd) and copy the following code into it:
libraryieee;
useieee.std_logic_1164.all;
--empty entity for testbenchentitytb_bramisendtb_bram;
architectureBehavioraloftb_bramis--copy paste the port declaration of the bram from the xilinx generated file.componentbram_testisPORT (
clka : INSTD_LOGIC;
ena : INSTD_LOGIC;
wea : INSTD_LOGIC_VECTOR(0DOWNTO0);
addra : INSTD_LOGIC_VECTOR(7DOWNTO0);
dina : INSTD_LOGIC_VECTOR(7DOWNTO0);
douta : OUTSTD_LOGIC_VECTOR(7DOWNTO0)
);
endcomponent;
--port signals for connecting with the bramsignal clka, ena : std_logic := '0';
signal wea : std_logic_vector(0downto0) := "0";
signal addra, dina, douta : std_logic_vector(7downto0) := (others => '0');
constant clk_period : time := 10 ns; --clock period.begin--componenent instantiation using named association.
bram : bram_test portmap(
clka => clka,
ena => ena,
wea => wea,
addra => addra,
dina => dina,
douta => douta);
--generate the clock for bram
clk_generation: processbeginwaitfor clk_period/2;
clka <= not clka;
endprocess;
--this is where we generate the inputs to apply to the bram
stimulus: processbeginwaitfor clk_period;
ena <= '1';
wea <= "1";
addra <= x"00"; dina <= x"A5"; waitfor clk_period;
addra <= x"04"; dina <= x"B6"; waitfor clk_period;
addra <= x"05"; dina <= x"C7"; waitfor clk_period;
ena <= '0';
addra <= x"07"; dina <= x"D8"; waitfor clk_period;
wea <= "0";
ena <= '1';
addra <= x"00"; waitfor clk_period;
addra <= x"04"; waitfor clk_period;
addra <= x"05"; waitfor clk_period;
addra <= x"07"; waitfor clk_period;
wait;
endprocess;
endBehavioral;
12. Right click on "tb_bram.vhd" and click on "set as Top".
13. Run Behavioral Simulation. You should get the following waveform:
You can verify that, when the enable signal ena is low, BRAM doesnt respond to any read or write instruction. Also, there is a 2 clock cycle delay (or latency as they call it) for reading any address from bram. This is as expected as the summary page in the IP generate window says this: "Total port a read Latency: 2 clock cycles".
Note :- What we have tried out here is a very simple BRAM. But it demonstrates how we can work with Xilinx in built IPs. The design will get complicated when you go from single port to dual port RAM's. But the basic idea remains the same. By reading the documentation supplied by Xilinx you can explore more settings used in the GUI tool. For testing purpose I have used Xilinx Vivado 2023.2. The options in the IP tool may vary slightly depending on the version you are using.
If you prefer to see this in action, watch this Youtube video I have created.