在解码器上放置使能输入 (VHDL)

Putting an enable input on a decoder (VHDL)

我有一个 4 到 16 的 vhdl 解码器。我想输入一个启用输入,但我是 vhdl 编码的新手。我想保留代码的这种结构(我不想使用任何其他快捷方式或完全更改的代码)。我尝试为启用编写一个 e 输入,并尝试执行 if e = "1" then 但它不起作用。

library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity decode4to16 is
port(
oct : in std_logic_vector(3 downto 0);
e : in std_logic;
dec : out std_logic_vector(15 downto 0));
end decode4to16;
architecture arch of decode4to16 is
begin
if e = "1" then
with oct select
dec <=
"0000000000000001" when "0000",
"0000000000000010" when "0001",
"0000000000000100" when "0010",
"0000000000001000" when "0011",
"0000000000010000" when "0100",
"0000000000100000" when "0101",
"0000000001000000" when "0110",
"0000000010000000" when "0111",
"0000000100000000" when "1000",
"0000001000000000" when "1001",
"0000010000000000" when "1010",
"0000100000000000" when "1011",
"0001000000000000" when "1100",
"0010000000000000" when "1101",
"0100000000000000" when "1110",
"1000000000000000" when "1111",
"0000000000000000" when others;
end if;
end arch;

以后请使用适当的缩进,以方便阅读。

if 语句只能在进程中使用,正如@Josh 指出的那样,e 是一个 std_logic],在验证或分配它的值时需要单引号。最终结果是这样的:

DECODER: process(e, oct) -- e and oct are in sensitivity list, which means output the process statements are executed whenever one of these change
begin
    if e = '1' then
        case oct is
            when "0000" => dec <= X"0001";
            when "0001" => dec <= X"0002";
            ...
            when others => dec <= X"0000";
        end case;
    end if;
end process DECODER;

附带说明一下,这将创建一个 锁存器 ,因为存在一个隐式行为,即信号的值在未分配时不会更改。在这种情况下,当 e 为“0”时会发生这种情况;即您的陈述中没有其他内容。这可能不是您想要的,当 e 为“0”时,应该为 dec 赋值。