首页 文章

CPU频率和上升沿计数

提问于
浏览
0

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

我认为看完这个YouTube video之后我已经有了充分的理解,并且阅读了this web page,但是当我回到关于时钟速度的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频率在上升沿和下降沿方面实际意味着什么,以及“滴答”?图表会非常感激,因为我不再确定链接上的图表是否正确...

1 回答

  • 1

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

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

    刻度线是一个时钟周期,因此50 MHz时钟将产生每秒5000万个刻度 .

相关问题