Showing results for 
Search instead for 
Did you mean: 

Trouble with Elapsed Time function

I am trying to alternate between feeding HCl gas and CO gas into my system.  I have exposure of HCl for a specified time in a while loop, then CO for a specified time in another while loop.  I do this multiple times in a for loop.  What I'm running into difficulty with is that the Elapsed Time function is not resetting itself back to zero after leaving the while loop.  I then get data that looks like:
Comment - Time
HCl - 0
HCl - 1
HCl - 2
CO - 0
CO - 1
CO - 2
HCl - 3
CO - 3
CO - 4
CO - 5
HCl - 4
Any help?
0 Kudos
Message 1 of 13

Sorry, I cannot test because I don't have any DAQ installed and I also don't have your hardware.

Have you tried to wire a "=0?" to [i] of the While loops, and then the boolean output to the "reset" input of the timer?

(Overall, your code is way too linear and "duplicative" (is this even a word :o).  One simple while loop and state machine architecture would be sufficient.)

Message 2 of 13

I am attempting to go through with what you suggested but what does "state machine architecture" mean?


Thanks for your help!

0 Kudos
Message 3 of 13

The State Machine Design Pattern uses three elements.
  • while loop
  • shift register
  • case structure.
This Architecture is explained on Application Design Patterns: State Machines

Best regards
0 Kudos
Message 4 of 13

I have seen similar issues with the elapsed time Express VI.

You could use a shift register and pass the "Time Elapsed" value back into the "Reset" boolean... personally I opted to create my own elapsed time VI.

I attached a screen shot of my version that will automatically reset itself when the time has elapsed.

Message Edited by MattH on 07-18-2007 04:20 PM

Message 5 of 13
Attached example of the other suggestion. This would be VERY easy to implement in your code.
Message 6 of 13
Tip: You can accomplish the same thing by checking if the while loop iteration count is equal to 0. This eliminates the shift register:

Basically, you need to reset the Elapsed Time VI each time you restart the while loop. The reason for this is that internally it's a VI with an uninitialized shift register. With Auto Reset it stores the time when the VI ended. Well, after you run the second loop time has passed, and when it comes back to the first loop it's comparing the current time with the internally stored time, which was in the past. Hence, the first loop will only run once.

Long-term you should look into the state machine architecture, as suggested above.

Message Edited by smercurio_fc on 07-18-2007 04:34 PM

Message 7 of 13
Excellent point. I feel silly for missing that! Smiley Very Happy
I am certainly relieved that I tend to use my VI, so that I don't have to go back and replaced all those shift registers with =0 comparisons!
Message 8 of 13
Hhhhmm!!! 🙂

altenbach wrote (in the first answer of this thread!) :

... Have you tried to wire a "=0?" to [i] of the While loops, and then the boolean output to the "reset" input of the timer? ...

Message 9 of 13
Opps! I guess I am so used to reading blocks of code versus text that I didn't even notice (An unfotunate side to LabVIEW developement?). 5 stars to both your posts sir.
Message 10 of 13