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

ST Condition " CASE... OF" is not working in CoDesys SP RTE
https://forum.codesys.com/viewtopic.php?f=4&t=2077
Page 1 of 1

Author:  asifdip [ Fri Oct 21, 2011 2:24 pm ]
Post subject:  ST Condition " CASE... OF" is not working in CoDesys SP RTE

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

Author:  Edwin Schwellinger [ Tue Oct 25, 2011 4:57 am ]
Post subject:  Re: ST Condition " CASE... OF" is not working in CoDesys SP

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

Author:  shooter [ Tue Nov 01, 2011 6:20 pm ]
Post subject:  Re: ST Condition " CASE... OF" is not working in CoDesys SP

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 www.oscat.de
or have a look in SFC here you can do exactly same, as this chart is designed for this type of statemachines.

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