Jump to content
    

Запись в память N бит (больше 16), чтение по 16 бит

собственно само описание (для простоты тестбенча использовал инициализацию блочной памяти)

 

library ieee;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity xxx is  
       port (
    clk		  	   : in std_logic;
  rst		  	   : in std_logic;
  we           : in std_logic;
  din              : in std_logic_vector (127 downto 0);
  data_out         : out std_logic_vector (15 downto 0);
  memory_width_read         : in std_logic_vector (6 downto 0)
             );
end xxx;

architecture rtl of xxx is 

attribute ramstyle : string;

type srl_ram is array (127 downto 0) of std_logic_vector(127 downto 0);

signal ram : srl_ram :=  --(OTHERS => (OTHERS => '0'));
(
--57 bit
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110110
00000000000000000000000000000000000000000000000000110",--64
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110110
00000000000000000000000000000000000000000000000000110", 
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110000
00000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000000000000000000001111
11111111111111111111111111111111111111111111111111111", 
"111111111111111111111111111111111111111111111111111111111111111111111110110
00000000000000000000000000000000000000000000000000110"
);


--attribute ramstyle of ram : signal is "MLAB,no_rw_check";
constant mem_width_read_max_val : integer  := 128;
signal mem_width_read : integer range 0 to mem_width_read_max_val := 57;

signal cnt :  std_logic_vector (5 downto 0):= (OTHERS => '0'); 
--signal reg_mux, reg_reg_mux :  std_logic := '0';
signal reg_data_mem, reg_new, reg_old : STD_LOGIC_VECTOR(127 DOWNTO 0):= (OTHERS => '0');
signal addr_mem : STD_LOGIC_VECTOR(6 DOWNTO 0):= (OTHERS => '0');
signal bit_counter, bit_counter_reg : integer range 0 to 127 := 0;
signal slash_reg_data : STD_LOGIC_VECTOR (mem_width_read_max_val*2 DOWNTO 0 ):= (OTHERS => '0');

function prepare_bit_vector (reg_data_mem_v : std_logic_vector(127 downto 0); bit_vector_s : std_logic_vector(mem_width_read_max_val*2 DOWNTO 0 ); bit_quantity : integer range 0 to 16 ) return std_logic_vector is
variable result : std_logic_vector (mem_width_read_max_val*2 DOWNTO 0 ):= (OTHERS => '0');
variable reg_result : bit_vector (mem_width_read_max_val*2 DOWNTO 0 ):= (OTHERS => '0'); 
variable i : integer := 0;
begin

result(mem_width_read_max_val-1 downto 0) := reg_data_mem_v ( (mem_width_read_max_val - 1) downto 0) ;
reg_result := to_bitvector(result);
reg_result := reg_result sll bit_quantity;
result := to_stdlogicvector(reg_result);
--result(bit_quantity-1 downto 0) := bit_vector_s (15+bit_quantity downto 16);
i := 0;
while (i < bit_quantity) loop
	result(i) := bit_vector_s(16+i);
	i:=i+1;
end loop;

return result;
end function;

begin

    process (clk)                                                
      begin                                                        
      if rising_edge(clk) then 
         if we = '1' then                                             
     ram(conv_integer(addr_mem)) <= din;         
         end if; 
    reg_data_mem <= ram(conv_integer(addr_mem)); 
     end if;  

end process; 

data_out <= slash_reg_data(15 downto 0);

process (clk)
 begin


if rising_edge(clk) then

	if rst = '1' then
			cnt <= (OTHERS => '0');
		else

       mem_width_read <= conv_integer(memory_width_read);

		bit_counter_reg <= bit_counter;

		if ( bit_counter / 16  = 0) then
			cnt <= cnt + "000001";
			addr_mem <= addr_mem + '1';
			bit_counter <= mem_width_read + bit_counter - 16;
		else
			bit_counter <= bit_counter - 16;
		end if;

		if (cnt > 0) then

			if (bit_counter_reg = 0) then
				slash_reg_data( (mem_width_read_max_val - 1) downto 0) <= reg_data_mem( (mem_width_read_max_val - 1) downto 0);					
			elsif (bit_counter_reg <= 16) then
				slash_reg_data <= prepare_bit_vector(reg_data_mem, slash_reg_data, bit_counter_reg);
			else
				slash_reg_data( ((mem_width_read_max_val*2)-16) DOWNTO 0 ) <= slash_reg_data( (mem_width_read_max_val*2) DOWNTO 16 );
			end if;

		end if;

	end if;

end if;

 end process;

end rtl;  

 

testbench

 

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.numeric_std.all;                                

ENTITY xxx_vhd_tst IS
END xxx_vhd_tst;
ARCHITECTURE xxx_arch OF xxx_vhd_tst IS
-- constants                                                 
-- signals                                                   
SIGNAL clk : STD_LOGIC;
SIGNAL memory_width_read  :  std_logic_vector (6 downto 0);
SIGNAL data_out : STD_LOGIC_VECTOR(15 DOWNTO 0);
SIGNAL din : STD_LOGIC_VECTOR(127 DOWNTO 0);
SIGNAL rst : STD_LOGIC;
SIGNAL we : STD_LOGIC;
COMPONENT xxx
PORT (
clk : IN STD_LOGIC;
memory_width_read  : in std_logic_vector (6 downto 0);
data_out : OUT STD_LOGIC_VECTOR(15 DOWNTO 0);
din : IN STD_LOGIC_VECTOR(127 DOWNTO 0);
rst : IN STD_LOGIC;
we : IN STD_LOGIC
);
END COMPONENT;
BEGIN
i1 : xxx
PORT MAP (
-- list connections between master ports and signals
clk => clk,
memory_width_read => memory_width_read,
data_out => data_out,
din => din,
rst => rst,
we => we
);


clk_gen: process
begin
clk <= '1';
wait for 2.5 ns;
clk <= '0';
wait for 2.5 ns;
end process;

rst_gen: process
begin
rst <= '1';
wait for 5 ns;
rst <= '0';
wait;
end process;

din <= (OTHERS => '0');
we <= '0';
memory_width_read <= std_logic_vector(to_unsigned(57, memory_width_read'length)); --57 bit


END xxx_arch;

Share this post


Link to post
Share on other sites

Можно же просто двухпортовую память сделать. С разной шириной шины на запись и чтение.

Share this post


Link to post
Share on other sites

Можно же просто двухпортовую память сделать. С разной шириной шины на запись и чтение.

попробуйте сделать 57, 18 или 112 бит в 16 бит

 

Я пробовал когда-то давно, ничего не получилось, там есть ограничения по разрядностям вход/выход и их соотношению

Share this post


Link to post
Share on other sites

То есть память получается на регистрах?

блочная.

там так сказать конвеер организован который делает из N бит, которые прочитались из памяти раскладывает по 16 бит.

Для понимания просимулируйте и все увидите... :)

 

во вложении - do файлы для моделсима

do_files.zip

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...