首页 文章

VHDL:std_logic信号的“其他类似”命令

提问于
浏览
0

我想编写一个代码,其中我的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只是一个位,“其他”不能与它一起使用 . 所以我想问你是否有某种方法来实现命令“如果在过程中没有不同的指定,则设置为零” .

PS:我知道我可以简单地编写if的else分支,但我不想这样做,因为我的实际代码会更有问题 .

PPS:我目前发现的唯一解决方案是更换线路:

one_if_one <= (others => '0');

one_if_one <= 'L';

但这会有不同的含义,因为“他人”强加的零是强者 .

预先感谢您的帮助 .

1 回答

  • 0

    你不需要在这里做任何特别的事情 . 如果在特定进程中多次分配信号,则最后一次分配是实际分配的值 .

    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 类型的对象无关 .

相关问题