【问题标题】:VHDL - Assigning Default ValuesVHDL - 分配默认值
【发布时间】:2013-01-25 17:29:24
【问题描述】:

我有以下架构:

architecture datapath of DE2_TOP is

begin
  U1: entity work.lab1 port map ( --error on this line
    clock => clock_50,
    key => key,
    hex6 => hex6,
    hex5 => hex5,
    hex4 => hex4
  );

end datapath;

这个架构显然依赖于 lab1 实体。这是我的 lab1 实体和架构:

entity lab1 is
    port(
        clock : in std_logic;
        key : in std_logic_vector(3 downto 0);
        hex4, hex5, hex6 : out std_logic_vector(6 downto 0);
        value_counter   : in unsigned(7 downto 0);
        register_counter : in unsigned(3 downto 0)
        );
end lab1;

architecture up_and_down of lab1 is
    signal hex5_value : unsigned(7 downto 0);
        begin
    process(clock)
        begin
            value_counter<="00000000"; --default values?
            register_counter<="0000";
            if rising_edge(clock) then
                if (key(3)='0' and key(2)='0' and key(1)='1' and key(0)='0') then
                    value_counter <= value_counter + "1";   
                elsif (key(3)='0' and key(2)='0' and key(1)='0' and key(0)='1') then  
                    value_counter <= value_counter - "1";   
                end if;
            end if;
            hex5_value <= (value_counter - (value_counter mod 10))/10;
    end process;

end architecture up_and_down;

我收到以下错误:Error (10346): VHDL error at DE2_TOP.vhd(280): formal port or parameter "value_counter" must have actual or default value 在指示的行上。在我看来,我已经在我的 lab1 架构中设置了默认值。有谁知道问题出在哪里?

【问题讨论】:

    标签: compiler-errors default-value vhdl


    【解决方案1】:

    这不是“默认值”,而是初始化它的赋值。它还分配给非法的输入端口。此外,实体是在架构之前编译的,因此(非法)分配还不存在。

    signal value_counter : unsigned(7 downto 0) := (others => 'X'); 
    

    是一个默认值(或初始值),在声明中提供

    port (
       value_counter   : in unsigned(7 downto 0) := (others => '1'); 
    

    将是输入端口的默认值,但我从未见过这样做。 我一直在端口映射中连接所有输入端口。如果这行得通,我(有点)印象深刻,但可能不足以对未连接的输入感到高兴;这样一来似乎很容易忽略错误。

    【讨论】:

    【解决方案2】:

    您没有在value_counter 输入上驱动任何东西。所有实体输入都必须有驱动它们的信号,或者实体声明中指定的默认值。

    后者对于可选的输入很有用:

    entity lab1 is
        port(
            clock : in std_logic;
            key : in std_logic_vector(3 downto 0);
            hex4, hex5, hex6 : out std_logic_vector(6 downto 0);
            value_counter   : in unsigned(7 downto 0) := (others => '-');
            register_counter : in unsigned(3 downto 0)
            );
    end lab1;
    

    如果您不连接它,将确保 value_counter 获得分配给它的无关位 (-)。或者,如果您希望它全部为零,

            value_counter   : in unsigned(7 downto 0) := (others => '0');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多