User Tools

Site Tools


plc:m88_m89_stop_motion_from_plc_if_input_pin_activated

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
plc:m88_m89_stop_motion_from_plc_if_input_pin_activated [2018/09/25 13:12] skirillovplc:m88_m89_stop_motion_from_plc_if_input_pin_activated [2018/09/25 18:39] skirillov
Line 14: Line 14:
 This procedure can be handled in Hardware PLC. We offer M88 and M89 PLC procedures which do this job as a standard procedure. However, it can be customized easily according to customer needs. This procedure can be handled in Hardware PLC. We offer M88 and M89 PLC procedures which do this job as a standard procedure. However, it can be customized easily according to customer needs.
  
-<code C M88.plc> 
-//Watch on given sensor number, Soft Stop if sensor triggered 
-//used for homing, surface measure, tool length measure etc 
  
 +A source code for M88 PLC procedure is shown below
 +
 +<code C M88.plc>
 main () main ()
 { {
Line 23: Line 23:
   input=eparam&0xFFFF; //P-parameter   input=eparam&0xFFFF; //P-parameter
   state=eparam>>16; //L-parameter   state=eparam>>16; //L-parameter
-  timer=0; 
  
   message=PLCCMD_MOTION_CONTINUE;   message=PLCCMD_MOTION_CONTINUE;
Line 48: Line 47:
 }; };
 </code> </code>
 +
 +
 +Input pin number and pins state (normally opened/closed) comes from G-code P/L parameters in **eparam** internal variable.
 +Pin number comes in P-parameter and pin state in L-parameter.
 +  * L=0 means the procedure waits logical "0" on selected input pin
 +  * L=1 means the procedure waits logical "1" on selected input pin
 +
 +Example:
 +<code>M88 P7 L0 (The procedure will wait "0" level on input pin #7)
 +G90 G0X-1000 F300</code>
 +
 +<code>M88 P3 L1 (The procedure will wait "1" level on input pin #3)
 +G90 G0Y300 F100</code>
 +
 +A two-lines block to decode Input pin number and a pin state from **eparam** variable is shown below
 +<code C M88.plc>
 +  input=eparam&0xFFFF; //P-parameter
 +  state=eparam>>16; //L-parameter
 +</code>
 +
 +
 +After input pin number and state is decoded, the PLC procedure sends to the Motion controller a command to start next G-code line which is supposed to be a G0-positioning line.
 +
 +<code C>
 +  message=PLCCMD_MOTION_CONTINUE;
 +  timer=30;do{timer--;}while(timer>0);</code>
 +  
 +Then the PLC procedure tests selected pin and is waiting till the pin comes to the given state (depends on L/state parameter)  
 +The test code is wrapped in **do{}while;** loop.
 +
 +<code C>
 +  ready=0;
 +
 +  do {
 +    a=portget(input);
 +    if (state==0)
 +    {
 +      if (a==0) {ready=1;};
 +    };
 +    if (state!=0)
 +    {
 +      if (a!=0) {ready=1;};
 +    };
 +  }while(ready==0);
 +</code>
 +
 +
 +After the pin came to the given state, the PLC sends to the Motion controller to skip the current motion command and load the next. 
 +
 +<code>
 +  message=PLCCMD_MOTION_SOFT_SKIP;
 +  timer=30;do{timer--;}while(timer>0);
 +</code>
 +
 +There are 2 scenarios how to Stop the current motion.
 +  - Immediate STOP (abort pulses generation right away)
 +  - Soft STOP (do soft deceleration with given deceleration time, programmed as **Soft stop time, s** in Configuration settings of the myCNC control software.
 +
 +If motion speed is low and you need to find a precise position of input pin triggered you would need **Immediate STOP**. However, if motion speed is high and you need to find the first estimate, Immediate STOP would be harmful for machine mechanics and **Soft STOP** might be more preferable.
 +
 +The Immediate of Soft stop can be choosen by sending PLC message to the Motion Controller
 +
 +^ Message Code ^ Value ^ Description ^
 +| PLCCMD_MOTION_SOFT_SKIP | 1003 | Soft stop and jump to the next command |
 +| PLCCMD_MOTION_SKIP | 1002 | Immediate stop and kump to the next command | 
 +
 +M88.plc procedure does **Soft Stop** if a input pin activated.
 +M89.plc procedure does **Immediate Stop** if a input pin activated.
 +
 +The only difference between M88 and M89 procedures are message to the Motion controller to skip current motion.
 +
 +for M89.plc the code is
 +<code>
 +  message=PLCCMD_MOTION_SKIP;
 +  timer=30;do{timer--;}while(timer>0);
 +</code>
 +
 +A complete source for M89.plc is shown below
 +
 +<code C M89.plc>
 +main ()
 +{
 +
 +  input=eparam&0xFFFF; //P-parameter
 +  state=eparam>>16; //L-parameter
 +
 +  message=PLCCMD_MOTION_CONTINUE;
 +  timer=30;do{timer--;}while(timer>0);
 +
 +  ready=0;
 +
 +  do {
 +    a=portget(input);
 +    if (state==0)
 +    {
 +      if (a==0) {ready=1;};
 +    };
 +    if (state!=0)
 +    {
 +      if (a!=0) {ready=1;};
 +    };
 +  }while(ready==0);
 +
 +  message=PLCCMD_MOTION_SKIP;
 +  timer=30;do{timer--;}while(timer>0);
 +
 +  exit(99);
 +};
 +</code>
 +
plc/m88_m89_stop_motion_from_plc_if_input_pin_activated.txt · Last modified: 2021/01/13 12:52 by ivan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki