2017-04-17 56 views
1

当所有输入为xclk = 1时,它应该输出Qpl的值,但它不会。下面的代码有什么问题;VHDL设计意外的结果

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; 

下图显示了上述设计的波形和所需的操作要求; waveform

+0

请注意'SET'不适用于应用'D'。像“复位”将寄存器设置为“0”,“设置”通常将寄存器设置为“1”。通常的名称是“加载”或“启用”。我认为“负载”是最好的选择。 – JHBonarius

回答

1

从波形图,似乎一切正常正常的,当输入信号变为SETU,if条件不能评价,因此输出Q也变为这样,即U。您可以看到SET0,输出Q正确得到Qpl的值。

enter image description here

对不起,粗拉,但你可以在圆圈时钟的上升边看边SET0Q得到预期的Qpl值。 SET信号变为U只有后,输出Q也失去了在下一个时钟上升时它的价值,也成为U

+0

所以我的代码也是正确的问题吗?(在波形图像之上) –

+0

除了'Qpl'部分,你没有设置它,并且逻辑有错误。它不应该是一个输入信号,而应该是一个本地存储的值 - >你应该有一个变量'Qtemp',并且在你保留该值的同时保持'Q'的值,检查[this](http:/ /stackoverflow.com/a/14593941/3641067) –

+0

大概这将会是很多要问,但我不知道如何实现这些东西到我的code.I真的是新的这种代码语言我不知道该怎么做甚至与你的帮助 –

1

你的代码和注释不同。正如表格/图表一样。一个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;