library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity decim_al2 is Generic( num : integer range 0 to 1022 := 7; -- numerateur du rapport de decimation den : integer range 0 to 1023 := 25; -- denominateur du rapport de decimation Wdata : integer range 0 to 64 := 12; Wfeed : integer range 0 to 10 := 5 -- ceil(log2(den)), adresse du tableau (urne) ); Port( clk : in std_logic; data_in : in std_logic_vector(Wdata-1 downto 0); data_out : out std_logic_vector(Wdata-1 downto 0); delta_t : out std_logic_vector(Wfeed-1 downto 0); clk_out : out std_logic; feed : in std_logic_vector(Wfeed-1 downto 0) ); end decim_al2;
architecture Behavioral of decim_al2 is
SIGNAL var_clk_out : std_logic := '0'; SIGNAL var_data_out : std_logic_vector(Wdata-1 downto 0); SIGNAL delta_t_inter : std_logic_vector(Wfeed-1 downto 0); SIGNAL inter2,inter3 : integer range 0 TO den-1;
begin
-- tirage aleatoire sans remise tr : PROCESS(clk) IS VARIABLE num_case : integer range 0 TO den-1; VARIABLE var_delta : integer range 0 TO 2*(num+1); VARIABLE n_tir : integer range 0 TO den-1; VARIABLE inter1 : integer range 0 TO den-1; VARIABLE urne_1 : std_logic := '0'; VARIABLE urne_0 : std_logic := '0'; VARIABLE var_feed : std_logic_vector(Wfeed-1 downto 0); VARIABLE tmp_feed : integer; VARIABLE Nfeed : integer range -1 TO Wfeed-1; VARIABLE urne : std_logic_vector(den-1 DOWNTO 0) := (others => '0'); VARIABLE init : boolean; VARIABLE visu : std_logic; BEGIN IF rising_edge(clk) THEN IF not init THEN urne(den-1 DOWNTO den-num-1) := (others => '1'); urne(den-num-2 DOWNTO 0) := (others => '0'); init := true; ELSE inter3 <= inter2; --delta_t <= delta_t_inter; -- delta_t : intervalle entre 2 閏hantillons al閍toires data_out <= var_data_out; -- Synchro de data_out sur clk_out var_feed := feed; urne_1 := urne_0; IF n_tir = 0 THEN n_tir := den-1; --inter2 := n_tir; inter1 := n_tir; var_feed := (others => '0'); ELSE n_tir := n_tir - 1; -- WHILE conv_integer((not(var_feed(Wfeed-1))&var_feed(Wfeed-2 DOWNTO 0))) > n_tir LOOP -- WHILE conv_integer(unsigned(var_feed)) > n_tir LOOP FOR i in Wfeed-1 DOWNTO 0 LOOP IF var_feed(Nfeed) = '1' THEN var_feed(Nfeed) := not(var_feed(Nfeed)); END IF; -- Nfeed := Nfeed-1; IF conv_integer(unsigned(var_feed)) > n_tir THEN exit; END IF; END LOOP; END IF; num_case := conv_integer(var_feed); Nfeed := Wfeed-1; urne_0 := urne(num_case); IF urne_0 = '1' THEN --data_out <= data_in; -- modif 08/12/06 var_data_out <= data_in; var_clk_out <= '1'; inter2 <= inter1 - n_tir; inter1 := n_tir; --delta_t_inter <= CONV_STD_LOGIC_VECTOR(conv_unsigned(var_delta,Wfeed),Wfeed); -- Rajout 08/12/06 --var_delta := 0; -- Rajout 08/12/06 ELSE var_clk_out <= '0'; --var_delta := var_delta + 1; -- Rajout 08/12/06 END IF; -- Mis en commentaires 08/12/06 --IF urne(num_case) = not(urne_1) THEN -- delta_t <= CONV_STD_LOGIC_VECTOR(conv_unsigned(var_delta,Wfeed),Wfeed); -- var_delta := 0; --ELSE -- var_delta := var_delta + 1; --END IF; urne(num_case) := urne(n_tir); urne(n_tir) := urne_0; END IF; END IF; clk_out <= clk AND var_clk_out; END PROCESS tr;
delta_t <= CONV_STD_LOGIC_VECTOR(conv_unsigned(inter3,Wfeed),Wfeed); -- Rajout 12/12/06
end Behavioral;
研究别人的代码,增加我们的见识!
|