首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >你知道我如何使这段代码只在1到6之间生成数字,它在1到7之间生成数字吗?

你知道我如何使这段代码只在1到6之间生成数字,它在1到7之间生成数字吗?
EN

Stack Overflow用户
提问于 2021-04-23 13:10:52
回答 1查看 70关注 0票数 0
代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-26 11:16:25

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

代码语言:javascript
复制
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 libraries

  • process

  • 为异步reset

  • rearranged

  • ext_inbit添加了更新的灵敏度列表,以避免工具高呼灵敏度列表是不完整的。考虑到该值与lfsr(2)在精化后相同,您甚至可以将其放在process.
  • signal名称之外,并且实体名称是相同的。重命名以增加可读性。重新检查标准,以确定是否允许。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67230580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档