CPU 频率和上升沿计数



我对CPU时钟速度感到困惑。

在观看了这个YouTube视频并阅读了这个网页之后,我以为我已经有了深刻的理解,但是当我回到Pluralsight上的VHDL教程(链接未给出,因为它不是免费的)时,我不确定。

请考虑以下代码,它被设计为一个非常简单的计时器:

entity boardio is
port (
clock_50: in bit;
hex0 : out bit_vector(0 to 6);
hex1 : out bit_vector(0 to 6);
hex2 : out bit_vector(0 to 6);
hex3 : out bit_vector(0 to 6);
key : in bit_vector(0 to 3);
sw: bit_vector(0 to 9);
ledr: buffer bit_vector (0 to 9)
);
end boardio;
architecture arch of boardio is
signal count : integer := 1; -- not a variable!
signal clock_1hz : bit := '0';
signal mins, secs : integer range 0 to 59 := 0;
function hex_digit(x:integer; constant hide_zero:boolean := false) return bit_vector is
begin
case x is
when 0 => 
if hide_zero then
return "1111111";
else
return "0000001";
end if;
when 1 => return "1001111";
when 2 => return "0010010";
when 3 => return "0000110";
when 4 => return "1001100";
when 5 => return "0100100";
when 6 => return "0100000";
when 7 => return "0001111";
when 8 => return "0000000";
when 9 => return "0000100";
when others => return "1111111";
end case;
end function;
begin
-- 1hz clock
-- ****************************************************
process(clock_50)
begin
if (clock_50'event and clock_50 = '1') then
count <= count + 1;
if (count = 25000000) then -- half the rate
clock_1hz <= not clock_1hz;
count <= 1;
end if;
end if;
end process;
-- ****************************************************
process(clock_1hz, key)
begin
-- update # of seconds
if (clock_1hz'event and clock_1hz = '1') then
if (key(0) = '0') then
secs <= 0;
mins <= 0;
else
if (secs = 59) then
mins <= (mins + 1) rem 60;
end if;
secs <= (secs + 1) rem 60;
end if;
end if;
end process;
process(clock_1hz)
begin
hex0 <= hex_digit(secs rem 10);
hex1 <= hex_digit(secs / 10, true);
hex2 <= hex_digit(mins rem 10, mins = 0);
hex3 <= hex_digit(mins / 10, true);
end process;
end arch;

我已经发布了所有代码,以便每个人都有完整的上下文,但我真正感兴趣的是我用星号表示的1hz clock过程。

这表明在50MHz时钟的一秒钟内,一秒钟内将有250,000,000个上升沿。 但是,我链接的视频和网页表明,对于 1hz 时钟,一秒钟内将有一个上升沿和一个下降沿,因此对于 50Mhz 时钟,每个时钟将有 500,000,000 个。

有人可以澄清一下 CPU 频率在上升沿和下降沿方面的实际含义,以及"滴答"吗? 图表将不胜感激,因为我不再确定我链接上的图表是否正确......

xHz 的频率意味着您每秒有 x 个完整的信号周期。如果你有一个典型的矩形时钟信号,这意味着每秒x上升沿和x下降沿。在 1 Hz 时钟上,每秒有一个上升沿和一个下降沿,给出一个完整的周期。在 50 MHz 时钟(5000 万赫兹)上,您有 5000 万个上升沿和下降沿。

为了从 50 MHz 时钟生成 1 Hz 时钟,您需要将时钟周期减少 5000 万倍。但是,由于每个时钟周期都包含一个上升沿和一个下降沿,因此您需要在每个周期更改输出时钟信号两次(即每秒两次)。因此,您示例中的计数器计数为 2500 万(不是您编写的 2.5 亿,请仔细查看代码!),然后反转输出信号。这每秒产生一个下降沿和一个上升沿,每半秒相隔,这正是您通常想要的 - 每秒重复一次的信号,并在"导通"状态和"关闭"状态之间平均分配,这称为50%占空比。您的时钟实际上不需要 50% 的占空比即可正常工作,因为时钟逻辑使用边沿而不是时钟状态,但如果时钟的"开"或"关"脉冲太短,逻辑可能无法正确检测到它并出错。

时钟周期是一个时钟周期,因此 50 MHz 时钟每秒将生成 5000 万个时钟周期。

最新更新