6.24 Spindle Preheat Function


When executing the program, NC will pre-read S code, and send a M33134 command to the PLC. The PLC will decide whether the spindle rotates at the S code speed to the set warm-up time before starting the program execution. Among them, s is the value of S Code.


The PLC program example is as follows:

static short int SpindleAdvanceRun_Flag;


#define paSPAdvanceRunON  (para[93])  ;Whether to activate the warm-up function 1: Enable the warm-up function else: Does not enable the warm-up function

#define paSPAdvanceRunCW  (para[94])  ;Whether to use the spindle to reverse the warm-up 1: Spindle reversal warm-up else: Spindle reversal warm-up  

#define paSPAdvanceRunTime (para[95]) ;Spindle warm-up time setting  



  if(plc.mCode.flag && !plc.mCode.finish)

  {

     switch (plc.mCode.data)

     {

        case 33134:

            if(paSPAdvanceRunON){    ;Whether to start the warm-up function

                if( plc.mhAttr ) {

                    plc.sCode.flag = 1;

                    plc.sCode.data = plc.mhCode0;

                  ;Conversion spindle DA output value

                    vSCodeSave = short ( long (2047 * plc.sCode.data) / paMaxSpeed)

                    if(paSPAdvanceRunCW){                      ;Use spindle reverse heating

                        smSpindleCCW.flag = STAGE_TEMP3;

                    }else{smSpindleCW.flag = STAGE_TEMP3;}

                    plc.mhAttr = 0;

                }

             if(SpindleAdvanceRun_Flag){                     ;When spindle warm-up function is completed in M3/M4

                SpindleAdvanceRun_Flag = 0;                  ;End M33134, processing

                  plc.mCode.finish = 1;

                    break;

                }

           

            }else{                                            ;No spindle warm-up function

                plc.mCode.finish = 1;                         ;Directly end M33134

                break;

            }

        break;


      }

  }


  switch(smSpindleCW.flag)

  {

     case STAGE_START:

           ......

     break;


     case STAGE_TEMP1:

           ......

     break;


     case STAGE_TEMP2:        ;Check or not check the spindle reaches the speed, then delay for a period of time and then end M3

        if((giSpindleSpeedReach && !giSpindleZeroSpeed) && tSpindleSpeedUp++ > 128

                 || ( smSpindleCW.timer++ > paSpindleOnTime*13 ) || ( sts.mode1.mM29 && paRegidType ) )

        { smSpindleCW.flag=STAGE_FINISH;  }

     break;


     case STAGE_TEMP3:        ;Forward warm-up time setting

           SpindleTimeOutTick = sts.sysTimeTick + paSPAdvanceRunTime*256;

           smSpindleCW.flag = STAGE_TEMP4;

     break;


     case STAGE_TEMP4:         ;Spindle forward start

           goSpindleServoOn=1;

           goSpindleRun=1;

           poSpindleCW=1;

           poSpindleCCW=0;

           poSpindleStop=0;

                       

           if(sts.sysTimeTick >= SpindleTimeOutTick){      ;Preheating time

               smSpindleCW.flag = STAGE_TEMP2;

               SpindleAdvanceRun_Flag = 1;

           }

     break;


  }


  switch(smSpindleCCW.flag)

  {

     case STAGE_START:

           ......

     break;


     case STAGE_TEMP1:

           ......

     break;


     case STAGE_TEMP2:           ;End spindle reversal

        if((giSpindleSpeedReach && !giSpindleZeroSpeed) && tSpindleSpeedUp++ > 128

                 || ( smSpindleCCW.timer++ > paSpindleOnTime*13 ) || ( sts.mode1.mM29 && paRegidType ) )

        { smSpindleCCW.flag=STAGE_FINISH;  }

     break;


     case STAGE_TEMP3:          ;Reverse warm-up time setting

           SpindleTimeOutTick = sts.sysTimeTick + paSPAdvanceRunTime*256;

           smSpindleCCW.flag = STAGE_TEMP4;

     break;


     case STAGE_TEMP4:          ;Spindle reverse start

           goSpindleServoOn=1;

           goSpindleRun=1;

           poSpindleCW=0;

           poSpindleCCW=1;

           poSpindleStop=0;

       

           if(sts.sysTimeTick >= SpindleTimeOutTick){  ;Preheating time        

               smSpindleCCW.flag = STAGE_TEMP2;

               SpindleAdvanceRun_Flag = 1;

           }

     break;


  }