05-08-2013 12:55 PM - edited 05-08-2013 12:55 PM
I am doing a walking ones test on my FPGA. This leaves me with the array in the attached snippet. For each subset of 48 elements, I want all array elements to be 0, except for the one which is currently being "walked".
So, for example...
I will be reading an array using array subset to break it into 48 element arrays. The first array subset, all elements should be 0.
The second array subset, element 1 should be 1 and the 47 other elements 0.
The third array subset will have element 1 be 10 (binary) and the rest 0's
Fourth should have element 1 be 100b and the rest 0's etc.
These are 16 bit numbers, so once we've set the 16th bit to one, we move onto array element 2 and do the same thing. The attached code I believe does what I want. But considering the mess of wires there must be an easier/cleaner way. So, I thought I'd dish it out to the experts.
05-08-2013 01:53 PM
I suppose I could just keep the array I have as a constant (it is what I am expecting), take subsets of it and compare it to each subset I get from the FPGA, keeping a counter so I know which subset to grab.
It would definitely be more readable if nothing else.
05-08-2013 02:02 PM
Comparison against a constant is fast and simple. If you're trying to avoid storing a large array constant, there's probably an easier way to do this by storing a previous value in a shift register and using the rotate or logical shift function to move the 1 bit over one place. Also the second select can definitely be replaced by some boolean operation (this is generally true any time you wire the boolean value to both the select and either the true or false input). In this case it's an AND, because you'll only get a TRUE output if both inputs are true.
I don't have time right now to work through a faster version but I'll try if I have time later.
05-08-2013 02:04 PM - edited 05-08-2013 02:05 PM
Yes, the constant is definitely quicker, if you can make the constant, which I did programmatically. But, I realized after I wrote the thought about the constant, if the array sizes ever change, you have to generate a new constant or else you will get unwanted behavior. In this case, this is not an issue (until it is )
05-08-2013 02:15 PM
No time to profile, now, but how about something like this:
05-08-2013 03:59 PM
Careful with the front panel arrays in FPGA, they eat your resources really quickly.
-Nick-
05-08-2013 04:11 PM
Todd - good improvement. I like the use of XOR for the comparison. One note: the inner for loop isn't needed, both the equals and xor operations can operate on arrays.
05-08-2013 04:40 PM - edited 05-08-2013 04:42 PM
@Nick-C wrote:
Careful with the front panel arrays in FPGA, they eat your resources really quickly.
-Nick-
Sorry, I should have clarified. This processing is not being done on the FPGA. The FPGA has an array constant of only 48 U16 elements which are updated using replace array subset. I then stick these 48 elements in a FIFO and read them in chunks on the RT and process in chunks (also on the RT). The processing shown is done on the RT, and is not done on the whole array at once like I have in my snippet. I just threw this VI together to show what I was trying to accomplish and provide all the data needed, in one single array, for others to attack the problem.
05-08-2013 04:44 PM
@nathand wrote:
One note: the inner for loop isn't needed, both the equals and xor operations can operate on arrays.
Yes! I tossed that in at the last second because I wasn't sure if he REALLY wanted to test one bit at a time, which the inner loop gets one step closer towards.
05-08-2013 04:48 PM
@for(imstuck) wrote:
Sorry, I should have clarified. This processing is not being done on the FPGA. The FPGA has an array constant of only 48 U16 elements which are updated using replace array subset. I then stick these 48 elements in a FIFO and read them in chunks on the RT and process in chunks (also on the RT). The processing shown is done on the RT, and is not done on the whole array at once like I have in my snippet. I just threw this VI together to show what I was trying to accomplish and provide all the data needed, in one single array, for others to attack the problem.
Indeed your post was just an array constant, I must have missed that. The other proposed solution had some array indicators, I think I got the two confused before I made the post...oops!
-Nick-