-
Notifications
You must be signed in to change notification settings - Fork 28
OSCAT BASIC MeasuringModules
Matthias Mersch edited this page Apr 11, 2018
·
1 revision
Type Function module
Input X: REAL (input)
RST: BOOL (reset input for alarm output)
Output LOW: BOOL (TRUE, if X < TRIGGER_LOW)
ALARM_2 examine whether X exceeds up the limits HI_1 or HI_2 and relies
on the outputs Q1_HI or Q2_HI TRUE. If the limits LO_2 or LO_1 are below,
it set Q1_LO or Q2_LO to TRUE. The outputs will remain TRUE as the corre-
sponding limit over-or under-rature. To prevent a futter of the outputs al-
ternatively a Hysteresis HYS may be set. HYS is set to a value > 0, then
the corresponding output is set only when the limit is exceeded or below
by more than HYS/2. Accordingly, the input X is the limit by more than
HYS/2 on or before exceeding the corresponding outputs are deleted.
ALARM_2 for example, with HI_1 and LO_1 can control the level of a liquid
container and with HI_2 and LO_2 trigger an alarm when a critical level is
exceeded or below.
Type Function module
Input X: REAL (input)
RST: BOOL (reset input for alarm output)
Output LOW: BOOL (TRUE, if X < TRIGGER_LOW)
Q1 Q6: BOOL (trigger output)
HIGH: BOOL (TRUE if X >= TRIGGER_HIGH)
ALARM: BOOL (alarm output)
STATUS: Byte (ESR status output)
Setup TRIGGER_LOW: REAL (trigger threshold for LOW Output)
TRIGGER_HIGH: REAL (trigger threshold for High Output)
ALARM_LOW: BOOL ( Enable Alarm Low Output)
ALARM_HIGH: BOOL ( Enable Alarm High Output)
LOG_SCALE : BOOL (output is logarithmic if TRUE)
BAR_GRAPH is a level Detector, which activates depending on the input
value an output. The threshold for the LOW and HIGH Outputs can be set
by the setup variables TRIGGER_LOW and TRIGGER_HIGH. LOW is TRUE if
X is less than TRIGGER_LOW and HIGH is true if X is greater or equal than
TRIGGER_HIGH. If the setup variables ALARM_LOW and / or ALARM_HIGH
set to TRUE, the output ALARM set to TRUE if the value will be lower than
TRIGGER_LOW or exceed of TRIGGER_HIGH , and the output LOW or HIGH
and ALARM remains TRUE until the input RST is TRUE and the alarm is re-
seted. The outputs Q1 to Q6 divide the area between between
TRIGGER_LOW and TRIGGER_HIGH in seven equal areas. If the setup varia-
ble LOG_SCALE is set, the area between TRIGGER_LOW and
TRIGGER_HIGH is divided logarithmically.
The output Status is an ESR compliant output and forwards states and
alarms to ESR components.
Status
110 Input is between Trigger_Low and Trigger_High.
111 Input lower than Trigger_Low , Output LOW is TRUE
112 Input higher than Trigger_High , Output HIGH is TRUE.
1 Input lower than Trigger_low and Alarm_Lowis TRUE
2 Input higher than Trigger_high and Alarm_High is TRUE
The following example shows a signal characteristic of n Bar_Graph:
Type Function module
Input X: REAL (input)
CO: BOOL (pulse for storing the ofset)
CS: BOOL (pulse for storing the gain factor)
Output Y: REAL (Calibrated output signal)
Setup Y_OFFSET: REAL (Y value in which the ofset is set)
Y_SCALE: REAL (Y value in which the amplifcation factor
is set)
CALIBRATE serves for calibrating an analog signal. In order to allow a cali-
brating two reference values (Y_OFFSET and Y_SCALE) must be set by dou-
ble-clicking on the icon of the module. Y_OFFSET is the starting value at
which the ofset is set by a pulse at CO and Y_SCALE is the value at which
the gain is determined. A calibration can only be successful if the frst of-
set and gain are then calibrated.
Example :
An input signal of 420 mA can be calibrated at the temperature values
from 0 70 ° C. Therefore the setup variables Y_OFFSET = 0 and Y_SCALE
= 70 are set. Then the sensor is placed in ice water and after the response
of the sensor, a pulse at the input C0 is triggered to initiate a calculation
of the correction value for ofset and store it internally. Next, then the
sensor is applied with 70 ° C and after the response a pules is triggered on
the CS input, which calculates in the module a gain factor that is stored in-
ternally. The calibration values are permanently stored. That means, they
are also not lost when a reset is executed, or turn of the power to the
PLC.
Type Function module
Input RES: BOOL (Reset)
Output CT_MIN: TIME (minimum measured cycle time)
CT_MAX: TIME (maximum measured cycle time)
CT_LAST: TIME (recently measured cycle time)
SYSTIME: TIME (duration since last start)
SYSDAYS: INT (number of days since last start)
CYCLES: DWORD (number of cycles since the last start)
CYCLE_TIME monitors the cycle time of a PLC and provides the user with a
range of information about cycle times and run times. The total number of
cycles is also measured. Hereby, the user can, for example ensure that a
function is called every 100 cycles. Control modules can report errors if
the cycle time is too long and therefore the control parameters can not be
guaranteed.
Type Function module
Input START DT (start DATETIME)
SPEED: REAL (speed for the output DTS)
Output DTS: DT (Simulated DATE TIME)
DT_SIMU simulates on output DTS a date value that starts with the initial
value of START and continues with the speed SPEED. If SPEED intthe input
value not used, the device operates with the internal standard value 1.0
and the DTS output is running forward at 1 second/second. With the input
SPEED at the output DTS an arbitrarily fast or slow clock can be simulated.
The module can be used in the simulation environment to simulate an RTC
and also adjust the speed of the RTC for testing. If the input SPEED = 0,
the output DTS at each PLC cycle is further increased by a second.
Type Function module
Input VX: REAL (volume per hour)
E: BOOL (Enable Input)
RST: BOOL (Reset input)
I / O X:REAL fow rate fractional part)
Y:UDINT (fow rate integer part)
SETUP PULSE_MODE: BOOL (pulse counter when TRUE)
UPDATE_TIME: TIME (measuring time for F)
Output F: REAL (actual fow)
The function module FLOW_METER determines the fow rate per unit of
time and count quantities. FLOW_METER determines the fow rate from the
input VX and E. The module supports two operating modes are determined
by the variable setup PULSE_MODE. If PULSE_MODE = TRUE is the volume
fow and the amount determined by is added at each rising edge at E, the
value of VX upon itself. If the PULSE_MODE = FALSE the input VX is inter-
preted as fow per unit time and is added up as long as E = TRUE. Using
the input RST, the internal counter can be always set to zero. X and Y are
external to be declared variables and can be declared retentive / perma-
nent to be permanent in case of power failure. The module provides the
instantaneous fow value F as the Real in accordance to the unit connec-
ted to VX. If a value at VX is applied eg. in liters / hour so is the measured
value at the output F in l / h. The output F is set at the constant intervals
UPDATE_TIME. The outputs X and Y make up the over time accumulated
measure values where X in REAL represent in the decimal point and Y in
UDINT the integer part. A count of 234.111234 is represented by 0.111234
at X and a value of 234 at Y. If for count only a REAL is used then the reso-
lution (for Real to IEEE32), is only 7-8 position. The above described me-
thod can provide more than 9 digits before the decimal point (2^32-1) and
at least 7 digits after the decimal point. Since in this case X is always
smaller than 1, Y can be used for output without decimal places. The two
variables X and Y must be declared external and can, as the following ex-
ample, also be secured against power failure.
Example 1:
VX := 4 m³/h;
PULSE_MODE := FALSE;
UPDATE_TIME := T#100ms;
The device measures the fow in m³/h and counts the fow as long as the
input E is TRUE. The output F shows (4.0m³/h) as long as E is TRUE, other-
wise it shows (0.0). The value of F is re-calculated every 100 milliseconds.
Example2:
VX := 0,024 l/Puls;
PULS_MODE := TRUE;
UPDATE_TIME := T#1s;
In this example, the fow at the output F is displayed in l/h and with each
rising edge at E the counter is increased by 0.024 l.
Type Function module
Input START: BOOL (input)
STOP: BOOL (input)
TMAX : TIME (Timeout für ET)
RST: BOOL (Reset input)
Output PT: TIME (elapsed time)
ET: TIME (Elapsed time since last rising edge)
RUN: BOOL (TRUE if measure processes)
M_D measures the time between a rising edge of START and a rising edge
on STOP. PT is the result of the last measurement. Output ET is the elapsed
time since the last rising edge of START. M_d requires a rising edge to start
the measurement. If at the frst call already START is TRUE, it is not seen
as a rising edge. Even if STOP is TRUE, a rising edge of START is not
counted. Only when all start conditions (STOP = FALSE, RST: = FALSE and
rising edge at START) are present, the output RUN gets TRUE and a
measurement is started. With TRUE at the input RST, the outputs can
always be reset to 0. If ET reaches the value of TMAX, automatically a
reset is generated in the module to reset all outputs to 0. TMAX is
internally assigned with default value of T#10d and normally can be
unconnected. TMAX serves to defne a maximum value range for PT. The
output RUN is TRUE if is a measurement is processed.
Type Function module
Input IN: BOOL (Input)
TMAX : TIME (Timeout für ET)
RST: BOOL (Reset input)
Output PT: TIME (measured pulse duration from the rising to the
falling edge)
ET: TIME (Elapsed time since last rising edge)
M_T measures the time how long IN was TRUE. PT is the time from the
rising edge of signal IN to the falling edge of the IN signal. The Output ET
passes the elapsed time since the last rising edge to falling edge. As long
as the input signal is FALSE, ET = 0. M_T requires a rising edge to trigger
the measurement. If at the frst call IN is already TRUE, it is not seen as a
rising edge. For more examples, see the description of M_TX. With TRUE at
the input RST, the outputs can always be reset to 0. If ET reaches the
value of TMAX, automatically a reset is generated in the module to reset
all outputs to 0. TMAX is internally assigned with default value of T#10d
and normally can be unconnected.
Type Function module
Input IN: BOOL (Input)
TMAX : TIME (Timeout für ET)
RST: BOOL (Reset input)
Output TH: TIME (Ontime the input signal)
TL: TIME (Of time of the input signal)
DC: REAL (duty cycle / Duty Cycle the input signal)
F: REAL (the input signal frequency in Hz)
ET: TIME (Elapsed time during the measurement)
M_TX determined from the input signal IN the time which the signal IN was
TRUE (TH) and the time the signal was set to FALSE (TL). The times of TH
and TL are only measured after a rising or falling edge. If IN is at the frst
call of the module already high, this is not seen as a rising edge. From the
measured values of TH and TL the Duty Cycle and the frequency in Hz are
calculated. A Duty Cycle of 0.4 means the signal was 40% TRUE and 60%
FALSE. Output ET of type TIME is started with each rising edge at 0 and
runs up until the next rising edge it starts again at 0. With a TRUE at the
input RST, the outputs can be reset at any time to 0. The input TMAX sets,
after which the elapsed time at ET, the outputs automatically are reseted.
TMAX is internally assigned a default value of T#10d and can normally be
left open. The input TMAX is primarily used to reset in the absence of input
signal for a defned time the outputs. An example of a possible application
is to measure the speed of a wave, indicating absence of the sensor si-
gnals to the speed (frequency) 0. TMAX is used with caution because, for
example, a TMAX of 10 seconds at the same time limits the smallest mea-
surable frequency to 0.1 Hz.
Type Function module
Input M1: REAL (consumption value of 1)
M2: REAL (consumption value of 2)
I1: BOOL (enable input 1)
I2: BOOL (enable input 2)
D: REAL (divider for the output)
RST: BOOL (Reset input)
I / O MX: REAL (consumption value)
METER is a meter, the two independent inputs (M1 and M2) are added up
over time. The counting is controlled the inputs I1 and I2. With the reset
input RST the counter can be reset at any time. The value of M1 is added
to the output value per second as long as I1 is TRUE analogous the value
of M2 is added per second to output value if I2 is TRUE. If I1 and I2 TRUE,
the value of M1 + M2 is added per seconds once to the output. The input
D Splits the output MX. Thus i.e. watt-hours can be counted instead of
watt-seconds. The module uses internally the OSCAT specifc data type
REAL2 which allows a resolution of 15 digits. This the module can capture
smallest consumption levels at the inputs of M1 and M2 with short cycle ti-
mes and add them up to high overall values at the output MX. The resolu-
tion of the block can be determined as follows. MX is defned as I/O and
must be placed on an external variable of type REAL. The external variable
can be declared as retentive and/or persistent in order to obtain the value
in case of power failure.
MX/10^15 corresponds to the minimum resolution at the inputs M1 and
M2.
Example :
MX = 10E6 the utility meter is at 10 MWh
M1 = 0.09 Watt Current consumption is 0.1 watts
D = 3600 Output operates in Wh (Watt hours)
Cycle time is 10ms
In this example, at each cycle a value of 0.09[W] * 0.01[S]/3600 = 2.5E-
7[Wh] on the output MX is added. This represents a change in the 14 deci-
mal place of the output.
example 1 power consumption meter:
The power consumption counter of kilowatt second counts the input M1.
By the input D the output is divided by 3600, so that the output displays
kilowatt hours.
Example 2 Consumption calculation for a 2 stage burner:
In this example, the output of level 1 (M1) 85KW and stage 2 (M2) 60KW.
The inputs S1 and S1 (I1 and I2) are TRUE, if the corresponding level is
running. By the constant 3600 at D, the output is divided by 3600, so kilo-
watt hours are shown.
Type Function module
Input IN: REAL (input signal)
DI: DATE (date input)
RST: BOOL (Reset input)
I / O LAST_DAY: REAL (consumption value of the previous day)
CURRENT_DAY: REAL (consumption value of the current day)
LAST_WEEK: REAL (consumption value over the past week)
CURRENT_WEEK: REAL (consumption value of the current
week)
LAST_MONTH: REAL (consumption value of the last month)
CURRENT_MONTH: REAL (consumption of the current month)
LAST_YEAR: REAL (consumption value of last year)
Current_year: REAL (consumption value of the current year)
METER_STAT calculates the consumption of the current day, week, month
and year and shows the value of the last corresponding period. The accu-
mulated consumption value is at the IN input, while at the DI input is app-
lied the current date. With the RST input, the counter can be reset at any
time. For ease of storage in the persistent and retentive memory, the out-
puts are defned as I / O.
The following example shows the application of METER_STAT with the mo-
dule METER:
Type Function module
Input IN: BOOL (Input)
RST: BOOL (Reset input)
Output SECONDS: UDINT (operating time in seconds)
CYCLES: UDINT (switch cycles of the input IN)
ONTIME is an hour meter. It is summed up the entire time that the signal
IN was since the last RESET to TRUE. Additionally, the number of the total
on/of cycles is determined. The output values are of type UDINT. With the
input RST, the output values will be reset at any time. The output values
are not stored in variables of the module, but are applied externally atta-
ched and connected over IO (Pointer). This has the distinct advantage that
as desired by the user the variables can be determined as RETAIN or PER-
SISTENT. It is thus possible to store old operating hours and restore it la-
ter, for example, at CPU change.
The declaration of the variables at the inputs SECONDS and CYCLES must
be of type UDINT and can either be created as a VAR, VAR RETAIN or VAR
RETAIN PERSISTENT.
The declaration of the variables for the operating time and cycles must be
UDINT type and can be alternatively RETAIN or PERSISTENT.
VAR RETAIN PERSISTENT
Betriebszeit_in_Sekunden: UDINT;
Cycles: UDINT;
END_VAR
The following table explains, RETAIN and PERSISTENT:
Type variables Retain and Persistent retain their value during download,
online change and reset. In a cold reset or reset source, lose these varia-
bles the values. The user can save, but the values in the fle system or
network, and to restore itself, eg after changing the CPU.
Type Function: DWORD
Output DWORD (SPS Timer in milliseconds)
T_PLC_MS returns the current internal PLC time in milliseconds. This has
nothing to do with a possibly existing clock (real time module), but is the
internal Timer of a PLC, which is used as a time reference.
The source code of the module has the following characteristics:
FUNCTION T_PLC_MS : DWORD
VAR CONSTANT
DEBUG : BOOL := FALSE;
N : INT := 0;
OFFSET := 0;
END_VAR
VAR
TEMP : DWORD := 1;
END_VAR
T_PLC_MS := TIME_TO_DWORD(TIME());
IF DEBUG THEN
T_PLC_MS := SHL(T_PLC_US,N) OR SHL(TEMP,N)-1 + OFFSET;
END_IF;
In normal operation, the module reads the function TIME() the internal
Timer of the PLC, and returns it. The internal Timer the PLC according to
IEC standard has one millisecond resolution.
Another feature of T_PLC_MS is a debug mode, which allows to test the
overfow of the internal PLC Timers and verify the developed software shu-
re. The internal Timer of any PLC has, independent of manufacturer and
type of implementation, after a fxed time an overfow. That means that it
is running against FF FFFF (highest value of the corresponding type can
be stored) and then starts again at 0000000. At standard PLC Timers is
the overfow time 2^32 -1 milliseconds, which is about 49.71 days. Since
this Timer is implemented in a hardware, it initial value can not be set, so
that after starting the PLC it always starts at 0 and runs up to the maxi-
mum value. After reaching the maximum value, the infamous Timer Over-
fow arises, which causes fatal consequences in the application software ,
but can only be tested extremely difcult.
T_PLC_MS ofers several ways to test the overfow and time-dependent
software. With the constant DEBUG, the test mode is switched on and
then, using the constants N and ofset , starts the timer at a certain level,
thus specifcally the overfow can be tested without waiting the 49. Ofset
defnces which ist addeed to the value of the internal Timer. With the con-
stant N is determined by how many bits of the internal Timer Value is shif-
ted to the left, while the lower N bits are flled with 1. With N thus the
speed of the internal Timers can be increased by factors of 2,4,8,16 and
so on.
T_PLC_US thus ofers all possibilities to test time-dependent software, both
for the problem of overfow, and for very slow time-dependent functions.
The constant DEBUG, N and OFFSET were intentionally not implemented
as inputs of the function to avoid accidental misuse.
Type Function: DWORD
Output DWORD (SPS Timer in microseconds)
T_PLC_US returns the current internal PLC time in microseconds. This has
nothing to do with a possibly existing clock (Real Time Module), but is the
internal Timer of a PLC that is used as a time reference.
The source code of the module has the following characteristics:
FUNCTION T_PLC_US : DWORD
VAR CONSTANT
DEBUG : BOOL := FALSE;
N : INT := 0;
OFFSET := 0;
END_VAR
VAR
TEMP : DWORD := 1;
END_VAR
T_PLC_US := TIME_TO_DWORD(TIME())*1000;
IF DEBUG THEN
T_PLC_US := SHL(T_PLC_US,N) OR SHL(TEMP,N)-1 + OFFSET;
END_IF;
In normal operation, the module reads the function TIME() the internal
Timer of the PLC. Since the internal Timer of the PLC works according to
IEC standard with 1 millisecond resolution, the read value is multiplied by
1000 to deliver the value in micro-seconds back. This function was created
for compatibility reasons in that way, to provide microseconds timer for
controls, that has a resolution no better than milliseconds, which can then
be used in other modules. If the existing PLC supports microseconds, this
function can easily be adjusted only at this point and the accuracy chan-
ges by this simple patch for all the modules that call this feature. The soft-
ware remains portable and future proof. Already, virtually all PLC control-
lers support a resolution in microseconds. This will however not be read
using standard routines, but provided vendor specifc and non-standard.
The module T_PLC_US provides so an appropriate interface to these ven-
dor-specifc timers.
Another feature of T_PLC_US is a Debug Mode, which allows to produce
the overfow of the internal PLC Timers and test the software developed
right shure. The internal Timer of any PLC has, independent of manufac-
turer and type of implementation, after a fxed time an overfow. That
means that it is running against FFFFFF (highest value of the correspon-
ding type can be stored) and then starts again at 0000000. At standard
PLC Timer is the overfow time 2^32 -1 milliseconds, which is about 49.71
days. Since this Timer is implemented in a hardware, it initial value can
not be set, so that after starting the PLC it always starts at 0 and runs up
to the maximum value. After reaching the maximum value, the infamous
Timer Overfow arises, which causes fatal consequences in the application
software , but can only be tested extremely difcult.
T_PLC_US ofers several ways to test the overfow and time-dependent
software. With the constant DEBUG, the test mode is switched on and
then, using the constants N and ofset , starts the timer at a certain level,
thus specifcally the overfow can be tested without waiting the 49. Ofset
defnces a value which is added to the value of the internal Timer. With
the constant N is determined by how many bits of the internal Timer Value
is shifted to the left, while the lower N bits are flled with 1. With N thus
the speed of the internal Timers can be increased by factors of 2,4,8,16
and so on.
T_PLC_US thus ofers all possibilities to test time-dependent software, both
for the problem of overfow, and for very slow time-dependent functions.
The constant DEBUG, N and OFFSET were intentionally not implemented
as inputs of the function to avoid accidental misuse.
Type Function module
Output TC: DWORD (last cycle time in milliseconds)
TC_MS determines the last cycle time, that is the time since the last call of
the module has passed. The time comes in milliseconds.
Type Function module
Output TC: REAL (last cycle time in seconds)
TC_S determines the last cycle time, that is the time since the last call of
the module has passed. The time will be delivered in seconds, but has an
accuracy in microseconds. The module calls the function T_PLC_US().
T_PLC_US () returns the internal PLC Timer in microseconds with a step
width of 1000 microseconds. If a higher resolution is required the function
T_PLC_US() has to be adjusted to the appropriate system.
Type Function module
Output TC: DWORD (last cycle time in milliseconds)
TC_US determines the last cycle time, that is the time since the last call of
the module has passed. The time comes in milliseconds. The module calls
the function T_PLC_US(). T_PLC_US () returns the internal PLC Timer in mi-
croseconds with a step width of 1000 microseconds. If a higher resolution
is required the function T_PLC_US() has to be adjusted to the appropriate
system.