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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop Auto Index Comparison and Data

I have a question about synchronization. I have a for loop inside a while loop. The while loop is reading an analog input, which is a 1d array, and is passing it to the for loop. Auto Indexing is enabled on the for loop. Inside the for loop, I'm comparing values being passed, with a numerical constant I've defined. Once the passed data is equal to/or greater than this constant, a true value is passed from the comparison function in the for loop to a write to measurements enable input function in the above mentioned while loop. The measurements is recording the analog input.

 

When I look at my data file, the measurements don't seem to match with my conditions I've set up in my for loop. They're close, but behind. For instance, if my comparison inside my for loop tells the measurements to enable when the passing data is >0.02mV than my defined constant, my first data point is 0.001. It's close, but not exact. It's even enabling the measurements FASTER (or earlier) than it should be. I've probed the conditions and they seems to be ok. The conditions are appropriately met and the actions are carried out as expected. Is this a problem with the speed of the for loop compared to the speed of my while loop?

 

   

0 Kudos
Message 1 of 12
(3,410 Views)

I don't see a while loop in your attached snippet.

 

It is also rather hard to follow because things are spread out and wires are overlapping and running backwards.  Can you run a block diagram cleanup, then attach the file as a VI?

0 Kudos
Message 2 of 12
(3,388 Views)

Can you post your actual VI?  Creating a snippet created a major mess.  I'm guessing you used locals and you have a race condition in there.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 12
(3,383 Views)

I apologize, I've tried cleaning it up time and time again. I'm still (slowly) learning. The bottom for loop in the strain state is the focus of my question.

 

I had to change the .vi to -vi. It's not uploading due to this error: "The contents of the attachment doesn't match its file type."

0 Kudos
Message 4 of 12
(3,379 Views)

I'm not sure I understand the race condition with using local variables...I only write once then switch to a read. So in the strain state I'm reading the variable. I'm not saying you're wrong, I just need to understand how these things work a little bit better. 🙂

0 Kudos
Message 5 of 12
(3,375 Views)

It is related to your Record button.  (Why do you not have a label for that control?  Because the label is empty, the local variable of it has a question mark rather than a meaningful name.)

 

The value of that button determines whether the loop continues or not.  The value is read from a local variable which is probably read very early in the loop iteration.  But in a case structure, you write a False to a local variable of that control.  Well, that False is probably going to get written very late in the loop iteration.  The while loop will continue for another iteration because it had already read the local variable as true.

 

You also have a weird construct there, and I swear I think I had pointed this out to you in another thread within recen weeks.  What is the point of the select statement with the "Start" vs. "Reset Counter" constants?  The only value that can ever execute the while loop on that wire is "Reset Counter".  In order for the while loop to end, you need a false value going into the while loop's conditional terminal.  That means the "Reset counter" value will hit the tunnel and leave the loop.  If the boolean is true, "Start" hits the tunnel.  But that value never goes anywhere besides that because the loop continues and another iteration starts all over again.  Just wire a "Reset Counter" constant to the tunnel and eliminate the entire Select function.  It will do the same thing!

Message 6 of 12
(3,363 Views)

I think it's that way because my control1.vi wasn't included in the vi I uploaded. It's on the test machine and I forgot to move it. With that control, everything works properly and the Record button is labeled. I did correct this after you mentioned it weeks ago.

 

My worry is the basic function of the write in relation to my limits set in the bottom for loop as mentioned above.

0 Kudos
Message 7 of 12
(3,359 Views)

Is it possible that I'm only reading 100 samples per sec and it's not able to catch up with my number comparison?

0 Kudos
Message 8 of 12
(3,293 Views)

This IS my problem. I'm reading at 100 samples per second but my analog channel increases faster than it can read. I could change this to 1000 samples per channel but how would I only record 100 data points per second in my data file?

0 Kudos
Message 9 of 12
(3,267 Views)

I would change it to 1000 samples per second.  If you want to reduce the number of samples actually written to the file, you could use functions such as Decimate, or Resample to resample the 1000 samples into a group of 100 samples.

Message 10 of 12
(3,256 Views)