Jump to content
OMRON Forums

Stopping "infinite loop" CPLC


KEJR

Recommended Posts

Hello, I wrote a CPLC that simply jogged a motor back and forth with the command interface. (See code below). When using the IDE I cannot seem to stop the CPLC until the while loop has exited (i.e when I set P10==0). If I use the task manager to stop the CPLC while it is looping it reports it as being stopped, but in fact the motor keeps turning. How do I kill this CPLC short of killing power, and what is the use of the task manager if it doesn't report correct status? (Firmware 1.1.0.40 IDE 1.1.0.50) ******* Code start here *************** #include #include #include void user_plcc() { if(pshm->P[10] == 1) { Command("#2 j/"); while(pshm->P[10] == 1) { Command("#2j+"); sleep(1); Command("#2j-"); sleep(1); } } Command("#2k"); }
Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The CPLCs have a data structure UserAlgo.BgCplc[i]. When this is set to 1 the plc is enabled. When it is set to 0 the Cplc is disabled. This is what the task manager is doing. The next process to understand is what happens during a PLC scan. A CPLC can be considered to have a big WHILE loop around it, Basically a while (UserAlgo.BgCplc[i] == 1). This is the same logic as the script PLCs. Capps do not have this logic. When the PLC starts a scan it will run until it releases the thread or for 250usec. In your case this is at the Sleep(1). Then the next CPLC gets its chance. And so forth for all the CPLCs and then we run background and then start over. Only CPLC that are enabled (UserAlgo.BgCplc[i] = 1) will get their thread started. So in your code the motor has been told to jog and then the thread is released. Then the task manager disables the PLC. So the last command was for the motor to be in continous jogging mode and it sounds like that is what it is doing. The task manager is correct, the CPLC has stopped executing but the last thing it told the motor to do was run forever and that is what the motor is doing. When you set P10=0 the last command is to kill the motor so it goes into open loop disabled state and coasts to a stop. Then the CPLC skips all the code until p10 is again set to 1. I know this is just a test. But if you wanted it to work so that when the While loop stops but the last part of the PLC is not executed you should not use a continuous JOG command but rather a definite JOG command. Use a J: and calculate the distance based on the jog acceleration rate and the jog speed. Then you will be command only a fixed distance each plc cycle and if the PLC is terminated the motor will just stop.
Link to comment
Share on other sites

I thought it was probably something like that. I think the confusing part is that the equivalent code in a script PLC does not have this behavior. The reason, I'm guessing, is that the stopping of the PLC can be handled in between interpreted commands. I think that the power of Capps is where we want to go. It sounds like the CPLCs (including the servo interrupt PLC) are mostly intended for things that can be "scanned", similar to ladder logic, or in this case it is most similar to structured text execution on a traditional PLC controller. This can be useful for combinatorial logic, latching, etc. Thanks, Ken
Link to comment
Share on other sites

I would like to see the script PLC you tested because the equivalent in my opinion behaves the same. I would write this PLC as follows. open plc 1 if (p10 == 1) { jog/ 2; while (p10 == 1) { jog+ 2; p1 = Sys.Time + 1; while ( Sys.Time < p1){}; jog- 2; p1 = Sys.Time + 1; while ( Sys.Time < p1){}; } kill 2; } close As for the use of Capp or Cplc there are differences. A Capp will run like the CPLC, in a cyclic manner, if you encapsulate your code in a While loop. A CPLC will only scan once like a Capp if you end it with the UserAlgo.BgCplc[i] = 0 (i is the plc number) which will disable it from futher scans.
Link to comment
Share on other sites

The script PLC behaves the same as the CPLC in terms of jogging the motors, but you can start and stop the script PLC from the task manager or terminal even when it is in the while loop indefinitely. Here is the code. I wrote a subroutine to do the delay. open plc 1 jog/ 1; jog/ 2; while(p0==0) { jog 1 = 10000; jog 2 = 10000; call PLCDelay(3); //Delays using Sys.Time (seconds) jog 1 = 0; jog 2 = 0; call PLCDelay(3); //Delays using Sys.Time (seconds) } close
Link to comment
Share on other sites

I think the confusion here is understanding what the different Jog commands do. In the Cplc you use J+ and J- which have no endpoint and will therefore cause the motor to run forever unless another command is given. This happens regardless of if the task that sent the command is running or stopped after the command is issued. In this Script PLC you used J= which sends the motor to an absolute position where it will stop. So what you are seeing in both cases is that the PLC issues one of its commands and then falls into a while loop to give up the thread. The PLC is then disabled so it never runs any more code. The motor executes the last command it was given whic in the case of the Cplc was to run forever and in the case of the script PLC was to stop at a fixed position.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...