基于时钟的 8 位素数检测器

Clock based 8 bit prime number detector

我正在用 VHDL 开发一个 8 位无符号素数检测器,可综合,project.The objective 不仅要避免使用任何类型的循环或锁存器,还要限制它仅适用于 FPGA 50Mhz 时钟。

我们尝试了使用连续分频的基于时钟的方法,但是当我们尝试输出结果时,这种实现不符合 Quartus Timequest 中的时序要求。 当我们评论输出时它似乎工作得很好,我们不完全理解为什么。

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity primeChecker is
    generic(NumCyclesWait :integer := 1000);
    port(   clock: in  std_logic;
            enable: in  std_logic;
            reset   : in  std_logic;
            input   : in std_logic_vector(7 downto 0);
            output  : out std_logic_vector(7 downto 0);
            isPrime   : out std_logic_vector(0 downto 0));
end primeChecker;

architecture arch of primeChecker is

    signal count: integer := 0;
    signal numToCheck : integer := 0;
    signal prime, primeOut : integer := 1;
    signal s_out: unsigned(7 downto 0);
    signal div : integer := 2;
    signal clockCount : unsigned(0 downto 0) := "0";

begin

    numToCheck <= to_integer(unsigned(input));

    process(clock)
    begin
        if(rising_edge(clock)) then
                if(count = NumCyclesWait) then

                    if ((numToCheck = 1) OR (numToCheck = 0)) then

                        prime <= 0;     --Not Prime

                    elsif(numToCheck > 2 and prime =1 and div < numToCheck) then
                            if (numToCheck rem div = 0) then
                                -- if the number is divisible
                                prime <= 0; 
                            end if;
                            div <= div +1;

                    end if;
                else

                    count <= count +1;

                end if;

                if(enable = '1') then
                    s_out <= to_unsigned(numToCheck,8);
                    count <= 0;
                    div <= 2;
                    primeOut <= prime;
                    prime <= 1;
                else
                    s_out <= s_out;
                end if;
        end if;



    end process;



    isPrime <= std_logic_vector(to_unsigned(primeOut,1));
    output <= std_logic_vector(s_out);

end arch ; -- arch

我希望它不会触发 "Timing requirement not met" 错误并完全编译。

为了最快的恒定时间响应,我会采用不同的方法。您的任务是仅处理八位数字,您的 FPGA 可能有足够的 RAM 来设置 8 位素数查找 table,其中每个 table 条目仅指示其索引是否为素数数与否:

type prime_numbers_type is array(0 to 255) of std_ulogic;
constant prime_numbers    : prime_numbers_type :=
                            ( '0', '0', '1', '1', '0', '1', ... );

这使得素数检测器的重要部分过于简单:

is_prime <= prime_numbers(to_integer(unsigned(num_to_check)));

我可能只编写一个小的 Tcl 脚本来设置查找 table。