Fixed-point with fixed_pkg
Understand ufixed, sfixed, fractional bits, resize and conversion to std_logic_vector.
Why fixed-point
An FPGA naturally manipulates bits. To represent values such as 0.75, -1.25 or a filter gain, floating-point is often avoided. A common solution is fixed-point: a binary integer with a known binary point position.
Example on 8 bits in Q4.4:
- 4 bits for the integer part;
- 4 bits for the fractional part;
- the physical value is the binary word divided by
2^4.
The fixed_pkg package
VHDL-2008 provides fixed_pkg:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.FIXED_PKG.ALL;It mainly defines:
| Type | Use |
|---|---|
ufixed | unsigned fixed-point number |
|