#include "global.h" #if JIA_CHENG_WEI_YE_MACHINE void DK_InitAction(void); void DK_Action(void); void DK_XM_ChuiQi(void); void DK_FL_ChuiQi(void); void DK_ChaoSheng(void); void DK_XiaChong(void); void DK_SetAlarmCode(unsigned alarm_code); void DK_StartStopAction(void); void DK_AutoRunStep(void); void DK_Motor(void); void DK_SetAlarmCode(unsigned alarm_code) { SetAlarmCode(DK_ALARM_ADDR,alarm_code); DK_bAlarmStop = 1; /* switch(alarm_code) { case DK_KADAI_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break; case DK_XIACHONG_ARRIVE_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break; case DK_XM_LIMIT_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break; case DK_SM_LIMIT_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break; case DK_GUOLIAN_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break; default:; }*/ } void DK_InitAction(void) { XGearRatio = 1; } void DK_XM_ChuiQi(void) { if(DK_XMCQ_VAVLE && (dwTickCount >= DK_XMCQ_Delay)) { DK_XMCQ_VAVLE = 0; } } void DK_FL_ChuiQi(void) { if(DK_FLCQ_VAVLE && (dwTickCount >= DK_FLCQ_Delay)) { DK_FLCQ_VAVLE = 0; } } void DK_ChaoSheng(void) { if(DK_CS_OUT && (dwTickCount >= DK_CS_Delay)) { DK_CS_OUT = 0; } } //手动动作 void DK_ManualAction(void) { if(!DK_bRunning) { //警告跳出 if(bClearTotal) { bClearTotal = 0; ClrcToTal(DK_TOTAL_ADDR); } if(DK_bMotor) { if(!X_DRV)AxisContinueMove(X_AXIS,DK_PARAM_HIGH_SPEED,DK_DIR_P); } else { if(X_DRV)AxisDecStop(X_AXIS); } if(DK_bGouZhen) { DK_bGouZhen = 0; DK_GZ_VAVLE = ~DK_GZ_VAVLE; } if(DK_bYaDai) { DK_bYaDai = 0; DK_YD_VAVLE = ~DK_YD_VAVLE; } if(DK_bSM) { DK_bSM = 0; DK_SM_VAVLE = ~DK_SM_VAVLE; } if(DK_bXM) { DK_bXM = 0; DK_XM_VAVLE = ~DK_XM_VAVLE; } if(DK_bCS) { DK_bCS = 0; DK_CS_OUT = 1; DK_CS_Delay = dwTickCount + DK_PARAM_CS_TIME; } if(DK_bXMCQ) { DK_bXMCQ = 0; DK_XMCQ_VAVLE = 1; DK_XMCQ_Delay = dwTickCount + DK_PARAM_XMCQ_TIME; } if(DK_bFLCQ) { DK_bFLCQ = 0; DK_FLCQ_VAVLE = 1; DK_FLCQ_Delay = dwTickCount + DK_PARAM_FLCQ_TIME; } if(DK_bChuDai) { DK_bChuDai = 0; DK_CD_MOTOR = ~DK_CD_MOTOR; } if(DK_bManXiaChong) { DK_bManXiaChong = 0; if(DK_XiaChongStep == 0) { DK_XiaChongStep = 1; } } } } //打孔动作 void DK_Action(void) { DISPLAY_DATA0 = GetEncodeCount(); DK_ManualAction(); DK_XM_ChuiQi(); DK_FL_ChuiQi(); DK_ChaoSheng(); DK_XiaChong(); DK_StartStopAction(); DK_AutoRunStep(); DK_Motor(); } //下冲动作 void DK_XiaChong(void) { if(DK_XiaChongStep == 1) { DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_DELAY; DK_XiaChongStep = 2; } else if((DK_XiaChongStep == 2) && (dwTickCount >= DK_XiaChongDelay)) { DK_XM_VAVLE = 1; DK_XiaChongDelay = dwTickCount + VAVLE_ALARM_TIME; DK_XiaChongStep = 3; } else if(DK_XiaChongStep == 3) { if(DK_XM_LIMIT_IN) { DK_SM_VAVLE = 1; DK_XiaChongDelay = dwTickCount + VAVLE_ALARM_TIME; DK_XiaChongStep = 4; } else if(dwTickCount >= DK_XiaChongDelay) { DK_SetAlarmCode(DK_XM_LIMIT_ALARM); } } else if(DK_XiaChongStep == 4) { if(DK_SM_LIMIT_IN) { DK_SM_VAVLE = 1; DK_XiaChongDelay = dwTickCount + DK_PARAM_DELAY_CS; DK_XiaChongStep = 5; } else if(dwTickCount >= DK_XiaChongDelay) { DK_SetAlarmCode(DK_SM_LIMIT_ALARM); } } else if((DK_XiaChongStep == 5) && (dwTickCount >= DK_XiaChongDelay)) { DK_CS_OUT = 1; DK_CS_Delay = dwTickCount + DK_PARAM_CS_TIME; DK_XiaChongStep = 6; } else if((DK_XiaChongStep == 6) && (DK_CS_OUT == 0)) { DK_XiaChongDelay = dwTickCount + DK_PARAM_COLD_TIME; DK_XiaChongStep = 7; } else if((DK_XiaChongStep == 7) && (dwTickCount >= DK_XiaChongDelay)) { DK_SM_VAVLE = 0; DK_XM_VAVLE = 0; DK_XiaChongDelay = dwTickCount + VAVLE_ALARM_TIME; DK_XiaChongStep = 8; } else if(DK_XiaChongStep == 8) { if(!DK_SM_LIMIT_IN && !DK_XM_LIMIT_IN) { DK_XiaChongStep = 0; } else if(dwTickCount >= DK_XiaChongDelay) { if(DK_SM_LIMIT_IN)DK_SetAlarmCode(DK_SM_LIMIT_ALARM); else if (DK_XM_LIMIT_IN)DK_SetAlarmCode(DK_XM_LIMIT_ALARM); } } } //启动停止故障停止动作 void DK_StartStopAction(void) { if((START_IN_UP || DK_bStart) && !DK_bRunning && (DK_AutoStep ==0)) { if(GetTotal(DK_TOTAL_ADDR) >= SET_TOTAL)DK_SetAlarmCode(DK_TOTAL_ALARM); else { DK_AutoStep = 1; DK_bRunning = 1; DK_AutoDelay = 0; } DK_bStart = 0; } if(DK_KaDai_IN && (GetAlarmCode(DK_ALARM_ADDR) == 0)) { DK_SetAlarmCode(DK_KADAI_ALARM); } if(STOP_IN_UP || DK_bStop) { DK_bStop = 0; if(DK_bRunning && (SingOneFlg == 0)) { SingOneFlg = 1; } else { DK_GZ_VAVLE = 0; DK_YD_VAVLE = 0; DK_XM_VAVLE = 0; DK_XMCQ_VAVLE = 0; DK_SM_VAVLE = 0; DK_FLCQ_VAVLE = 0; DK_CS_OUT = 0; DK_CD_MOTOR = 0; DK_XiaChongStep = 0; DK_bRunning = 0; DK_AutoStep = 0; AxisEgmStop(X_AXIS); } } if(DK_bAlarmStop) { DK_bAlarmStop = 0; AxisEgmStop(X_AXIS); DK_AutoStep = 0; DK_XiaChongStep = 0; DK_bRunning = 0; SingOneFlg = 0; } } //电机动作 void DK_Motor(void) // { static long save_buff,length_buff; switch(DK_MotorStep) { case 0: break; case 1: QD_MotorStep = 2; break; case 2: save_buff = GetPos(X_AXIS); if(dwZipCnt <= 1) { AxisContinueMove(X_AXIS,DK_PARAM_LOW_SPEED,DK_DIR_P); //第一条走低速 } else { AxisMoveTwoPos(X_AXIS,DK_PARAM_HIGH_SPEED,(length_buff - DK_PARAM_LOWSPEED_LENGTH),DK_PARAM_LOW_SPEED,0xFFFFFF,DK_DIR_P);//第二条开始走两段速 } DK_MotorDelay = dwTickCount + GUO_LIAN_OVER_TIME; QD_MotorStep = 3; break; case 3: if(DK_GUO_LIAN_IN_UP) { QD_MotorStep = 4; DK_MotorDelay = dwTickCount + DK_PARAM_DELAY_GZ; } else if(dwTickCount >= DK_MotorDelay) { } if(DK_GZ_IN) { AxisEgmStop(X_AXIS); QD_MotorStep = 6; } break; case 4: if(dwTickCount >= DK_MotorDelay) { DK_GZ_VAVLE = 1; QD_MotorStep = 5; } if(DK_GZ_IN) { AxisEgmStop(X_AXIS); QD_MotorStep = 6; } break; case 5: if(DK_GZ_IN) { AxisEgmStop(X_AXIS); QD_MotorStep = 6; } break; case 6: if(!X_DRV) { if(dwZipCnt == 1)length_buff = GetPos(X_AXIS) - save_buff; //以第二条测量出来的长度为准来做减速 QD_MotorStep = 0; } break; } } //自动运行动作 void DK_AutoRunStep(void) { if(DK_bRunning) { if(DK_AutoStep == 1) { dwZipCnt = 0; DK_AutoStep = 2; } else if((DK_AutoStep == 2) && (dwTickCount >= DK_AutoDelay)) { if(QD_MotorStep == 0)QD_MotorStep = 1; DK_AutoStep = 3; } else if(DK_AutoStep == 3) { if(QD_MotorStep == 0) { DK_AutoStep = 4; } } else if(DK_AutoStep == 4) { if(DK_XiaChongStep == 0)DK_XiaChongStep = 1; DK_AutoStep = 5; } else if(DK_AutoStep == 5) { if(DK_XiaChongStep == 0) { DK_AutoStep = 6; } } else if(DK_AutoStep == 6) { AddToTal(DK_TOTAL_ADDR); dwZipCnt++; if((GetTotal(DK_TOTAL_ADDR) >= DK_PARAM_SET_TOTAL) || SingOneFlg) { if(SingOneFlg) { DK_AutoStep = 0; DK_bRunning = 0; SingOneFlg = 0; } else { DK_SetAlarmCode(DK_TOTAL_ALARM); } } else { DK_AutoStep = 2; DK_AutoDelay = DK_PARAM_CYCLE_DELAY + dwTickCount; CalProSP(DK_PROSPEED_ADDR); } } } } #endif