0

I am creating a stack based on the artix-7 fabric on the zynq soc. To create the stack I want to use the BRAM, I'm having a problem that the BRAM read output doesn't change, I've used BRAMS many times before (not 7-series so I may be missing something subtle) and am totally perplexed as to why it is doing this.

I filled the stack with values: 1, 2 ,3

When I then call pop successively the only value it reads out is 3 for each pop and read address (even after waiting for the one clock read delay). I have also tried with dual port rams and had the same issue, i'm sticking to single port as it simpler to try and workout what is going wrong!

I have verified the logic behavior using an array based ram which has the correct behavior. For verification I also checked the logic from this source: http://vhdlguru.blogspot.co.uk/2011/01/implementation-of-stack-in-vhdl.html.

So the issue appears to be with the BRAM, either it is not reading properly or for some reason it is writing the value 3 to all previous memory address which makes no sense as each data item is synced with a write signal and correct address.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
use IEEE.numeric_std.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
library UNISIM;
use UNISIM.VComponents.all;

-- Stack implementation for 32 bit data items using BRAM componenets
entity stack_32_BRAM is
    generic( ADDR : integer :=32);
    Port ( clk : in  STD_LOGIC;
           rst : in  STD_LOGIC;
           en : in  STD_LOGIC;
           push_pop : in  STD_LOGIC;
           data_in : in  STD_LOGIC_VECTOR (31 downto 0);
           data_out : out  STD_LOGIC_VECTOR (31 downto 0));
end stack_32_BRAM;

architecture Behavioral of stack_32_BRAM is

COMPONENT BRAM_32_1K
  PORT (
    clka : IN STD_LOGIC;
    rsta : IN STD_LOGIC;
    wea : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
    addra : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    dina : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    douta : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
    clkb : IN STD_LOGIC;
    rstb : IN STD_LOGIC;
    web : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
    addrb : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    dinb : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    doutb : OUT STD_LOGIC_VECTOR(31 DOWNTO 0)
  );
END COMPONENT;

COMPONENT BRAM_32_1K_SP
  PORT (
    clka : IN STD_LOGIC;
    rsta : IN STD_LOGIC;
    wea : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
    addra : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    dina : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    douta : OUT STD_LOGIC_VECTOR(31 DOWNTO 0)
  );
END COMPONENT;

--The read ptr is a function of the write ptr
signal stack_ptr_read, stack_ptr_write : std_logic_vector(ADDR-1 downto 0) := (others =>'0');
signal full, empty : std_logic := '0';

 signal     WEA : std_logic_vector(3 downto 0) :=(others=>'0');                      -- 4-bit input: A port write enable
 signal         addra, addrb, dinb, doutb, dina, douta : std_logic_vector(31 downto 0) := (others => '0');
 signal         rsta, rstb :std_logic := '0' ; 

 type ram is array (4 downto -2) of std_logic_vector(31 downto 0) ;
 signal mem : ram :=(others=>(others=>'0'));

begin

 ---STACK LOGIC ---

 PUSH : process (clk, push_pop, en, full, empty)
    begin
        if(clk'event and clk='1') then
        WEA <= "0000";          
            if(en='1' and push_pop = '1' and full = '0') then
                mem(to_integer(unsigned(stack_ptr_write))) <= data_in;
                WEA <= "1111";  
                dina <= data_in ;
                ADDRA <= stack_ptr_write;
                stack_ptr_write <= stack_ptr_write + 1; 
            elsif(en='1' and push_pop = '0' and empty = '0') then   
                data_out <= douta ;--
                doutb <= mem(to_integer(unsigned(stack_ptr_write - 1)));
                ADDRA <= stack_ptr_write - 1;
                stack_ptr_write <= stack_ptr_write - 1;
            end if;
        end if;
    end process;

BRAM_SP : BRAM_32_1K_SP
  PORT MAP (
    clka => clk,
    rsta => rsta,
    wea => wea,
    addra => addra,
    dina => dina,
    douta => douta
  );






end Behavioral;

Many thanks Sam

0

1 Answer 1

1

The solution entails several things:

1) You have to explicitly reset the signals with the rst port in every process. Initializing them in their declaration just doesn't cut it. The process' code with a proper reset and sensitivity list should then look like this:

PUSH : process (rst, clk)
begin
    if (rst = '1') then --supposing active-high async. reset
       WEA <= (others => '0');
       ADDRA <= (others => '0');
       dina <= (others => '0');
       data_out <= (others => '0');
       full <= '0';
       empty <= '0';
       stack_ptr_write <= (others => '0');
    elsif(clk'event and clk='1') then
       --your code

2) I understand you have several layers/tries of code here in the same place. This is messy to read. I see you are using a "mem" to hold your example (so that WEA, ADDRA, dina, etc are ignorable), but when you get back to BRAM_32_1K_SP remember to check it has 32 bits addresses which, coupled with 32 bits data, mean that you have a 32 * 2**32 bits ram... that is around 128 Gbits, typo I guess.

However, to make a clearer question you should leave only the code pertaining to the memory solution you're having a problem with.

3) your code does include some typos that you should fix, like assigning "doutb" in the process, whereas I guess you wanted to assign data_out instead:

data_out <= mem(to_integer(unsigned(stack_ptr_write - 1)));

And this is the reason why you don't see what you want at the output.

Sign up to request clarification or add additional context in comments.

1 Comment

In the end myself and my supervisor couldn't work out what was wrong, so instead i am now inferring BRAM (better for design portability as well). And yes I will admit the example I gave was messy and confused after many attempts! But thanks for your time. Sam

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.