【问题标题】:Unexpected result from VHDL designVHDL 设计的意外结果
【发布时间】:2017-04-17 15:13:52
【问题描述】:

当所有输入都是xclk = 1时,它应该输出Qpl的值,但它没有。以下代码有什么问题;

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
--This is a D Flip-Flop with Synchronous Reset,Set and Clock Enable(posedge clk).
--Note that the reset input has the highest priority,Set being the next highest
--priority and clock enable having the lowest priority.
ENTITY syn IS
    PORT (
        Q : OUT std_logic; -- Data output
        CLK : IN std_logic; -- Clock input
        Qpl : IN std_logic;
        RESET : IN std_logic; -- Synchronous reset input
        D : IN std_logic; -- Data input
        SET : IN std_logic -- Synchronous set input
    );
END syn;
ARCHITECTURE Behavioral OF syn IS --architecture of the circuit.
BEGIN
    --"begin" statement for architecture.
    PROCESS (CLK) --process with sensitivity list.
    BEGIN
        --"begin" statment for the process.
        IF (CLK'EVENT AND CLK = '1') THEN --This makes the process synchronous(with clock)
            IF (RESET = '1') THEN
                Q <= '0';
            ELSE
                IF (SET = '1') THEN
                    Q <= D;
                ELSE
                    Q <= Qpl; 
                END IF;
            END IF; 
        END IF;
    END PROCESS; --end of process statement.
END Behavioral;

下图显示了上述设计的波形,以及所需的操作要求;

【问题讨论】:

  • 注意SET不是申请D的好选择。就像“reset”将寄存器设置为“0”一样,“set”通常将寄存器设置为“1”。通常的名称是“加载”或“启用”。我认为“加载”是最好的选择。

标签: vhdl waveform


【解决方案1】:

从波形图看来,一切正常,当输入信号SET变为U时,if条件无法求值,因此输出Q也变为这样,即U。您可以看到,当 SET0 时,输出 Q 正确地获取了 Qpl 的值。

对于粗略的绘图很抱歉,但是您可以看到圆圈时钟在上升,而SET0Q 按预期获得了Qpl 的值。只有在SET信号变为U后,输出Q在下一个时钟上升事件中也失去其值,也变为U

【讨论】:

  • 所以我的代码也正确回答了这个问题吧?(在波形图像上方)
  • 除了Qpl部分,你没有设置,那里的逻辑是错误的。它不应该是输入信号,而是本地存储的值 -> 你应该有一个变量Qtemp,并在保留值的同时将Q 的值保持在其中,检查this
  • 可能会有很多问题要问,但我不知道如何在我的代码中实现这些东西。我对这种代码语言真的很陌生,即使有你的帮助我也不知道该怎么做跨度>
【解决方案2】:

您的代码和 cmets 不同。表格/图表也是如此。 D触发器/寄存器是一个非常简单的组件。示例:

entity dff is
    port (
        clk : in std_logic;
        rst : in std_logic;
        set : in std_logic;
        load : in std_logic;
        d : in std_logic;
        q : out std_logic
    );

architecture rtl of dff is
begin
    dff_proc : process(clk)
    begin
        if rising_edge(clk) then
            if rst='1' then
                q <= '0';
            elsif set='1' then
                q <= '1';
            elsif load='1' then
                q <= d;
            end if;
        end if;
    end process;
end architecture;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-01
    • 2018-04-25
    • 1970-01-01
    • 2023-02-26
    • 2011-09-15
    • 2012-04-02
    • 2019-05-14
    • 2017-07-11
    相关资源
    最近更新 更多