LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

[FPGA] Reinterpret FXP

Is there a way to reinterpret a FXP number with a control? So that I can choose the number of positions I want the decimal point to move without increasing the number of bits used, nor losing precision. 

0 Kudos
Message 1 of 6
(2,970 Views)

Hi gerard,

 

what about the ToFXP function? It's available in the FPGA…

 

So that I can choose the number of positions I want the decimal point to move without increasing the number of bits used, nor losing precision. 

How do you want to change the number? Could you provide an example?

When you use the same amount of bits and the same resolution then where do you want to "move the decimal point"? (Btw. FXP numbers use a binary point as they are coded using base 2! :D)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(2,954 Views)

Can you explain more about the use case you have in mind for such functionality?

0 Kudos
Message 3 of 6
(2,923 Views)

Yes, I should have said binary point. In any case: the application is real time signal processing with an FPGA. There is a signal that I may want to, internally, amplify by multiplying it by 2^n (where n can be negative). I'm not multiplying by an arbitrary constant because execution time and number of DSPs used are crucial. For this, I would just need to change the "binary point" position (aka reinterpret the number) dynamically, meaning that I would like to change this prefactor arbitrarily, but without truncating the variable, as to FXP seems to do. Just move the point up and down to whatever position I want without changing the number of bits. 

 

I'm not sure that is possible though. It's a pity I can't work with floating point variables.

0 Kudos
Message 4 of 6
(2,920 Views)

If you're just wanting to scale by a power of 2, that's not really a problem. Scaling by a power of 2 is supported on LabVIEW FPGA:

http://zone.ni.com/reference/en-XX/help/371361J-01/glang/scale_by_power_of_2/

 

Alternatively, you can also use a Shift function to perform the same operation but you have to be careful about your sign bit (which makes the Scale by Power of 2 safer if your FXP type is signed):

http://zone.ni.com/reference/en-XX/help/371361J-01/glang/logical_shift/

 

Also, you actually can work with floating point numbers on FPGA -SGLs are a supported data type but your operations become more "expensive" because of having to deal with the mathematical operations to deal with moving the decimal point around. I'd most likely recommend sticking with FXP and keeping enough bits to handle your desired precision.

 

 

 

0 Kudos
Message 5 of 6
(2,912 Views)

Hi Gerard,

 

Since the FXP precision and generally the types are configured at compile time then they have to be fixed. I think you have a couple of options though:

 

  1. Make the control large and at the last minute use the scale by power of 2 to change the number to what you want. That way you save resources all the way to the end. 
  2. There is a fixed point to integer cast. This would let you transfer it as an integer and then you can probably do some form of cast/conversion on the host to the expected number.
  3. Ignore fixed point! do everything as integer maths and then do a cast to fixed point at the end on the host. Mathematically it is the same - as you point out it is purely your interpretation of where the "binary point" is that makes it a real number.

I'm not sure I fully understand your entire structure but hopefully that helps give some ideas.

 

Cheers,

James

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 6 of 6
(2,904 Views)