试图显示一个带有VHDL的8位LFSR周期 [英] Trying to show one cycle of 8 bit LFSR with VHDL

查看:86
本文介绍了试图显示一个带有VHDL的8位LFSR周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个VHDL代码,目的是制作一个8位LFSR并显示所有随机状态,并且在一个周期(最后一个状态为相同的种子值)之后停止.但是我有一个问题,一直说:循环必须在10,000次迭代中终止".我正在使用Quartus II-Altera.

I'm trying to do a VHDL code with the objective to make a 8 bit LFSR and show all the random states, and after one cycle (when the last state be the same seed value) it stop. But I'm have a problems, keep saying: "loop must terminate within 10,000 iterations". I'm using Quartus II-Altera.

代码:

entity lfsr_8bit is
    --generic ( n : integer := 2**8 );
    port (
        clk : in bit;
        rst : in bit;
        lfsr : out bit_vector(7 downto 0)
    );
end lfsr_8bit;

architecture behaviour of lfsr_8bit is
    --signal i : integer := 0;
    --signal seed : bit_vector(7 downto 0) := "10000000";
    signal rand : bit_vector(7 downto 0);
begin
    ciclo : process (clk,rst)
    begin
        loop
            if (rst='0') then
                rand <= "10000000";
            elsif (clk'event and clk='1') then
                rand(0) <= rand(6) xor rand(7);
                rand(7 downto 1) <= rand(6 downto 0);
            end if;

            -- wait until rand = "10000000" for 100 ns;
            exit when rand = "10000000";

            --      case rand is
            --      when "10000000" => EXIT;
            --      when others     => NULL;
            --      end case;
            --  i <= i +1;
        end loop;
        lfsr <= rand(7 downto 0);
    end process ciclo;
end behaviour;

感谢您的帮助.

推荐答案

摆脱该循环,该循环无法像您认为的那样起作用!不要像软件设计师那样思考,而像硬件设计师那样思考.硬件中的循环用于复制逻辑.因此,您的循环实际上是在尝试生成10,000个LFSR!

Get rid of that loop, that loop does not work the way you think it does! Stop thinking like a software designer and think like a hardware designer. Loops in hardware are used to replicate logic. So that loop of yours is literally trying to generate 10,000 LFSRs!

我认为您根本不需要在其中使用该循环.如果将其卸下,则LFSR应该可以正常工作.您可能需要添加控制信号来启用/禁用LFSR,但是绝对不要使用循环.

I don't believe that you need to be using that loop there at all. If you remove it your LFSR should work as intended. You may need to add a control signal to enable/disable the LFSR, but definitely do not use a loop.

这里有一些示例代码演示了这一点.将rand的默认值更改为其他值,否则LFSR将永远无法运行!它将立即设置lfsr_done信号.

Here's some example code demonstrating this. Change the default value of rand to something else or the LFSR will never run! It will immediately set the lfsr_done signal.

ciclo : process (clk,rst)
begin
if (rst='0') then
    rand      <= "10000000";  -- SET THIS TO SOMETHING DIFFERENT
    lfsr_done <= '0';
elsif (clk'event and clk='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;

这篇关于试图显示一个带有VHDL的8位LFSR周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