【发布时间】:2014-08-01 20:24:16
【问题描述】:
我试图看到一个 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;
感谢您的帮助。
【问题讨论】:
-
“不起作用”是否意味着您也看到了 rand 的重置值?这两件事的共同点是重置。它来自设备中的哪里是正确的极性? KEY(0) 看起来应该是去弹跳的,否则你将无法准确地看到序列。可能错误的时钟或复位连接的共同点还可能包括与 FPGA 的引脚连接。
-
您确定从另一端看到的是“00000001”而不是“10000000”吗?
-
抱歉花了这么多时间来回答,因为我正在旅行。好吧,我认为你是对的,我看到的是另一端的“1000000”。可能是重置问题,我不知道,我再看看。感谢您的帮助