#include "global.h" #if FU_JIAN_MACHINE //免修齿 //输入说明 //X000 启动 //X001 停止 //X002 手动下冲 //X003 勾针到位接近开关 //X004 减速信号 //X005 卡带、数量到 //X006 左分针退到位 //X007 左分针到位信号 //STOP_IN0 下冲原位 //STOP_IN1 右分针退到位 //STOP_IN2 右分针到位信号 // //STOP_IN3 左大微动(吹气信号) //STOP_IN4 有链检测(数控定寸时的光电开关,不用是请接电源的GND) //STOP_IN5 色标信号 //STOP_IN6 下止选择(有触摸屏时不用接) //STOP_IN7 发超声信号 //X020 分带信号 //X021 过链(固定勾针)接近开关 //X022 0普通勾针方式,1勾针固定方式 //输出说明 //输出说明 //Y000 离合器(离合器方式时才接线) //Y001 刹车 //Y002 吹气电磁阀 //Y003 下止电磁阀 //Y004 左分针电磁阀 //Y005 勾针/储带 //Y006 右分针电磁阀 //Y007 下冲电机/ //Y010 超声输出/ //Y011   计数(不用触摸屏用) //Y012   拖带电机(步进型不用接) //Y013 分带电磁阀 //Y014   储带 //Y015 固定勾针 //Y017 拖带步进松轴/伺服电机使能 //步进驱动 板 //PU+ PU+ //PU- PU- //MF+ 24V //MF- Y17 /* D[0] 下止电磁阀输出时间 D[1] 吹气时间 D[2] 超声时间 D[3] 延时刹车 D[4] 刹车时间 D[5] 延时停下冲电机   D[6] 起动速度 D[7] 加速度 D[8] 最高速度 D[9] 空位最低速度 D[10] 定位时间(慢速长度) D[11] 动作配置 {D11->0 0普通下止,1超声下止;D11->1 0刹车不释放,1释放, } D[12] 延时上勾针 D[13] 模具长度(刀口长度) D[14] 拖带轮长度 D[15] 拉链长度低位 D[16] 拉链长度高位 D[17] 修正长度低位 D[18] 修正长度高位 D[19] 勾针伺服选择 D[20] 下止选择{0 选择,1 不下止} D[21] 勾针定寸时的减速方式(0勾针减速信号,1长度自动减速同用) D[22] 产量设定低位 D[23] 产量设定高位 D[24] 勾针方式选择 D24 0普通勾针方式,1勾针固定方式 D[25] 固定勾针方式时感应信号(0, 空位时亮,空位时灭) D[26] 延时发超声 D[27] 下冲电机配置(0,普通电机,1 步进电机) D[28] 下冲电机的起动速度 D[29] 下冲电机的最高速度 D[30] 拖带电机配置(0 步进 1 伺服) D[31] 延时吹气 D[32] 勾针定寸方式第一条的最高速度 */ void MXC_NiLongXiuCiJiCheckStart(void); void CuiQi_Start(void); void ShaChe_Output(void); void Output_XiaCi(void); void Close_XiaCi(void); void NiLongXiuCiJi_Motor(void); void NiLongXiuCiJi_XiaC(void); void Start_FenZ(void); void NiLongXiuCiJi_FenZhengProc(void); void ChuiQiProc(void); void JiaoDao(void); void MXC_ManualAction(void); void MXC_AutoAction(void); unsigned char cLFengTimer,cRFengTimer,cGuZhangStop = 0; unsigned long cShaCheTime,cLaLianLine,cGouZhenTime; unsigned char cChuiQiStep = 0,cGouZhenResetOK; unsigned short cBudaiCheckDelay = 0; unsigned char bHandWork,bPulseTatol_EN,bFirst,cInt1_OK,cStopFlag,cOneTimes,cKey_Time,cHMI_Test; long cSetEncode,cTotal,cDinWeiTime,cAddSetPulseNum,cEncodePulse,cWorkPulseNum; void MXC_InitAction(void) { MXC_XC_SongZhou = 1; XIA_ZHI_ENABLE = 0; if(MOTOR_MODE == 0) MXC_TuoDaiSongZhou = 1; else MXC_TuoDaiSongZhou = 0; if(XIA_ZHI_ENABLE) MXC_XiaZhi_MOTOR = 1; else MXC_XiaZhi_MOTOR = 0; } void MXC_NiLongXiuCiJiAction(void) { MXC_NiLongXiuCiJiCheckStart(); //启动 NiLongXiuCiJi_FenZhengProc(); //左右分针 NiLongXiuCiJi_XiaC(); //下冲 NiLongXiuCiJi_Motor(); //拖带控制 JiaoDao(); MXC_ManualAction(); MXC_AutoAction(); /* if(cHMI_Test == 0) { if(user_datas[100] < 32) { if(user_datas[75] == 6) //输入 { user_datas[100] += 48; } else if(user_datas[75] == 7) //输出 user_datas[100] += 32; } } */ } void MXC_ManualAction(void) { long i; //清总产量 if(MXC_bClear) //清总产量 { MXC_bClear = 0; ClrcToTal(76); } //当长度改变时,生产总量自动清零 if(MXC_bChangeLength) { MXC_bChangeLength = 0; i = SET_ZIPPER_LENGTH; if(cLaLianLine != i) { cLaLianLine = i; SetZipperLength(17,0); ClrcToTal(76); } } //加10 if(MXC_bAddLength) { MXC_bAddLength = 0; i = SET_REVISE_ZIPPER_LENGTH; i += 10; SetZipperLength(17,i); } //减10 if(MXC_bDecLength) { MXC_bDecLength = 0; i = SET_REVISE_ZIPPER_LENGTH; i -= 10; SetZipperLength(17,i); } //工作方式选择(数控定寸和勾针定寸)  if(MXC_bSetDCMode) { MXC_bSetDCMode = 0; if(!bRunning) { DC_MODE++; if(DC_MODE > 2)DC_MODE = 0; if(DC_MODE != 0) { MXC_GouZhen_VAVLE = 1; XIA_ZHI_ENABLE = 0; MXC_XiaZhi_MOTOR = 0; } } } //勾针方式选择(活动勾针和固定勾针)  if(MXC_bChangeGouZhenMode) { MXC_bChangeGouZhenMode = 0; if(!bRunning) { GOU_ZHEN_MODE++; if(GOU_ZHEN_MODE > 1)GOU_ZHEN_MODE = 0; } } //下止工作选择)  if(MXC_bChangeXiaZhiMode) { MXC_bChangeXiaZhiMode = 0; if(!bRunning) { XIA_ZHI_ENABLE++; if(XIA_ZHI_ENABLE > 1)XIA_ZHI_ENABLE = 0; if(XIA_ZHI_ENABLE) MXC_XiaZhi_MOTOR = 1; else MXC_XiaZhi_MOTOR = 0; } } if(MXC_bJiaoDao) { cJiaoDaoStep = 1; MXC_bJiaoDao = 0; } //吹气 if((MXC_ChuiQi_VAVLE == 0)) { if(MXC_DingChuPian_IN_DW) { MXC_bChuiQi = 0; cChuiQiDelay = dwTickCount + 10*PARAM_DELAY_CHUIQI_TIME; cChuiQiStep = 1; } else if(MXC_bChuiQi == 1) { MXC_bChuiQi = 0; cChuiQiDelay = 0; cChuiQiStep = 1; } } ChuiQiProc(); if(MXC_ChuiQi_VAVLE && (dwTickCount >= cChuiQiDelay)) { MXC_ChuiQi_VAVLE = 1;// MXC_XiChiChuiQi = 1; cChuiQiDelay = dwTickCount + 10 * PARAM_CHUIQI_TIME; } if(MXC_XiChiChuiQi && (dwTickCount >= cChuiQiDelay)) { MXC_XiChiChuiQi = 0; } //刹车方式 if(ShaCheMode) { if(MXC_XC_SongZhou && (dwTickCount >= cShaCheTime) && (XiaCongMotorMode == 0)) MXC_XC_SongZhou = 0; } if((bRunning) == 0) ////手动 { if(DC_MODE != 0) //伺服定寸 { MXC_GuDingGouZhen = 1; MXC_GouZhen_VAVLE = 1; } else if((GouZMode == 0) )//普通勾针(活动)过链 { if(dwTickCount >= cGouZhenTime) MXC_GouZhen_VAVLE = 0; } else { if(XiaMode) //0普通下止,1超声下止 { if(MXC_GuoLian_IN_UP) { MXC_GuDingGouZhen = 0; } } else //刘铁方式(下拉一下就可以复位) { if(MXC_GuDingGouZhen && (dwTickCount >= cGouZhenTime)) MXC_GuDingGouZhen = 0; } } //下止动作 if(MXC_XiaZhi_IN_UP || MXC_bXiaZhi) { MXC_bXiaZhi = 0; if(MXC_XiaZhi_VAVLE) { MXC_XiaZhi_VAVLE = 0; MXC_ChaoSheng = 0; MXC_FenDai_VAVLE = 0; //分带输出 } else Output_XiaCi(); } else if(MXC_XiaZhi_IN_DW) { MXC_XiaZhi_VAVLE = 0; //下止电磁阀 MXC_ChaoSheng = 0; //超声输出 MXC_FenDai_VAVLE = 0; //分带输出 } Close_XiaCi(); if(MXC_bChuDai) { MXC_ChuDai_VAVLE = 1; } else { MXC_ChuDai_VAVLE = 0; } if((!STOP_IN) && (MXC_ManXiaChong_UP || (MXC_bXiaChong)) && (bHandWork == 0))//加模到位 2006.7.31 { MXC_bXiaChong = 0;//cMidleCoil[0] &= ~((1<<3)); cAutoStep = 1; MXC_XiaChong_MOTOR = 0; bHandWork = 1; } switch(cAutoStep) { case 1: //先启动分针 Start_FenZ(); cAutoStep = 2; break; case 2://左右分针都已完成 if((cLeftFenZhenStep == 0) && (cRightFenZhenStep == 0)) { cXiaChongStep = 1; //下冲电机启动 cAutoStep = 3; } break; case 3: //下冲已完成 if(cXiaChongStep == 0) { MXC_LeftFenZhen_VAVLE = 0; MXC_RightFenZhen_VAVLE = 0; cAutoStep = 4; cAutoDelay = dwTickCount + 50; } break; case 4: if(dwTickCount >= cAutoDelay) { cAutoStep = 5; } break; case 5: if((dwTickCount >= cGouZhenTime)) { bHandWork = 0; cAutoStep = 0; if(DC_MODE == 0) { MXC_GouZhen_VAVLE = 0; } } break; } if(bHandWork == 0) //在未手动下冲的情况下 { if(MXC_bLeftFenZhen) { MXC_LeftFenZhen_VAVLE = 1; } else MXC_LeftFenZhen_VAVLE = 0; if(MXC_bRightFenZhen) { MXC_RightFenZhen_VAVLE = 1; } else MXC_RightFenZhen_VAVLE = 0; if(MXC_bGouZhen) { MXC_bGouZhen = 0;//cMidleCoil[0] &= ~((1<<9)); cGouZhenTime = dwTickCount + (unsigned long)300; //勾针延时退 if((GouZMode == 0))//普通勾针(活动)过链 { if(MXC_GouZhen_VAVLE) MXC_GouZhen_VAVLE = 0; else { MXC_GouZhen_VAVLE = 1; } } else //固定勾针 { if(MXC_GuDingGouZhen) MXC_GuDingGouZhen = 0; else { MXC_GuDingGouZhen = 1; } } } //点动下冲 if((MXC_bDotXiaChong)) { MXC_bDotXiaChong = 0; if(MXC_LeftFenZhen_IN && MXC_RighttFenZhen_IN) { MXC_bDotXiaChongDisplay = 1; MXC_XiaChong_MOTOR = 1;//下冲电机 bPulseTatol_EN = 1; if(XiaCongMotorMode == 0) cAutoDelay = dwTickCount + 50; else { MXC_XC_SongZhou = 0; cAutoDelay = dwTickCount + 65; AxisContinueMove(X_AXIS,PARAM_LOW_SPEED,0); } } else { SetAlarmCode(100,MXC_XIA_CHONG_ALARM); //下冲条件不满足 // user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; } } if((!MXC_XiaChong_MOTOR) && (dwTickCount >= cAutoDelay) && (MXC_bDotXiaChongDisplay)) { MXC_XiaChong_MOTOR = 1; //下冲电机 } if((MXC_XiaChong_MOTOR) && (dwTickCount >= cAutoDelay) && (MXC_bDotXiaChongDisplay)) { bPulseTatol_EN = 0; AxisDecStop(X_AXIS); MXC_XiaChong_MOTOR = 0; //下冲电机 MXC_bDotXiaChongDisplay = 0; ShaChe_Output();// } } else { MXC_bLeftFenZhen = 0;MXC_bRightFenZhen = 0;MXC_bDotXiaChong = 0;MXC_bDotXiaChongDisplay = 0;MXC_bGouZhen = 0; } } } void MXC_AutoAction(void) { unsigned long i; if(!bRunning) { if(MXC_XiaZhi_IN || (!MXC_Zipper_IN)) MXC_ChuDai_VAVLE = 0; else MXC_ChuDai_VAVLE = 1; if((DC_MODE == 0) && (GouZMode == 0)) { if(MXC_GouZhen_IN_UP)cGouZhenTime = 1; } else cGouZhenTime = 1; switch(cAutoStep) { case 0: break; case 1: //左右分针要退到位,过链到位要离开 if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN && (dwTickCount >= cAutoDelay)) { cAutoStep = 2; cMotorStep = 1; //启动拖带 } break; case 2: //拖带已经完成 if(cMotorStep == 0) { bFirst = 1; //调试功能 if(DC_MODE != 2)cAutoStep = 3; // 调试功能 下一条 下冲 else if((!MXC_bDingWei) || MXC_bNext || MXC_ManXiaChong_UP || MXC_bXiaChong) { if(MXC_bNext) { cAutoStep = 1; MXC_bNext = 0; cInt1_OK = 0; } else { cAutoStep = 3; MXC_bDingWei = 0; } } cAutoDelay = dwTickCount + 5; //延时分针 } break; case 3: if((dwTickCount >= cAutoDelay) && cGouZhenTime) { cGouZhenTime = 0; cAutoStep = 4; Start_FenZ(); if(XiaCongMotorMode == 1) { MXC_XiaChong_MOTOR = 1; //下冲电机 } } break; case 4: //左右分针都已完成 if((cLeftFenZhenStep == 0) && (cRightFenZhenStep == 0)) { cXiaChongStep = 1; //下冲电机启动 cAutoStep = 5; AddToTal(76); //计数增加和保存 CalProSP(78); } break; case 5: //下冲已完成 if(cXiaChongStep == 0) { cAutoStep = 6; cAutoDelay = dwTickCount + (unsigned long)15; //延时检测退到位 } break; case 6: if(dwTickCount >= cAutoDelay) { if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN) { cAutoDelay = dwTickCount + (unsigned long)15; //延时检测退到位 cAutoStep = 7; i = SET_TOTAL; if(cTotal >= i) { cStopFlag = 1; SetAlarmCode(100,MXC_FEN_ZHEN_ALARM);//分针不成功 // user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; } } } break; case 7: if((dwTickCount >= cAutoDelay) && (MXC_Dec_IN || user_datas[21] || DC_MODE)) { if(cOneTimes == 0) { cAutoStep = 1; } else { cStopFlag = 1; } } break; case 8: if((dwTickCount >= cAutoDelay)) { if(DC_MODE == 0) { cAutoStep = 9; } else { if(cOneTimes == 0) { cAutoStep = 1; } else { cStopFlag = 1; } } } break; case 9: if((dwTickCount >= cGouZhenTime) && (MXC_Dec_IN == 1)) { MXC_GouZhen_VAVLE = 0; if(cOneTimes == 0) { cAutoStep = 1; } else { cStopFlag = 1; } } break; } } } // 检测是否踏了脚踏开关 void MXC_NiLongXiuCiJiCheckStart(void) { // 停止键 不能在工作,手动,停止过程中 if((!STOP_IN) && (bHandWork == 0) && (bRunning == 0) && (cStopFlag==0) // 启动 && (START_IN_UP || (MXC_bStart)) && (cKey_Time == 0) && (!MXC_GuoLian_IN)) { if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_KaDai_IN) { bRunning = 1; MXC_bClearAlarm = 1; cKey_Time = 10; cAutoStep = 1; cMotorStep = 0; cXiaChongStep = 0; cLeftFenZhenStep = 0; cRightFenZhenStep = 0; SetAlarmCode(100,MXC_NO_ALARM); cAutoDelay = dwTickCount + (unsigned long)200; //先锁轴 cOneTimes = 0; cGouZhenTime = 1; MXC_XiaChong_MOTOR = 0; // if(XiaCongMotorMode == 1) { MXC_XC_SongZhou = 0; } if(MOTOR_MODE == 0) MXC_TuoDaiSongZhou = 0; else MXC_TuoDaiSongZhou = 1; if(MXC_bDingWei)cSetEncode = 0; bFirst = 0; } else { // user_datas[75] = 5; //页面跳转 if(MXC_KaDai_IN) SetAlarmCode(100,MXC_KA_DAI_ALARM); //卡带 else SetAlarmCode(100,MXC_START_ALARM); //起动条件不满足 } MXC_bStart = 0; } //卡带感应 if(MXC_KaDai_IN && (dwTickCount >= cKaDaiDelay)) { SetAlarmCode(100,MXC_KA_DAI_ALARM); //警告清 // user_datas[75] = 5; //页面跳转 cKaDaiDelay = dwTickCount + 2200; } if(MXC_KaDai_IN_UP) { MXC_bSaveWorkData = 1; } //停止 if((STOP_IN_UP || (MXC_bStop))) { // 不是下冲状态 if((cXiaChongStep == 0) && (bRunning == 0)) { CuiQi_Start(); if(!MXC_XiaChong_MOTOR)MXC_XC_SongZhou = 1; } if((cStopFlag == 0) && (cKey_Time == 0)) { cKey_Time = 4; if(((DC_MODE == 0) || STOP_IN_UP) && ((XiaCongMotorMode == 0) || (cXiaChongStep == 0))) { AxisDecStop(X_AXIS); } MXC_GuDingGouZhen = 0; CuiQi_Start(); if(X_DRV && !MXC_XiaChong_MOTOR && (DC_MODE == 1)) { cGuZhangStop = 1; } if((++cOneTimes >= 2) || !bRunning || !X_DRV) { cStopFlag = 1; SetAlarmCode(100,MXC_NO_ALARM); // user_datas[75] = 50; if(!X_DRV) { if(MOTOR_MODE == 0) MXC_TuoDaiSongZhou = 1; else MXC_TuoDaiSongZhou = 0; } } cKaDaiDelay = dwTickCount + 1200; cGouZhenTime = dwTickCount + (unsigned long)300; //勾针延时退 } MXC_bStop = 0; MXC_bSaveWorkData = 1; } if((cXiaChongStep == 0) && (((cStopFlag) != 0) || (MXC_KaDai_IN))) { bRunning = 0; bHandWork = 0; cStopFlag = 0; cAutoStep = 0; cMotorStep = 0; cXiaChongStep = 0; cLeftFenZhenStep = 0; cRightFenZhenStep = 0; MXC_XC_SongZhou = 0; MXC_XiaZhi_VAVLE = 0; MXC_LeftFenZhen_VAVLE = 0; MXC_RightFenZhen_VAVLE = 0; MXC_XiaChong_MOTOR = 0; MXC_ChaoSheng = 0; MXC_JiaoDao_OUT = 0; MXC_FenDai_VAVLE = 0; MXC_ChuDai_VAVLE = 0; MXC_GuDingGouZhen = 0; if(!X_DRV) { if(MOTOR_MODE == 0) MXC_TuoDaiSongZhou = 1; else MXC_TuoDaiSongZhou = 0; } if(MXC_KaDai_IN_UP)CuiQi_Start(); MXC_XC_SongZhou = 1; // 刹车 if(GouZMode != 0) //超声(固定)勾针 MXC_GuDingGouZhen = 1; if(DC_MODE != 0) { if(X_DRV)cGuZhangStop = 1; } else AxisDecStop(X_AXIS); cGouZhenTime = dwTickCount + (unsigned long)300; //勾针延时退 } } void JiaoDao(void) { if(cJiaoDaoStep == 1) { cChuiQiDelay = dwTickCount + 500; MXC_JiaoDao_OUT = 1; cJiaoDaoStep = 2; } else if((cJiaoDaoStep == 2) && (dwTickCount >= cChuiQiDelay)) { MXC_JiaoDao_OUT = 0; cJiaoDaoStep = 0; } } void CuiQi_Start(void) { //启动吹气 cChuiQiDelay = dwTickCount + (unsigned long)50 * PARAM_CHUIQI_TIME; MXC_ChuiQi_VAVLE = 1; MXC_XiChiChuiQi = 0; } void ChuiQiProc(void) { if(cChuiQiStep == 0) { } else if((cChuiQiStep == 1) && (dwTickCount >= cChuiQiDelay)) { CuiQi_Start(); cChuiQiStep = 0; } } void ShaChe_Output(void) { //启动吹气 cShaCheTime = dwTickCount + (unsigned long)120; if(XiaCongMotorMode == 0)MXC_XC_SongZhou = 1; } void Output_XiaCi(void)//下止输出 { if(MXC_XiaZhi_IN || (XIA_ZHI_ENABLE && cHMI_Test)) //下止选择 { //下止输出 cXiaZhiDelay = dwTickCount + 10 * PARAM_XIAZHI_TIME; MXC_XiaZhi_VAVLE = 1; } } //关下止动作 void Close_XiaCi(void) { if((XiaMode != 0))//普通下止 { if(MXC_GuoLian_IN_UP|| MXC_FenDai_IN_UP) MXC_FenDai_VAVLE = 1; if(bRunning) { if(MXC_GuoLian_IN_UP && MXC_XiaZhi_VAVLE) { cXiaZhiDelay = dwTickCount + 10 * PARAM_XIAZHI_DELAY_TIME; } if(MXC_GuoLian_IN && MXC_XiaZhi_VAVLE) { if(!MXC_ChaoSheng && (dwTickCount >= cXiaZhiDelay)) { MXC_ChaoSheng = 1; cXiaZhiDelay = dwTickCount + (unsigned long)10 * PARAM_CHAOSHENG_TIME; } if(MXC_ChaoSheng && (dwTickCount >= cXiaZhiDelay)) { MXC_FenDai_VAVLE = 0; //分带输出 MXC_ChaoSheng = 0; //超声输出 MXC_XiaZhi_VAVLE = 0; //下止阀 } } } } else { //下止下冲电磁铁 if((MXC_XiaZhi_VAVLE != 0) && (dwTickCount >= cXiaZhiDelay)) { MXC_XiaZhi_VAVLE = 0; } } } unsigned long LengthCallPulse(unsigned long length) { return (length * 2000 / PARAM_DAILUN_LENGTH); } void NiLongXiuCiJi_Motor(void) { unsigned long ch; switch(cMotorStep) { case 0: return; break; // 过链 左分针退位 左到位 case 1: if(MXC_LeftFenZhen_Origin_IN && (!MXC_LeftFenZhen_IN) && MXC_RightFenZhen_Origin_IN && (!MXC_RighttFenZhen_IN)) { cAutoDelay = dwTickCount + (unsigned long)35; //延时检测 MXC_LIHE_VAVLE = 1; //离合器 //计算长度脉冲 // 拉链长度 ch = SET_ZIPPER_LENGTH; if(DC_MODE != 2) { ch += SET_REVISE_ZIPPER_LENGTH; ch += PARAM_DAOKOU_LENGTH;//模具长度(刀口长度) } cSetEncode = LengthCallPulse(ch); //慢速长度 ch = LengthCallPulse(PARAM_LOWSPEED_LENGTH); //色标的定位长度 cDinWeiTime = LengthCallPulse(PARAM_SEBIAO_DW_LENGTH); //色标提前检测距离 cAddSetPulseNum = LengthCallPulse(PARAM_SEBIAO_TQ_LENGTH); cEncodePulse = 0; cInt1_OK = 0; if(DC_MODE == 0) { if((GouZMode == 0))//普通勾针(活动)过链 { cMotorStep = 2; if(bFirst == 0) AxisMoveTwoPos(X_AXIS,PARAM_FIRST_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0); else AxisMoveTwoPos(X_AXIS,PARAM_SET_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0); } else //带下止型勾针 { cMotorStep = 11; if(bFirst == 0) AxisMoveTwoPos(X_AXIS,PARAM_FIRST_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0); else AxisMoveTwoPos(X_AXIS,PARAM_SET_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0); cAutoDelay = dwTickCount + (unsigned long)70; //延时检测 } cGuZhangStop = 0; cWorkPulseNum = 0; if(!MXC_GouZhen_VAVLE) { cMotorStep = 3; } } else if(DC_MODE == 1) { cMotorStep = 20; MXC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀 MXC_GuDingGouZhen = 1; //定位(活动勾针)电磁阀 cAutoDelay = dwTickCount + 130; //要检测对射 if(cWorkPulseNum >= cSetEncode)cMotorStep = 0; else { AxisMovePos(X_AXIS,PARAM_SET_SPEED,cSetEncode); } } else { if(cWorkPulseNum >= cSetEncode)cMotorStep = 0; else { AxisMoveTwoPos(X_AXIS,PARAM_SET_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0); } } } break; // step2-5 活动勾针定寸 case 2:if((dwTickCount >= cAutoDelay)) { MXC_GouZhen_VAVLE = 0;//定位电磁阀 } if(!MXC_GouZhen_VAVLE && !MXC_GouZhen_IN) { if(!PWM_RUN_STATE) TuoDaiStartPWM(cStepNum); cStepMode = 1; //加速模式 cMotorStep = 3; cAutoDelay = dwTickCount + (unsigned long)10000; } break; case 3: if(cStepNum > (cLowSpeadLimit + 1)) { cAutoDelay = dwTickCount + (unsigned long)10000; } //减速信号方式 数控减速方式 if(((IN04 != 0) && (user_datas[21] == 0)) || ((cPulseStepDEC >= cPulseCount) && (user_datas[21] == 1))) { user_datas[126] = cPulseCount; cSPDec = 3; cStepNum = cLowSpeadLimit+1; cPulseCount = cPulseStepDEC; cStepMode = 2; //减速模式 cMotorStep = 4; cAutoDelay = dwTickCount + (unsigned long)10000; } if((MXC_GouZhen_IN)) //X003 到位信号也要停 { cStepMode = 2; //减速模式 cMotorStep = 4; CLRQ00; //离合器断开 StopPWM(); //PWMTCR = 0x02; //在设置之前,先将定时器复位 } else if((dwTickCount >= cAutoDelay) && (cStepNum <= cLowSpeadLimit)) { cStopFlag = 1; user_datas[100] = 7; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; } break; case 4: if(MXC_GouZhen_IN) { cMotorStep = 0; StopPWM();//PWMTCR = 0x02; //在设置之前,先将定时器复位 } else if((dwTickCount >= cAutoDelay)) { cStopFlag = 1; user_datas[100] = 7; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; } /* //布带对射检测 if(X14) { cBudaiCheckDelay = dwTickCount + 30000; } else if(dwTickCount >= cBudaiCheckDelay) //没布带了 { cStopFlag = 1; user_datas[100] = 7; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_GouZhen_VAVLE = 0; MXC_bSaveWorkData = 1; } */ break; //以下为固定勾针方式 case 11: if(XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针 { if(dwTickCount >= cAutoDelay)MXC_GuDingGouZhen = 0; if(!X21) { cSPDec =1; //减速度 cStepMode = 2; //减速模式 cMotorStep = 12; cAutoDelay = dwTickCount + (unsigned long)1500; //延时检测 } } else { bFlag = X21; if(GuoLianCheckMode) bFlag = ~bFlag; if(bFlag) { cStepMode = 2; //减速模式 cMotorStep = 12; cAutoDelay = dwTickCount + (unsigned long)user_datas[12]; //延时检测 } } break; case 12: if(dwTickCount >= cAutoDelay) { if(Y15) { MXC_GuDingGouZhen = 0; cAutoDelay = dwTickCount + (unsigned long)1500; //延时检测 } else if(!Y15) { cStopFlag = 1; user_datas[100] = 7; //没链停机 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; } } if(XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针 { if(!IN21) { MXC_GuDingGouZhen = 0; cMotorStep = 13; cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机 } } else { if(GuoLianCheckMode) bFlag = X21_UP; else bFlag = X21_DW; if(bFlag) { MXC_GuDingGouZhen = 0; cMotorStep = 13; cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机 } } break; case 13: if((dwTickCount >= cAutoDelay)) { if(XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针 { StopPWM(); if(X21) { cMotorStep = 0; CLRQ00; } } else { if(GuoLianCheckMode) bFlag = !X21; else bFlag = X21; if(!bFlag) { cMotorStep = 0; StopPWM(); CLRQ00; } } } if(MXC_Zipper_IN) { cBudaiCheckDelay = dwTickCount + 30000; } else if(dwTickCount >= cBudaiCheckDelay) //没布带了 { cStopFlag = 1; SetAlarmCode(100,MXC_NO_ZIPPER_ALARM); //没拉链 // user_datas[75] = 5; //页面跳转 MXC_GouZhen_VAVLE = 0; MXC_bSaveWorkData = 1; } break; //伺服定寸 case 20: if(!X_DRV)cMotorStep = 0; //布带对射检测 if(MXC_Zipper_IN) { cAutoDelay = dwTickCount + 140; } else if(dwTickCount >= cAutoDelay) //没布带了 { cStopFlag = 1; SetAlarmCode(100,MXC_NO_ZIPPER_ALARM); //没拉链 // user_datas[75] = 5; //页面跳转 MXC_GouZhen_VAVLE = 0; MXC_bSaveWorkData = 1; } break; case 50: cStopFlag = 1; SetAlarmCode(100,MXC_NO_SEBIAO_ALARM); // // user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; } } //下冲 void NiLongXiuCiJi_XiaC(void) { if(bRunning) Close_XiaCi(); switch(cXiaChongStep) { case 0: return; break; case 1: cXiaChongStep = 2; MXC_XC_SongZhou = 0;//cMidleCoil[2] &= ~Q01;//CLRY001; //刹车打开 cDelayTime4 = dwTickCount + (unsigned long)7; //刹车放开时间 //下止输出 if(bRunning) Output_XiaCi(); break; case 2: if(dwTickCount >= cDelayTime4) { bPulseTatol_EN = 1; cXiaChongStep = 3; MXC_XiaChong_MOTOR = 1;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机 cDelayTime4 = dwTickCount + (unsigned long)ERRORTIME; //下冲最长时间 cPulseCount = 0; cGuZhangStop = 0; if(XiaCongMotorMode == 1) { cStepMode = 4; //计脉冲模式 cPulseCount = 2020; cSPDec = 3; cPulseStepCount = 0; cStepSet = user_datas[29]; cPulseStepDEC = cStepSet * cSPDec + 250; cSPAdd = 12;//user_datas[30]; cStepNum = user_datas[28]; cLowSpeadLimit = cStepNum + 3; StartPWM(cStepNum); MXC_ChuiQi_VAVLE = 1; } } break; case 3: //碰到右大微动,延时停 if((X10_UP)) { cDelayTime4 = dwTickCount + (unsigned long)user_datas[5];//cSetPara[5]; cXiaChongStep = 4; MXC_LeftFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q04;//CLRY004; //退左分针 MXC_RightFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q06;//CLRY006; //退右分针 cStepMode = 2; //减速模式 cGouZhenTime = dwTickCount + (unsigned long)150; //勾针延时退 MXC_GouZhen_VAVLE = 1; MXC_GuDingGouZhen = 1; } else if(dwTickCount >= cDelayTime4) //自动停机 { bPulseTatol_EN = 0; StopPWM(); cXiaChongStep = 0; cStopFlag = 1; ShaChe_Output();//MXC_XC_SongZhou = 1;//cMidleCoil[2] |= Q01;//SETY001; //刹车 MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] &= ~Q00;//CLRY000; //下冲电机 user_datas[100] = 5; //下冲异常 user_datas[75] = 5; //页面跳转 MXC_LeftFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q04;//CLRY004; //退左分针 MXC_RightFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q06;//CLRY006; //退右分针 MXC_bSaveWorkData = 1; } // if(X14_DW) // { // } break; case 4: // if(cStepNum <= cLowSpeadLimit) // StopPWM(); if(dwTickCount >= cDelayTime4) { cXiaChongStep = 5; bPulseTatol_EN = 0; cWorkPulseNum = 0; StopPWM(); MXC_XiaChong_MOTOR = 0; //延时刹车 cDelayTime4 = dwTickCount + (unsigned long)user_datas[3];//cSetPara[3]; } break; case 5: if((dwTickCount >= cDelayTime4)) { cXiaChongStep = 6; ShaChe_Output();//MXC_XC_SongZhou = 1;//cMidleCoil[2] |= Q01;//SETY001; cDelayTime4 = dwTickCount + (unsigned long)30; } break; case 6: if(!X17 && !MXC_XiaZhi_VAVLE && !MXC_ChaoSheng && (dwTickCount >= cDelayTime4)) { cXiaChongStep = 0; } break; } } //启动分针 void Start_FenZ(void) { cDelayTime5 = dwTickCount + 30; cLeftFenZhenStep = 1; cRightFenZhenStep = 0; cRFengTimer = 0; cLFengTimer = 0; } #define FenZhengErrorTime 5000 //分针 void NiLongXiuCiJi_FenZhengProc(void) { if(FenZSelect != 0) { cLeftFenZhenStep = 0; cRightFenZhenStep = 0; } //右分针 switch(cLeftFenZhenStep) { case 0: break; case 1: if(dwTickCount >= cDelayTime5) { cLeftFenZhenStep = 2; MXC_RightFenZhen_VAVLE = 1;//cMidleCoil[2] |= Q06;//SETY006; //右分针电磁阀 cDelayTime5 = dwTickCount + (unsigned long)FenZhengErrorTime; } break; case 2: //碰到右大微动,延时停 if(!MXC_RightFenZhen_Origin_IN) //右分针原点离开 { cDelayTime5 = dwTickCount + 500; cLeftFenZhenStep = 3; // cRightFenZhenStep = 1; //左分针延时启动 cDelayTime6 = dwTickCount + (unsigned long)20; }//右分针不下去 else if(dwTickCount >= cDelayTime5) { cStopFlag = 1; user_datas[100] = 4; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; if(XiaCongMotorMode == 1) { MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机 } } break; case 3: if(MXC_RighttFenZhen_IN) //插针到位 { cLeftFenZhenStep = 0; cRightFenZhenStep = 1; //左分针延时启动 } else if(dwTickCount >= cDelayTime5) { MXC_RightFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q06;//CLRY006; //右分针 cRFengTimer++; //当右分针分不到位时,左分针也要重新分针 MXC_LeftFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q04;//CLRY004; cRightFenZhenStep = 0; if(cRFengTimer < 4) { cLeftFenZhenStep = 4; cDelayTime5 = dwTickCount + FenZhengErrorTime; } else { cStopFlag = 1; user_datas[100] = 4; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; if(XiaCongMotorMode == 1) { MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机 } } } break; case 4: if(MXC_RightFenZhen_Origin_IN) //退到位 { cLeftFenZhenStep = 5; cDelayTime5 = dwTickCount + 150; } else if(dwTickCount >= cDelayTime5) { cStopFlag = 1; user_datas[100] = 4; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; if(XiaCongMotorMode == 1) { MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机 } } break; case 5: if(dwTickCount >= cDelayTime5) { cDelayTime5 = dwTickCount + 30; cLeftFenZhenStep = 1; } break; } //左分针 switch(cRightFenZhenStep) { case 0: break; case 1: if(dwTickCount >= cDelayTime6) { cRightFenZhenStep = 2; MXC_LeftFenZhen_VAVLE = 1;//cMidleCoil[2] |= Q04;//SETY004; //左分针电磁阀 cDelayTime6 = dwTickCount + (unsigned long)FenZhengErrorTime; } break; case 2: //碰到右大微动,延时停 if(!MXC_LeftFenZhen_Origin_IN) //右分针原点离开 { cDelayTime6 = dwTickCount + 500; cRightFenZhenStep = 3; }//左分针不下去 else if(dwTickCount >= cDelayTime6) { cStopFlag = 1; user_datas[100] = 4; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; if(XiaCongMotorMode == 1) { MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机 } } break; case 3: if(MXC_LeftFenZhen_IN) //插针到位 cRightFenZhenStep = 0; else if(dwTickCount >= cDelayTime6) { MXC_LeftFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q04;//CLRY004; //左分针 cLFengTimer++; if(cLFengTimer < 6) { cRightFenZhenStep = 4; cDelayTime6 = dwTickCount + FenZhengErrorTime; if((cLFengTimer%2) == 0) { MXC_RightFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q06;//CLRY006; cLeftFenZhenStep = 0; } } else { if(XiaCongMotorMode == 1) { MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机 } cStopFlag = 1; user_datas[100] = 4; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; } } break; case 4: if(MXC_LeftFenZhen_Origin_IN) //退到位 { cRightFenZhenStep = 5; cDelayTime6 = dwTickCount + 150; } else if(dwTickCount >= cDelayTime6) { cStopFlag = 1; user_datas[100] = 4; //分针不成功 user_datas[75] = 5; //页面跳转 MXC_bSaveWorkData = 1; if(XiaCongMotorMode == 1) { MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机 } } break; case 5: if(dwTickCount >= 36) { cDelayTime6 = dwTickCount + 30; if((cLFengTimer%2) == 0) //左边插两次都插不到,就退右边再同时插 { cDelayTime5 = dwTickCount + 30; cLeftFenZhenStep = 1; cRFengTimer = 0; cRightFenZhenStep = 0; } else { cRightFenZhenStep = 1; } } break; } } #endif