vhdl将新输入与旧输入进行比较

时间:2013-05-04 11:47:34

标签: input store vhdl

你怎么做的?

我对此非常陌生,我确信这很容易,但我似乎无法弄清楚如何

这里有一些伪代码

port(x,y: in std_logic_vector (2 downto 0) -- 3 bit input that is basically counted eg ("000", "001", "010"... "111", "000" ...)
    q_out : out integer); -- this is just an example

signal temp_q_out: integer;

when x (or y) increments -- THIS IS THE PART I CAN'T GET
    temp_q_out <= temp_ q_out + 1;


case temp_q_out is
    when 0 q_out <= 7
    when 1 q_out <= 12
    when 2 q_out <= 4
    when others q_out <= 100

如果仅在x或y增加时才进行temp_q_out计数,而且没有其他时间?我希望我的输出q_out一直是7,直到x或y变化然后是12,直到x或y再次变化然后是2.通常会发生的是输出立即变为100。

任何帮助都将受到赞赏

干杯伙伴: - )

2 个答案:

答案 0 :(得分:1)

我认为没有一种安全的方法可以用异步逻辑做你想做的事。假设你想要合成它,你需要一个时钟输入。然后,您可以添加存储先前值xy的进程,并检查新值是否等于旧值。这是一个例子:

process(clk)
  variable prev_x, prev_y : std_logic_vector(2 downto 0) := (others => '0');
begin
  if rising_edge(clk) then
    if (x /= prev_x) or (y /= prev_y) then
      temp_q_out <= temp_q_out + 1;
    end if;
    prev_x := x;
    prev_y := y;
  end if;
end process;

答案 1 :(得分:0)

使用流程。进程像原子语句一样执行。您可以在其中使用变量。以下过程侦听x和y信号。当其中一个发生变化时,该过程将按顺序执行。

process(x, y)
variable tmpX: integer := -1;
variable tmpY: integer := -1;
begin
    if (x = tmpX + 1) or (y = tmpY + 1) then
        temp_q_out <= temp_ q_out + 1;
    tmpX := x;
    tmpY := y;
end process;

首次执行该过程取决于您的具体情况,因此请根据需要修改“-1”值。