In some FPGAs, floating point numbers cannot be operated directly, but only fixed points can be used for numerical operations. For FPGA, the book involved in mathematical operations is a 16-bit integer number. What if there is a decimal number in the mathematical operation? You must know that FPGA is powerless to decimal places. One solution is to adopt calibration. The number calibration is to increase the number of floating-point numbers to many times, then take an integer, and use this number for calculation. Then, the result of the calculation can be reduced to a specific multiple. Do not forget the decimal point during design. In FPGA, decimal points are not displayed. Only programmers know the decimal point. Q indicates the decimal place. q15 indicates that the decimal point is 15th digits.
Convert a floating point number (X) to a fixed point number (XQ): XQ = (INT) x * 2 ^ Q
X: x = (float) XQ * 2 ^ (-q)
For example, if the hexadecimal number is 2000 h, q0 is 8192. If q15 is used, it is 0.25.
The following describes how to determine the Q value in Q format calculation:
(1) fixed-point addition and subtraction: The addition and subtraction must be converted to the same Q format.
(2) Fixed-Point multiplication: data in different Q formats is multiplied, which is equivalent to the sum of Q values.
(3) fixed-point Division: Division of data in different Q formats, equivalent to subtraction of Q values
(4) shift left: equivalent to increasing the Q value
(5) shift right of a fixed point: equivalent to reducing the Q value
For example, q15 represents 4000 H (floating point number 0.5) multiplied by q15 represents 4000 H, 4000 H × 4000 H = 1000 0000 h, after which the Q value becomes 15 + 15 = 30, the result is 0.01b, indicating that the floating point number is 0.25.
Implementation of floating-point operations in FPGA-Calibration