Ich schreibe ein Paket, um unterstützende Funktionen und Typen zum Erstellen eines FIR-Filters hinzuzufügen. In der mult
Funktion versuche ich, zwei signierte Typen zu multiplizieren, die in der IEEE.numeric_std
Bibliothek unterstützt werden sollten. Der Fehler, den ich bekomme (mit Libero IDE) ist:
0 definitions of operator "*" match here
Hier ist der Code:
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;
Zeigen Sie mir, warum Sie keine fract- und fract2-Untertypen von std_logic_vector erstellen können:
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
. Danke!signed
direkt anstelle von std_logic_vector
.fract2
ist nicht kompatibel mit signed
, daher kann keine Multiplikatorfunktion mit dem richtigen Rückgabetyp gefunden werden.
Ändern Sie die Definition von fract
und fract2
wie folgt:
subtype fract is signed(bit_width-1 downto 0);
subtype fract2 is signed((2*bit_width)-1 downto 0);
Das Problem war, dass das Ergebnis des Produkts erwartet wurde, signed
aber fract2
stattdessen (hier definierter benutzerdefinierter Typ) war.
Also müssen wir eine Funktion erstellen, um den Typ zu konvertieren. Die Typumwandlung wird hier erklärt .
Der Code für die Konvertierungsfunktion hier:
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;
Benutzer8352
Prabhpreet
seq(i)
in der nächsten Anweisung. Wie kann ich Konvertierungsoperatoren von signiert zu meinem benutzerdefinierten Typ erstellen (immer noch basierend aufstd_logic
)?Prabhpreet