Forum: FPGA, VHDL & Co. Rechnen mit Fixed Point


von Fellap (Gast)


Lesenswert?

Hallo mal wieder...

ich versuche "bloß" zwei fixed pointed zahlen von einander abzuziehen 
und diese dann mit einer constanten zu mulitplizieren...

z.B.

a = 0.000001;
b = 0.000020;
c = 5;

z = (a - b) * c;

Nun die ganzen Fragen...

welche libraries benoetige ich hierfuer?
- ist unbedingt IEEE.Fixed_Pkg noetig?
- bzw. ist das auch mit folgenden Paketen moeglich:
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL; ?


Gibt es irgendwo Tutorials oder Beispielcode für solche Rechnungen? 
(Konnte nichts finden)

Wie kann man denn neue Libraries einbinden? - Habe fixed_pkg_c.vhdl in 
meinen Projektorder kopiert und dann use IEEE.fixed_pkg_c.ALL in mein 
geschrieben... Aber ihr werdet sicher wissen, dass dies nicht 
funktioniert hat...?!

Vielen Dank an euch!

von Christoph Z. (christophz)


Lesenswert?

Fellap schrieb:
> Wie kann man denn neue Libraries einbinden? - Habe fixed_pkg_c.vhdl in
> meinen Projektorder kopiert und dann use IEEE.fixed_pkg_c.ALL in mein
> geschrieben... Aber ihr werdet sicher wissen, dass dies nicht
> funktioniert hat...?!

Im Fall von lokalen packages versuche es mit (work ist die 
Projekt-lokale Library):
1
use work.fixed_pkg_c.ALL

von Marius W. (mw1987)


Lesenswert?

Fixed-Point ist doch nichts anderes als geeignetes Skalieren der Zahlen 
und sich merken, an welcher Stelle das Komma sitzt. Der Rest ist reine 
Integer-Arithmetik.

Gruß
Marius

von Valko Z. (hydravliska)


Lesenswert?


von Fellap (Gast)


Lesenswert?

Christoph Z. schrieb:
> Im Fall von lokalen packages versuche es mit (work ist die
> Projekt-lokale Library):use work.fixed_pkg_c.ALL

Dankeschön! :)

Ich habe mal den MinimalCode von  Andreas Schwarz ausprobiert und wollte 
diesen auf meinem BASYS2 testen...

1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
use work.math_utility_pkg.all;
5
use work.fixed_pkg.all;
6
entity top is
7
  
8
  port (
9
    in1        : in  STD_LOGIC_VECTOR (7 downto 0);  -- inputs
10
    out1       : out STD_LOGIC_VECTOR (7 downto 0)   -- output
11
   );  
12
                   
13
14
end entity top;
15
16
architecture rtl of top is
17
18
  signal x, y : sfixed (3 downto -3);
19
  
20
begin
21
  x <= to_sfixed(in1, 3, -3);
22
  y <= x * 2;
23
  out1 <= to_slv(y);
24
end rtl;

Jedoch bekomme ich andauernd die Warnung:
WARNING:Par:288 - The signal in1<0>_IBUF has no load.  PAR will not 
attempt to route this signal.
WARNING:Par:288 - The signal in1<1>_IBUF has no load.  PAR will not 
attempt to route this signal.
WARNING:Par:288 - The signal in1<2>_IBUF has no load.  PAR will not 
attempt to route this signal.
WARNING:Par:288 - The signal in1<3>_IBUF has no load.  PAR will not 
attempt to route this signal.
WARNING:Par:288 - The signal in1<4>_IBUF has no load.  PAR will not 
attempt to route this signal.
WARNING:Par:288 - The signal in1<5>_IBUF has no load.  PAR will not 
attempt to route this signal.
WARNING:Par:288 - The signal in1<6>_IBUF has no load.  PAR will not 
attempt to route this signal.
WARNING:Par:288 - The signal in1<7>_IBUF has no load.  PAR will not 
attempt to route this signal.

und deswegen funktioniert natuerlich auch gar nichts auf dem board...

