Forum: FPGA, VHDL & Co. Verständnisfrage zu Fixed-Point Zahlen


von Marius S. (lupin) Benutzerseite


Lesenswert?

Ich möchte Werte im Bereich von -1 bis +1 als Fixed-Point abbilden.

Wenn ich dafür z.B. 8 Bit nehme wären das ja -128 bis 127. Hier ist auch 
schon das Problem. Wenn ich 127 wieder als Gleitkomma interpretiere 
kommen da ja 0,9921875 raus.

Also nehme ich jetzt 9 Bit zum speichern der Werte und nutze nur -128 
bis +128 als Wertebereich. Gibt es da eine bessere Methode?

Und jetzt stehe ich auch noch vor dem Problem, dass ich bei einer 8 Bit 
Zahl mit -128 und 127 durch den Überlauf quasi eine Modulo-Operation 
umsonst bekomme.

Wenn ich 9 Bit nehme möchte ich gerne den Wertebereich auf -128 bis +128 
einschränken. Wie würde man das in VHDL am geschicktesten realisieren?

von Ale (Gast)


Lesenswert?

What you have to keep in mind is that in fixed point notation the binary 
point remains at a specific place. The bits at the right are the 
fraction, then you have for the first bit 1/2, sencod 1/4 third 1/8 and 
so on from left to right.

1/2 = 0.1000000
1,5 = 1.1000000
0,333 ~ 0.0101010

You always calculate with all the bits and then you can to convert to 
decimal if necessary.

Of course you have to take overflow in account and check if it happens 
and scale accoringly...

A simple test for overflow is: V = A7  B7  (~R7) + (~A7) * (~B7) * R7 
for addition
and V = A7 * (~B7) * (~R7) + (~A7)  B7  R7 for subtraction.
A7, B7 and R7 are the MSBs of the two operand and the result 
respectively. When it gives 1, then there was overflow.

Hope it helps

von Ale (Gast)


Lesenswert?

It seems that the * where eaten in the equations avobe :(

add : V = A7 | B7 | (~R7) & (~A7) | (~B7) | R7
sub : V = A7 | (~B7) | (~R7) & (~A7) | B7 | R7

von optiker (Gast)


Lesenswert?

Marius S. schrieb:
> Wenn ich 9 Bit nehme möchte ich gerne den Wertebereich auf -128 bis +128
> einschränken. Wie würde man das in VHDL am geschicktesten realisieren?

Naja, einfach mit if then limitieren oder in INT rechnen und den 
Wertebereich passend setzen. Man sollte aber in Erwägung ziehen auf 127 
zu limitieren, da man so Bits spart

----

Simply Limit by IF THEN construct or better use integer values as 
signals. you might also consider to Limit to 127 not be require another 
bit for just one single value

von Marius S. (lupin) Benutzerseite


Lesenswert?

If i limit to 127 i can not correctly represent my fixed point numbers. 
Using integers might be the best idea.

Actually, where is the difference between using integer or 
signed/unsigned data type? Can i specify signed/unsigned with a range 
also?

von Michael S. (decimad)


Lesenswert?

Meinem Verständnis nach sind 9 bit nicht genug, wenn Du weiter im 
2er-Komplement arbeiten willst UND 1.0 und -1.0 darstellen möchtest.

Also ich würde jetzt denken: 2.8 fixed point und für "10......." und 
"01......." alle Folgestellen auf 0 setzen, also so dass die Zahl 
sozusagen saturiert.

von Michael S. (decimad)


Lesenswert?

Erm, natürlich muss für "10" am Ende alles mit Einsen aufgefüllt werden 
hüstel

von Lupin (Gast)


Lesenswert?

Michael, dann hast du glaube ich was falsch verstanden denn -1 wäre 
0b111111111

von Michael S. (decimad)


Lesenswert?

Ja, da hätte ich noch etwas rumprokeln müssen, also nicht "10" -> mit 
einsen auffüllen, sondern "1......." mit einsen auffüllen, da erwischt 
man sowieso auch die -2 :D
Aber zu der 2.8 stehe ich noch immer, wenn es um 8 nachkomma-bits geht. 
Oder nicht?

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.