LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

[FPGA] Smartest conversion of boolean to U8

Hi All,

 

in my FPGA code I need to make the FPGA LED blink (Green/Dark).

Although it could be of negligible importance, since my cRIO has a 2 colors LED (1: green, 2:amber), I'm concerned about the smartest way to convert the toggling boolean value (LED ON/OFF) to U8.

Among the two solutions in snippet, which is to be considered "best" in terms of area and resources occupation on FPGA? Apart from these, are there any other aspects that could lead toward one solution instead the other?

 

Personally, I always try to avoid coercion and, in this special case, I doubt the compiler would be smart enough to avoid allocating a 16bit line even if not used by the destination I/O node.

Conversion thru array seems good, but I'm not sure whether the compiler would allocate some extra space for array indexing, even if useless in this case.

 

Thank you

 

Bye

 

Raf

 

0 Kudos
Message 1 of 8
(4,156 Views)

That's an interesting question, Raf.

 

I would like to think the second option (with the coercion dot) works better, since the compiler doesn't have to allocate memory resources to handle arrays.

 

Moreover, maybe this third solution can help to optimize resources, too:Toggle User LED.PNG

 

 

 

All the best,

0 Kudos
Message 2 of 8
(4,098 Views)

Hi Oscar,

 

that's an interesting solution.

I believe those two constants would be converted to memory block data by compiler. It remains unclear how the compiler will join data read from memory with the boolean switch.

 

I think that the only way to deeply understand the differences between the various options would be to directly look at the intermediate VHDL files generated by LV and fed to Xylinx compiler.

 

Bye

 

Raf

0 Kudos
Message 3 of 8
(4,084 Views)

I reckon they compile to the exact same result.  The upper 8 bits of the output of the "0,1 to Integer" are unused and will be optimised away.  The "array" doesn't exist as such on FPGA anyway, a U16 and an array of 16 booleans is essentially equivalent on FPGA (where a boolean is a bit and not a byte like on windows).

 

I would still, however, preferthe first option.

0 Kudos
Message 4 of 8
(4,076 Views)

This is more an academic question (perfectly ok though), in real life I doubt this would ever become relevant.

 

You can avoid the Boolean conversion altogether (sorry, no FPGA toolkit installed):

Blinking LED.png

Not sure if the XOR on an integer compiles smaller then a Boolean invert+Boolean to integer conversion...

 

Note that the compiler results are inconclusive, as the compiler won't really try to optimize for size until needed,

 

0 Kudos
Message 5 of 8
(4,069 Views)

I don't think it gets more efficient than this:

 

snippet.png

Boolean array to number coverts a 1 element array to FXP 1,1.

 

Shane

0 Kudos
Message 6 of 8
(4,060 Views)

@Intaris wrote:

I don't think it gets more efficient than this:

 

snippet.png

Boolean array to number coverts a 1 element array to FXP 1,1.

 

Shane


I'd use my solution (0 conversions iso 3), but strictly speaking it doesn't answer to the question "smartest conversion of Boolean to U8".

0 Kudos
Message 7 of 8
(4,054 Views)

The question of "converting boolean to U8" is flawed because you never need to create a U8 at all if you're only going to be setting the lowest bit.  "smartest" on FPGA usually translates to fewest resources and fastest possible execution speed.  If you can meet both of these in one scenario, then I'd place my vote for that.  That is of course if readability doesn't suffer too much.  But for such a trivial example, a single comment can sort that out quickly.

 

"conversions" on FPGA are often not real.  Everything is just bits (or fabric interconnects or registers or whatever).  Even if LV tries to tell you otherwise.  Many conversions are completely free on FPGA because they reduce to purely semantic differences with no actual change in underlying data or representation on FPGA.  What looks efficient and what is actually efficient are sometimes greatly different on FPGA than on other targets.

 

At the end of the day, we're talking about such a small optimisation here that even the effort of considering the best solution out weighs the actual possible benefits.  But applying the same principles to other code can, in the end, make noticeable differences.

 

 

0 Kudos
Message 8 of 8
(4,051 Views)