12-09-2021 03:53 PM
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?
Solved! Go to Solution.
12-09-2021 05:18 PM
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?
12-10-2021 12:51 AM - edited 12-10-2021 01:03 AM
12-10-2021 11:26 AM
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.
12-10-2021 11:46 AM
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.
12-10-2021 11:47 AM
@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!
12-10-2021 04:26 PM
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!
12-11-2021 03:19 AM - edited 12-11-2021 03:20 AM
@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?
12-11-2021 04:28 AM
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?)
12-11-2021 05:30 AM - edited 12-11-2021 05:44 AM
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.