【问题标题】:VHDL-Implement LFSRVHDL 实现 LFSR
【发布时间】:2017-05-18 16:00:40
【问题描述】:

我在下面写了 Vhdl 代码和测试台代码,用于在 ISE 上实现 LFSR。 我从 ISE 上的这条路径获取 LFSR 代码。 语言模板--VHDL--综合构造--编码示例-- 计数器---LFSR

我的问题在于 simulink(isim),我总是面对 out_lfsr 的“U”符号。 你能帮帮我吗?

vhdl 代码:

    library IEEE;
        use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use IEEE.std_logic_unsigned.all;



entity lfsr is

port(rst,clk,clk_en:in std_logic;
out_lfsr: inout std_logic_vector(31 downto 0);
init_value:in std_logic_vector(31 downto 0)
);

end lfsr;

architecture Behavioral of lfsr is


begin

process(clk)
begin
   if ( clk'event and clk ='1') then
      if (rst = '1') then
         out_lfsr <= init_value;
      elsif clk_en='1' then 
         out_lfsr(31 downto 1) <= out_lfsr(30 downto 0) ;
         out_lfsr(0) <= not(out_lfsr(31) XOR out_lfsr(21) XOR out_lfsr(0)); 
      end if;
   end if;
end process; 


end Behavioral;

测试台:

    LIBRARY ieee;
USE ieee.std_logic_1164.ALL;



ENTITY tb_lfsr IS
END tb_lfsr;

ARCHITECTURE behavior OF tb_lfsr IS 

    -- Component Declaration for the Unit Under Test (UUT)

    COMPONENT lfsr
    PORT(
         rst : IN  std_logic;
         clk : IN  std_logic;
         clk_en : IN  std_logic;
         out_lfsr : INOUT  std_logic_vector(31 downto 0);
         init_value : IN  std_logic_vector(31 downto 0)
        );
    END COMPONENT;


   --Inputs
   signal rst : std_logic := '0';
   signal clk : std_logic := '0';
   signal clk_en : std_logic := '1';
   signal init_value : std_logic_vector(31 downto 0) := (others => '1');

    --Outputs
   signal out_lfsr : std_logic_vector(31 downto 0):=(others => '0');

   -- Clock period definitions
   constant clk_period : time := 10 ns;

BEGIN

    -- Instantiate the Unit Under Test (UUT)
   uut: lfsr PORT MAP (
          rst => rst,
          clk => clk,
          clk_en => clk_en,
          out_lfsr => out_lfsr,
          init_value => init_value
        );

   -- Clock process definitions
   clk_process :process
   begin
        clk <= '0';
        wait for clk_period/2;
        clk <= '1';
        wait for clk_period/2;
   end process;



END;

【问题讨论】:

    标签: vhdl lfsr


    【解决方案1】:

    您必须在其他中重置此块才能使其工作。重置时,它将输入值加载到输出。

    reset_p: process begin
        rst <= '1';
        wait for 10 * clk_period;
        rst <= '0';
        wait;
    end process;
    

    我认为最好不要使用 inout,因为它并不总是适合合成,而是使用存储 out_lfsr 值的内部信号。

    entity lfsr is
    
    port(
        rst,clk,clk_en:in std_logic;
        out_lfsr: out std_logic_vector(31 downto 0);
        init_value: in std_logic_vector(31 downto 0)
    );
    
    end lfsr;
    
    architecture Behavioral of lfsr is
    
    signal s_out_lfsr : std_logic_vector(31 downto 0);
    begin
    
    process(clk)
    begin
       if ( clk'event and clk ='1') then
          if (rst = '1') then
             s_out_lfsr <= init_value;
          elsif clk_en='1' then 
             s_out_lfsr(31 downto 1) <= s_out_lfsr(30 downto 0) ;
             s_out_lfsr(0) <= not(s_out_lfsr(31) XOR s_out_lfsr(21) XOR s_out_lfsr(0)); 
          end if;
       end if;
    end process; 
    
    out_lfsr <= s_out_lfsr;
    
    end Behavioral;
    

    我对此并不完全确定,因为您的代码在编码示例中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      • 2017-08-22
      • 2011-08-25
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多