LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fpga

Solved!
Go to solution

Hi,

 

i'm working on a 7856R USB FPGA and i want calculate pow(x,y) (x to the power of y). 

Is it possible to calculate it on the fpga ?

 

thks

0 Kudos
Message 1 of 11
(3,220 Views)

I don't believe the FPGA has a default function to do X^Y.  But here is some simple math than can be used.  This could be created into a SubVI for instance:

 

X^Y.png

 

Example execution:

 

 example.png

 

I tested this very quickly and it seems to mathematically make sense.  But if there are any issues, it should be "similar" to a correct approach at least 😄

 

EDIT:

 

Per the post below me (with much better FPGA specific info than I provided), you can use the following function on the Host: http://zone.ni.com/reference/en-XX/help/371361J-01/glang/power_of_x/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 2 of 11
(3,211 Views)

That depends on your values of x and y.  Remember X^Y can be represented in other ways.  You could say take X and multiply it by X in for loop, Y number of times.  But depending on your values of X and Y this may rollover.  

 

Another option is to do this on the host side if it is not a time critical function.

Message 3 of 11
(3,204 Views)

thks guys,

In my case it's 10 power of a a(-2;2). It's time critical and i have to implement it in a sctl loop. i'll test your proposition!

 

0 Kudos
Message 4 of 11
(3,187 Views)

I don't think a single multiple takes place in a SCTL.  The fact that you'll need many means you will not be able to do this the way you want.  Keep in mind that these FPGAs already have dedicated multiply functions built on the FPGA.  Normally you'd need to implement the multiply with gates taking tons of resources and time for a single multiply.

 

Edit:  Wait so are you saying you need to perform 10^A where the variable A will only have 5 different values? -2, -1, 0, 1, and 2?  If so this is super easy just use a case structure and output a constant for the values of A.

0 Kudos
Message 5 of 11
(3,166 Views)

@Hooovahh wrote:

I don't think a single multiple takes place in a SCTL.


You can put a mutiply inside a SCTL.

 

Your suggestion is exactly right that if it's a small, fixed range of values, it will be better to pre-compute.

0 Kudos
Message 6 of 11
(3,156 Views)

in my case 10^a with a a real in range [-2;2] with increment of 0.1 !

0 Kudos
Message 7 of 11
(3,134 Views)

40 data in fact!

 

0 Kudos
Message 8 of 11
(3,132 Views)

Hi damien,

 

is it that hard to pre-calc 40 values? Come on…

Best regards,
GerdW


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

GerdW: It's not very hard to calculate but i'm looking for an automatic function to calculate any entry value !

For the community i found an answer in fpga module help!

10^a is equal to exp(a*ln(10)).

ln(10) is a constant in my case => 2.30

 

In fpga exponential fonction exp(x) with x  must be in the range [–1, 1). To compute exp(x) when x is outside this range, find an integer q and a real number r, where ris in the range [0, ln(2)), such that x = q × ln(2) + r. You then can compute 2^q × exp(r), which is equivalent to exp(x). Because r is in the valid range of [–1, 1), you can use this function to compute exp(r).

i compute it in a simple vi and it calculate well !

 

I'm going to implement it on the fpga with high throughput function!Smiley Tongue

 

Thanks to all for your help!

regards,

0 Kudos
Message 10 of 11
(3,122 Views)