10-22-2013 07:29 AM
I am having a array of Boolean consider the following example
My goal is to count the first LOW or HIGH values of array continuously and it should output the counted value . Then the next value is HIGH or LOW, it should count and display it to next.
For easy understand I can say diagrammatically which is given below
w
HIGH value count should be in positive and LOW value count should be in negative. The output is array. I think this is quite simple but I don't know the logic.
10-22-2013 07:40 AM - edited 10-22-2013 07:41 AM
That was a fun little exercise. What I did was use a Feedback Node to look for a transition. If they were the same, I incremented a count. If they were different, I took the count and negated if the previous value was a false and then added it to an array. For the setup, I also added the inverse of the last value to the array to make sure there was a final transition to get the end of the array.

10-22-2013 08:46 AM
It was fun.
Here is what I came up with. The XOR with 1 cycle input delay finds the edges.
The conditional tunnel builds the array on the edges.
Since there is no last edge, I concantenated the counter after the loop finishes.
10-22-2013 09:25 AM
I thought I could do better but I don't think it is. But there is room for improvement.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
10-22-2013 10:21 AM
I'm a little surprised how tedious this task it but here is my attempt using array search. It will be interesting to see a side by side comparison of the different methods.
10-22-2013 10:35 AM
Oops....i just realized my code is wrong if the last boolean is a F. The count is not negated.
10-22-2013 11:01 AM - edited 10-22-2013 11:28 AM
@aputman wrote:
I'm a little surprised how tedious this task it but here is my attempt using array search. It will be interesting to see a side by side comparison of the different methods.
@aputman wrote:
Oops....i just realized my code is wrong if the last boolean is a F. The count is not negated.
It is tedious. I had that same bug.
I think it is fixed now, although it is starting to feel a bit rube-ish.
This has to be a more elegant solution to the adding last counter problem... (creating the last edge)
10-22-2013 01:10 PM
Okay got it fixed.
I was stuck on using the negate function foolishly.
10-22-2013 01:19 PM
@WillD wrote:
I was stuck on using the negate function foolishly.
I hear you. Here is my updated version without negate.
10-22-2013 01:48 PM
@aputman wrote:
@WillD wrote:
I was stuck on using the negate function foolishly.
I hear you. Here is my updated version without negate.
Hope you don't mind but I found orders of magnitude improvement by removing the for loop, and replacing the while loop with a for loop. In my test running the code 10000000 times took about 8459ms to execute, but after these two changes took 2ms. I tried a few other ideas but couldn't come close to this. Oh automatic error handling and debugging was turned off for the test.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord