微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 问一个VHDL 函数的问题

问一个VHDL 函数的问题

时间:10-02 整理:3721RD 点击:
文件ahb_func.vhd的内容如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
package ahb_funct is

function nb_bits (A : INTEGER) return NATURAL;
end ahb_funct;
package body ahb_funct is
   function nb_bits (A : INTEGER) return NATURAL is
    variable logres : NATURAL ;
    begin
     logres := 1;
     for i in 0 to 30 loop
      if 2**i <= A then
        logres := i+1;
      end if;
     end loop;
     return logres;
   end nb_bits;
end ahb_funct;

文件tb.vhd的内容如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use work.ahb_funct.all;
library novas;
use novas.pkg.all;
entity tb is
generic (
  fifo_length: in integer:= 4);
end
architecture rtl of tb is
signal count: std_logic_vector(nb_bits(fifo_length)-1 downto 0);
begin
dump_pr: process
begin
  fsdbDumpfile("tb.fsdb");
  fsdbDumpvars(0, "tb");
  wait;
end process;
end rtl;
仿真后用Debussy查看count信号,为什么是count[-1:0]?正确的应该是count[2:0]。
函数nb_bits哪里有错误么?
望高手指正!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top