LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Alarm delay problem

I am trying to write a VI that will email an alarm to users of a LN system when the LN tank is low. With this I'd like to have a 10 minute delay occur after the alarm condition is met to prevent spurious emails when the tank is just being filled. Alarm occurs --> Delay starts --> Delay ends and the CURRENT alarm condition is checked to see if it still met. If so, email sent, if not, back to regular operation. My problem is that I don't seem to be able to get the current (after 10 minute delay) alarm condition, but only the initial (before 10 minute delay) alarm condition that started the delay in the first place. If I let the VI loop around again it grabs the new alarm condition, but has no "memory" that it already ran the delay. Thanks for y
our help.
0 Kudos
Message 1 of 9
(3,624 Views)
It sounds like you should be using a finite state machine
0 Kudos
Message 2 of 9
(3,624 Views)
It sounds like you are running the code in a loop. Use a shift register to pass a boolean flag around. If the alarm is set and the flag is false, then set the flag true. If the flag is true and 10 min has elapsed and the alarm is false, set the flag false. If the flag is true and the alarm is true, send the email and set the flag false.

You will need a shift register (look in the shipping loop examples or the LV user manual for an explaination), a way to measure time (it sounds like you have that, some boolean logic, and a case structure. The key is the shift register.
0 Kudos
Message 3 of 9
(3,624 Views)
The attached VI should do what you want. Put this VI in the loop where you are reading the Nitrogen level. The three inputs are the current level, the low limit that should trigger the alarm, and the timeout (in seconds) before the alarm is generated. The output is a boolean that goes true when the specified delay times out.

Mike...

PS: as with all things involving uninitialized shift registers, if you want to use this VI in more than one place, make sure it is set to be reentrant...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 4 of 9
(3,624 Views)
Thanks, but I think I tried this with no luck. How do I set the intial state of the flag? I can set the intial shift register value coming into the loop, but as soon as I exit the loop to check on the current alarm condition and then re-enter the loop with the new alarm value the shift register also reinitializes. If I don't initialize the shift register then obviously I have no idea where the loop is starting.
0 Kudos
Message 5 of 9
(3,624 Views)
Thanks, but I don't think this will work. Reading the NI definition of state machine: "A State Machine relies on user input or in-state calculation to determine which state to go to next." I have neither. My alarm is coming from outside the state machine and I want to avoid user input (undergrad and grad students) if at all possible :-).
0 Kudos
Message 6 of 9
(3,624 Views)
I like Jeremy's answer.
What is the overall structure of your program? Do you have one big loop that keeps checking on the tank level? Does it do anything else?
If you take the simplest approach that you don't want to do anything else while you're delaying, all you need is a call to wait mS with the input set to 10 minutes * 60 sec/min * 1000 ms/sec. The wait mS will be in a case: if you detect an alarm, wait, then check the alarm again. In the real world, you probably want to do other things in those 10 minutes, so don't wait for the delay: check the time and see if ten minutes have passed from the initial alarm.
Don't use a separate loop just to do the delay. The delay (or the check for time difference) should be in the main loop where you're checking for alarms. You don't want to "exit the loop to check on the current alarm condition and then re-enter the loop with the new alarm value". Shift registers can keep track of whether an initial alarm was detected and what time the alarm was detected. Initialize both shift registers at the start of the program: Initialize Alarm Time to the current time; initialize Alarm Detected to False. When an alarm is detected, set Alarm Detected to True and use a case to get the current time and send that to the Alarm Time shift register.
Every time through the main loop, if Alarm Detected (shift register) is True, compare the current time to the Alarm Time. If the difference is greater than 10 minutes, check the current alarm condition (by reading your instrument, not the shift register). If the alarm still exists, send your emails and set the Alarm Time to the current time. If the alarm doesn't exist, set Alarm Detected False. Don't set Alarm Detected every time through the loop: set it (the shift register) if it's currently False and you detect an alarm condition or if you're at the end of your 10 minute delay.
You can also limit it to sending only one set of emails by adding another shift register: Email Sent (initialized to False). When you send your first email, set Email Sent True. Leave Email Sent True until the current alarm goes False. Continue to check your alarms and time the delay as before, but at the end of the next 10 minutes, don't send emails if Email Sent is True. This could prevent filling up some email inboxes if the tank goes dry overnight.
0 Kudos
Message 7 of 9
(3,624 Views)
Does the code I posted for you do what you need?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 9
(3,624 Views)
Mike,
Sorry I didn't answer you right away, but I was busy fiddling with your vi. I think it will work for me. I needed to add another case that would "reset" the timer once the alarm condition, after the time delay, was met. Otherwise I had a constant alarm once the delay was satisfied and I was pumping out emails at a prodigious rate. I'm quite new to Labview and it just amazes me the convolutions required to do what appears to be such a simple thing on paper. Still, this is much better than writing regular code. Its almost fun :-). Thanks for your help. Daniel
0 Kudos
Message 9 of 9
(3,624 Views)