从 VHDL 中的输入值开始倒数

Has*_*san 2 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;  
Run Code Online (Sandbox Code Playgroud)

我应该做什么才能减少过程中的输入“aa”?该程序旨在将输入值递减aa至 0。

ric*_*ick 5

看起来您正在尝试使用负载输入来实现递减计数器。在这样的计数器中,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;
Run Code Online (Sandbox Code Playgroud)

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