#include "global.h" #if JIN_HONG_MACHINE==1 void MXC_InitAction(void); void MXC_Action(void); void MXC_CheckStart(void); void MXC_ManualAction(void); void MXC_DC_AutoAction(void); void MXC_DC_Motor(void); void MXC_XiaChong(void); void MXC_ChuiQi(void); void MXC_FenZhen(void); void MXC_DC_SongDai(void); void MXC_DC_ShaChe(void); void MXC_DC_XC_BuJin_motor(void); void MXC_ExtiAcitionX20(void); unsigned long cZipperLength[2]; #define SB_CHECK_IN !PAin(15) //故障报警 void MXC_SetAlarmCode(unsigned alarm_code) { SetAlarmCode(MXC_ALARM_ADDR,alarm_code); MXC_DC_bAlarmStop = 1; } //X20中断 void MXC_ExtiAcitionX20(void) { if (cSeBiaoEn && !cSeBiaoOk) { cSeBiaoOk = 1; MXC_SB_SaveLength = GetPos(X_AXIS); MXC_SB_ENCODE_MIN=dwEnRealPos; //MXC_Clear_Servo_Pos=1; } } void MXC_SBCHECK_PROC(void) { static unsigned short flitering=0; if(SB_CHECK_IN) { flitering++; if(flitering>=2) { if (cSeBiaoEn && !cSeBiaoOk) { cSeBiaoOk = 1; MXC_SB_SaveLength = GetPos(X_AXIS); MXC_SB_ENCODE_MIN=dwEnRealPos; } } } else { flitering=0; } } unsigned char ComPareLength(void)//前后拉链对比 { if ((cZipperLength[0] != 0) && (cZipperLength[1] != 0)) { if (cZipperLength[0] > cZipperLength[1]) { if ((cZipperLength[0] - cZipperLength[1]) > 50) { return 0; } else return 1; } else { if ((cZipperLength[1] - cZipperLength[0]) > 50) { return 0; } else return 1; } } else return 0; } void MXC_JiaoDao(void) { if (MXC_cJiaoDaoStep == 1) { MXC_cJiaoDaoDelay = dwTickCount + 500; MXC_SeBiao_JiaoDao = 1; MXC_cJiaoDaoStep = 2; } else if ((MXC_cJiaoDaoStep == 2) && (dwTickCount >= MXC_cJiaoDaoDelay)) { MXC_SeBiao_JiaoDao = 0; MXC_cJiaoDaoStep = 0; } } //步进电机下冲 void MXC_DC_XC_BuJin_motor(void) { switch(MXC_cXiaChongStep) { case 0: break; case 1: if(GetEn(Z_AXIS) == XC_MOTOR_DISEN) { SetEn(Z_AXIS,XC_MOTOR_EN); MXC_BUJIN_XC_Delay = dwTickCount + 170; } MXC_cXiaChongStep = 2; MXC_cRightFZStep = 1;//启动右分针 MXC_cLeftFZStep = 0; break; case 2: if((MXC_cRightFZStep == 0) && (MXC_cLeftFZStep == 0) && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN ) { SetPos(Z_AXIS, 0); if (MXC_DC_bRunning) { MXC_BUJIN_XC_Delay = dwTickCount + MXC_PARAM_DELAY_XC; } MXC_cXiaChongStep = 3; } break; case 3: if(dwTickCount >= MXC_BUJIN_XC_Delay) { MXC_cXiaChongStep = 4; if(MXC_DC_bRunning) MXC_GouZhen_VAVLE = 1; AxisMovePosAccDecNotStop(Z_AXIS,MXC_DC_XC_MOTOR_HIGH_SPEED,2000, 1200,MXC_DC_XC_MOTOR_LOW_SPEED, 100,100,MXC_DC_XC_MOTOR_LOW_LENGTH); MXC_BUJIN_XC_Delay = dwTickCount + MXC_XIACHONG_EEROR_TIME; } break; case 4: if(MXC_XiaChong_IN_UP) { SetEncodePos(ENCODE_X22X23, 0); AxisMovePosAccDec(Z_AXIS,MXC_DC_XC_MOTOR_LOW_SPEED,MXC_DC_XC_MOTOR_GO_LENGTH, 1200,MXC_DC_XC_MOTOR_LOW_SPEED, 100,100,MXC_DC_XC_MOTOR_GO_LENGTH/3); MXC_LeftFenZhen_VAVLE = 0; MXC_RightFenZhen_VAVLE = 0; MXC_cXiaChongStep = 5; MXC_BUJIN_XC_Delay = dwTickCount; } else if(dwTickCount >= MXC_BUJIN_XC_Delay)//步进异常 { MXC_SetAlarmCode(MXC_XC_ALARM); MXC_LeftFenZhen_VAVLE = 0; MXC_RightFenZhen_VAVLE = 0; MXC_cXiaChongStep = 0; } break; case 5: if(dwTickCount >= MXC_BUJIN_XC_Delay && !Z_DRV) { MXC_MOTOR_DATA_Num++; if(MXC_MOTOR_DATA_Num > 99) MXC_MOTOR_DATA_Num = 0; if(!MXC_DC_bRunning){ SetEncodePos(ENCODE_X22X23, 0); SetPos(X_AXIS, 0); } MXC_cXiaChongStep = 0; } break; } } void MXC_InitAction(void) { float length_buff,pulse_buff; length_buff = MXC_MXC_PARAM_DAILUN_LENGTH; pulse_buff = MXC_MXC_PARAM_CYCLE_PULSE; XGearRatio = pulse_buff/length_buff; length_buff = MXC_BM_LENGTH; pulse_buff = MXC_BM_CYCLE_PULSE * 4; SetEncodeGearRatio(ENCODE_X22X23, pulse_buff/length_buff); ZGearRatio = 1;//z轴用脉冲数做单位 SetEn(X_AXIS,DC_Motor_DISEN); SetEn(Y_AXIS,XZ_Motor_DISEN); SetDirReverse(X_AXIS, MXC_DC_Reverse_EN); MXC_STOP_IN_FLAG = MXC_STOP_IN; MXC_STOP_IN_FLAG_OLD = MXC_STOP_IN_FLAG; MXC_SaveLength = 0; //外部中断配置 USE_X20_EXTI = 1; X20EXTI_DIR = 0; //设置X轴的加速模式 axis_set_parameter(axis_x,AXIS_ACCDEC_MODE,4); //只有编码器的情况长度由编码器值确定 SetEncode_enable(ENCODE_X22X23); MXC_DC_KongWei_Length = MXC_PARAM_DAOKOU_LENGTH; } void MXC_Action(void) { MXC_CheckStart(); //启动 MXC_ManualAction(); MXC_DC_AutoAction(); MXC_DC_Motor(); //定寸电机控制 if(!MXC_DC_XC_MODE) MXC_XiaChong(); //下冲 else if(MXC_DC_XC_MODE) MXC_DC_XC_BuJin_motor(); MXC_DC_ShaChe(); MXC_FenZhen(); //分针 MXC_ChuiQi(); //吹气 MXC_DC_SongDai(); //送带控制 MXC_JiaoDao(); //色标教导 //servo_com_run(); } void MXC_DC_SongDai(void) { if(!MXC_SongDai_MOTOR) { MXC_SongDai_LongTime = dwTickCount; } else//送带一直输出无法触发送带到位 { if((dwTickCount - MXC_SongDai_LongTime) >= MXC_PARAM_SD_Pretect_TIME) { if(!MXC_DC_bRunning) { MXC_PARAM_SongDai_Switch = 0; MXC_SetAlarmCode(MXC_DC_SONGDAI_ALARM); } else { MXC_SongDai_MOTOR = 0; MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay; } } } } void MXC_ManualAction(void) { char i; short *revise_buff; revise_buff =(short *)( &user_datas[17]); if(MXC_DATA_Clean) { i = 0; while(i < 100) { user_datas[200 + i] = 0; i++; } MXC_DATA_Clean = 0; MXC_MOTOR_DATA_Num = 0; } //清总产量 if(MXC_bClear) { MXC_bClear = 0; ClrcToTal(MXC_DC_TOTAL_ADDR); } if(MXC_bAddLength) { MXC_bAddLength=0; *revise_buff += 5; } if(MXC_bDecLength) { MXC_bDecLength=0; *revise_buff -= 5; } //当长度改变时,生产总量自动清零 if(MXC_bChangeLength) { MXC_bChangeLength = 0; MXC_SaveLength = 0; MXC_bClear = 1; } //工作方式选择(数控定寸和勾针定寸)  if (MXC_bSetDCMode) { MXC_bSetDCMode = 0; if (!MXC_DC_bRunning) { MXC_DC_MODE++; if (MXC_DC_MODE > 2) MXC_DC_MODE = 0; if (MXC_DC_MODE != 0) { MXC_GouZhen_VAVLE = 1; } } } //有链感应 if (MXC_DC_bRunning)//检测拉链,由于拉链有间隙,故需要延迟检测 { if (MXC_Zipper_IN) { MXC_cBudaiCheckDelay = dwTickCount + MXC_PARAM_BUDAI_ALARM_TIME; } else if (dwTickCount >= MXC_cBudaiCheckDelay) { MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM); //没拉链 } } if(MXC_PARAM_SongDai_Switch) { if(!MXC_SongDai_IN && MXC_Zipper_IN && (dwTickCount >= MXC_cSongDaiDelay)) { MXC_SongDai_MOTOR = 1; } else if(MXC_SongDai_IN) { MXC_SongDai_MOTOR = 0; MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay; } } else { MXC_SongDai_MOTOR = 0; MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay; } if((MXC_DC_bRunning) == 0) ////手动 { //送带 if(MXC_bSongDai) { MXC_SongDai_MOTOR = 1; } //顶刀保护 if(MXC_bDingDao_Baohu) { MXC_bDingDao_Baohu = 0; MXC_DingDao_BaoHu_VAVLE = ~MXC_DingDao_BaoHu_VAVLE; } //吹气 if (MXC_bChuiQi) { MXC_bChuiQi = 0; if (MXC_cChuiQiStep == 0) MXC_cChuiQiStep = 1; } //定寸电机拖带 if(MXC_bDCTD_P) { if(!X_DRV) { // MXC_TuoDaiSongZhou= MXC_SERVER_EN; SetEn(X_AXIS, DC_Motor_EN); AxisContinueMoveAcc(X_AXIS, MXC_DC_PARAM_MUL_SPEED, MXC_DC_DIR_P, 1200, 1200, 120, 120); } } if(X_DRV && !MXC_bDCTD_P && !MXC_DC_bRunning && (MXC_DC_cMotorStep == 0)) { AxisEgmStop(X_AXIS); } //下冲电机正转 if(MXC_bXCDJ_P) { if(!Z_DRV) { SetEn(Z_AXIS, XC_MOTOR_EN); AxisContinueMoveAcc(Z_AXIS, 3000, MXC_XC_DIR_P, 1200, 1200, 120, 120); } } if(Z_DRV && !MXC_bXCDJ_P && !MXC_DC_bRunning && (MXC_cXiaChongStep == 0)) { // SetEn(Z_AXIS, XC_MOTOR_DISEN); AxisEgmStop(Z_AXIS); } //分针+下冲 if (MXC_ManXiaChong_UP || MXC_bXiaChong) { MXC_bXiaChong = 0; if (MXC_cXiaChongStep == 0) MXC_cXiaChongStep = 1; } //下冲单一动作 if (MXC_cXiaChongStep == 0) { if (MXC_bLeftFenZhen) { MXC_bLeftFenZhen = 0; MXC_LeftFenZhen_VAVLE = ~MXC_LeftFenZhen_VAVLE; } if (MXC_bRightFenZhen) { MXC_bRightFenZhen = 0; MXC_RightFenZhen_VAVLE = ~MXC_RightFenZhen_VAVLE; } if(MXC_bDotXiaChong && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN) { MXC_bDotXiaChong = 0; if(MXC_cXiaChongStep == 0) MXC_cXiaChongStep = 1; } } if(MXC_bSeBiaoJiaoDao) { MXC_bSeBiaoJiaoDao = 0; MXC_cJiaoDaoStep = 1; } if(MXC_bGouZhen && MXC_DC_MODE == 0) { MXC_bGouZhen = 0; MXC_GouZhen_VAVLE = ~MXC_GouZhen_VAVLE; } if (MXC_DC_MODE != 0) //非钩针模式 { MXC_GouZhen_VAVLE = 1; } } } void MXC_DC_AutoAction(void) { if(MXC_MOTOR_DATA_Num <= 99)user_datas[420+MXC_MOTOR_DATA_Num] = MXC_ENCODE_FENZHEN_Lenth; dwZRealPos = GetPos(Z_AXIS); //DISPLAY_DATA0 = cCheckLengthOk;//Cur_DC_length;//MXC_cXiaChongStep;//MXC_DC_cAutoStep; //DISPLAY_DATA1 = MXC_bSeBiao_CheckOK;//cZipperLength[0];//Cur_XZ_length;//MXC_XZ_cAutoStep; DISPLAY_DATA2 = MXC_bSeBiao_CheckOK;//cZipperLength[1];// DISPLAY_DATA3 = MXC_DC_cAutoStep;//MXC_XZ_cMotorStep; DISPLAY_DATA4 = MXC_SB_ENCODE_MIN;//MXC_DC_cMotorStep; DISPLAY_DATA5 = MXC_SB_SaveLength;//MXC_cXiaChongStep; DISPLAY_DATA6 = dwXRealPos; DISPLAY_DATA7 = dwEnRealPos; if(MXC_DC_bRunning) { switch(MXC_DC_cAutoStep) { case 0: break; case 1: if(dwTickCount >= MXC_DC_cAutoDelay) { SetEn(X_AXIS, DC_Motor_EN); MXC_DC_cAutoDelay = dwTickCount + 700; //先锁轴; MXC_DC_cAutoStep = 2; } break; case 2: //左右分针要退到位,过链到位要离开 if((dwTickCount >= MXC_DC_cAutoDelay) && !MXC_RighttFenZhen_IN && !MXC_LeftFenZhen_IN && MXC_RightFenZhen_Origin_IN && MXC_LeftFenZhen_Origin_IN) { switch(MXC_DC_MODE) { case MXC_DC_SF_MODE:MXC_DC_cMotorStep = 1; break; //伺服 case MXC_DC_GZ_MODE:MXC_DC_cMotorStep = 20;break; //钩针 case MXC_DC_SB_MODE:MXC_DC_cMotorStep = 40;break; //色标 //case MXC_DC_BMQ_MODE:MXC_DC_cMotorStep = 60; break; //编码器 } MXC_DC_cAutoStep = 3; } else if(dwTickCount >= MXC_DC_cAutoDelay + MXC_ERRORTIME) { if (MXC_RighttFenZhen_IN)MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM); if (MXC_LeftFenZhen_IN)MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM); if (!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM); if (!MXC_LeftFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM); } break; case 3: //拖带已经完成 if(MXC_DC_cMotorStep == 0) { MXC_cXiaChongStep = 1; MXC_DC_cAutoStep = 4; } break; case 4://下冲完成 if((MXC_cXiaChongStep == 0) || (MXC_cXiaChongStep >= 5)) { dwZipCnt++; MXC_DC_cAutoStep = 5; //除齿判断 if(MXC_CRUKONGWEILENGTH >= MXC_DC_KongWei_Length || MXC_DC_MODE==0 || MXC_DC_MODE==2) { MXC_CRUKONGWEILENGTH = 0; if(!MXC_DC_SingOneFlag) { AddToTal(MXC_DC_TOTAL_ADDR); CalProSP(MXC_DC_PROSPEED_ADDR); } MXC_DC_cAutoStep = 5; } else { MXC_DC_cAutoStep = 2; MXC_DC_cAutoDelay = dwTickCount; } } break; case 5: if(GetTotal(MXC_DC_TOTAL_ADDR) >= MXC_SET_TOTAL) { MXC_SetAlarmCode(MXC_TOTAL_ALARM); MXC_DC_cAutoStep = 0; } else MXC_DC_cAutoStep = 6; break; case 6: MXC_DC_cAutoStep = 2; //MXC_Clear_Servo_Pos=0; MXC_DC_cAutoDelay = dwTickCount+1; if(MXC_DC_SingOneFlag || MXC_DC_Single_Stop) { dwZipCnt = 0; MXC_DC_bAlarmStop = 1; MXC_DC_SingOneFlag = 0; MXC_DC_cAutoStep = 0; MXC_DC_bRunning = 0; MXC_DC_Single_Stop = 0; } break; } } } // 检测是否踏了脚踏开关 void MXC_CheckStart(void) { // 开始键 if((MXC_START_IN_UP || MXC_DC_bStart || MXC_DC_bStart_Single)) { if(MXC_DC_bStart_Single) { MXC_DC_bStart = 1; MXC_DC_SingOneFlag = 1; MXC_DC_bStart_Single = 0; } if(MXC_START_IN_UP || MXC_DC_bStart) { //定寸启动 if(!MXC_DC_bRunning) { if (MXC_KaDai_IN)MXC_SetAlarmCode(MXC_KA_DAI_ALARM); else if (!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_START_RFZ_ORIGIN_ALARM); else if (!MXC_Zipper_IN)MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM); else { dwZipCnt = 0; cZipperLength[0] = 0; cZipperLength[1] = 0; MXC_DC_cAutoStep = 1; MXC_DC_bRunning = 1; MXC_DC_cAutoDelay = dwTickCount; MXC_DC_cMotorDelay = dwTickCount; MXC_cXiaChongDelay = dwTickCount; MXC_cChuiQiDelay = dwTickCount; MXC_CRUKONGWEILENGTH=0; MXC_ENCODE_FENZHEN_Lenth = 0; cSeBiaoOk=0; } } cCheckLengthOk = 0; MXC_bSeBiao_Check=0; MXC_PARAM_SongDai_Switch = 1; } MXC_DC_bStart = 0; MXC_DC_bStart_Single = 0; } //卡带感应 if(MXC_KaDai_IN) { MXC_SetAlarmCode(MXC_KA_DAI_ALARM); } else { if((GetAlarmCode(MXC_ALARM_ADDR) == MXC_KA_DAI_ALARM)) SetAlarmCode(MXC_ALARM_ADDR,0); } if(MXC_KaDai_IN_UP) { if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1; } //停止 MXC_STOP_IN_FLAG_OLD = MXC_STOP_IN_FLAG; if(MXC_STOP_IN) { if(MXC_STOP_FILTER < 50) { MXC_STOP_FILTER++; } else MXC_STOP_IN_FLAG = 1; } else if(MXC_STOP_FILTER > 25) { MXC_STOP_FILTER--; } else MXC_STOP_IN_FLAG = 0; //停止键 if(MXC_STOP_IN_FLAG && !MXC_STOP_IN_FLAG_OLD || MXC_bStop) { MXC_bStop = 0; MXC_bSeBiao_Check=0; if(MXC_DC_bRunning) { if(MXC_DC_cMotorStep==0 && MXC_cXiaChongStep!=0) { MXC_DC_Single_Stop = 1; } else { if(MXC_cXiaChongStep==0) { if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1; } MXC_DC_SingOneFlag = 0; MXC_DC_bRunning = 0; MXC_DC_cAutoStep = 0; MXC_DC_cMotorStep = 0; MXC_cXiaChongStep = 0; AxisEgmStop(X_AXIS); AxisEgmStop(Z_AXIS); //MXC_cJiaoDaoStep = 0; MXC_Zipper_cnt = 0; //输出 MXC_LeftFenZhen_VAVLE = 0; MXC_SongDai_MOTOR = 0; MXC_RightFenZhen_VAVLE = 0; MXC_DingDao_BaoHu_VAVLE = 0; MXC_PARAM_SongDai_Switch = 0; cSeBiaoOk=0; if(MXC_DC_MODE==0) MXC_GouZhen_VAVLE = 0; } } else { MXC_DC_SingOneFlag = 0; MXC_DC_bRunning = 0; MXC_DC_cAutoStep = 0; MXC_DC_cMotorStep = 0; MXC_cXiaChongStep = 0; MXC_cXiaChongStep = 0; MXC_cRightFZStep = 0; MXC_cLeftFZStep = 0; SetEn(X_AXIS,DC_Motor_DISEN); SetEn(Z_AXIS,XC_MOTOR_DISEN); if((MXC_cChuiQiStep == 0) &&(MXC_cXiaChongStep==0))MXC_cChuiQiStep = 1; AxisEgmStop(X_AXIS); AxisEgmStop(Z_AXIS); MXC_SetAlarmCode(MXC_NO_ALARM); //输出 if(MXC_cXiaChongStep == 0) { MXC_XiaChong_MOTOR = 0; } MXC_LeftFenZhen_VAVLE = 0; MXC_SongDai_MOTOR = 0; MXC_RightFenZhen_VAVLE = 0; MXC_DingDao_BaoHu_VAVLE = 0; MXC_PARAM_SongDai_Switch = 0; MXC_MOTOR_DATA_Num = 0; cSeBiaoOk=0; if(MXC_DC_MODE==0) MXC_GouZhen_VAVLE = 0; } } if(MXC_DC_bAlarmStop) { MXC_DC_bAlarmStop = 0; MXC_DC_bRunning = 0; MXC_DC_cAutoStep = 0; MXC_DC_cMotorStep = 0; MXC_cXiaChongStep = 0; MXC_cRightFZStep = 0; MXC_cLeftFZStep = 0; MXC_DC_SingOneFlag = 0; MXC_cXiaChongStep = 0; MXC_XiaChong_MOTOR = 0; MXC_LeftFenZhen_VAVLE = 0; MXC_RightFenZhen_VAVLE = 0; MXC_DingDao_BaoHu_VAVLE = 0; MXC_cShaCheStep = 1; AxisEgmStop(X_AXIS); } } void MXC_ChuiQi(void) { //吹气 if(MXC_XiaChong_IN_DW && !MXC_DC_XC_MODE) { if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1; MXC_cDDBH_Step = 1; } if(MXC_DC_XC_MODE) { if(PosToPulse(Z_AXIS,GetPos(Z_AXIS)) >= MXC_DC_XC_CHUIQI_PULSE && PosToPulse(Z_AXIS,GetPos(Z_AXIS)) <= MXC_DC_XC_CHUIQI_PULSE + 30) if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1; if(PosToPulse(Z_AXIS,GetPos(Z_AXIS)) >= MXC_DC_XC_DINDAO_PULSE && PosToPulse(Z_AXIS,GetPos(Z_AXIS)) <= MXC_DC_XC_DINDAO_PULSE + 30) if(MXC_cDDBH_Step == 0)MXC_cDDBH_Step = 1; } switch(MXC_cChuiQiStep) { case 1: MXC_cChuiQiStep = 2; MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_DELAY_CHUIQI_TIME; break; case 2: if(dwTickCount >= MXC_cChuiQiDelay) { MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_CHUIQI_TIME; MXC_ChuiQi_VAVLE = 1;// MXC_cChuiQiStep = 3; } break; case 3: if(dwTickCount >= MXC_cChuiQiDelay) { MXC_ChuiQi_VAVLE = 0;// MXC_cChuiQiStep = 0; } break; } switch (MXC_cDDBH_Step) { case 1: MXC_cDDBH_Step = 2; MXC_cDDBHDelay = dwTickCount + MXC_PARAM_DDBH_delay; break; case 2: if(dwTickCount >= MXC_cDDBHDelay) { MXC_cDDBH_Step = 3; MXC_DingDao_BaoHu_VAVLE = 1; MXC_cDDBHDelay = dwTickCount + MXC_DDBH_TIME; } break; case 3: if(dwTickCount >= MXC_cDDBHDelay) { MXC_cDDBH_Step = 0; MXC_DingDao_BaoHu_VAVLE = 0; } break; } } void MXC_DC_Motor(void) { static long zipper_length; short *revise_buff; unsigned long cmp=0; unsigned long cyclenum=0; dwXRealPos = GetPos(X_AXIS); dwEnRealPos = GetEncodePos(ENCODE_X22X23); revise_buff = (short *)(&user_datas[17]); switch(MXC_DC_cMotorStep) { case 0: break; //电机定寸模式 case 1: if(dwEnRealPos>(MXC_SET_ZIPPER_LENGTH + MXC_PARAM_DAOKOU_LENGTH) && MXC_CRUKONGWEILENGTH==0) { MXC_DC_cMotorStep = 0; MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH; MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME; SetEncodePos(ENCODE_X22X23, 0); } else { MXC_DC_cMotorStep = 2; MXC_DC_cMotorDelay = dwTickCount; SetPos(X_AXIS, 0); } break; case 2: if(dwTickCount >= MXC_DC_cMotorDelay) { if(MXC_CRUKONGWEILENGTH==0)//MXC_CRUKONGWEILENGTH 记录已除齿长度 { zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - dwEnRealPos; MXC_CRUKONGWEILENGTH=MXC_PARAM_DAOKOU_LENGTH; } else if(MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH>=MXC_PARAM_DAOKOU_LENGTH) { zipper_length=MXC_PARAM_DAOKOU_LENGTH; MXC_CRUKONGWEILENGTH+=zipper_length; } else { zipper_length=MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH; MXC_CRUKONGWEILENGTH+=zipper_length; } if(zipper_length>MXC_MXC_PARAM_DAILUN_LENGTH) { cmp=MXC_PARAM_LENGTH_CMP; cyclenum=zipper_length/MXC_MXC_PARAM_DAILUN_LENGTH; zipper_length=zipper_length+(zipper_length*cyclenum*cmp)/((cyclenum+1)*MXC_MXC_PARAM_DAILUN_LENGTH); DISPLAY_DATA0=zipper_length; } AxisMovePosAccDec(X_AXIS, MXC_PARAM_SK_HIGH_SPEED, zipper_length, 1000, MXC_PARAM_SK_SLOW_SPEED, 150, 150, MXC_PARAM_SK_SLOW_LENGTH); MXC_DC_cMotorStep = 3; MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME; } break; case 3: if(!X_DRV) { if(MXC_MOTOR_DATA_Num<=99)user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos; //SetEncodePos(ENCODE_X22X23, 0); MXC_DC_cMotorStep = 4; MXC_DC_cMotorDelay = dwTickCount + 20; } else if(dwTickCount >= MXC_DC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM); break; case 4: if(dwTickCount >= MXC_DC_cMotorDelay) { MXC_DC_cMotorStep = 0; } break; //钩针定寸 step20-24 case 20: if (MXC_DEC_MODE) //减速方式:1数控模式 0感应方式 { SetPos(X_AXIS, 0); if (MXC_PARAM_AUTO_CHECK_MODE) //1为自动测长0为手动输入长度 { if (cCheckLengthOk) { if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH) { AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED, zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH, 2000, MXC_DC_PARAM_LOW_SPEED, 150, 150, 0); } else { AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length, 1000, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0); } } else { if (cCheckLengthOk == 0) { cZipperLength[0] = cZipperLength[1]; cZipperLength[1] = zipper_length_buff; if (ComPareLength())//返回1,前后拉链没有明显变化 { cCheckLengthOk = 1; } } if (cCheckLengthOk) { zipper_length = cZipperLength[1]; if (zipper_length > MXC_PARAM_DAOKOU_LENGTH) { SetData32bits(MXC_XC_ZIPPER_LENGTH_ADDR, zipper_length - MXC_PARAM_DAOKOU_LENGTH); } if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH) { AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED, zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH, 2000, MXC_DC_PARAM_LOW_SPEED, 100, 100, 100); } else { AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length, 1000, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0); } } else { AxisContinueMoveAcc(X_AXIS, MXC_PARAM_FIRST_SPEED, MXC_DC_DIR_P, 1200, 800, 80, 120); } } } else//手动输入长度模式 { if (dwZipCnt == 0) AxisContinueMoveAcc(X_AXIS, MXC_PARAM_FIRST_SPEED, MXC_DC_DIR_P, 1200, 1200, 80, 120); else { zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH; //输入长度过大 if (zipper_length > zipper_length_buff && dwZipCnt > 1) zipper_length = zipper_length_buff; if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH) { AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED, zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH, 1000, MXC_DC_PARAM_LOW_SPEED, MXC_DC_PARAM_SET_SPEED / 300, MXC_DC_PARAM_SET_SPEED / 300, 0); } else { AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length, 800, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0); } } } MXC_DC_cMotorStep = 22; } else // 感应方式 { AxisContinueMoveAcc(X_AXIS, MXC_DC_PARAM_SET_SPEED, MXC_DC_DIR_P,1000,1000,30,30); MXC_DC_cMotorStep = 21; } MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY; MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME; break; case 21: //if ((dwTickCount >= MXC_cGouZhenTime)) // MXC_GouZhen_VAVLE = 0; if (MXC_DEC_MODE == 0) // 感应模式 { if (MXC_JianSu_IN_DW) { AxisChangeSpeedDirect(X_AXIS, MXC_DC_PARAM_LOW_SPEED); //MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY; MXC_DC_cMotorStep = 23; } if (MXC_GouZhen_IN) { MXC_DC_cMotorStep = 24; AxisEgmStop(X_AXIS); } } if (dwTickCount >= MXC_DC_cMotorDelay) MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM); break; case 22: // if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0)) // MXC_GouZhen_VAVLE = 0; if (MXC_DEC_MODE) // 数控方式 { if (MXC_PARAM_AUTO_CHECK_MODE)///1为自动测长0为手动输入长度 { if (cCheckLengthOk) { if ((dwXRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH)) && MXC_PARAM_GZ_RESET_MODE) MXC_GouZhen_VAVLE = 0; } else { if (dwTickCount >= MXC_cGouZhenTime) MXC_GouZhen_VAVLE = 0; } } else { if ((dwXRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH)) && MXC_PARAM_GZ_RESET_MODE) MXC_GouZhen_VAVLE = 0; if ((dwZipCnt == 0) && (dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 1)) MXC_GouZhen_VAVLE = 0; } if (MXC_JianSu_IN_DW) { if (cCheckLengthOk) { ; } else { AxisChangeSpeedDirect(X_AXIS, MXC_DC_PARAM_LOW_SPEED); } } if (MXC_GouZhen_IN_UP) { MXC_GouZhen_VAVLE = 0; MXC_DC_cMotorStep = 23; AxisEgmStop(X_AXIS); } } if (dwTickCount >= MXC_DC_cMotorDelay) MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM); break; case 23: if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0)) MXC_GouZhen_VAVLE = 0; if (MXC_DEC_MODE) // 数控方式 { if (!X_DRV) { MXC_DC_cMotorStep = 0; zipper_length_buff = dwXRealPos; } } else // 感应方式 { if (MXC_GouZhen_IN) { MXC_DC_cMotorStep = 24; AxisEgmStop(X_AXIS); } } if (dwTickCount >= MXC_DC_cMotorDelay) MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM); break; case 24: if (!X_DRV) { MXC_DC_cMotorStep = 0; } if (dwTickCount >= MXC_DC_cMotorDelay) MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM); break; //色标定寸 step 40-42 case 40: SetPos(X_AXIS, 0); MCX_SB_ENCODE_END=dwEnRealPos; SetEncodePos(ENCODE_X22X23, 0); if ((dwZipCnt == 0) || SingOneFlg) { AxisContinueMoveAcc(X_AXIS, 1000, MXC_DC_DIR_P, 1000, 1000, 10, 10); MXC_DC_cMotorStep = 41; } else { zipper_length=MXC_SET_ZIPPER_LENGTH+ (*revise_buff)-MXC_DC_PARAM_SEBIAO_DW_LENGTH; if(zipper_length>MXC_MXC_PARAM_DAILUN_LENGTH) { cmp=MXC_PARAM_LENGTH_CMP; cyclenum=zipper_length/MXC_MXC_PARAM_DAILUN_LENGTH; zipper_length=zipper_length+(zipper_length*cyclenum*cmp)/((cyclenum+1)*MXC_MXC_PARAM_DAILUN_LENGTH); } if(zipper_length>0) { AxisMovePosAccDecNotStop(X_AXIS,MXC_PARAM_SB_HIGH_SPEED,zipper_length, 1500,MXC_PARAM_SB_LOW_SPEED,100,100, PosToPulse(X_AXIS,MXC_PARAM_SEBIAO_LOWSPEED_LENGTH)); } else { MXC_SetAlarmCode(MXC_ZIPPER_SB_LENGTH_ALARM); } MXC_DC_cMotorStep = 41; } cSeBiaoOk = 0; cSeBiaoEn = 0; MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME; break; case 41://使能色标位置 if (dwZipCnt == 0) { cSeBiaoOk = 0; cSeBiaoEn = 1; MXC_DC_cMotorStep = 42; } else { if (dwXRealPos>=zipper_length-MXC_PARAM_SEBIAO_LOWSPEED_LENGTH) { if ((dwXRealPos+MXC_PARAM_SEBIAO_TQ_LENGTH) >= zipper_length+MXC_PARAM_First_CMP) { cSeBiaoOk = 0;//开启色标中断 cSeBiaoEn = 1;//色标中断使能 MXC_DC_cMotorStep = 42; MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME; } else if (dwXRealPos > (zipper_length + MXC_PARAM_SEBIAO_ERROR_LENGTH+MXC_PARAM_First_CMP)) { MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM); } } } break; case 42://色标定位 if(cSeBiaoOk && cSeBiaoEn) { cSeBiaoEn = 0; if (dwZipCnt == 0) { zipper_length= MXC_DC_PARAM_SEBIAO_DW_LENGTH-(MXC_SB_SaveLength-MXC_SB_ENCODE_MIN); AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SB_OFFSET_SPEED, MXC_DC_PARAM_SEBIAO_DW_LENGTH, 800, 800, 120, 100, 50); MXC_DC_cMotorStep = 44; MXC_Clear_Servo_Pos=1; } else { zipper_length= MXC_DC_PARAM_SEBIAO_DW_LENGTH-MXC_PARAM_First_CMP; AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SB_OFFSET_SPEED, zipper_length, 800, 800, 120, 100, 50); MXC_DC_cMotorStep = 44; MCX_XPOS_BUFF=dwXRealPos; DISPLAY_DATA0=dwXRealPos-MXC_SB_SaveLength; } } break; case 44://色标定位 if (dwZipCnt == 0&&!X_DRV) { MXC_DC_cMotorStep = 45; MXC_bSeBiao_Check=1;//第一条,屏幕弹出小窗口,人工确认色标定位位置 MXC_bSeBiao_CheckOK=0; MXC_bSeBiao_CheckStop=0; MXC_Clear_Servo_Pos=0; } else if(!X_DRV) { MXC_DC_cMotorStep = 0; } else if (dwTickCount >= MXC_DC_cMotorDelay) { MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM); } break; case 45: if(MXC_bSeBiao_CheckOK)//人工确认位置色标定位位置正确 { MXC_bSeBiao_CheckOK=0; MXC_DC_cMotorStep = 0; MXC_bSeBiao_Check=0; } if(MXC_bSeBiao_CheckStop)//位置不正确,停止 { MXC_bSeBiao_CheckStop=0; dwZipCnt = 0; MXC_DC_bAlarmStop = 1; MXC_DC_SingOneFlag = 0; MXC_DC_cAutoStep = 0; MXC_DC_bRunning = 0; MXC_bSeBiao_Check=0; } break; #if 0 //编码器定位 case 60: if(dwEnRealPos>(MXC_SET_ZIPPER_LENGTH+MXC_PARAM_DAOKOU_LENGTH) && MXC_CRUKONGWEILENGTH==0) { MXC_DC_cMotorStep = 64; MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH; MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME; } else { MXC_DC_cMotorStep = 61; MXC_DC_cMotorDelay = dwTickCount; SetPos(X_AXIS, 0); } break; case 61: if(dwTickCount >= MXC_DC_cMotorDelay) { SetPos(X_AXIS, 0); if(MXC_CRUKONGWEILENGTH==0) { zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - dwEnRealPos ;//- MXC_ENCODE_FENZHEN_Lenth/3;//-(MXC_ENCODE_FENZHEN_Lenth); // MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH; } else if(MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH>=MXC_PARAM_DAOKOU_LENGTH) { zipper_length=MXC_PARAM_DAOKOU_LENGTH; MXC_CRUKONGWEILENGTH+=zipper_length; } else { zipper_length=MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH; MXC_CRUKONGWEILENGTH+=zipper_length; } if(zipper_length<1400) { if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH) { AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SET_SPEED * 3 / 4 + 600, zipper_length, 1200, MXC_DC_PARAM_LOW_SPEED, MXC_DC_PARAM_SET_SPEED/300, MXC_DC_PARAM_SET_SPEED/300, PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH)); //1200 600 } else { AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length, 1200, MXC_DC_PARAM_LOW_SPEED, 50, 50, 0); //1200 600 } } else if(zipper_length<2400) { AxisMovePosAccDec(X_AXIS,MXC_DC_PARAM_SET_SPEED*7/8,zipper_length,1200,MXC_DC_PARAM_LOW_SPEED,MXC_DC_PARAM_SET_SPEED/300,MXC_DC_PARAM_SET_SPEED/300,PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH));//1200 600 } else { AxisMovePosAccDec(X_AXIS,MXC_DC_PARAM_SET_SPEED,zipper_length,1200,MXC_DC_PARAM_LOW_SPEED,MXC_DC_PARAM_SET_SPEED/300,MXC_DC_PARAM_SET_SPEED/300,PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH));//1200 600 } MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME; MXC_DC_cMotorStep = 62; } break; case 62: if(!X_DRV)//||(dwEnRealPos>=dwXRealPos)&&(dwXRealPos>=MXC_PARAM_DAOKOU_LENGTH)) { //AxisEgmStop(X_AXIS); MXC_DC_cMotorStep = 63; MXC_DC_cMotorDelay = dwTickCount+0; } else if(dwTickCount >= MXC_DC_cMotorDelay) MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM); break; case 63: if(dwTickCount >= MXC_DC_cMotorDelay) { // if(MXC_MOTOR_DATA_Num<=99)user_datas[420+MXC_MOTOR_DATA_Num] = dwEnRealPos; if(dwEnRealPos= MXC_DC_cMotorDelay) // MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM, MXC_ALARM_DC); break; case 65: if(dwXRealPos<=zipper_length-500)//剩余长度小于5CM { AxisMovePosAccDec(X_AXIS,1000,300,600,600,20,20,0); MXC_DC_cMotorStep = 66; } else { MXC_DC_cMotorStep = 62; } break; case 66: if(!X_DRV) { MXC_DC_cAutoStep=2; MXC_DC_cMotorStep=0; MXC_CRUKONGWEILENGTH=0; } break; #endif } } //下冲 void MXC_XiaChong(void) { switch(MXC_cXiaChongStep) { case 0: break; case 1: MXC_cXiaChongStep = 2; MXC_cRightFZStep = 1;//启动右分针 MXC_cLeftFZStep = 0; break; case 2: if((MXC_cRightFZStep == 0) && (MXC_cLeftFZStep == 0) && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN) { MXC_XC_ShaChe = 0;//打开刹车 if (MXC_DC_bRunning) { MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_DELAY_XC; } MXC_cXiaChongStep = 3; } break; case 3: if(dwTickCount >= MXC_cXiaChongDelay) { MXC_cXiaChongStep = 4; MXC_XiaChong_MOTOR = 1; if(MXC_DC_bRunning) MXC_GouZhen_VAVLE = 1; MXC_cXiaChongDelay = dwTickCount + MXC_XIACHONG_EEROR_TIME; } break; case 4: if(MXC_XiaChong_IN_UP) { SetEncodePos(ENCODE_X22X23, 0); // if(MXC_MOTOR_DATA_Num<=99)user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos; MXC_LeftFenZhen_VAVLE = 0; MXC_RightFenZhen_VAVLE = 0; MXC_cXiaChongStep = 5; MXC_cShaCheStep = 1; MXC_cXiaChongDelay = dwTickCount + MXC_XC_Stop_Delay; } else if(dwTickCount >= MXC_cXiaChongDelay)//感应异常 { MXC_SetAlarmCode(MXC_XC_ALARM); MXC_LeftFenZhen_VAVLE = 0; MXC_RightFenZhen_VAVLE = 0; MXC_cXiaChongStep = 0; MXC_XiaChong_MOTOR = 0; MXC_cShaCheStep = 1; } break; case 5: if(dwTickCount >= MXC_cXiaChongDelay) { // user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos; MXC_MOTOR_DATA_Num++; if(MXC_MOTOR_DATA_Num > 99) MXC_MOTOR_DATA_Num = 0; if(!MXC_DC_bRunning){ SetEncodePos(ENCODE_X22X23, 0); SetPos(X_AXIS, 0); } MXC_XiaChong_MOTOR = 0; MXC_cXiaChongStep = 0; } break; } } void MXC_DC_ShaChe(void) { //刹车 switch(MXC_cShaCheStep) { case 1: MXC_cShaCheStep = 2; MXC_cShaCheDelay = dwTickCount + MXC_PARAM_ShaChe_Delay; break; case 2: if(dwTickCount >= MXC_cShaCheDelay) { MXC_cShaCheStep = 3; MXC_cShaCheDelay = dwTickCount + MXC_PARAM_ShaChe_TIME; MXC_XC_ShaChe = 1; } break; case 3: if(dwTickCount >= MXC_cShaCheDelay) { MXC_XC_ShaChe = 0; MXC_cShaCheStep = 0; } break; } } void MXC_FenZhen(void) { switch (MXC_cRightFZStep) { case 0: break; case 1: MXC_cRightFZ_Delay = MXC_RightFZ_Delay + dwTickCount; MXC_cRightFZStep = 2; break; case 2: if (dwTickCount >= MXC_cRightFZ_Delay) { MXC_cRightFZStep = 3; MXC_RightFenZhen_VAVLE = 1; //右分针电磁阀 MXC_cRightFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME; } break; case 3: if (!MXC_RightFenZhen_Origin_IN) //右分针原点离开 { MXC_cRightFZ_Delay = dwTickCount + MXC_DC_RightFZ_AGAIN_TIME; MXC_cRightFZStep = 4; } //右分针不下去 else if (dwTickCount >= MXC_cRightFZ_Delay) { MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);//警告暂停 分针下冲步骤都清零 MXC_RightFenZhen_VAVLE = 0; } break; case 4: if (MXC_RighttFenZhen_IN) //插针到位 { MXC_ENcode_Cul = dwEnRealPos; MXC_cRFengTimer = 0; MXC_cRightFZStep = 0; MXC_cLeftFZStep = 1; //左分针延时启动 } else if (dwTickCount >= MXC_cRightFZ_Delay) { MXC_RightFenZhen_VAVLE = 0; //右分针 MXC_cRFengTimer++; //当右分针分不到位时,左分针也要重新分针 MXC_LeftFenZhen_VAVLE = 0; MXC_cRightFZStep = 0; if (MXC_cRFengTimer < 4)//times 次数 { MXC_cRightFZStep = 5; MXC_cRightFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME; } else { MXC_cRFengTimer = 0; MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM); MXC_cRightFZStep = 0; MXC_RightFenZhen_VAVLE = 0; } } break; //5-6重新下右分针 case 5: if (MXC_RightFenZhen_Origin_IN) //退到位 { MXC_cRightFZStep = 2; } else if (dwTickCount >= MXC_cRightFZ_Delay) { MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM); MXC_RightFenZhen_VAVLE = 0; } break; } //左分针 switch (MXC_cLeftFZStep) { case 0: break; case 1: MXC_cLeftFZ_Delay = MXC_LeftFZ_Delay + dwTickCount; MXC_cLeftFZStep = 2; break; case 2: if (dwTickCount >= MXC_cLeftFZ_Delay) { MXC_cLeftFZStep = 3; MXC_LeftFenZhen_VAVLE = 1; //左分针电磁阀 MXC_cLeftFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME; } break; case 3: //离开左分针原点 if (!MXC_LeftFenZhen_Origin_IN) //左分针原点离开 { MXC_cLeftFZ_Delay = dwTickCount + MXC_DC_LeftFZ_AGAIN_TIME; MXC_cLeftFZStep = 4; } //左分针不下去 else if (dwTickCount >= MXC_cLeftFZ_Delay) { MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM); MXC_LeftFenZhen_VAVLE = 0; } break; case 4: if (MXC_LeftFenZhen_IN) //左插针到位 { MXC_ENCODE_FENZHEN_Lenth = dwEnRealPos - MXC_ENcode_Cul; MXC_cLFengTimer = 0; MXC_cLeftFZStep = 0; } else if (dwTickCount >= MXC_cLeftFZ_Delay) { MXC_LeftFenZhen_VAVLE = 0; //左分针 MXC_cLFengTimer++; if (MXC_cLFengTimer < 6) { MXC_cLeftFZStep = 5; MXC_cLeftFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME; if ((MXC_cLFengTimer % 2) == 0) { MXC_RightFenZhen_VAVLE = 0; MXC_cRightFZStep = 0; } } else { MXC_cLFengTimer = 0; MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM); MXC_cLeftFZStep = 0; MXC_LeftFenZhen_VAVLE = 0; } } break; //5-6重新下左分针 case 5: if (MXC_LeftFenZhen_Origin_IN) //退到位 { MXC_cLeftFZStep = 6; } else if (dwTickCount >= MXC_cLeftFZ_Delay) { MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM); MXC_cLeftFZStep = 0; MXC_LeftFenZhen_VAVLE = 0; } break; case 6: if ((MXC_cLFengTimer % 2) == 0) //左边插两次都插不到,就退右边再同时插 { if(MXC_RightFenZhen_Origin_IN) { MXC_cRightFZStep = 1; MXC_cRFengTimer = 0; MXC_cLeftFZStep = 0; } } else { MXC_cLeftFZStep = 2; } break; } } #endif