我对你所拥有的东西进行了一些细微的修改(尽管你很漂亮);我不认为LFSR会采取其他措施。我向LFSR添加了一个启用信号,因此您可以有效地控制何时需要它。得到的SIM卡是 这里 。
正如旁注,你也可以包括一个 load 和 seed 输入,如果你想用不同的值为LFSR播种(而不是使它成为常量)。
load
seed
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity pseudorng is Port ( clock : in STD_LOGIC; reset : in STD_LOGIC; en : in STD_LOGIC; Q : out STD_LOGIC_VECTOR (7 downto 0); check: out STD_LOGIC); -- constant seed: STD_LOGIC_VECTOR(7 downto 0) := "00000001"; end pseudorng; architecture Behavioral of pseudorng is --signal temp: STD_LOGIC; signal Qt: STD_LOGIC_VECTOR(7 downto 0) := x"01"; begin PROCESS(clock) variable tmp : STD_LOGIC := '0'; BEGIN IF rising_edge(clock) THEN IF (reset='1') THEN -- credit to QuantumRipple for pointing out that this should not -- be reset to all 0's, as you will enter an invalid state Qt <= x"01"; --ELSE Qt <= seed; ELSIF en = '1' THEN tmp := Qt(4) XOR Qt(3) XOR Qt(2) XOR Qt(0); Qt <= tmp & Qt(7 downto 1); END IF; END IF; END PROCESS; -- check <= temp; check <= Qt(7); Q <= Qt; end Behavioral;
并且tb:
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity tb_pseudorng is end tb_pseudorng; architecture bench of tb_pseudorng is COMPONENT pseudorng Port ( clock : in STD_LOGIC; reset : in STD_LOGIC; en : in STD_LOGIC; Q : out STD_LOGIC_VECTOR (7 downto 0); check: out STD_LOGIC); END COMPONENT; signal clock1: STD_LOGIC; signal reset1: STD_LOGIC; signal Q1: STD_LOGIC_VECTOR(7 downto 0); signal check1: STD_LOGIC; signal en : STD_LOGIC; begin mapping: pseudorng PORT MAP( clock => clock1, reset => reset1, en => en, Q => Q1, check => check1); clock: PROCESS BEGIN clock1 <= '0'; wait for 50 ns; clock1 <= '1'; wait for 50 ns; END PROCESS; reset: PROCESS BEGIN reset1 <= '0'; en <= '1'; wait for 900 ns; END PROCESS; end bench;