Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VHDL中子程序的条目_Vhdl - Fatal编程技术网

VHDL中子程序的条目

VHDL中子程序的条目,vhdl,Vhdl,我的代码中有两个函数: function derivative(error, previous_error, dt :in std_logic_vector(7 downto 0)) return std_logic_vector is variable derivative_val: std_logic_vector(15 downto 0); begin derivative_val := div(sub(error,previous_error),dt);

我的代码中有两个函数:

 function derivative(error, previous_error, dt :in std_logic_vector(7 downto 0)) return std_logic_vector is
  variable derivative_val: std_logic_vector(15 downto 0);
  begin
      derivative_val := div(sub(error,previous_error),dt);
      return derivative_val;
  end derivative;


function mul(num1,num2 : in std_logic_vector(7 DOWNTO 0)) return std_logic_vector is
    variable v_TEST_VARIABLE1 : integer;
    variable v_TEST_VARIABLE2 : integer;
    variable n_times: integer:=1;
    variable product: integer:=0;
    begin 
       v_TEST_VARIABLE1 := to_integer(unsigned(num1)) ; 
       v_TEST_VARIABLE2 := to_integer(unsigned(num2)) ;
      for n_times in 1 to v_TEST_VARIABLE2 loop
        product:=product + v_TEST_VARIABLE1;
      end loop;
    return std_logic_vector(to_unsigned(product,16));
  end mul;
在下半部分中,我尝试分配一个变量

 variable derivative_term: std_logic_vector(15 downto 0) := x"0000";
  derivative_term := mul(mul(Kp,Td), derivative(error, previous_error,dt));
在汇编方面,我得到了:

No feasible entries for subprogram "mul".
还有其他的使用方法吗?
提前感谢。

函数
mul
使用
num*
类型为
std\u logic\u vector的参数
num*
(7到 0)
因此长度为8,并返回类型为
std\u logic\u vector
长度的结果 十六,

因此,当调用
mul(mul(…),…)
时,外部
mul
将使用 类型
标准逻辑向量
的长度16,与要求的长度不匹配
函数的参数长度

您可以使用中的
“*”
,而不是编写自己的乘法函数
ieee.numeric\u std
,可用作:

slv_16_0 <= std_logic_vector(unsigned(slv_8_0) * unsigned(slv_8_1));

slv_16_0不,它有两个,mul(Kp,Td)和导数(error,previous_error,dt)。请为您的问题选择一个SE站点。(这是EE.SE上的一个副本。)正如您所解释的,如果slv_8_0的长度为16,slv_8_1的长度为8,并且我使用的函数取长度为8和8,那么考虑到没有明显的损失,是否有必要调整slv_8_0的大小?如果您想将16位
std_逻辑向量
调整为8位
std_逻辑向量
,然后你会松一些碎片。在这种情况下,可以使用
slv_8_1来截断MSB。这就是我所做的:变量积分1:std_逻辑向量(15到0):=x“0000”;变量v2:std_逻辑_向量(15到0);变量v3:std_逻辑_向量(7到0);v2:=标准逻辑向量((无符号(Kp)*无符号(积分1));v3:=标准逻辑向量(调整大小(无符号(v2)),8);在v3的赋值语句中,我得到了“类型转换(到std_逻辑_向量)不能有聚合操作数。”函数的
resize
有两个参数,但是
,8
是在end
)或resize之后给出的,因此
,8
std_逻辑_向量的参数一起,因此出现了错误。您可能还需要检查Kp*integration1的长度,因为它对于v2可能太长了。