12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208 |
- #include "global.h"
- #if XI_DONG_MACHINE
- void MXC_NiLongCheckStart(void);
- void MXC_NiLongMotor(void);
- void MXC_NiLongXiaChong(void);
- void MXC_NiLongFenZhen(void);
- void MXC_NiLongChuiQi(void);
- void MXC_ManualAction(void);
- void MXC_AutoAction(void);
- unsigned char MXC_CheckPos(void);
- unsigned char cLFengTimer,cRFengTimer;
- unsigned long cShaCheTime,cLaLianLine,cGouZhenTime;
- unsigned char cChuiQiStep = 0,cGouZhenResetOK;
- unsigned short cBudaiCheckDelay = 0;
- unsigned char bHandWork,bPulseTatol_EN,bFirst,cInt1_OK,cStopFlag,cOneTimes;
- long cSetEncode,cTotal,cDinWeiTime,cAddSetPulseNum,cEncodePulse,cWorkPulseNum;
- unsigned long cZipperLength[2];
- unsigned char cCheckLengthOk=0,cDaoJu_Flag=0;
- unsigned char STOP_IN_FLAG,STOP_IN_FLAG_OLD,STOP_FILTER;
- unsigned char MXC_SingOneFlag = 0;
- unsigned char MXC_KD_Flag = 0,KD_GO_ON_FLAG = 0,cAlarmStopFlg = 0;
- long MXC_KD_pos = 0,save_pos_buff = 0;
- long MXC_dwEncPos = 0;
- unsigned long MXC_SaveLength = 0;
- //故障报警
- void MXC_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(MXC_ALARM_ADDR,alarm_code);
- MXC_bAlarmStop = 1;
- cAlarmStopFlg = 1;
- }
- //高速输入X20外部色标信号中断
- void MXC_ExtiActionX20(void)
- {
- if(cSeBiaoEn && !cSeBiaoOk)
- {
- cSeBiaoOk = 1;
- cSeBiaoEn = 0;
- if(X_DRV)SetRemainLength(X_AXIS, MXC_PARAM_SEBIAO_DW_LENGTH,MXC_PARAM_SB_OFFSET_SPEED);
- }
- }
- void MXC_InitAction(void)
- {
- float length_buff,pulse_buff;
-
- CalFreqTab_X_Free(25);
- length_buff = MXC_PARAM_DAILUN_LENGTH;
- pulse_buff = MXC_PARAM_CYCLE_PULSE;
- XGearRatio = pulse_buff/length_buff;
-
- length_buff = MXC_BM_LENGTH;
- pulse_buff = 1000;
- BMGearRatio = pulse_buff/length_buff;
-
- MXC_XCSZ_OUT = MXC_XC_SERVER_DISEN;
-
- STOP_IN_FLAG = STOP_IN;
- STOP_IN_FLAG_OLD = STOP_IN_FLAG;
- MXC_SaveLength = 0;
- }
- void MXC_NiLongXiuCiJiAction(void)
- {
- MXC_NiLongCheckStart(); //启动
- MXC_NiLongFenZhen(); //左右分针
- MXC_NiLongXiaChong(); //下冲
- MXC_NiLongChuiQi();
- MXC_NiLongMotor(); //拖带控制
- MXC_ManualAction();
- MXC_AutoAction();
- }
- void MXC_ManualAction(void)
- {
- long i;
- short *len_buff;
- //清总产量
- if(MXC_bClear) //清总产量
- {
- MXC_bClear = 0;
- ClrcToTal(MXC_TOTAL_ADDR);
- MXC_bSaveWorkData = 1;
- }
- //当长度改变时,生产总量自动清零
- if(MXC_bChangeLength)
- {
- MXC_bChangeLength = 0;
- MXC_SaveLength = 0;
- MXC_bClear = 1;
- }
- //加10
- if(MXC_bAddLength)
- {
- MXC_bAddLength = 0;
- i = MXC_SET_REVISE_ZIPPER_LENGTH;
- i += 10;
- SetData32bits(MXC_ZIPPER_LENGTH_ADDR,i);
- }
- //减10
- if(MXC_bDecLength)
- {
- MXC_bDecLength = 0;
- i = MXC_SET_REVISE_ZIPPER_LENGTH;
- i -= 10;
- SetData32bits(MXC_ZIPPER_LENGTH_ADDR,i);
- }
- //工作方式选择(数控定寸和勾针定寸)
- if(MXC_bSetDCMode)
- {
- MXC_bSetDCMode = 0;
- MXC_SaveLength = 0;
- if(MXC_DC_MODE != 0)
- {
- MXC_GouZhen_VAVLE = 1;
- MXC_cGouZhenTime = 300;
- MXC_XiaZhi_MOTOR = 0;
- }
-
- if(MXC_DC_MODE == MXC_DC_SF_MODE)
- {
- MV_Set_Command_Pos_CPU(X_AXIS,0);
- }
- }
- if(MXC_bSetLength)
- {
- MXC_bSetLength = 0;
- if(MXC_PARAM_INCH_MODE)
- {
- SetData32bits(15,CalLengthCM(MXC_SET_ZIPPER_LENGTH_INCH));
- len_buff = &MXC_SET_REVISE_ZIPPER_LENGTH_INCH;
- MXC_SET_REVISE_ZIPPER_LENGTH = CalLengthCM2(*len_buff);
- }
- else
- {
- SetData32bits(18,CalInch(MXC_SET_ZIPPER_LENGTH));
- len_buff = &MXC_SET_REVISE_ZIPPER_LENGTH;
- MXC_SET_REVISE_ZIPPER_LENGTH_INCH = CalInch2(*len_buff);
- }
- MXC_SaveLength = 0;
- }
-
- if((MXC_bRunning) == 0) ////手动
- {
- if(MXC_bXiaChong)
- {
- MXC_bXiaChong = 0;
- MXC_SaveLength = 0;
- if(MXC_cXiaChongStep == 0)MXC_cXiaChongStep = 1;
- }
-
- if(MXC_bLeftFenZhen)
- {
- MXC_bLeftFenZhen = 0;
-
- if(MXC_cXiaChongStep == 0) MXC_LeftFenZhen_VAVLE = ~MXC_LeftFenZhen_VAVLE;
-
- }
-
- if(MXC_bRightFenZhen)
- {
- MXC_bRightFenZhen = 0;
- if(MXC_cXiaChongStep == 0)MXC_RightFenZhen_VAVLE= ~MXC_RightFenZhen_VAVLE;
- }
-
- //点动下冲
- if((MXC_bDotXiaChong))
- {
- MXC_bDotXiaChong = 0;
- if(MXC_LeftFenZhen_IN && MXC_RighttFenZhen_IN)
- {
- if(MXC_cXiaChongStep == 0)MXC_cXiaChongStep = 20;
- }
- else
- {
- MXC_SetAlarmCode(MXC_XIA_CHONG_ALARM); //下冲条件不满足
- }
- }
-
- if(MXC_bGouZhen)
- {
- MXC_bGouZhen = 0;
- MXC_cGouZhenTime = dwTickCount + 300;
- MXC_GouZhen_VAVLE = ~MXC_GouZhen_VAVLE;
- }
-
- if(MXC_DC_MODE != 0) //伺服定寸
- {
- MXC_GouZhen_VAVLE = 1;
- }
- else
- {
- if(dwTickCount >= MXC_cGouZhenTime) MXC_GouZhen_VAVLE = 0;
- }
-
- if(MXC_bTestMotor)
- {
- if(!MXC_LeftFenZhen_Origin_IN)
- MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
- else if(!MXC_RightFenZhen_Origin_IN)
- MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
- else if(MXC_LeftFenZhen_IN)
- MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
- else if(MXC_RighttFenZhen_IN)
- MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
- else
- {
- if(!X_DRV && MXC_CheckPos())MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P, 10,1,5,5);
- }
- }
- else
- {
- if(X_DRV)AxisDecStop(X_AXIS);
- }
-
- }
-
-
- }
- void MXC_AutoAction(void)
- {
- DISPLAY_DATA0 = MXC_cAutoStep;
- DISPLAY_DATA1 = MXC_cMotorStep;
- DISPLAY_DATA2 = MXC_SaveLength;
- DISPLAY_DATA3 = MXC_cRightFenZhenStep;
- DISPLAY_DATA4 = MXC_cXiaChongStep;
- DISPLAY_DATA5 = dwRealPos;
- DISPLAY_DATA6 = MXC_dwEncPos;
-
- if(MXC_XZ_ENABLE)MXC_XiaZhi_MOTOR = 1;
- else MXC_XiaZhi_MOTOR = 0;
-
- if(dwTickCount >= MXC_cXiaZhiDelay)MXC_XiaZhi_VAVLE = 0;
-
- if(MXC_bRunning)
- {
- switch(MXC_cAutoStep)
- {
- case 0:
- break;
- case 1:
- if(dwTickCount >= MXC_cAutoDelay)
- {
- MXC_cAutoDelay = dwTickCount + MXC_ERRORTIME;
- MXC_cAutoStep = 2;
- }
- break;
- case 2:
- if(!MXC_GouZhen_IN)
- {
- MXC_cAutoStep = 3;
- switch(MXC_DC_MODE)
- {
- case MXC_DC_SF_MODE:MXC_cMotorStep = 20; break; //伺服
- case MXC_DC_SB_MODE:MXC_cMotorStep = 40; break; //色标
- case MXC_DC_BMQ_MODE:MXC_cMotorStep = 60; break; //编码器
- default:MXC_cMotorStep = 1; //启动拖带 ;//勾针
- }
- }
- else if(dwTickCount >= MXC_cAutoDelay)
- MXC_SetAlarmCode(MXC_NO_GOUZHEN_ALARM);
- break;
- case 3:
- //拖带已经完成
- if(MXC_cMotorStep == 0)
- {
- if(SingOneFlg)
- {
- dwZipCnt = 0;
- SingOneFlg = 0;
- MXC_cAutoStep = 0;
- MXC_bRunning = 0;
- }
- else
- {
- MXC_cAutoStep = 4;
- }
- }
- break;
- case 4:
- MXC_cAutoStep = 5;
- break;
- case 5:
- //左右分针都已完成
- if((MXC_cLeftFenZhenStep == 0) && (MXC_cRightFenZhenStep == 0))
- {
- MXC_cXiaChongStep = 1; //下冲电机启动
- MXC_cAutoStep = 6;
- }
- break;
- case 6: //下冲已完成
- if((MXC_cXiaChongStep == 0) || (MXC_cXiaChongStep == 5))
- {
- switch(MXC_DC_MODE)
- {
- case MXC_DC_SF_MODE:
- {
- MXC_SaveLength += MXC_PARAM_DAOKOU_LENGTH;
- if(MXC_SaveLength >= MXC_PARAM_KONG_WEI_LENGTH)
- {
- dwZipCnt++;
- MV_Set_Command_Pos_CPU(X_AXIS,0);
- MXC_SaveLength = 0;
- AddToTal(MXC_TOTAL_ADDR); //计数增加和保存
- CalProSP(MXC_PROSPEED_ADDR);
- MXC_cAutoStep = 7;
- }
- else
- {
- if((MXC_PARAM_KONG_WEI_LENGTH - MXC_SaveLength) >= MXC_PARAM_DAOKOU_LENGTH)
- {
- MXC_cAutoStep = 2;
- }
- else
- {
- MXC_SaveLength = MXC_PARAM_KONG_WEI_LENGTH - MXC_PARAM_DAOKOU_LENGTH;
- MXC_cAutoStep = 2;
- }
- }
- }break; //伺服
- case MXC_DC_BMQ_MODE:
- {
- MXC_SaveLength += MXC_PARAM_DAOKOU_LENGTH;
- if(MXC_SaveLength >= MXC_PARAM_KONG_WEI_LENGTH)
- {
- dwZipCnt++;
- SetEncodePos(0);
- MXC_SaveLength = 0;
- AddToTal(MXC_TOTAL_ADDR); //计数增加和保存
- CalProSP(MXC_PROSPEED_ADDR);
- MXC_cAutoStep = 7;
- }
- else
- {
- if((MXC_PARAM_KONG_WEI_LENGTH - MXC_SaveLength) >= MXC_PARAM_DAOKOU_LENGTH)
- {
- MXC_cAutoStep = 2;
- }
- else
- {
- MXC_SaveLength = MXC_PARAM_KONG_WEI_LENGTH - MXC_PARAM_DAOKOU_LENGTH;
- MXC_cAutoStep = 2;
- }
- }
- }
- break; //编码器
- default:
- {
- dwZipCnt++;
- AddToTal(MXC_TOTAL_ADDR); //计数增加和保存
- CalProSP(MXC_PROSPEED_ADDR);
- MXC_cAutoStep = 7;
- }
- }
- }
- break;
- case 7:
- if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN)
- {
- if(GetTotal(MXC_TOTAL_ADDR) >= MXC_SET_TOTAL)MXC_SetAlarmCode(MXC_TOTAL_ALARM);
-
- MXC_cAutoStep = 8;
- }
- break;
- case 8:
- MXC_cAutoDelay = dwTickCount + MXC_PARAM_MOTOR_DELAY;
-
- if(MXC_SingOneFlag)
- {
- dwZipCnt = 0;
- MXC_SingOneFlag = 0;
- MXC_cAutoStep = 0;
- MXC_bRunning = 0;
- }
- MXC_cAutoStep = 1;
- break;
- }
- }
- }
- // 检测是否踏了脚踏开关
- void MXC_NiLongCheckStart(void)
- {
- // 停止键 不能在工作,手动,停止过程中
- if((MXC_bRunning == 0) && (START_IN_UP || MXC_bStart || MXC_bNext))
- {
- if(!MXC_LeftFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM); //没拉链
- else if(GetTotal(MXC_TOTAL_ADDR) >= MXC_SET_TOTAL)MXC_SetAlarmCode(MXC_TOTAL_ALARM);
- else if(!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
- else if((MXC_PARAM_SEBIAO_DW_LENGTH > MXC_SET_ZIPPER_LENGTH) && (MXC_DC_MODE==2))MXC_SetAlarmCode(MXC_SEBIAO_ZIPPER_LENGTH_ALARM);
- else if(MXC_KaDai_IN)MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
- else if(MXC_GouZhen_IN)MXC_SetAlarmCode(MXC_NO_GOUZHEN_ALARM);
- else
- {
- if(MXC_bNext)
- {
- SingOneFlg = 1;
- MXC_bNext = 0;
- }
- MXC_bRunning = 1;
- MXC_cAutoStep = 1;
- cGouZhenTime = 1;
- cCheckLengthOk = 0;
- cZipperLength[0] = 0;
- cZipperLength[1] = 0;
- dwZipCnt = 0;
- MXC_cAutoDelay = dwTickCount;
- MXC_cMotorDelay = dwTickCount;
- MXC_cXiaChongDelay = dwTickCount;
-
- }
- MXC_bStart = 0;
- }
- //卡带感应
- if(MXC_KaDai_IN && (dwTickCount >= MXC_cKaDaiDelay))
- {
- MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
- MXC_cKaDaiDelay = dwTickCount + 2200;
- }
-
-
- if(MXC_KaDai_IN_UP)
- {
- if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
- }
- //停止
- STOP_IN_FLAG_OLD = STOP_IN_FLAG;
-
- if(STOP_IN)
- {
- if(STOP_FILTER < 50)
- {
- STOP_FILTER++;
- }
- else
- STOP_IN_FLAG = 1;
- }
- else if(STOP_FILTER > 25)
- {
- STOP_FILTER--;
- }
- else
- STOP_IN_FLAG = 0;
-
- if(MXC_bStop)
- {
- MXC_bStop = 0;
- if(MXC_bRunning)MXC_SingOneFlag = 1;
- }
-
-
-
- if(((STOP_IN_FLAG && !STOP_IN_FLAG_OLD)))
- {
- MXC_bStop = 0;
- if(MXC_bRunning)
- {
- if(MXC_cXiaChongStep==0)
- {
- if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
-
- // if(!MXC_XiaChong_MOTOR)MXC_XC_SongZhou = MXC_SERVER_DISEN;
- }
-
- MXC_bRunning = 0;
- MXC_cAutoStep = 0;
- MXC_cMotorStep = 0;
- AxisDecStop(X_AXIS);
- MXC_cJiaoDaoStep = 0;
- SingOneFlg = 0;
- MXC_SingOneFlag = 0;
- }
- else
- {
- MXC_bRunning = 0;
-
- cStopFlag = 0;
- MXC_cAutoStep = 0;
- MXC_cMotorStep = 0;
- MXC_cXiaChongStep = 0;
- MXC_cLeftFenZhenStep = 0;
- MXC_cRightFenZhenStep = 0;
- MXC_cJiaoDaoStep = 0;
- MXC_cDCPStep = 0;
- MXC_XiaZhi_VAVLE = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_RightFenZhen_VAVLE = 0;
- SingOneFlg = 0;
- MXC_SingOneFlag = 0;
- MXC_XCSZ_OUT = MXC_XC_SERVER_DISEN;
- MXC_XC_ShaChe = MXC_SC_DISEN;
- if((MXC_cChuiQiStep == 0) &&(MXC_cXiaChongStep==0))MXC_cChuiQiStep = 1;
- AxisDecStop(X_AXIS);
- SetAlarmCode(MXC_ALARM_ADDR,MXC_NO_ALARM);
- }
- }
-
- /* if(!MXC_bRunning && (MXC_cMotorStep==0) && (MXC_cXiaChongStep == 0))
- {
- if(!X_DRV)MXC_TuoDaiSongZhou = MXC_SERVER_DISEN;
- }*/
- if(MXC_bAlarmStop)
- {
- MXC_bAlarmStop = 0;
- MXC_bRunning = 0;
- MXC_cAutoStep = 0;
- MXC_cMotorStep = 0;
- MXC_cLeftFenZhenStep = 0;
- MXC_cRightFenZhenStep = 0;
- MXC_cDCPStep = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_SingOneFlag = 0;
- AxisDecStop(X_AXIS);
-
- if((GetAlarmCode(MXC_ALARM_ADDR) == MXC_XIA_CHONG_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_XC_ALARM) ||
- (GetAlarmCode(MXC_ALARM_ADDR) == MXC_LFZ_ORIGIN_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_LFZ_LIMIT_ALARM) ||
- (GetAlarmCode(MXC_ALARM_ADDR) == MXC_RFZ_ORIGIN_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_RFZ_LIMIT_ALARM))
- {
- MXC_cXiaChongStep = 0;
- MXC_XiaChong_MOTOR = 0;
- }
- }
- }
- void MXC_NiLongChuiQi(void)
- {
- //吹气
- if(MXC_XiaChong_IN_DW)
- {
- if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 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_cDCPStep = 1;
- MXC_cChuiQiStep = 3;
- }
- break;
- case 3:
- if(dwTickCount >= MXC_cChuiQiDelay)
- {
- MXC_ChuiQi_VAVLE = 0;//
- MXC_cChuiQiStep = 0;
- }
- break;
- }
- }
- unsigned char ComPareLength(void)
- {
- if((cZipperLength[0] != 0) && (cZipperLength[1] != 0))
- {
- if(cZipperLength[0] > cZipperLength[1])
- {
- if((cZipperLength[0] - cZipperLength[1]) > 200)
- {
- return 0;
- }
- else
- return 1;
- }
- else
- {
- if((cZipperLength[1] - cZipperLength[0]) > 200)
- {
- return 0;
- }
- else
- return 1;
- }
- }
- else
- return 0;
- }
- unsigned char MXC_CheckPos(void)
- {
- unsigned long zipper_length;
- short *revise_buff;
- if(MXC_DC_MODE == MXC_DC_BMQ_MODE)
- {
- revise_buff = &user_datas[17];
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
- if(MXC_dwEncPos >= zipper_length)return 0;
- else
- return 1;
- }
- else if(MXC_DC_MODE == MXC_DC_GZ_MODE)
- {
- if(MXC_GouZhen_IN)
- return 0;
- else
- return 1;
- }
- else if(MXC_DC_MODE == MXC_DC_GZ_MODE)
- {
- revise_buff = &user_datas[17];
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
- if((0 - dwRealPos) > zipper_length) return 0;
- else
- return 1;
- }
- else
- return 1;
- }
- void MXC_NiLongMotor(void)
- {
- static long save_buff,gou_zhen_buff,zipper_length_buff;
- static unsigned long zipper_length;
- short *revise_buff;
-
- dwRealPos = GetPos(X_AXIS);
- MXC_dwEncPos = GetEncodePos();
-
- if(MXC_bRunning)
- {
- if(!MXC_Zipper_IN && (MXC_DC_MODE != MXC_DC_BMQ_MODE)) MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM);
- }
-
- if(!MXC_bRunning)
- {
- if(MXC_CheckPos() == 0)AxisEgmStop(X_AXIS);
- }
- switch(MXC_cMotorStep)
- {
- case 0:
- break;
- case 1:
- MXC_cMotorStep = 2;
- break;
- case 2://勾针模式
- if(dwTickCount >= MXC_cMotorDelay)
- {
- save_buff = dwRealPos;
- revise_buff = &user_datas[17];
- save_pos_buff = dwRealPos;
- if(cCheckLengthOk)
- {
- MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_SET_SPEED,1,5,1);
- }
- else
- {
- if(cCheckLengthOk == 0)
- {
- cZipperLength[0] = cZipperLength[1];
- cZipperLength[1] = zipper_length_buff - dwRealPos;
- zipper_length_buff = dwRealPos;
- if(ComPareLength())
- {
- cCheckLengthOk = 1;
- }
- }
- if(cCheckLengthOk)zipper_length = cZipperLength[1] + (*revise_buff);
- MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_FIRST_SPEED,1,5,1);
- }
- MXC_cMotorDelay = dwTickCount + MXC_PARAM_MOTOR_ALARM_TIME;
- MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
- MXC_cMotorStep = 3;
- }
- break;
- case 3:
- if(((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0)) || (cCheckLengthOk == 0))MXC_GouZhen_VAVLE = 0;
- if(MXC_PARAM_AUTO_CHECK_MODE)
- {
- if(cCheckLengthOk)
- {
- if(((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_GZ_LENGTH))&&MXC_PARAM_GZ_RESET_MODE)MXC_GouZhen_VAVLE = 0;
-
- if((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_LOWSPEED_LENGTH))
- {
- AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
- MXC_cMotorStep = 4;
- }
- }
- else
- {
- if(MXC_GouZhen_IN)
- {
- MXC_GouZhen_VAVLE = 0;
- MXC_cMotorStep = 5;
- AxisEgmStop(X_AXIS);
- }
- else
- {
- if(dwTickCount >= MXC_cGouZhenTime)MXC_GouZhen_VAVLE = 0;
- MXC_cMotorStep = 4;
- }
- }
-
- }
-
- if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 4:
- if(((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0)) || (cCheckLengthOk == 0))MXC_GouZhen_VAVLE = 0;
- if(MXC_PARAM_AUTO_CHECK_MODE)
- {
- if(((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_GZ_LENGTH))&&MXC_PARAM_GZ_RESET_MODE &&cCheckLengthOk)MXC_GouZhen_VAVLE = 0;
- }
- else
- {
- if(((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_GZ_LENGTH))&&MXC_PARAM_GZ_RESET_MODE)MXC_GouZhen_VAVLE = 0;
- }
-
- if(MXC_GouZhen_IN)
- {
- MXC_GouZhen_VAVLE = 0;
- MXC_cMotorStep = 5;
- AxisEgmStop(X_AXIS);
- }
-
- if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 5:
- if(((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0)) || (cCheckLengthOk == 0))MXC_GouZhen_VAVLE = 0;
- if(!X_DRV)
- {
- MXC_cMotorStep = 0;
- MXC_cMotorDelay = dwTickCount;
- }
- else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 20:
- MXC_cMotorStep = 21;
- break;
- case 21:
- if(dwTickCount >= MXC_cMotorDelay) //电机定寸模式
- {
- revise_buff = &user_datas[17];
-
- if(cAlarmStopFlg)
- {
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
- cAlarmStopFlg = 0;
- }
- else
- {
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH + MXC_SaveLength;
- if((0 - dwRealPos) > zipper_length)
- zipper_length = 0;//MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
- else
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH + MXC_SaveLength - (0 - dwRealPos);
- }
- AxisMovePosAccDec(X_AXIS,MXC_PARAM_SET_SPEED,zipper_length,1,5,1);
- MoveChangSpeedPos(X_AXIS, MXC_PARAM_LOW_SPEED,(PosToPulse(X_AXIS,MXC_PARAM_LOWSPEED_LENGTH) + MV_Cal_Dec_pulse(MXC_PARAM_SET_SPEED,MXC_PARAM_LOW_SPEED,1)));
- MXC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
- MXC_cMotorStep = 22;
- MXC_cMotorDelay = dwTickCount + MXC_PARAM_MOTOR_ALARM_TIME;
- }
- break;
- case 22:
- if(!X_DRV)
- {
- MXC_cMotorStep = 0;
- MXC_cMotorDelay = dwTickCount;
- }
- else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 40:
- MXC_cMotorStep = 41;
- break;
- case 41:
- if(dwTickCount >= MXC_cMotorDelay)
- {
- save_buff = dwRealPos;
- revise_buff = &user_datas[17];
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff);
-
- if((dwZipCnt==0)||SingOneFlg)MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_SB_LOW_SPEED,1,5,1);
- else MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_SB_HIGH_SPEED,1,5,1);
-
- cSeBiaoOk = 0;
- cSeBiaoEn = 0;
- MXC_cMotorStep = 42;
- MXC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
- MXC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- }
- break;
- case 42:
- if(dwZipCnt==0)
- {
- cSeBiaoOk = 0;
- cSeBiaoEn = 1;
- MXC_cMotorStep = 43;
- }
- else
- {
- if((save_buff - dwRealPos + MXC_PARAM_LOWSPEED_LENGTH) >= (zipper_length -MXC_PARAM_SEBIAO_DW_LENGTH)) AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
- if((save_buff - dwRealPos + MXC_PARAM_SEBIAO_TQ_LENGTH) >= (zipper_length - MXC_PARAM_SEBIAO_DW_LENGTH))
- {
- cSeBiaoOk = 0;
- cSeBiaoEn = 1;
- MXC_cMotorStep = 43;
- }
- else if((save_buff - dwRealPos) > (zipper_length + MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
-
- }
- break;
- case 43:
- if(dwZipCnt!=0)
- {
- if((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_LOWSPEED_LENGTH)) AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
- if((save_buff - dwRealPos) > (zipper_length + MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
- }
-
- if(!X_DRV)
- {
- if(dwZipCnt!=0)
- {
- if((save_buff - dwRealPos) < (zipper_length - MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
- }
- MXC_cMotorStep = 0;
- MXC_cMotorDelay = dwTickCount;
- }
- else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
- break;
- case 60:
- MXC_cMotorStep = 61;
- break;
- case 61:
- if(dwTickCount >= MXC_cMotorDelay)
- {
- save_buff = MXC_dwEncPos;
- revise_buff = &user_datas[17];
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH + MXC_SaveLength;
- MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_SET_SPEED,1,5,1);
- MXC_cMotorDelay = dwTickCount + MXC_PARAM_MOTOR_ALARM_TIME;
- MXC_cMotorStep = 62;
- }
- break;
- case 62:
- if((MXC_dwEncPos) >= (zipper_length - MXC_PARAM_LOWSPEED_LENGTH))
- {
- AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
- MXC_cMotorStep = 63;
- }
- else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 63:
- if((MXC_dwEncPos) >= zipper_length)
- {
- MXC_cMotorStep = 64;
- AxisEgmStop(X_AXIS);
- }
- else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 64:
- if(!X_DRV)
- {
- MXC_cMotorStep = 0;
- MXC_cMotorDelay = dwTickCount;
- }
- else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- }
- }
- //下冲
- void MXC_NiLongXiaChong(void)
- {
- switch(MXC_cXiaChongStep)
- {
- case 0:
- return;
- break;
- case 1:
- {
- MXC_cRightFenZhenStep = 1;
- MXC_cLeftFenZhenStep = 0;
- cRFengTimer = 0;
- cLFengTimer = 0;
- }
- MXC_cXiaChongStep = 2;
- break;
- case 2:
- if((MXC_cRightFenZhenStep==0) && (MXC_cLeftFenZhenStep==0))
- {
- MXC_XC_ShaChe = MXC_SC_DISEN;
- MXC_XCSZ_OUT = MXC_XC_SERVER_EN;
- if(MXC_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_bRunning)MV_Set_Command_Pos_CPU(X_AXIS,0);
- if(!MXC_bRunning)SetEncodePos(0);
- MXC_cXiaChongDelay = dwTickCount + (unsigned long)MXC_ERRORTIME; //下冲最长时间
-
- if(MXC_bRunning && MXC_XZ_ENABLE)
- {
- if(MXC_DC_MODE == MXC_DC_GZ_MODE)
- {
- MXC_XiaZhi_VAVLE = 1;
- MXC_cXiaZhiDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
- }
- else
- {
- if(MXC_PARAM_DAOKOU_LENGTH >= MXC_PARAM_KONG_WEI_LENGTH)
- {
- MXC_XiaZhi_VAVLE = 1;
- MXC_cXiaZhiDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
- }
- }
- }
- if(MXC_XiaChongMotorMode == 1)
- {
- AxisMoveTwoPos(Y_AXIS,MXC_XiaChongSpeed,2000,MXC_XiaChongLowSpeed,9999999,0);
- }
- }
- break;
- case 4: //碰到右大微动,延时停
- if(MXC_XiaChong_IN_UP)
- {
- MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_XC_DELAY;
- MXC_cXiaChongStep = 5;
- MXC_LeftFenZhen_VAVLE = 0; //退左分针
- MXC_RightFenZhen_VAVLE = 0; //退右分针
- MXC_GouZhen_VAVLE = 1;
- MXC_cGouZhenTime = dwTickCount + 300;
- }
- else if(dwTickCount >= MXC_cXiaChongDelay) //自动停机
- {
- MXC_cXiaChongStep = 0;
- // MXC_ShaChe_Output();////刹车
- MXC_XiaChong_MOTOR = 0;// //下冲电机
- MXC_SetAlarmCode(MXC_XC_ALARM);
- MXC_LeftFenZhen_VAVLE = 0; //退左分针
- MXC_RightFenZhen_VAVLE = 0; //退右分针
- AxisEgmStop(Y_AXIS);
- }
-
- break;
- case 5:
- if(dwTickCount >= MXC_cXiaChongDelay)
- {
-
- AxisEgmStop(Y_AXIS);
- MXC_XiaChong_MOTOR = 0; //延时刹车
- if(MXC_PARAM_SC_MODE)
- {
- MXC_cXiaChongStep = 0;
- }
- else
- {
- MXC_cXiaChongStep = 6;
- }
- }
- break;
- case 6:
- {
- MXC_cXiaChongStep = 7;
- MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_SC_DELAY;
- }
- break;
- case 7:
- if((dwTickCount >= MXC_cXiaChongDelay))
- {
- MXC_cXiaChongStep = 8;
- MXC_cXiaChongDelay = dwTickCount+ 150;
- // MXC_XC_SongZhou = MXC_SERVER_DISEN;
- MXC_XC_ShaChe = MXC_SC_EN;
- }
- break;
- case 8:
- if((dwTickCount >= MXC_cXiaChongDelay))
- {
- MXC_cXiaChongStep = 0;
- // MXC_XC_SongZhou = MXC_SERVER_DISEN;
- MXC_XC_ShaChe = MXC_SC_DISEN;
- MXC_XCSZ_OUT = MXC_XC_SERVER_DISEN;
-
- }
- break;
- case 20: // 点动普通下冲动作
- // MXC_XC_SongZhou = MXC_SERVER_EN;
- MXC_XC_ShaChe = MXC_SC_DISEN;
- MXC_cXiaChongDelay = dwTickCount + 50;
- MXC_cXiaChongStep = 21;
- break;
- case 21:
- if((dwTickCount >= MXC_cXiaChongDelay))
- {
- MXC_XiaChong_MOTOR = 1;
- MXC_cXiaChongDelay = dwTickCount + 50;
- MXC_cXiaChongStep = 22;
- }
- break;
- case 22:
- if((dwTickCount >= MXC_cXiaChongDelay))
- {
- MXC_XiaChong_MOTOR = 0;
- // MXC_XC_SongZhou = MXC_SERVER_EN;
-
- if(MXC_XiaChongMotorMode)
- MXC_cXiaChongStep = 0;
- else
- {
- MXC_XC_ShaChe = MXC_SC_EN;
- MXC_cXiaChongDelay = dwTickCount + 150;
- MXC_cXiaChongStep = 23;
- }
- }
- break;
- case 23:
- if((dwTickCount >= MXC_cXiaChongDelay))
- {
- //MXC_XC_SongZhou = MXC_SERVER_DISEN;
- MXC_XC_ShaChe = MXC_SC_DISEN;
- MXC_cXiaChongStep = 0;
- }
- break;
- case 40: // 点动电机下冲动作
- //MXC_XC_SongZhou = MXC_SERVER_EN;
- MXC_cXiaChongDelay = dwTickCount + 50;
- MXC_cXiaChongStep = 41;
- break;
- case 41:
- if(!Y_DRV)AxisMovePos(Y_AXIS,20,10);
- MXC_cXiaChongStep = 42;
- break;
- case 42:
- if(!Y_DRV)
- {
- MXC_cXiaChongStep = 0;
- }
- break;
- }
- }
- //分针
- void MXC_NiLongFenZhen(void)
- {
- //右分针
- switch(MXC_cRightFenZhenStep)
- {
- case 0:
- break;
- case 1:
- MXC_cFenZhenRightDelay = MXC_PARAM_R_FZ_DELAY+dwTickCount;
- MXC_cRightFenZhenStep = 2;
- break;
- case 2:
- if(dwTickCount >= MXC_cFenZhenRightDelay)
- {
- MXC_cRightFenZhenStep = 3;
- MXC_RightFenZhen_VAVLE = 1;//右分针电磁阀
- MXC_cFenZhenRightDelay = dwTickCount + MXC_FenZhengErrorTime;
- }
- break;
- case 3: //碰到右大微动,延时停
- if(!MXC_RightFenZhen_Origin_IN) //右分针原点离开
- {
- MXC_cFenZhenRightDelay = dwTickCount + MXC_FenZhengErrorTime;
- MXC_cRightFenZhenStep = 4;
- }//右分针不下去
- else if(dwTickCount >= MXC_cFenZhenRightDelay)
- {
- MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
- }
- break;
- case 4:
- if(MXC_RighttFenZhen_IN) //插针到位
- {
- MXC_cRightFenZhenStep = 0;
- MXC_cLeftFenZhenStep = 1; //左分针延时启动
- }
- else if(dwTickCount >= MXC_cFenZhenRightDelay)
- {
- MXC_RightFenZhen_VAVLE = 0;//右分针
- cRFengTimer++;
- //当右分针分不到位时,左分针也要重新分针
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_cRightFenZhenStep = 0;
- if(cRFengTimer < 4)
- {
- MXC_cRightFenZhenStep = 5;
- MXC_cFenZhenRightDelay = dwTickCount + MXC_FenZhengErrorTime;
- }
- else
- {
- MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
- }
- }
- break;
- case 5:
- if(MXC_RightFenZhen_Origin_IN) //退到位
- {
- MXC_cRightFenZhenStep = 6;
- }
- else if(dwTickCount >= MXC_cFenZhenRightDelay)
- {
- MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
- }
- break;
- case 6:
- {
- MXC_cRightFenZhenStep = 1;
- }
- break;
- }
- //左分针
- switch(MXC_cLeftFenZhenStep)
- {
- case 0:
- break;
- case 1:
- MXC_cFenZhenLeftDelay = MXC_PARAM_L_FZ_DELAY+dwTickCount;
- MXC_cLeftFenZhenStep = 2;
- break;
- case 2:
- if(dwTickCount >= MXC_cFenZhenLeftDelay)
- {
- MXC_cLeftFenZhenStep = 3;
- MXC_LeftFenZhen_VAVLE = 1; //左分针电磁阀
- MXC_cFenZhenLeftDelay = dwTickCount + MXC_FenZhengErrorTime;
- }
- break;
- case 3: //离开左分针原点
- if(!MXC_LeftFenZhen_Origin_IN) //左分针原点离开
- {
- MXC_cFenZhenLeftDelay = dwTickCount + MXC_FenZhengErrorTime;
- MXC_cLeftFenZhenStep = 4;
- }//左分针不下去
- else if(dwTickCount >= MXC_cFenZhenLeftDelay)
- {
- MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
- }
- break;
- case 4:
- if(MXC_LeftFenZhen_IN) //插针到位
- MXC_cLeftFenZhenStep = 0;
- else if(dwTickCount >= MXC_cFenZhenLeftDelay)
- {
- MXC_LeftFenZhen_VAVLE = 0;//左分针
- cLFengTimer++;
- if(cLFengTimer < 6)
- {
- MXC_cLeftFenZhenStep = 5;
- MXC_cFenZhenLeftDelay = dwTickCount + MXC_FenZhengErrorTime;
- if((cLFengTimer%2) == 0)
- {
- MXC_RightFenZhen_VAVLE = 0;
- MXC_cRightFenZhenStep = 0;
- }
- }
- else
- {
- MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
- }
- }
- break;
- case 5:
- if(MXC_LeftFenZhen_Origin_IN) //退到位
- {
- MXC_cLeftFenZhenStep = 6;
- }
- else if(dwTickCount >= MXC_cFenZhenLeftDelay)
- {
- MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
- }
- break;
- case 6:
- if((cLFengTimer%2) == 0) //左边插两次都插不到,就退右边再同时插
- {
- MXC_cRightFenZhenStep = 1;
- cRFengTimer = 0;
- MXC_cLeftFenZhenStep = 0;
- }
- else
- {
- MXC_cLeftFenZhenStep = 1;
- }
- break;
- }
- }
- #endif
|