I'm trying to use a function created by myself (it's the first time I try it so I might probably have done something wrong there).
When I try to compile I get the following error message: Error (13815): VHDL Qualified Expression error at Averageador.vhd(38): divide type specified in Qualified Expression must match unsigned type that is implied for expression by context
Divide is the name of my function. This function divides any 16bit unsigned value by an unknown unsigned value and gives the result as a fixed point 32bit unsigned value, where 16bit are on each side of the point. This is the code:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
package propios is
--function declaration.
function divide (a : UNSIGNED; b: UNSIGNED) return UNSIGNED;
end propios; --end of package.
package body propios is --start of package body
--definition of function
function divide (a : UNSIGNED; b: UNSIGNED) return UNSIGNED is
variable a_int : unsigned(a'length+7 downto 0):= (others => '0');
variable b_int : unsigned(b'length-1 downto 0):=b;
variable r : unsigned(b'length downto 0):= (others => '0');
variable q : unsigned(31 downto 0):= (others => '0');
begin
a_int(a'length+7 downto 16):=a;
for i in a'length+7 downto 0 loop
r(b'length downto 1):=r(b'length-1 downto 0);
r(0) := a_int(i);
if (r>=q) then
r:=r-b_int;
q(i):='1';
end if;
end loop;
return q;
end divide;
--end function
end propios; --end of the package body
I return q which is a 32-bit unsigned.
This is a code in which I use the function and prompts the error message:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.propios.all;
ENTITY test IS --Con alimentación de datos posición a posición, no vector de golpe.
END test;
Architecture simple of test is
signal a:unsigned(15 downto 0);
signal b:unsigned(13 downto 0);
signal c: unsigned(31 downto 0);
begin
process
begin
a<="1100100110100111";
b<="00000000000010";
c<= divide(a,b);
end process;
end simple;
Any suggestions? Thank you
if posicion <= "00000000" thenposicion is unsigned, it's never less than 0. - user1155120a_int(a'length + 7 downto 16) := a;will generate an error in function divide. IEEE Std 1076-2008 10.6.2 Simple variable assignments, 10.6.2.1 paragraphs 5 and 7. The subtype of the right hand side expression does not belong to the target subtype, that's an error. - user1155120