【问题标题】:near "when": syntax error in VHDL“when”附近:VHDL 中的语法错误
【发布时间】:2023-03-21 14:34:01
【问题描述】:

我正在尝试编写一些代码来模拟具有两个三态缓冲器和一个 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;

我在第 14 行遇到编译器错误near "when": syntax error,即when (S = '1') and (T = '0') =&gt; TriOut &lt;= A; 行。我一辈子都搞不清楚语法错误是什么。

任何帮助将不胜感激。

谢谢。

【问题讨论】:

    标签: syntax-error vhdl tri-state-logic


    【解决方案1】:

    两件事。在process 之后不需要is。更重要的是,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;
      ...
    

    你不能做的是混搭。

    【讨论】:

    • 很好的答案。感谢您的帮助。您可能会说,我对 VHDL 还很陌生。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-18
    • 1970-01-01
    相关资源
    最近更新 更多