我试图看到8位LFSR在Altera DE2上运行,我用VHDL编写了一个代码并且它在ModelSim上运行良好,但是我无法在FPGA上工作。下面是代码:
library ieee;
use ieee.std_logic_1164.all;
entity lfsr_8bit is
port (
CLOCK_50 : in std_logic;
rst : in std_logic;
LEDG : out std_logic_vector(7 downto 0));
end lfsr_8bit;
architecture behaviour of lfsr_8bit is
signal lfsr_done : std_logic;
signal rand : std_logic_vector(7 downto 0);
begin
ciclo : process (CLOCK_50, rst)
begin
if (rst='0') then
rand <= "00000001"; -- seed
lfsr_done <= '0';
elsif (CLOCK_50'EVENT AND CLOCK_50 = '1') then
if rand = "10000000" then
lfsr_done <= '1';
end if;
if lfsr_done = '0' then
rand(0) <= rand(6) xor rand(7);
rand(7 downto 1) <= rand(6 downto 0);
end if;
end if;
LEDG <= rand(7 downto 0);
end process ciclo;
end behaviour;
我在FPGA上看到的只是种子(00000001),仅此而已。我认为这是因为时钟,它对我的眼睛来说更快,但我不知道如何解决这个问题,因为我开始用VHDL编程。我也试图改变按钮的时钟,但也不起作用。我在这里尝试过:
library ieee;
use ieee.std_logic_1164.all;
entity lfsr_8bit is
port (
KEY : in std_logic_vector(3 downto 0);
rst : in std_logic;
LEDG : out std_logic_vector(7 downto 0));
end lfsr_8bit;
architecture behaviour of lfsr_8bit is
signal lfsr_done : std_logic;
signal rand : std_logic_vector(7 downto 0);
begin
ciclo : process (KEY, rand, rst)
begin
if (rst='0') then
rand <= "00000001"; -- seed
lfsr_done <= '0';
elsif (KEY(0) = '0') then
if rand = "10000000" then
lfsr_done <= '1';
end if;
if lfsr_done = '0' then
rand(0) <= rand(6) xor rand(7);
rand(7 downto 1) <= rand(6 downto 0);
end if;
end if;
LEDG <= rand(7 downto 0);
end process ciclo;
end behaviour;
感谢您的帮助。
答案 0 :(得分:0)
我认为您在FPGA上看到种子是正常的,因为它是信号“rand”将停止的值。
在rand为“10000000”的时钟周期内,lfsr_done将设置为“1”,但rand也将被更改!在这个非常时钟周期,lfsr_done仍为'0'。然后rand收到值“00000001”并且永远不会再次进化。
你确定在modelsim上没有看到这种行为吗?
我建议使用非常低频的时钟(1或2 Hz),而不是使用按钮来触发过程。您可以使用其他过程中的计数器轻松创建它。您还可以使用与结束值不同的其他种子值。
还有一件事,就是“LEDG&lt; = rand(7 downto 0)”;“可能是在进程之外,而它只是并发声明。