我是VHDL的新手,在处理case语句时,我有一些类似以下的东西:
process(state)
begin
case state is
when stop =>
a <= input;
b <= output;
when move =>
a <= input_1;
b <= output_1;
end case;
end process;其中a、b、input、output、input_1和output 1是信号。
我的问题是,我希望在其中一个选项中只有一个嵌套的案例:
例如:
process(state)
begin
case state is
when stop =>
a <= input;
b <= output;
when move =>
a <= if c='0' then input_1 else input_2;
b <= if c='0' then output_1 else output_2;
end case;
end process;我的问题是,如果不是所有的case选项都嵌套在一起,但只有其中的一些是嵌套的,或者在这种情况下有没有其他方法,我可以做上面的事情吗?我尝试使用when else,但得到了一个错误,说这种语法不受支持。
任何帮助我们都将不胜感激
发布于 2014-05-20 19:08:40
我不太确定你在问什么:
如果不是所有的case选项都嵌套在一起,但其中只有一部分是嵌套的,或者在这种情况下有没有其他方法,我是否可以这样做?
但这就是你想要做的吗?(请注意,我已经将c添加到敏感度列表中):
process(state,c)
begin
case state is
when stop =>
a <= input;
b <= output;
when move =>
case c is
when '0' =>
a <= input_1;
b <= output_1;
when '1' =>
a <= input_2;
b <= output_2;
when others => null;
end case;
end process;发布于 2014-05-20 08:19:50
你的问题充满了危险。将输出分配给内部信号可能需要输出端口模式为inout或buffer或VHDL2008支持,这对于合成来说并不通用。通常,模式缓冲区也不受支持。
为了切中问题的核心,顺序信号赋值支持何时在VHDL2008中被支持,但通常在综合中不被支持。
case语句选择包含顺序语句。
您可以改用if语句:
library ieee;
use ieee.std_logic_1164.all;
entity foo is
port (
signal input: in std_logic;
signal output: inout std_logic;
signal input_1: in std_logic;
signal input_2: in std_logic;
signal output_1: inout std_logic;
signal output_2: inout std_logic
);
end entity;
architecture fum of foo is
signal a, b: std_logic;
signal c: std_logic;
type some_state is (stop, move);
signal state: some_state;
begin
UNLABELED:
process(state)
begin
case state is
when stop =>
a <= input;
b <= output;
when move =>
if c = '0' then
a <= input_1;
b <= output_1;
else
a <= input_2;
b <= output_2;
end if;
end case;
end process;
end architecture;请注意,您对c的两次评估已合并为一次。
除了在VHDL2008中作为顺序语句支持的条件信号赋值状态之外,还有选定的信号赋值语句(同样,合成通常不支持作为顺序语句)。
发布于 2014-05-20 12:20:02
VHDL2008之前的版本没有用于顺序语句的三元运算符(类似于C的? :),因此您不能编写if c='0' then input_1 else input_2,但在VHDL2008中,您可以编写input_1 when c='0' else input_2。
然而,紧凑的编码风格可以通过制作一个小函数来实现:
function ternary(cond : boolean; res_true, res_false : std_logic) return std_logic is
begin
if cond then
return res_true;
else
return res_false;
end if;
end function;因此,代码的移动部分可以写成:
when move =>
a <= ternary(c='0', input_1, input_2);
b <= ternary(c='0', output_1, output_2);您还可以创建一个嵌套案例,如:
when move =>
case c is
when '0' =>
a <= input_1;
b <= output_1;
when others =>
a <= input_2;
b <= output_2;
end case;或者像大卫展示的那样使用if then else。
https://stackoverflow.com/questions/23748767
复制相似问题