--- Quote Start ---
You can do a further modification if you want to get rid of zero data and interrupted read by reading into two further rams.
one for code and one for duration, both rams addressed by counter that increments only if non zero data arrives... then finally read out both rams from 0 to count value.
i try to modify the code it is as you suggest kaz
library ieee;
use ieee.std_logic_1164.all;
use IEEE.numeric_std.all;
entity bubblesort is
port(
clk : in std_logic;
we : in std_logic := '1';
trigraph : in std_logic_vector(7 downto 0) := x"0F";
duration : in integer range 0 to 1023 := 5;
read : in std_logic := '0';
code : out std_logic_vector(7 downto 0)
);
end entity;
architecture rtl of bubblesort is
signal address, rd_addr : integer range 0 to 1023 := 0;
signal trigraph_d,dout : std_logic_vector(7 downto 0);
signal we_d : std_logic := '0';
signal N : integer := 0;
type mem is array(0 to 1023) of std_logic_vector(7 downto 0);
signal ram : mem := ((others=> (others=>'0')));
begin
--infer ram
process(clk)
begin
if(rising_edge(clk)) then
dout <= ram(address);
if(we_d = '1') then
ram(address) <= trigraph_d;
end if;
end if;
end process;
process(clk)
begin
if rising_edge(clk) then
we_d <= we;
trigraph_d <= trigraph;
if read = '1' then
if rd_addr < 1023 then
rd_addr <= rd_addr + 1;
end if;
end if;
if read = '0' then
address <= duration;
else
address <= rd_addr;
end if;
end if;
end process;
------discard zero values
process(read,dout)
begin
if read = '1' then
if dout /= "00000000" then
N <= N + 1;
code <= dout;
end if;
end if;
end process;
end rtl;