Codesys - cpu load

damian177
2022-06-30
2022-07-04
  • damian177 - 2022-06-30

    Hi,
    I using codesys to my app. Somethimes when I do update my project and try run my application the CPU load exceed 95% and program stop with exception code. What are my ways of getting out of this situation ? During operation, the CPU load is about 20%

     
  • paulpotat

    paulpotat - 2022-07-01

    Hi,
    You should check for an infinite / very long loop in your code that could be blocking the execution.
    What kind of PLC are you using ?

     
  • damian177 - 2022-07-01

    Codesys proces eating all the CPU during running my project. The problem is in the loop - please find in attachement . I do not what can be wrong...

     
  • i-campbell

    i-campbell - 2022-07-01

    what is the sizeof dataimagelogoP1inv equal to? if it is 255, your for loop will be an infinite loop..

     
  • damian177 - 2022-07-01

    Size like below :
    dataImageLogoP1inv : ARRAY[0..203] OF BYTE;

    SIZEOF return 204 in my example ?,so my loop should be :

    IF firstScan THEN
        FOR iCount:=0 TO UINT_TO_BYTE(SIZEOF(dataImageLogoP1inv) -1) DO
            dataImageLogoP1inv[iCount] := GVL_Print.dataImageLogoP1[iCount] XOR 16#FF;
            dataImageLogoP2inv[iCount] := GVL_Print.dataImageLogoP2[iCount] XOR 16#FF;
            dataImageLogoP3inv[iCount] := GVL_Print.dataImageLogoP3[iCount] XOR 16#FF;
            dataImageLogoP4inv[iCount] := GVL_Print.dataImageLogoP4[iCount] XOR 16#FF;
        END_FOR
    
        MERGE_ARRAY(pointers := PHSpts, sizes := PHSss, destinationPtr := ADR(PrintHeaderSchem));
        firstScan:=FALSE;
    END_IF
    

    it can be a problem ?

     

    Last edit: damian177 2022-07-01
  • damian177 - 2022-07-02

    How is possible that my first solution worked time to time ?

     
  • fajean - 2022-07-03

    Looking at your code snippet, and assuming the arrays point to valid memory areas (not overlapping other variables), it seems off the top of my mind three things may be wrong :

    • the loop is infinite
    • MERGE_ARRAY is being passed arguments that cause a very long processing time or memory corruption.
    • Your code block is being called during every scan cycle, and the"firstScan" variable is local to the code block and being reinitialized to TRUE every time.

    It should be possible to rule of some of these easily with a few tests.

    Also, one quick note. You use this :

    UINT_TO_BYTE(SIZEOF(dataImageLogoP1inv) -1)
    

    If SIZEOF returns 0, then UINT_TO_BYTE will yield 255 (BYTE is unsigned), which is probably not what you want. It is hard to tell because we do not have all of the code, but I am not sure you should be using UINT_TO_BYTE, and iCount maybe should be a UINT (or something with a larger range).

     
    • damian177 - 2022-07-04

      In my project in one of program block it was declared this variable : VAR firstScan:BOOL:=TRUE; END_VAR Is not a global variable.

      I don't understand why variable "fisrtScan" would be reinitialize to TRUE every time ?

       
      • fajean - 2022-07-04

        I am not saying for sure that it is reinitialized to TRUE, but it could be if, say, the declaration of "firstScan" is located in a method rather than in the function block's body. I do not see the whole code, so it is hard to tell where your problem comes from.

         
  • damian177 - 2022-07-04

    Problem probably was in UINT_TO_BYTE(SIZEOF(dataImageLogoP1inv) -1) because oryginally I use :
    UINT_TO_BYTE(SIZEOF(dataImageLogoP1inv)).

    Thanks for help.

     

Log in to post a comment.