Hi Tim,
On 01/07/2016 10:41 AM, Southern, Tim wrote:
Problem:
We have a spark detector that will increment a counter every time a
spark is detected. The user requests an alarm when the counter
increments +5 times within an hour. How can this be implemented on an IOC?
Nice little problem.
A Solution:
I came up with a solution using compress records. First, I created
a 3600 element compress record using a circular buffer that records the
value of the PV counter every second for an hour. Next, I created two
more compress records, one that saved the lowest value, and one that
saved the highest value of the first record (N to 1 Low Value, N to 1
High Value). I then created a CALC record that calculated the difference
of the low and high values. When CALC is greater than 5 ... then alarm.
Is there a better implementation to do this? Is there anything wrong
with this solution?
Assuming that your input is a counter that only ever increments, you
really only need the first compress record and a calc. The output from
your High Value compress will always be the same as the current spark
count $(S):FltCtr, and the first element read from the circular buffer
is the oldest value in the buffer (the one from an hour ago), which is
always the same as the output from your Low Value compress. Thus the
following is equivalent to your solution with fewer records:
#########################################################################
# Alarm for greater than 5 counts in 1 hour
#########################################################################
# Circular buffer of spark counts
record(compress,"$(S):1HrCmp"){
field(SCAN, "1 second")
field(NSAM, "3600")
field(N, "3600")
field(ALG, "Circular Buffer")
field(INP, "$(S):FltCtr") # ←- Record that increments
}
# Difference of High and Low over time of circular buffer
# Alarms when count is greater than 5
record(calc, "$(S):1HrCmp_diff"){
field(INPA, "$(S):1HrCmp CP")
field(INPB, "$(S):FltCtr")
field(CALC, "B-A")
field(HIGH, "5")
field(HSV, "MAJOR")
}
HTH,
- Andrew