1

I am using Vivado for Zedboard. I have my custom IP contains 32 bit input and output .I need to do some arithmetic operation with fixed point number too. But this fixed point number shall be sent from SDK to FPGA part. So my question is how to represent float_value = 0.2 as fixed point in SDK ?

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • Can I ask you where in the fpga do you want to send the data? I mean: to an hardware accelerator created with HLS? To another ip of Xilinx? To an ip created with HLD? What about the interface you want to use? Give us some more details in order to be specific – Leos313 Jul 08 '16 at 17:43

2 Answers2

0

As it was explained here you can "translate" a floating point number in a fixed-point number using this simply code (it is just an example, you can use a lot of different way, I am sure better than this easy way):

#include <stdio.h>
typedef int Fixed;

#define FRACT_BITS 16
#define FRACT_BITS_D2 8
#define FIXED_ONE (1 << FRACT_BITS)
#define INT2FIXED(x) ((x) << FRACT_BITS)
#define FLOAT2FIXED(x) ((int)((x) * (1 << FRACT_BITS))) 
#define FIXED2INT(x) ((x) >> FRACT_BITS)
#define FIXED2DOUBLE(x) (((double)(x)) / (1 << FRACT_BITS))
#define MULT(x, y) ( ((x) >> FRACT_BITS_D2) * ((y)>> FRACT_BITS_D2) )

But you MUST be careful to many things. One is related with the eventually lose of the precision (not every times is like this); in any case the range of value is completly different and, in the FPGA, you should manage the data no more as float (for instance it mean that a multiplication is done in a different way, saving a lot of resources of course). After, if you want to send data to FPGA, you can use the standard AXI4 interface for example. I have some example about this with m_axi interface and with axis interface: it is a common way used to save resources, paying the price of losing computation precision. You should evaluate case by case of course.

Community
  • 1
  • 1
Leos313
  • 5,152
  • 6
  • 40
  • 69
-1

First you need to define the precision of your fixed point. Say you are using 16 bits precision.

You would represent 0.2 as 0.2 * 2 ^ 16 and losing every decimal case. You basically shift the number 16 times to the left.

which is 13107,2 then you lose everything after the , so 13107 or 0x3333.

aprado
  • 31
  • 2
  • 6
  • 1
    It is impossible to understand what you mean in the last sentence so I cannot say if I agree or not. In any case it is absolutely possible to represent data in fixed point (in Xilinx SDK) without losing precision. – Leos313 Jul 08 '16 at 13:39