Endless FOR Loop with CoDeSys 2.3.9.x

yanapa
2010-05-19
2010-05-20
  • yanapa - 2010-05-19
    PROGRAM PLC_PRG
    VAR
    Β  Β i : BYTE;
    Β  Β Test : WORD;
    END_VAR
    FOR i:= 0 TO 255 DO
    Β  Β Test := Test + 1;
    END_FOR;
    Test := 0;
    

    There is a mistake in the IEC61131 compiler, the loop exit condition must be verified before increasing the i value and when exiting just increase once more like other compilers.

     
  • shooter - 2010-05-20

    no you are in error, as it is overflowing,

    when the test is on zero before adding it would not start at all

    when the test is on 255 then it would not run the last one. And yes correct you get endless loop.

    this is same for word and dword and for int,dint all same problem.

    very old problem even in machinelanguage was this a problem.

     

Log in to post a comment.