LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fpga single versus fixed point

Yes, code inside a single-cyle timed loop is at least as efficient as the same code outside a single-cycle loop (if anyone has a weird case demonstrating otherwise, it would be fun to see). Not every FPGA function can run inside a SCTL (single-cycle timed loop), though - for example, many IO functions require more than one cycle to complete. It also may not make sense to put one or more single-cycle loops, each running a single iteration, inside a larger standard loop, because then you might force more cycles than necessary if the compiler could otherwise combine them in a single cycle.

 

I try to use single-cycle loops for as many of my long-running loops as possible, usually in a state machine so that even though some operations require multiple states (cycles), all of the code gets the benefit of executing in a single-cycle loop and I can determine exactly how many cycles it will take to get a result. I don't see any opportunities to do that here unless your IO can run in a single-cycle loop, which depends on your hardware.

 

In the case of the error you're seeing, the easiest thing to do would be to reduce the precision of one of the fixed-point operations, and see if it fixes the error without resulting in an unacceptable loss of precision. If you can't lose precision, then you need to rethink your math and try a different approach. I don't know what hardware you're using so I can't see what precision the analog input values are, but you have the subVI configured for a 26-bit input. Does your analog input have that much resolution? I don't see any NI cRIO modules with greater that 24-bit resolution. I'm also not sure why you have the reciprocal followed by a multiply, instead of using a simple divide - but the compiler likely optimizes it to the same operations. It would be interesting to know if changing that makes a difference, though.

0 Kudos
Message 11 of 13
(717 Views)

I have a sbRio 9612.  The analog outputs come out as 24,5, but following the math through we keep the same precision by moving up to the 26 bit fixed point (off the top of my head I don't remember exactly which operation that is).  I might just try changing it to 24,5 all the way through and see what happens. 

 

As for the divide, I have alwasy been told the inverse and then multiply is less cpu intensive than a divide.  I can't speak to that other than thats what I have been told.  I believe the I/O can run inside a SCTL, but when I originally wrote the code I had a divide instead of the inverse and mutiply and I got an error saying I couldn't run that in the SCTL.  So, I just put it in a normal loop.  However, when I changed to the inverse and multiply I never tried it again and maybe I should do that for grins.

 

The big thing I'm trying to do is run my analog sampling as fast as I can so I can run a fairly high gain.  That is what the sub vi is doing is a gain equation on the analog values.  Basically same thing I'm doing with the frequency in the 2nd loop.  Maybe there is an easier way to do that?

0 Kudos
Message 12 of 13
(712 Views)

Just in case anyone was wondering, the sbRio analog input can't be run inside of a single cycle loop.  Also, neither can the multiplication and inverse function.

 

No matter what I did my code was giving me issues.  I ended up solving it by removing all the individual front panel indicators and passing my I/O directly into a table, doing the operations on that and passing the single array to the host. 

 

Thanks everyone for your help.

0 Kudos
Message 13 of 13
(700 Views)