Flow chart level comparation

hi every body I need some help on a startegy that I’m currently working on…i have two signals(4-20ma)…from level transmitters that shloud be compared and a alarm generated from my strategy if the difference in the readings exceed 5% of the full scale value…my strategy also sholud select a reliable signal and then allows the operator to select level signal from the console process diagram…once the alarm is cleared then my strategy resumes the average of both level signals…any help will be apreciated…thanks

Hi BENO74,

I will take a crack at this…
(And trust that someone will come and show me where I am wrong and we will all learn something :-))

Here is what I would stick in an OptoScript block for a start.



if (IsWithinLimits (input1-input2, -5, 5)) then
   alarm = 0;
else
   alarm = 1;
endif


So, the way I read it, if the difference between the two analog inputs is outside those limits (of -5 to +5), then sound an alarm (in this case, just set the alarm variable true, this will be handled elsewhere).
If the difference is small, then the signals are Ok, so clear the alarm variable.

Of course, the hard limits I have set there could be swapped out for variables, so you could have a fine range at some times and the a bigger range at others (I’m thinking process start up or shutdown alarm suppression).

Can anyone see what I have missed?

Ben.

thankx Ben…

If I understand correctly, under normal circumstances you want the strategy to use the average of the two level sensors. If the difference between them ever exceeds 5% of full scale, you want the strategy only to use the sensor that an operator designates as reliable. Once the readings are back within range, the strategy resumes using the average.

I’m not sure how I would go about handling your alarm condition. How does the strategy know which of the two readings is reliable? How does the operator know? However, if you are able to answer those questions, it might make sense to implement this with a pointer. I’ve found that if PAC Display is involved in choosing what a pointer is supposed to reference, a pointer table makes it easier.

If you create the following tags:
aiLevel_Sensor_1 (your analog input point)
aiLevel_Sensor_2 (your analog input point)
fLevel_Sensor_Average (a float variable)
nLevel_Source_Index (an I32 variable)
pLevel_Reading (a pointer to a float variable)
ptLevel_Reading_Source (a pointer table)

Somewhere in your powerup chart, you would initialize the pointer table like this:
ptLevel_Reading_Source[0] = &fLevel_Sensor_Average;
ptLevel_Reading_Source[1] = &aiLevel_Sensor_1;
ptLevel_Reading_Source[2] = &aiLevel_Sensor_2;

and you would initialize the pointer as well. If you want to use the average by default, that is element 0.
nLevel_Source_Index = 0;
pLevel_Reading = ptLevel_Reading_Source[nLevel_Source_Index];

Your strategy would have sections of code that includes the following:

  1. Main flowchart activity that always looks at the pLevel_Reading pointer if it needs to know the level.

  2. A continuously running flowchart that updates the fLevel_Sensor_Average tag by averaging the two analog inputs.

  3. A continuously running flowchart that looks for changes to the nLevel_Source_Index tag and updates the pointer when detected.

  4. The alarm handling section would change the nLevel_Source_Index based on rules you define, and default back to 0 whenever things are running well.

Your PAC Display program would allow the operator to choose which signal source to use, and the dynamic attribute would the send the corresponding value (0 for average, 1 for sensor 1, 2 for sensor 2) to the nLevel_Source_Index tag.

I found this information very helpful for the strategy I am working on. Can I go deeper and ask how would it possible to compare the same analog input in a certain amount of time and if there is no change turn on an alarm?

Thanks

Sure, there are many ways to do this… Here is one that visually describes what some OptoScript might look like…

@pbg: consider something like the following:

' If analog input value has not changed since last pass, start timer. Stop timer on value change.
If AnalogInputValue = PreviousValue And UpTimerVariable = 0 Then
    StartTimer(UpTimerVariable);
ElseIf AnalogInputValue <> PreviousValue Then
    StopTimer(UpTimerVariable);
EndIf
PreviousValue = AnalogInputValue;

' Trigger alarm if timer reaches threshold.
AlarmTrigger = UpTimerVariable >= UnchangingValueLimit;

If you put that bit of code somewhere that’s executed repeatedly, I think it’ll do what you’re asking.

1 Like

Thank you @Beno and @varland . I will consider both graphic and script to develop my strategy.

One more thought, that makes the script a bit more like @Beno’s flowchart… The If statement should read more like this:

If AbsoluteValue(AnalogInputValue - PreviousValue) <= DeadbandValue And UpTimerVariable = 0 Then

That way you can control how much variation you actually want to see from your analog input.

1 Like

It really helped with the AbsoluteValue.

Thanks!