【问题标题】:Do you have any idea how I can make this code generate numbers only between 1 and 6, it generates between 1 and 7你知道如何让这段代码只生成 1 到 6 之间的数字,它生成 1 到 7 之间的数字吗?
【发布时间】:2021-04-26 20:21:15
【问题描述】:
entity LFSR is
  Port (   clk : in STD_LOGIC; 
           en: in STD_LOGIC; 
           reset: in STD_LOGIC;  
           output_lfsr: out STD_LOGIC_VECTOR(2 downto 0) 
           ); 
end LFSR;

architecture Behavioral of LFSR is
    signal lfsr : std_logic_vector(2 downto 0); 
    constant poly : std_logic_vector(2 downto 0) := "011"; 
    begin 
        process(clk, reset, lfsr)  
        variable ext_inbit: std_logic_vector(2 downto 0);
        variable inbit: std_logic;  
    begin 
        inbit:=lfsr(2);   -- preia valoarea iesirii Q2 
            for i in 0 to 2 loop    
        ext_inbit(i):=inbit; 
            end loop; 
        if (reset='1') then   
          lfsr<="111";
        elsif (clk'event and clk='1') then 
            if(en='1') then   
                   lfsr<=(lfsr(1 downto 0) & '0') xor (ext_inbit and poly);  
                                 
            end if; 
        end if; 
    end process; 
    output_lfsr <= lfsr;   
end Behavioral;

【问题讨论】:

    标签: vhdl


    【解决方案1】:

    这是一个快速而肮脏的解决方案。有一些方法可以清理它并通过管道传输它。 如果值为7,则再次执行该操作。

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    
    entity lfsr is
      port (clk         : in  std_logic;
            en          : in  std_logic;
            reset       : in  std_logic;
            output_lfsr : out std_logic_vector(2 downto 0)
            );
    end lfsr;
    
    architecture behavioral of lfsr is
    
      signal s_lfsr     : std_logic_vector(2 downto 0);
      constant poly     : std_logic_vector(2 downto 0) := "011";
    
    begin
      process(clk, reset)
        variable v_lfsr_int : std_logic_vector(2 downto 0);
        variable ext_inbit : std_logic_vector(2 downto 0);
        variable inbit     : std_logic;
      begin
    
        if (reset = '1') then
          s_lfsr <= "011";
        elsif (rising_edge(clk)) then
        
          inbit := s_lfsr(2);               -- preia valoarea iesirii Q2
          for i in 0 to 2 loop
            ext_inbit(i) := inbit;
          end loop;
          
          if(en = '1') then
            v_lfsr_int := (s_lfsr(1 downto 0) & '0') xor (ext_inbit and poly);
            if(v_lfsr_int = "111") then
              s_lfsr <= (v_lfsr_int(1 downto 0) & '0') xor (ext_inbit and poly);
            else
              s_lfsr <= v_lfsr_int;
            end if;
          end if;
        end if;
    
      end process;
    
      output_lfsr <= s_lfsr;
    
    end behavioral;
    

    如您所见,我也更改了一些内容:

    • 添加了 ieee 库
    • 为异步重置更新了进程敏感度列表
    • 重新排列了 ext_inbit 以避免工具喊出敏感列表不完整。考虑到精化后的值与 lfsr(2) 相同,你甚至可以把它放在进程之外。
    • 信号名称和实体名称相同。重命名以增加可读性。重新检查标准,看看是否允许。

    【讨论】:

    • 对不起,先生。但是您的解决方案不起作用。仍然生成数字 7。
    • @CebucAlexandruBogdan 究竟是什么时候?我编辑了重置值。那还是 7 点。
    • 是的,我看到了,但是我知道为什么不起作用,当我尝试使用接口 grafic 生成数字时,在生成过程中仍然得到 7。我得到了类似 1-3-7-5 的东西,7 仍然存在(只是一个例子)
    • 我在模拟中看不到它。添加波形的屏幕截图。在 edaplayground 中运行模拟并分享链接
    • 对不起,我忘了重写文件 .bit。您的解决方案效果很好。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多