From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate power of 10 on a FPGA vi??

Hi everyone, I have a question about the FPGA functions.  One can use scale by power of 2. But there is no possibility to use power of ten. I also installed the Fixed-Point Math library where one can choose the natural logarithmic but not logarithmic of 10. Has someone an idea how to do this very fast??

 

Regards, Irina

0 Kudos
Message 1 of 6
(4,914 Views)

 

Hi Irina,

 

The Scale by Power of 2 just multiplies x by 2n, but I think what you are asking for here is something analogous to the Square function (x2), where you need x10?

 

There are a number of possible approaches, but there is a fundamental limitation with fixed-point types that they aren't good at representing large dynamic ranges (ie, it takes a lot of bits to be able to represent very large and very small numbers in the same wire). With a power of 10, any inputs that are significantly different than 1 will give you very large or small numbers, so you'll need to have a very restricted input range to make this work, or use an alternate representation such as a logarithmic number system (LNS).

 

That said, one idea is to take the equation y = x10 and apply a natural log and exponential to both sides, giving y = e10 ln(x). This can be accomplished with the Fixed-Point Math library functions, but there are restrictions on the range of x that you'll have to deal with.

 

Other approaches include using a look-up table, computing directly via multiplication, doing the operation in floating-point or LNS (via 3rd party IP), or moving that portion of the computation to the host. There are often ways of re-posing the problem for an FPGA implementation, so if you can provide more details of what your application needs to do, we might be able to come up with a more efficient way to get this part done.

 

Jim

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

Hi Jim, what I mean with  power of 10 is 10x.And this seems to be not possible on FPGA!

 

Regards, Irina

0 Kudos
Message 3 of 6
(4,879 Views)

Hi Irina,

 

Oops, that would make more sense, since that's what you asked for! Good news is, I think that makes the problem a bit easier. Assuming the range of x is reasonable, this is very possible. All we have to do is solve ey = 10x, where y will be the input for the Fixed-Point Math library exponential function.

The result is to simply multiply your x by ln(10) = 2.3026... and use the exponential function. That function requires an input with magnitude less than 1, so you might have to apply another similar scaling trick to bring the input into that range. I believe that procedure is described in the documentation for the exponential function.


Hope this helps!

Jim
0 Kudos
Message 4 of 6
(4,866 Views)

Another option for small power of 10 is to use scale by power of 2 and additions.  You need to be aware of overflow and your datasize.

For y=x*10

y=x*2^1+x*2^3

 

For y=x*100

y=x*2^6+x*2^5+x*2^2

 

0 Kudos
Message 5 of 6
(4,858 Views)
My last was assuming that x has a non-integer value. For 10n, there are a limited number of possible n values that would fit in your data type, so you might also consider using a look-up table or even an array containing all the 10n results you need.
0 Kudos
Message 6 of 6
(4,805 Views)