从VHDL中的输入值向下计数

时间:2013-10-21 19:16:18

标签: vhdl

我正在尝试将输入aa的值分配给下面代码中的信号t。它编译成功,但有一个警告:

警告[9]:C:/Modeltech_5.7f/examples/hassan1.vhd(14):( vcom-1013)“t”的初始值取决于信号“aa”的值。

以下是代码:

library IEEE;
use IEEE.std_logic_1164.all; 
use IEEE.std_logic_unsigned.all ;
use ieee.numeric_std.all; 
entity counter is
port(clk :in std_logic;
 reset : in std_logic;
 aa: in std_logic_vector(3 downto 0);
 check : out std_logic_vector(3 downto 0));
end counter;     

architecture imp of counter is 
signal i:std_logic_vector(3 downto 0):="0000"; 
signal t:std_logic_vector(3 downto 0):=aa;
begin
 process(clk)
  begin
  if rising_edge(clk) and (t>0) then
      t<=t-1;
      i<=i+1;
  end if;
 end process;
check<=i;
end  imp;  

为了减少流程中的输入'aa',我应该怎么做?该程序旨在将输入aa的值减小为0。

1 个答案:

答案 0 :(得分:3)

看起来您正在尝试使用负载输入实现向下计数器。在这样的计数器中,当load_enable = '1'时,您应该将负载输入值(在您的情况下为aa)注册到内部信号中。当load_enable = '0'时,您将减少此计数值。这是一个代码示例:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std_unsigned.all;

entity down_counter is
  port (
    clock: in std_logic;
    reset: in std_logic;
    load_enable: in std_logic;
    load_data: in std_logic_vector(3 downto 0);
    output: out std_logic_vector(3 downto 0)
  );
end;

architecture rtl of down_counter is
    signal count: std_logic_vector(3 downto 0);
begin
    process (clock, reset) begin
        if reset then
            count <= (others => '0');
        elsif rising_edge(clock) then
            if load_enable then
                count <= load_data;
            else
                count <= count - 1;
            end if;
        end if;
    end process;

    output <= count;
end;

为了记录,上面的代码可以改进,但我不想一次扔太多东西。对计数信号使用整数而不是std_logic_vector可能是个好主意。此外,您应该检查计数是否按预期进行,因为该示例使用numeric_std_unsigned包。我建议您在完全理解代码后将其更改为numeric_std

相关问题