Commissioning
FOR i := 0 TO nOVS-1 DO
nDivVar := TRUNC_INT(tDecVar_InTaskCycle/nOVSTimeInterval_ns);
// Check, if new value is in grid
IF (nDivVar = i) THEN
nResultNoOfSamples := nResultNoOfSamples + 1;
// Calc slope by the left and right element values (dy/dx):
nDY := aOVS_SampleSets[i+1] - aOVS_SampleSets[i];
sVal := DINT_TO_LREAL(nDY)/nOVSTimeInterval_ns;
// Get the time (difference) from the left side element start to the desired time point:
nDX := tDecVar_InTaskCycle
- TRUNC_INT(tDecVar_InTaskCycle/nOVSTimeInterval_ns)
* UDINT_TO_LREAL(nOVSTimeInterval_ns);
// Calc timestamp
tVarDecResult := nDX + ULINT_TO_LREAL(nOVS_CycleCount);
// Calc new value:
nVarDecResult :=
LREAL_TO_DINT(DINT_TO_LREAL(aOVS_SampleSets[i]) + sVal * nDX);
// next decimation time step
tDecVar_InTaskCycle := tDecVar_InTaskCycle + nDecTimeInterval_ns;
tDecVar_InTaskCycle := tDecVar_InTaskCycle
- INT_TO_UDINT(TRUNC_INT(tDecVar_InTaskCycle/nTaskCycle_ns))
* nTaskCycle_ns;
END_IF
// Fill timestamp and new value allocated to the field element of its timestamp
aVarDecResult_TS[i] := tVarDecResult;
aVarDecResult[i] := nVarDecResult;
// For visualization of the original input:
aOVS_Samples[i] := aOVS_SampleSets[i];
aOVS_Samples_TS[i] := nOVS_CycleCount;
// Count the task cycle timestamp
nOVS_CycleCount := nOVS_CycleCount + nOVSTimeInterval_ns;
END_FOR
END_IF
IF nOVS_CycleCount = 1000000000 THEN
bEnable := FALSE;// Stop after 1s just for recording
IF NOT bEnable THEN
bEnable := TRUE; // OVS‑Samples transferred complete into both array sets
END_IF
END_IF
4.3.7
Sample program 8 (diagnosis messages)
Download TwinCAT 3 project: https://infosys.beckhoff.com/content/1033/epp3504/Resources/
4279234443/.zip
106
Version: 1.2
EPP3504-0023