Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • E escet
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 76
    • Issues 76
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 3
    • Merge requests 3
  • Deployments
    • Deployments
    • Releases
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Eclipse Projects
  • Eclipse ESCET (Supervisory Control Engineering Toolkit)
  • escet
  • Issues
  • #281

Closed
Open
Created Jan 01, 2022 by Ferdie Reijnen@freijnenDeveloper

Improve generated PLC code

While working on #142 (closed) I noticed the following things that could be improved. This would also simplify the conversion to Siemens S7.

  1. The generated main POU has (always exactly two) output variables (timerValue0 and timerValue1). These are special variables that other POU's can access. It is not clear why the code has output variables. The comments in the code say Add output variables. These are required for the 'TON' timers.. These are indeed used for the TON timers but that doesn't justify being output variables. The documentation also doesn't explain why we have these. Does anyone know why we have these? I think the code can be simplified as shown below.
// Handle 'time' and cycle time.
cnt := cnt + 1;

timer0(IN := curTimer = 0, PT := T#1D);
timer1(IN := curTimer = 1, PT := T#1D);
-  timerValue0 := timer0.ET;
-  timerValue1 := timer1.ET;

lastTimerValue := curTimerValue;
IF curTimer = 0 THEN
-    curTimerValue := timerValue0;
+    curTimerValue := timer0.ET;
ELSE
-    curTimerValue := timerValue1;
+    curTimerValue := timer1.ET;
END_IF;
curDeltaTime := curTimerValue - lastTimerValue;
curDeltaSecs := TIME_TO_LREAL(curDeltaTime) / 1000;
curTime := curTime + curDeltaSecs;

IF cnt MOD 10 = 0 THEN
    curTimer := 1 - curTimer;
    curTimerValue := T#0S;
    timer0(IN := curTimer = 0, PT := T#1D);
    timer1(IN := curTimer = 1, PT := T#1D);
-    timerValue0 := timer0.ET;
-    timerValue1 := timer1.ET;
END_IF;
  1. curTimer is a global variable of resource Timers, but should be a variable of the main program. This variable is used to indicate which timer is active, part of 'Handle 'time' and cycle time'. Now it seems like some kind of special variable, I don't see why that is necessary. It fits with variables such as curTimerValue, part of main.

  2. Functions use non-temporary variables. This means that memory is reserved to 'save' the value of the variables in the function between cycles. That is not necessary. Instead, all 'local' function variables should be temporary variables. See below how functions are now transformed. Instead, fvar_plus3_sum should be a temporary variable. They are temporary variables, TwinCAT doesn't make it explicitly by having VAR_TEMP, whereas Siemens does that.

4 PlcConfiguration java class has List<PlcGlobalVarList> globalVarLists, but that is never used. Instead, we always use the globalVarLists that is part of the PlcResource (which itself is part of PlcConfiguration). The globalVarLists code in PlcConfiguration can be removed.

Edited Jan 01, 2022 by Ferdie Reijnen
Assignee
Assign to
Time tracking

Copyright © Eclipse Foundation, Inc. All Rights Reserved.     Privacy Policy | Terms of Use | Copyright Agent