0

我正在尝试编写一些代码来模拟具有两个三态缓冲器和一个 VHDL 中的上拉电阻的电路。下面是我的代码:

library ieee;
use ieee.std_logic_1164.all;

entity PullUpResistor is
port (
A, S, B, T : IN std_logic;  -- select one of these four inputs
TriOut : OUT std_logic -- output (no ";" after last port)
);
end entity PullUpResistor;

architecture behavioral of PullUpResistor is
begin
process(A, S, B, T) is
when (S = '1') and (T = '0') => TriOut <= A;
when (S = '0') and (T = '1') => TriOut <= B;
when (S = '0') and (T = '0') => TriOut <= 'H';
when (S = '1') and (T = '1') => TriOut <= 'X';
end process;
end architecture behavioral;

near "when": syntax error在第 14 行遇到编译器错误,这是该when (S = '1') and (T = '0') => TriOut <= A;行。我一生都无法弄清楚语法错误是什么。

任何帮助将不胜感激。

谢谢。

4

1 回答 1

1

两件事情。之后就is不需要了process。更重要的是,when不能这样使用。你可以同时做你想做的事:

TriOut <=
  A when S = '1' and T = '0' else
  B when S = '0' and T = '1' else
  ...

或在一个过程中:

process (A, S, B, T)
begin
  if S = '1' and T = '0' then
    TriOut <= A;
  elsif ...

(或使用 VHDL-2008,两者的结合。)

您似乎在使用when它,就好像它在 case 语句中一样。考虑到这一点,您还可以(在一个过程中):

sel <= S & T;

case sel is
  when "10" =>
    TriOut <= A;
  when "01" =>
    TriOut <= B;
  ...

你不能做的就是混搭。

于 2015-03-10T20:26:39.677 回答