1

In my TwinCat 2 project, when I am initializing variables, their default value is not zero.

TPS750 : BOOL;
TPS750_OEE : REAL;
TP750_Perf : REAL;
TP750_Aval : REAL;
TP750_Qual : REAL;

When I start the project, the values are:

TPS750 = FALSE;
TPS750_OEE = 0;
TP750_Perf = 524288;
TP750_Aval = 3380.893;
TP750_Qual = 656709.1;

You can see, the first two are ok, but next ones are with a strange value for me. What can be the cause of this problem?

2 Answers2

0

Either those are initialized somewhere in the project and you don't see it or they are persistent values.

Persistent values are declared inside the

VAR PERSISTENT

END_VAR

definition.

Filippo Boido
  • 950
  • 5
  • 11
0

Please initialize variables explicitly. If you don't it is up to the compiler to do this or not and how. Note that many compilers do not zero out uninitialized variables so that these variables get a value based upon what happens to be in memory when you run your code.

owillebo
  • 545
  • 4
  • 7
  • not in Twincat 3 and I'm pretty confident that it's the same in Twincat 2...Everything that is not explicitly initialized is either 0 / 0.0 or FALSE – Filippo Boido Dec 11 '20 at 13:58