VHDL:"others-like" 命令用于 std_logic 信号
VHDL: "others-like" command for std_logic signals
我想编写一个代码,其中我的 W_EN (std_logic) 信号在需要时设置为一个(如果满足某些条件),否则(如果没有不同的指定)为零。如果 W_EN 将是一个 std_logic_vector,我可以使用 "others" 语句以这种方式执行此操作(在示例代码中 "W_EN" 被称为 "one_if_one") :
signal cnt : unsigned (1 downto 0); --incremented at every clk_cycle
signal one_if_one : std_logic;
process (cnt)
begin
one_if_one <= (others => '0');
if (cnt = "01") then
one_if_one <= '1';
end if;
end process;
但是由于W_EN只是一个位,所以"others"不能和它一起使用。
所以我想问问大家有没有什么方法可以实现命令"set to zero if not differently specified in the process".
PS:我知道我可以简单地编写 if 的 else 分支,但我不想这样做,因为这对我的实际代码来说会更有问题。
PPS:我目前找到的唯一解决方案是替换行:
one_if_one <= (others => '0');
和
one_if_one <= 'L';
但这会有不同的含义,因为 "others" 强加的零是一个强零。
预先感谢您的帮助。
您不需要在这里做任何特别的事情。如果信号在特定进程中被分配多次,则 last 分配是实际分配的值。
process (cnt)
begin
one_if_one <= '0';
if (cnt = "01") then
one_if_one <= '1';
end if;
end process;
相当于
process (cnt)
begin
if (cnt = "01") then
one_if_one <= '1';
else
one_if_one <= '0';
end if;
end process;
您尝试使用的 others
语法专门用于分配数组类型,因此它对于 std_logic
.
类型的对象没有任何意义
我想编写一个代码,其中我的 W_EN (std_logic) 信号在需要时设置为一个(如果满足某些条件),否则(如果没有不同的指定)为零。如果 W_EN 将是一个 std_logic_vector,我可以使用 "others" 语句以这种方式执行此操作(在示例代码中 "W_EN" 被称为 "one_if_one") :
signal cnt : unsigned (1 downto 0); --incremented at every clk_cycle
signal one_if_one : std_logic;
process (cnt)
begin
one_if_one <= (others => '0');
if (cnt = "01") then
one_if_one <= '1';
end if;
end process;
但是由于W_EN只是一个位,所以"others"不能和它一起使用。 所以我想问问大家有没有什么方法可以实现命令"set to zero if not differently specified in the process".
PS:我知道我可以简单地编写 if 的 else 分支,但我不想这样做,因为这对我的实际代码来说会更有问题。
PPS:我目前找到的唯一解决方案是替换行:
one_if_one <= (others => '0');
和
one_if_one <= 'L';
但这会有不同的含义,因为 "others" 强加的零是一个强零。
预先感谢您的帮助。
您不需要在这里做任何特别的事情。如果信号在特定进程中被分配多次,则 last 分配是实际分配的值。
process (cnt)
begin
one_if_one <= '0';
if (cnt = "01") then
one_if_one <= '1';
end if;
end process;
相当于
process (cnt)
begin
if (cnt = "01") then
one_if_one <= '1';
else
one_if_one <= '0';
end if;
end process;
您尝试使用的 others
语法专门用于分配数组类型,因此它对于 std_logic
.