我们尝试了使用连续除法的基于时钟的方法,但是当我们尝试输出结果时,这种实现方式不符合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
我希望它不会触发“未满足计时要求”错误,并使其完全编译。
答案 0 :(得分:1)
为了获得最快的恒定时间响应,我将采用其他方法。您的任务是仅处理8位数字,并且您的FPGA可能有足够的RAM来建立8位质数查找表,其中每个表项仅指示其索引是否为质数:
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脚本来建立查找表。