Estoy escribiendo un paquete para agregar funciones y tipos de soporte para crear un filtro FIR. En la mult
función, estoy tratando de multiplicar dos tipos firmados, que deberían ser compatibles con IEEE.numeric_std
la biblioteca. El error que recibo (usando Libero IDE) es:
0 definitions of operator "*" match here
Aquí está el código:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
package fir_pkg is
constant taps : integer := 8;
constant bit_width : integer := 8;
type fract is array(bit_width-1 downto 0) of std_logic;
type fract2 is array((2*bit_width)-1 downto 0) of std_logic;
type fract_sequence is array(taps-1 downto 0) of fract;
type fract2_sequence is array(taps-1 downto 0) of fract2;
function mult(a,b: fract_sequence) return fract2_sequence;
end package fir_pkg;
package body fir_pkg is
function mult(a,b: fract_sequence) return fract2_sequence is
variable a_s, b_s:signed(bit_width-1 downto 0);
variable seq: fract2_sequence;
begin
for i in a'range loop
a_s := signed(a(i));
b_s := signed(b(i));
seq(i) := a_s * b_s;
end loop;
return seq;
end mult;
end fir_pkg;
Muéstrame por qué no puedes hacer subtipos fract y fract2 de std_logic_vector:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
package fir_pkg is
constant taps : integer := 8;
constant bit_width : integer := 8;
subtype fract is std_logic_vector (bit_width-1 downto 0);
-- type fract is array(bit_width-1 downto 0) of std_logic;
-- type fract2 is array((2*bit_width)-1 downto 0) of std_logic;
subtype fract2 is std_logic_vector(2*bit_width-1 downto 0);
type fract_sequence is array(taps-1 downto 0) of fract;
type fract2_sequence is array(taps-1 downto 0) of fract2;
function mult(a,b: fract_sequence) return fract2_sequence;
end package fir_pkg;
package body fir_pkg is
function mult(a,b: fract_sequence) return fract2_sequence is
variable a_s, b_s:signed(bit_width-1 downto 0);
variable seq: fract2_sequence;
begin
for i in a'range loop
a_s := signed(a(i));
b_s := signed(b(i));
seq(i) := std_logic_vector(a_s * b_s);
end loop;
return seq;
end mult;
end fir_pkg;
subtype
. ¡Gracias!signed
directamente en lugar de std_logic_vector
.fract2
no es compatible con signed
, por lo que no se puede encontrar ninguna función multiplicadora con el tipo de retorno correcto.
Cambie la definición de fract
y fract2
a esto:
subtype fract is signed(bit_width-1 downto 0);
subtype fract2 is signed((2*bit_width)-1 downto 0);
El problema era que se esperaba que el resultado del producto fuera signed
( fract2
tipo personalizado definido aquí) en su lugar.
Entonces, necesitamos crear una función para convertir el tipo. La conversión de tipo se explica aquí .
El código para la función de conversión aquí:
function conv_fract2(a:signed) return fract2 is
variable var:fract2;
begin
assert a'length = bit_width;
for i in a'range loop
var(i) := a(i);
end loop;
return var;
end conv_fract2;
usuario8352
prabhpreet
seq(i)
en la siguiente declaración. ¿Cómo puedo crear operadores de conversión de firmado a mi tipo personalizado (todavía basado enstd_logic
)?prabhpreet