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.
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.
09-16-2016 12:55 PM
In the attached file, I need to detect a threshold around 0.5 in both signals then find the difference time between in all happening time in which threshold is met. In the example, two points are such as that. One of them is around the 10s and the other is around 130s. But my code detects just the last one (around 130s).
09-16-2016 01:10 PM - edited 09-16-2016 01:16 PM
After looking at your code for five seconds, it is peppered with race conditions and your results are unpredictable. In the second frame, the local variables is read way before the indicator gets updated with new values, because the inner FOR loops and the case structure execute in parallel.
As for the task, I am sure you could do it with 5% of the current code using a single loop. Try it.
(Your first inner FOR loops do absolutely nothing. What is their purpose? Your second FOR loops are pretty pointless. You need to iterate n-1 times, because else you run out of elements in the last iteration. Index array is resizeable, you only need once instance. There is the "in range and coerce function", try it). Your indicators get updated as many times as the boolean turns true and only the last value is available after the loops complete. Your sequence structure serves no purpose. Why is there an outer while loop? You are spinning it as fast as the computer allowws, recalculating the same over and over, burning 100% of a CPU code yielding nothing new ever.)
09-16-2016 01:14 PM
I changed it but it does not work. You can see in the attached file.
09-16-2016 01:18 PM - edited 09-16-2016 01:20 PM
Read the rest of my message above. Now you placed it inside the FOR loop, but there is sitll no way to tell if the local variable gets read before or after its indicator gets updated. Again, all you see at the end is the last update from some random calculation. Think dataflow!
You need to get rid of the local variables!
09-16-2016 01:32 PM
There is also a function called threshold detector which will do mcuh of what the For Loops in the 2nd frame are doing.
09-16-2016 02:22 PM
Thank you for your help. I think it works now but I am so eager to make it better. How is that now?
09-16-2016 04:05 PM
A bit better. But can still be improved based on Altenbach's comments and mine.
I cleaned up your code.
But it looks like your code can be replaced by the Threshold Detector. Two subVI's Done!
09-16-2016 04:13 PM
Thanks. But why Threshold Detector gives index one number less than my program? My code is still wrong?
09-16-2016 05:19 PM
Also don't forget about the conditional tunnel.
09-16-2016 09:56 PM
Your code is wrong. You started out with i=0 in the first iteration and compared i with i-1. When i is 0, i-1 = -1. There is no such thing as an array index of -1.
So working in the loop, you need to start at 0 and look ahead to i+1. When true, the code is returning i.
The Threshold detector is probably set up to (can't tell, the algorithm is hidden in a dll), to give the first index that is after the crossing.
To make them give identical results, you can easily do a +1 on the array of indices.