Alarms, scan by scan
I received this via e-mail:
I think I follow your code. What do you mean by "WAS_ALARM1" is this an actual bit?
All I want to do is sense alarm1 and trigger a horn. And then be able to silence Alarm1. If Alarm1 stays high fine but if Alarm2 goes high I need to have the horn again trigger. I need to silence Alarm2 and so on.
I hope this makes sence.
Thanks for your help.
Jason
Jason:
Most of us like to keep all exchanges on the forum, for lots of good reasons.
WAS_ALARM1 is an internal bit, used to capture the event of ALARM1 going ON. The label is shorthand for "ALARM #1 was ON last scan". Depending on your PLC type, this bit may not be needed. Some PLCs allow the following code:
ALARM1 ALARM_ONS
-----| |-------(DIFU)
In others, the instruction is not DIFU, but -(^)-. But since you asked for IEC 61131-3, I gave you a generic one-shot rung, which required the extra bit.
As for your requirements "sense alarm1...trigger a horn....silence Alarm1.... but if Alarm2 goes high I need to have the horn again trigger", the code I posted will do exactly that.
Here's how it works:
ALARM1 goes ON. Since WAS_ALARM1 is not ON yet, ALARM1_ONS will fire.
THEN WAS_ALARM1 will come ON, resetting ALARM1_ONS on the next scan, and preventing ALARM1_ONS from firing in any future scans until ALARM1 goes OFF (which turns WAS_ALARM1 off in the process).
Getting back to the scan that fired ALARM1_ONS: ALARM1_ONS fires off NEW_ALARM. NEW_ALARM makes the horn sound, and, since the horn is sounding, it will keep sounding until the SILENCE button is pressed.
The next scan, ALARM1_ONS is reset, and, as I said, can't fire again until ALARM1 goes OFF. With ALARM1_ONS reset, NEW_ALARM is reset. This is OK, because it has already done it's job making the horn sound. Since the horn is sounding, it continues to sound.
But pressing the SILENCE breaks the sealing-in of the horn circuit, bringing peace to the land. The horn can't sound off again until NEW_ALARM is true, and it's not, currently. Even though ALARM1 is still active, ALARM1_ONS isn't, and can't be until ALARM1 (and WAS_ALARM1) are false.
If and when another alarm occurs,
that alarm's associated _ONS bit will cause NEW_ALARM to fire again.
Does that clear things up? This is the "PLC mindset" that you need to practice getting into - being mindful of what's currently true at any particular point in the scan, and being mindful of what's going to happen next scan when the code loops back around. VB programmers have a particularly hard time with this - their code is triggered just once when some event occurs. PLCs are the Energizer Bunny's of the programming world - they keep going, and going, and going....