LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate what size fixed point type I need?

Solved!
Go to solution

Might be a stupid question but I know I'm limited on the values I can display when it comes to fixed point type. In my FPGA, I'm calculating power factor. But my fixed point value is coming out to a 1, when in reality its more like 0.98 or 0.97. 

 

Is there a way to figure out the correct word length for my FXP based on the value I need to display?

0 Kudos
Message 1 of 12
(4,533 Views)

This is a range analysis.  Have you seen the fixed point documents such as: https://zone.ni.com/reference/en-XX/help/371599N-01/lvfpgaconcepts/fpgafixedpoint/

 

You may need more bits on the fractional side of things.  Can you probe to see where the values saturate?


Certified LabVIEW Architect, Certified Professional Instructor
ALE Consultants

Introduction to LabVIEW FPGA for RF, Radar, and Electronic Warfare Applications
Message 2 of 12
(4,510 Views)

Hi David,

 

when configuring the FXP datatype you will see the range (min/max value) and the resolution (delta) in the properties dialog.

Is there any information else needed?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 12
(4,480 Views)

Well, the thing is is I can't change everything inside the high throughput cosine function. And I THINK this might be where my problem is.

cos 1.pngcos 2.png

0 Kudos
Message 4 of 12
(4,453 Views)

The output has 52-19-1=32 bits for the fractional side there shouldn't be rounding.  That is more than enough to see the decimal values you mention.  I think something else is your issue.


Certified LabVIEW Architect, Certified Professional Instructor
ALE Consultants

Introduction to LabVIEW FPGA for RF, Radar, and Electronic Warfare Applications
Message 5 of 12
(4,451 Views)

@Terry_ALE wrote:

The output has 52-19-1=32 bits for the fractional side there shouldn't be rounding.  That is more than enough to see the decimal values you mention.  I think something else is your issue.


Thank you, I'll keep digging!

0 Kudos
Message 6 of 12
(4,449 Views)
Solution
Accepted by topic author David99999

Alrighty. The problem was that I was inputting radians into the cosine function, and not pi radians. I did not know there was a difference! I needed to divide by pi a second time.

 

But I do understand FXP's a little better now so thanks!

0 Kudos
Message 7 of 12
(4,439 Views)

@David99999 wrote:

Alrighty. The problem was that I was inputting radians into the cosine function, and not pi radians. I did not know there was a difference! I needed to divide by pi a second time.

 

But I do understand FXP's a little better now so thanks!


But you multiply with pi in your snippet so how can you divide a second time?

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 12
(4,421 Views)

Hi David,

 


@David99999 wrote:

The problem was that I was inputting radians into the cosine function, and not pi radians. I did not know there was a difference!


What is "pi radians" exactly? What is the difference between "radians" and "pi radians"?

 

Other question:

In your image there is a "x" input defined as "±,52,19": Do you really need an input range of ±524288 for the SinCos calculation? Why is the range that large for a function basically defined from 0…2pi?

Do you really need a FXP resolution of 32 bits? What kind of data do you want to handle? (Which accuracy is needed for your calculations?)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 12
(4,417 Views)

I think the problem was that the normal floating point functions expect an input of radians (0 - 2pi) while the FPGA functions expect a normalized input (0 - 1). That fact is documented because is allows a significant more efficient implementation in FPGA fabric. 

The thing is, in the earlier image there was a division by 180 and then a multiplication by pi and then he talks about an additional division by 2pi, which would be simply a single division by 360. And yes if you make sure to limit the input to 0 - 360 respective 0 to 1 you can limit the FXP range to have one integer bit only and reduce the size significantly.

 

Strictly speaking you can limit the range to [0.0 - 360.0) respective [0.0 - 1.0), so excluding the upper limit and then you only need an FXP with enough fractional part bits. Depending on the accuracy your angle needs/can have a 16,0 FXP number (would be better than 4 digits or 0.1 degree accurate) could be more than enough.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 10 of 12
(4,408 Views)