【问题标题】:Putting an enable input on a decoder (VHDL)在解码器上放置启用输入 (VHDL)
【发布时间】:2015-05-31 06:18:54
【问题描述】:

我在 vhdl 中有一个 4 到 16 的解码器。我想输入一个启用输入,但我是 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;

【问题讨论】:

    标签: vhdl decoder


    【解决方案1】:

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

    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 分配一个值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 2016-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      相关资源
      最近更新 更多