Global variables turning into zero unexpectedly!?

2018-10-24
2018-11-06
  • SerkanCicek - 2018-10-24

    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.

     
  • josepmariarams - 2018-10-27

    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

     
  • SerkanCicek - 2018-11-06

    Josep M. Rams hat geschrieben:
    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.

     
  • josepmariarams - 2018-11-06

    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

     
  • josepmariarams - 2018-11-06

    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

     

Log in to post a comment.