我是VHDL的新手。我试图根据多个条件的状态设置信号值。它在进程块之外。我甚至想做什么?如果是这样,我做错了什么?
这是我到目前为止所做的:
signal1<= my_data
WHEN ( bit_cond_true
AND (my_array /= X"00000")
AND (my_array = another_array))
ELSE
other_data;
当我尝试在ModelSim中编译它时会发生这种情况:
** Error: file.VHD(62): No feasible entries for infix operator "and".
** Error: file.VHD(62): Bad expression in left operand of infix expression "and".
** Error: file.VHD(62): Type error resolving infix expression "and" as type std.standard.boolean.
** Error: file.VHD(67): No feasible entries for infix operator "and".
** Error: file.VHD(66): Bad expression in left operand of infix expression "and".
** Error: file.VHD(67): Type error resolving infix expression "and" as type std.standard.boolean.
** Error: file.VHD(100): VHDL Compiler exiting
答案 0 :(得分:3)
首先,您尝试做的事情确实可行,并且在VHDL术语中被称为“条件信号赋值语句”。
您尚未提供表达式中使用的信号的声明,但我将假设它们都是std_logic或std_logic_vector,因此:
signal signal1 : std_logic; -- Result
signal my_data : std_logic; -- Value if TRUE condition
signal other_data : std_logic; -- Value if FALSE condition
signal bit_cond_true : std_logic; -- Condition part
signal my_array : std_logic_vector(19 downto 0); -- --||--
signal another_array : std_logic_vector(19 downto 0); -- --||--
因此,VHDL是一种强类型语言,由于bit_cond_true
是std_logic而(my_array /= X"00000")
解析为布尔值,因此无法解决的条件无法解决。因此,ModelSim错误中缀运算符没有可行条目“和”。,因为ModelSim尝试使用{std_logic} and {boolean}
解析表达式,但它没有and
运算符的定义与参数的组合。
将bit_cond_true
转换为布尔值有不同的可能性,这与VHDL-2002和VHDL-2008都有关:
signal1 <= my_data when ((bit_cond_true = '1') and
(my_array /= X"00000") and
(my_array = another_array)) else
other_data;
仅在VHDL-2008中,您还可以使用??
运算符将std_logic值“1”或“H”转换为TRUE,将其他值转换为FALSE。然后代码看起来:
signal1 <= my_data when ((?? bit_cond_true) and
(my_array /= X"00000") and
(my_array = another_array)) else
other_data;
为了更多地使用VHDL语言,我建议您深入阅读其中一本书,在维基百科的“进一步阅读”中进行聆听VHDL