04-22-2014 10:35 AM
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
Solved! Go to Solution.
04-22-2014 10:43 AM - edited 04-22-2014 10:52 AM
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:
Example execution:
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/
04-22-2014 10:46 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-22-2014 10:59 AM
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!
04-22-2014 12:54 PM - edited 04-22-2014 12:56 PM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-22-2014 01:24 PM
@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.
04-23-2014 02:15 AM
in my case 10^a with a a real in range [-2;2] with increment of 0.1 !
04-23-2014 02:22 AM
40 data in fact!
04-23-2014 02:31 AM
04-23-2014 02:49 AM
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!
Thanks to all for your help!
regards,