mein UCF-File:
1
NET "out1<0>" LOC = "G1";
2
NET "out1<1>" LOC = "P4";
3
NET "out1<2>" LOC = "N4";
4
NET "out1<3>" LOC = "N5";
5
NET "out1<4>" LOC = "P6";
6
NET "out1<5>" LOC = "P7"; 
7
NET "out1<6>" LOC = "M11";
8
NET "out1<7>" LOC = "M5";
9
NET "in1<0>" LOC = "N3";
10
NET "in1<1>" LOC = "E2";
11
NET "in1<2>" LOC = "F3";
12
NET "in1<3>" LOC = "G3";
13
NET "in1<4>" LOC = "B4";
14
NET "in1<5>" LOC = "K3";
15
NET "in1<6>" LOC = "L3";
16
NET "in1<7>" LOC = "P11";

Wisst ihr vll wieso?

und was ich noch nicht ganz verstehe... was macht "to_slv(y)"?
Wenn ich nun wie oben zwei signale von einander subtrahieren moechte und 
anschliesend mit einer dritten, wie oben beschrieben, multiplizieren 
moechte...

wie wuerde dann der Code ungefaehr aussehen? (angenommen a und b hat nur 
max. 3 nachkommastellen)

dann waere doch ca. so oder?
1
architecture rtl of top is
2
3
  signal c : integer := 5;
4
  signal a, b, z : sfixed (3 downto -3); --a = 0.010; b =0.002; 
5
  
6
begin
7
  a <= to_sfixed(in1, 3, -3);
8
  b <= to_sfixed(in2, 3, -3); --wuerde auch (in1, 3, 0) mit (in2, 3, -3) funktionieren?
9
  
10
  z <= (a-b)*c;    --funktioniert das mit c oder muss ich das dann noch irgendwie casten?
11
  out1 <= to_slv(z);  --wozu dient to_slv(z)?
12
end rtl;

von Christoph Z. (christophz)


Lesenswert?

Fellap schrieb:
> out1 <= to_slv(z);  --wozu dient to_slv(z)?

Konvertiert in den Typ (S)tandard (L)ogic (V)ector (slv). z ist ja von 
dir mit dem Typ sfixed definiert worden.

von Duke Scarring (Gast)


Lesenswert?

Ich mache ja immer erstmal eine Simulation:

Fellap schrieb:
> library ieee;
> use ieee.std_logic_1164.all;
> use ieee.numeric_std.all;
> use work.math_utility_pkg.all; -- überflüssig?
> use work.fixed_pkg.all;
> entity top is
>
>   port (
>     in1        : in  STD_LOGIC_VECTOR (7 downto 0);  -- inputs
>     out1       : out STD_LOGIC_VECTOR (7 downto 0)   -- output
>    );
>
>
> end entity top;
>
> architecture rtl of top is
>
>   signal x, y : sfixed (3 downto -3);
>
> begin
>   x <= to_sfixed(in1, 3, -3);
>   y <= x * 2;
>   out1 <= to_slv(y); -- Fehler!
> end rtl;
Und da gibt es folgende aussagekräftige Fehlermeldung:
1
# ** Fatal: (vsim-3420) Array lengths do not match. Left is 8 (7 downto 0). Right is 7 (6 downto 0).

Duke

von Duke Scarring (Gast)


Angehängte Dateien:

Lesenswert?

Folgender Code wird bei mir erfolgreich simuliert:
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
--use work.math_utility_pkg.all;
5
6
library ieee_proposed;
7
use ieee_proposed.fixed_pkg.all;
8
9
entity top is
10
    port (
11
        in1  : in  std_logic_vector (7 downto 0);  -- inputs
12
        out1 : out std_logic_vector (7 downto 0)   -- output
13
        );
14
end entity top;
15
16
architecture rtl of top is
17
18
    signal x : sfixed (4 downto -3);
19
    signal y : sfixed (9 downto -3);
20
21
begin
22
23
    x    <= to_sfixed(in1, 4, -3);
24
    y    <= x * 2;
25
    out1 <= to_slv( y)(7 downto 0);
26
27
end architecture rtl;
Und auch synthetisiert (ISE 14.6), siehe Anhang.
Im Original scheinen die Bitbreiten nicht ganz zu passen.

Duke

von Fellap (Gast)


Lesenswert?

Duke Scarring schrieb:
> Folgender Code wird bei mir erfolgreich simuliert:

Ahh ja.. jetzt klappt es auch bei mir.. Danke!!!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.