CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

Global variables turning into zero unexpectedly!?
https://forum.codesys.com/viewtopic.php?f=6&t=9250
Page 1 of 1

Author:  SerkanCicek [ Wed Oct 24, 2018 5:40 pm ]
Post subject:  Global variables turning into zero unexpectedly!?

Hello.

We are using Codesys v3.5 sp10 in some of our applications, and we have noticed that some variables declared as global variables with a nonzero value, tend to get turned into zero for no reason. Having cross referenced the variables multiple times, we have found nothing in our code that alters the value of the mentioned variables. Also we have run the code both in a PLC and in the simulation mode, but the problem persists in both cases. This only happens to some of the global variables defined in that global variable block, and when we change the name of those variables, the error temporarily cedes. When we change the type of the variable, it starts to turn to zero of that variable type. (e.g. False for Boolean) When we write values to those variables in the code, the value immediately turns to zero. When we write values into the variable in the debugging mode, the value turns to zero again, immediately after pressing “write values”. When we force values, the value of the variable in the code remains to be zero. When we use pointers to write values, the value stored in that variable becomes a very small number. (Something close to 3e-305)

Althought we may delete the variable and write another variable with a different name to work-around this problem, we are worrying about this situation might be happening to some of the system variables that we would not be able to detect or it may spread to other variables over time, so we want to figure out the cause.

Thanks in advance for your replies.

Author:  Josep M. Rams [ Sat Oct 27, 2018 5:54 am ]
Post subject:  Re: Global variables turning into zero unexpectedly!?

Hi.

It could be cause by an array of variable types diferent than the problem variables running outside his limits, or a pointer to a variable of diferent kind pointing to bad.

Sent from my Moto G (5S) Plus using Tapatalk

Author:  SerkanCicek [ Tue Nov 06, 2018 6:47 pm ]
Post subject:  Re: Global variables turning into zero unexpectedly!?

Josep M. Rams wrote:
Hi.

It could be cause by an array of variable types diferent than the problem variables running outside his limits, or a pointer to a variable of diferent kind pointing to bad.

Sent from my Moto G (5S) Plus using Tapatalk


Hello.

Thank you for your reply. I am not sure if you got the point correctly or not. These variables have exact values at the begining and they are not being changed during the initialization of the program. Nevertheless, they are turning to zero unexpectedly.

Author:  Josep M. Rams [ Tue Nov 06, 2018 8:46 pm ]
Post subject:  Re: Global variables turning into zero unexpectedly!?

Hi.

Imagine you have declared an array of 100 integers, and after its you declare two reals.

Imagine that the compiler put your array beguining on memory position 1000, it will end on position 1199, and your first real will be on position 1200 and the second on 1204.

If you write something on the array index 102, you are writing over the exponent of the first real.

Sent from my Moto G (5S) Plus using Tapatalk

Author:  Josep M. Rams [ Tue Nov 06, 2018 9:54 pm ]
Post subject:  Re: Global variables turning into zero unexpectedly!?

Hi.

I don't know if that is the cause, but if in the exponent are wrote an big negative number your real will be a value near 0.

Could be....

Sent from my Moto G (5S) Plus using Tapatalk

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/