Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

ST Condition " CASE... OF" is not working in CoDesys SP RTE

asifdip
2011-10-21
2023-08-17
  • asifdip - 2011-10-21

    Hi Everybody,
    Hi,
    I have noticed a very interesting problem in CodeSys 2.3. Actaully I am using CodeSys SP RTE target PCAN PCI. Everything is ok. As I can get all "StatusWORD" signal from my Canopen Node. But problem is like that:

    If I have written a very simple program in ST for "CASE... OF" condition , It works only in Simulation mode but when I load it in RTE SP PLC then it build & runs but it does not change the "CASE..OF" State. Case state has no change, it goes only in State 0: as it is first commnad but not State 1 or further. But in simulation , it works fine in all State.

    calltimer;
    inputtime:=calltimer.timeroutput;

    CASE state OF
    0: output:=4;
    IF inputtime=t#5s THEN state:=State+1; END_IF;
    1: output:=5;
    IF inputtime=t#10s THEN state:=State+1;END_IF;
    2: output:=90;
    IF inputtime=t#15s THEN state:=3;END_IF;
    3: output:=80;
    IF inputtime=t#20s THEN state:=state+1;END_IF;
    4: output:=12;
    IF inputtime=t#25sTHEN state:=0;END_IF;
    END_CASE;

    But this program is ok in Simulation Mode It change the State from 0 to1, 1 to 2, 2 to 3. 3 to 4.
    But when I load this program in CoDesys SP RTE, then It runs but No chage of "state". That means "CASE... of " operation is not working.
    I have need suggestion because i have to use this "Case..OF" state ment for CANopen State Machine to take in opeartion.

    Thanks
    Asif

     
  • eschwellinger

    eschwellinger - 2011-10-25

    Hello,
    change the if case to >=...
    IF inputtime>=t#5s THEN
    then it works
    cu
    Edwin

     
  • shooter - 2011-11-01

    It is because the simulation checks the seconds but if you say time then it is in milliseconds. and as the program takes a few milliseconds to run the time is not exactly same but a little different.
    so the solution is good and will work.
    same is btw for almost all analog signals you will have to check the bounds.

    for this state machine look at w www.oscat.de w
    or have a look in SFC here you can do exactly same, as this chart is designed for this type of statemachines.

     

Log in to post a comment.