Handling Multiple Alarms


#1

Hi All,

We had a customer ask how he might solve this situation with multiple triggers for an alarm:

“…several conditions may trigger the alarm, and I typically use each of these conditions to set an ‘alarm flag.’ There needs to be a provision for a supervisory override to a specific alarm condition, essentially disabling this trigger. I plan to do that through another flag set via password protected Display screen.”

The first thing that popped in my geeky head went something like this:
[INDENT][U]VARIABLES NEEDED:[/U]

[B]nTriggerFlag[/B]s is a bitmask holding up to 32 (or 64 if you use an int64) different triggers. A bit is set if that trigger happens.

[B]nSuperEnableFlags[/B] is also a bitmask, initially set to all 1s meaning the Super has not disabled anything yet = 0xFFFFFFFF (in hex, assuming 32 bits here). Bit gets set back to 1 when we no longer want to override something. Set to 0 to disable the flag.

[B]nAlarmFlags[/B] is the triggers w/the super override taken into account

[U]LOGIC:[/U]

code loops around a few lines like this:

[B]nAlarmFlags[/B] = [B]nSuperEnableFlags[/B] bitand [B]nTriggerFlags[/B];

// check to see if at least one of the non-disabled triggers has been set
If ([B]nAlarmFlags[/B] <> 0) then
<code to sound/ turn off, alarm here>
Endif

<delay X period of time> and loop back to top
[/INDENT]He wasn’t familiar with the concept of a bitmask, so I promised him a bit more info on those.

Here’s a decent video on the topic:

Besides using a bitmask, there are a couple other ways to solve this one. But before I suggest other ways, anyone care to share other ideas or links to good material to explain bitmasks?

Do share!
-OptoMary


#2

Hi Mary
a quick search showed up this tutorial on bitwise operators. i thought it gave a good explanation of things, and threw in bit shifting as well!

i guess an alternative to bitwise operations is to use tables and loop through doing a comparison. not as efficient but easier to understand for people not familiar with bitwise operators.

i hope this helps.
Nick