我已经用VHDL写了一个LFSR。我已经在模拟中测试了它,它的工作与预期的一样(生成1到512之间的随机整数)。然而,当我把它放到硬件上时,它总是生成"000000000“。
代码如下:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity LFSR is
port(clk, reset : in bit;
random : out std_logic_vector (8 downto 0));
end entity LFSR;
architecture behaviour of LFSR is
signal temp : std_logic_vector (8 downto 0) := (8 => '1', others => '0');
begin
process(clk)
begin
if(clk'event and clk='1') then
if(reset='0') then --reset on signal high, carry out normal function
temp(0) <= temp(8);
temp(1) <= temp(0);
temp(2) <= temp(1) XOR temp(8);
temp(3) <= temp(2) XOR temp(8);
temp(4) <= temp(3) XOR temp(8);
temp(8 downto 5) <= temp(7 downto 4);
else
--RESET
temp <= "100000000";
end if;
end if;
random <= temp;
end process;
end architecture behaviour;它在Modelsim中进行了测试,并在Quartus II中针对Cyclone III DE0板进行了编译。有没有人能看到它为什么不工作(实际上,模拟是好的),并解释一下我需要做些什么才能让它工作?
发布于 2014-05-21 14:11:41
如果reset直接来自FPGA引脚,则它可能与clk不同步,因此无法保证正确的同步复位操作。
在过程中使用reset与clk同步之前,添加两个触发器。这可以通过以下方式完成:
...
signal reset_meta : bit; -- Meta-stable flip-flop
signal reset_sync : bit; -- Synchronized reset
begin
process(clk)
begin
if(clk'event and clk='1') then
reset_meta <= reset;
reset_sync <= reset_meta;
if (reset_sync = '0') then -- Normal operation
...Altera在External Reset Should be Correctly Synchronized中对此有一些评论。本说明涵盖具有异步复位的触发器,但使用两个触发器同步外部复位同样适用于您的情况。
请记住,正如大卫所指出的那样,要在if中移动random <= temp。
发布于 2015-07-24 05:55:47
如果你没有任何运气,你可能会看一下合成的原理图或执行合成后的仿真。如果在行为模拟中有不明显的东西,我偶尔会将RTL模型替换为后合成模型进行验证。-Jerry
https://stackoverflow.com/questions/23774028
复制相似问题