1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348 |
- #include "global.h"
- #if CHANG_SHENG_GEI_LI_MACHINE
- void HL_InitAction(void);
- void HL_Action(void);
- void HL_SetAlarmCode(unsigned alarm_code);
- void HL_StartStopAction(void);
- void HL_AutoRunStep(void);
- void HL_Motor(void);
- void HL_Step(void);
- void HL_PWMAction(void);
- unsigned char cDWflg=0,cZCXflg=0,cHLflg=0;
- unsigned char cBBflg = 0;
- short *offset_length_buff;
- static unsigned char OldGuoLian,GuoLian;
- static unsigned long guolian_flter;
- unsigned char work_flg,work_Num,cErrorStop_Flg;
- unsigned short cCheckStep;
- void HL_ConectAction(void)
- {
- static unsigned long start_delay;
- if(HL_PARAM_CONNECT_MODE)
- {
- if(cCheckStep == 1)
- {
- if(HL_LW_STOP_IN_DW)
- {
- start_delay = HL_PARAM_DELAY_START + dwTickCount;
- cCheckStep = 2;
- }
- else if(HL_LW_STOP_IN)
- work_flg = 0;
- }
- else if((cCheckStep == 2) && (dwTickCount >= start_delay))
- {
- work_flg = 1;
- cCheckStep = 3;
- }
- else if(cCheckStep == 3)
- {
- if(HL_LW_STOP_IN)
- {
- work_flg = 0;
- cCheckStep = 1;
- }
- }
- }
- else
- work_flg = 1;
- }
- void HL_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(HL_ALARM_ADDR,alarm_code);
- HL_bAlarmStop = 1;
- }
- void HL_InitAction(void)
- {
- CalFreqTab_X_Free(14);
- // length_buff = 54.1*3.14;//JYDC_CYCLE_LENGTH;
- // pulse_buff = 2000;//JYDC_CYCLE_PULSE;
- // XGearRatio = 2000pulse_buff/length_buff;
- XGearRatio = 1;
- SetEn(X_AXIS,HL_MOTOR_DISEN);
- #if IO_Change
- IOPinConfigure(); //可变IO初始化
- #endif
- }
- //手动动作
- void HL_ManualAction(void)
- {
- if(!HL_bRunning)
- {
- //清产量
- if(bClearTotal)
- {
- bClearTotal = 0;
- ClrcToTal(HL_TOTAL_ADDR);
- HL_bSetWorkData = 1;
- }
- //定位数据加
- if(HL_bAdd)
- {
- HL_bAdd = 0;
- HL_PARAM_DELAY_STOP += 10;
- }
- //定位数据减
- if(HL_bDec)
- {
- HL_bDec = 0;
- if(HL_PARAM_DELAY_STOP >= 10)
- HL_PARAM_DELAY_STOP -= 10;
- }
- //合模
- if(HL_bHM)
- {
- HL_bHM = 0;
- if(HL_HM_VAVLE)
- {
- HL_HM_VAVLE = 0;
- HL_YD_VAVLE = 0;
- }
- else if((!HL_TFK_VAVLE) || (!HL_BB_VAVLE))
- HL_HM_VAVLE = 1;
- }
- //推方块
- if(HL_bTFK)
- {
- HL_bTFK = 0;
- HL_TFK_VAVLE = ~HL_TFK_VAVLE;
- }
- //摆 臂
- if(HL_bBB)
- {
- HL_bBB = 0;
- HL_BB_VAVLE = ~HL_BB_VAVLE;
- if(HL_BB_VAVLE)cBBflg = 1;
- }
-
- if(cBBflg)
- {
- if(HL_BB_LIMIT_IN)
- {
- cBBflg = 0;
- }
- }
- //压插销
- if(HL_bYCX)
- {
- HL_bYCX = 0;
- HL_YCX_VAVLE = 1;
- HL_YCXDelay = dwTickCount + HL_PARAM_YCX_TIME;
- }
- //上挡块
- if(HL_bDK_UP)
- {
- HL_bDK_UP = 0;
- HL_DK_UP_VAVLE = ~HL_DK_UP_VAVLE;
- }
- //夹 带
- if(HL_bJD)
- {
- HL_bJD = 0;
- HL_JD_VAVLE = ~HL_JD_VAVLE;
- }
- //穿插销
- if(HL_bCCX)
- {
- HL_bCCX = 0;
- HL_CCX_VAVLE = ~HL_CCX_VAVLE;
- }
- //挡块前后
- if(HL_bDK_GO)
- {
- HL_bDK_GO = 0;
- HL_DK_GO_VAVLE = ~HL_DK_GO_VAVLE;
- }
- //压 带
- if(HL_bYD)
- {
- HL_bYD = 0;
- HL_YD_VAVLE = ~HL_YD_VAVLE;
- }
- //松 紧
- if(HL_bSJ)
- {
- HL_bSJ = 0;
- HL_SJ_VAVLE = ~HL_SJ_VAVLE;
- }
-
- if(HL_bHMYD)
- {
- HL_bHMYD = 0;
-
- if(HL_HM_VAVLE)
- {
- HL_HM_VAVLE = 0;
- }
- else
- {
- HL_HM_VAVLE = 1;
- }
- }
- //上挡块
- if(HL_bDKUP)
- {
- HL_bDKUP = 0;
- if(HL_DK_UP_VAVLE)
- {
- HL_DK_UP_VAVLE = 0;
- HL_DK_GO_VAVLE = 0;
- HL_YD_VAVLE = 0;
- }
- else
- {
- if(HL_ManDKStep == 0)HL_ManDKStep=1;
- }
- }
-
- if(HL_ManDKStep == 1)
- {
- HL_DK_UP_VAVLE = 1; //挡块上下
- HL_ManDKStep = 2;
- }
- else if((HL_ManDKStep == 2) && HL_DK_UP_LIMIT_IN)
- {
- HL_ManDKDelay = dwTickCount + HL_PARAM_DELAY_DK_UP;
- HL_ManDKStep = 3;
- }
- else if((HL_ManDKStep == 3) && (dwTickCount >= HL_ManDKDelay))
- {
- HL_DK_GO_VAVLE = 1; //挡块前后
- HL_ManDKStep = 0;
- }
-
- if(HL_bCD)
- {
- HL_bCD = 0;
- HL_CD_MOTOR = ~HL_CD_MOTOR;
- }
-
- if(HL_bYCD)
- {
- HL_bYCD = 0;
- HL_CD_VAVLE = ~HL_CD_VAVLE;
- }
- if(HL_bMotor)
- {
- SetEn(X_AXIS,HL_MOTOR_EN);
- if(!X_DRV)AxisContinueMove(X_AXIS,10,HL_DIR_P);
- }
- else
- {
- if(X_DRV)AxisDecStop(X_AXIS);
- }
- }
- }
- //合链动作
- void HL_Action(void)
- {
- #if IO_Change
- InputPinConfig();
- #endif
- HL_ConectAction();
- HL_ManualAction();
- HL_StartStopAction();
- HL_Motor();
- HL_Step();
- HL_AutoRunStep();
- #if IO_Change
- OutputPinConfig();
- #endif
- }
- //启动停止故障停止动作
- void HL_StartStopAction(void)
- {
- static unsigned long dwstop_cnt = 0;
- if((HL_START_IN_UP || HL_bStart || HL_bSingStart || HL_bDW || HL_bZCX || HL_bHL) && !HL_bRunning && (HL_AutoStep ==0))
- {
- if((GetTotal(HL_TOTAL_ADDR) >= SET_TOTAL) && !HL_bDW && SET_TOTAL)HL_SetAlarmCode(HL_TOTAL_ALARM);
- // else if(HL_SM_LIMIT_IN)HL_SetAlarmCode(HL_SM_LIMIT_ALARM);
- // else if(HL_XM_LIMIT_IN)HL_SetAlarmCode(HL_XM_LIMIT_ALARM);
- // else if(HL_BB_LIMIT_IN)HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
- // else if(HL_DK_LIMIT_IN)HL_SetAlarmCode(HL_DK_LIMIT_ALARM);
- // else if(!HL_DK_ORIGIN_IN)HL_SetAlarmCode(HL_DK_ORIGIN_ALARM);
- // else if(HL_DK_UP_LIMIT_IN)HL_SetAlarmCode(HL_DK_UP_LIMIT_ALARM);
- // else if(HL_CCX_LIMIT_IN)HL_SetAlarmCode(HL_CCX_LIMIT_ALARM);
- // else if(!HL_CCX_ORIGIN_IN)HL_SetAlarmCode(HL_CCX_ORIGIN_ALARM);
- // else if(HL_TFK_LIMIT_IN)HL_SetAlarmCode(HL_TFK_LIMIT_ALARM);
- // else if(!HL_TFK_ORIGIN_IN)HL_SetAlarmCode(HL_TFK_ORIGIN_ALARM);
- else
- {
- SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- HL_bRunning = 1;
- cCheckStep = 1;
- dwZipCnt = 0;
- if(HL_PARAM_CONNECT_MODE)
- {
- work_Num = 0;
- HL_OVEROUt_VAVLE = 1;
- HL_Y15Delay = dwTickCount + 100;
- }
- //单次启动
- if(HL_bSingStart)
- {
- HL_bSingStart = 0;
- SingOneFlg = 1;
- }
- //定位
- if(HL_bDW)
- {
- cDWflg = 1;
- dwZipCnt = 1;
- }
- work_Num = 0;
- bCheckOK = 1;
- cErrorStop_Flg = 0;
- if(HL_bZCX)cZCXflg = 1;//装插销
- if(HL_bHL)cHLflg = 1; //合链
- work_flg = 1;
- if(HL_bZCX)HL_AutoStep = 4;
- else if(HL_bHL)HL_AutoStep = 1;
- else HL_AutoStep = 1;
-
- }
- HL_bDW = 0;
- HL_bZCX = 0;
- HL_bHL = 0;
- HL_bSingStart = 0;
- HL_bStart = 0;
- }
-
- if(!HL_bMotor && !X_DRV && !HL_bRunning && (HL_MotorStep==0))
- SetEn(X_AXIS,HL_MOTOR_DISEN);
-
- if(HL_bStop)
- {
- HL_bStop = 0;
- if(HL_bRunning)
- SingOneFlg = 1;
- else
- {
- HL_HM_VAVLE = 0;
- HL_TFK_VAVLE = 0;
- HL_BB_VAVLE = 0;
- HL_DK_UP_VAVLE = 0;
- HL_JD_VAVLE = 0;
- HL_CCX_VAVLE = 0;
- HL_DK_GO_VAVLE = 0;
- HL_YD_VAVLE = 0;
- HL_SJ_VAVLE = 0;
- HL_CD_MOTOR = 0;
- HL_ALARM_OUT = 0;
- HL_bRunning = 0;
- HL_AutoStep = 0;
- HL_MotorStep = 0;
- SingOneFlg = 0;
- HL_bMotor = 0;
- cDWflg = 0;
- cZCXflg = 0;
- cHLflg = 0;
- HL_ManDKStep = 0;
- HL_CD_VAVLE = 0;
- AxisEgmStop(X_AXIS);
- SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- }
- }
-
- if(STOP_IN)dwstop_cnt++;
- else dwstop_cnt = 0;
-
- if(dwstop_cnt >= 10000)
- {
- HL_HM_VAVLE = 0;
- HL_BB_VAVLE = 0;
- }
- if(HL_STOP_IN_UP)
- {
- HL_bStop = 0;
- // if(HL_bRunning)
- {
- HL_TFK_VAVLE = 0;
- // HL_BB_VAVLE = 0;
- HL_DK_UP_VAVLE = 0;
- HL_JD_VAVLE = 0;
- HL_CCX_VAVLE = 0;
- HL_DK_GO_VAVLE = 0;
- HL_YD_VAVLE = 0;
- HL_SJ_VAVLE = 0;
- HL_CD_MOTOR = 0;
- HL_ALARM_OUT = 0;
- HL_bRunning = 0;
- HL_AutoStep = 0;
- HL_MotorStep = 0;
- HL_HLStep = 0;
- HL_ManDKStep = 0;
- SingOneFlg = 0;
- HL_bMotor = 0;
- cDWflg = 0;
- cZCXflg = 0;
- cHLflg = 0;
- SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- if(X_DRV)
- AxisEgmStop(X_AXIS);
- else
- SetEn(X_AXIS,HL_MOTOR_DISEN);
- }
- /* else
- {
- HL_HM_VAVLE = 0;
- HL_TFK_VAVLE = 0;
- HL_BB_VAVLE = 0;
- HL_DK_UP_VAVLE = 0;
- HL_JD_VAVLE = 0;
- HL_CCX_VAVLE = 0;
- HL_DK_GO_VAVLE = 0;
- HL_YD_VAVLE = 0;
- HL_SJ_VAVLE = 0;
- HL_CD_MOTOR = 0;
- HL_bRunning = 0;
- HL_AutoStep = 0;
- HL_MotorStep = 0;
- HL_HLStep = 0;
- SingOneFlg = 0;
- cDWflg = 0;
- cZCXflg = 0;
- cHLflg = 0;
- HL_bMotor = 0;
- SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- AxisEgmStop(X_AXIS);
- }*/
- }
-
-
- if(HL_bAlarmStop)
- {
- HL_ALARM_OUT = 1;
- HL_bAlarmStop = 0;
- AxisEgmStop(X_AXIS);
- HL_AutoStep = 0;
- HL_ManDKStep = 0;
- HL_MotorStep = 0;
- HL_HLStep = 0;
- HL_bRunning = 0;
- SingOneFlg = 0;
- cDWflg = 0;
- cZCXflg = 0;
- cHLflg = 0;
- }
- }
- //合链动作
- void HL_Step(void)
- {
- static long hm_save_buff;
- switch(HL_HLStep)
- {
- case 1:
- if(HL_GUO_LIAN_IN_UP)//过链上升沿
- {
- hm_save_buff = dwRealPos;
- HL_HLStep = 2;
- }
- break;
- case 2://上升沿后延迟长度开合模
- if(cErrorStop_Flg == 0)
- {
- if(((dwRealPos + HL_PARAM_DELAY_HM_BACK) <= hm_save_buff) || (!X_DRV))
- {
- HL_HM_VAVLE = 0;//开模
- HL_HLDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_HLStep = 3;
- }
- // else if(!X_DRV)HL_SetAlarmCode(HL_HM_BACK_ALARM);
- }
- else
- {
- if(((dwRealPos + HL_PARAM_ERROR_DELAY_STOP-150) <= hm_save_buff) || (!X_DRV))
- {
- HL_HM_VAVLE = 0;//开模
- HL_HLDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_HLStep = 3;
- }
- }
- break;
- case 3: //上下模到位离开
- if(!HL_SM_LIMIT_IN && !HL_XM_LIMIT_IN)
- {
- HL_HLStep = 4;
- //延时关摆臂
- HL_HLDelay = dwTickCount + HL_PARAM_DELAY_BB_BACK;
- }
- else if(dwTickCount >= HL_HLDelay)
- {
- if(HL_SM_LIMIT_IN)HL_SetAlarmCode(HL_SM_LIMIT_ALARM);
- else HL_SetAlarmCode(HL_XM_LIMIT_ALARM);
- }
- break;
- case 4:
- if(dwTickCount >= HL_HLDelay) //开模延时关摆臂
- {
- HL_HLStep = 5;
- HL_BB_VAVLE = 0; //
- HL_HLDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_TFK_VAVLE = 1; //推方块输出
- }
- break;
- case 5:
- if(!HL_BB_LIMIT_IN) //摆臂到位信号灭
- {
- HL_HLStep = 0;
- if(SingOneFlg) //单一自动
- {
- SingOneFlg = 0;
- HL_AutoStep = 0;
- HL_bRunning = 0;
- HL_MotorStep = 0;
- }
-
- HL_HLDelay = dwTickCount;
- }
- else if(dwTickCount >= HL_HLDelay)
- {
- HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
- }
- break;
- }
- }
- void HL_PWMAction(void)
- {
- }
- //电机动作
- void HL_Motor(void) //
- {
- static long save_buff;
- dwRealPos = GetPos(X_AXIS);
- DISPLAY_DATA0 = dwRealPos;
- DISPLAY_DATA1 = HL_AutoStep;
- DISPLAY_DATA2 = HL_MotorStep;
- DISPLAY_DATA3 = tXAxisStepper.cPmovPulse;//HL_HLStep;
- DISPLAY_DATA4 = tXAxisStepper.bAuto_Mov;//save_buff;
- //实时位置
-
- switch(HL_MotorStep)
- {
- case 0:break;
- case 1:
-
- // if(GetEn(X_AXIS) == 0) //未锁轴情况下有锁轴时间
- // {
- // SetEn(X_AXIS,HL_MOTOR_EN);
- // HL_MotorDelay = dwTickCount + 300; //100MSq锁轴时间
- // else
- HL_MotorDelay = dwTickCount + 0;
- HL_MotorStep = 2;
- break;
- case 2:
- if(dwTickCount >= HL_MotorDelay)
- {
- // if(START_IN)
- {
- HL_MotorDelay = dwTickCount + HL_PARAM_MOTOR_ALARM_TIME;
- SetPos(X_AXIS, 0);
- // DISPLAY_DATA5 = -dwRealPos-HL_PARAM_DELAY_STOP-300;
-
- if(dwZipCnt >= 2) //2条后测出拉链长度
- {
- AxisMovePosAccDecNotStop(X_AXIS,HL_PARAM_HIGH_SPEED*6/5,-(-dwRealPos-HL_PARAM_DELAY_STOP-200),6,HL_PARAM_HIGH_SPEED,2,4);
- // DISPLAY_DATA6 = tXAxisStepper.cCalAccPulse;
- // DISPLAY_DATA7 = tXAxisStepper.cCalSpeed;
- }
- else
- {
- if(cErrorStop_Flg)
- MoveAction_Const_AccDec(X_AXIS,HL_DIR_P,6,2,6,1);
- else
- MoveAction_Const_AccDec(X_AXIS,HL_DIR_P,HL_PARAM_HIGH_SPEED,2,6,1);
- }
- HL_MotorStep = 3;
-
- *offset_length_buff = 0;
- if(HL_HM_VAVLE) //如果合模有输出启动合链
- {
- if(HL_HLStep == 0)
- HL_HLStep = 1;
- }
- }
- }
- break;
- case 3://过链感应下降沿
- if(HL_GUO_LIAN_IN)
- { //变为低速
- if(cErrorStop_Flg == 0)
- {
- if(dwZipCnt >= 2)
- {
- tXAxisStepper.State = 1;
- // CancelPmoveState(X_AXIS);
- }
- if(tXAxisStepper.cCurSpeed >= HL_PARAM_HIGH_SPEED)
- AxisMovePosAccDec_LYQ(X_AXIS,tXAxisStepper.cCurSpeed,HL_PARAM_DELAY_STOP,
- tXAxisStepper.cCurSpeed,4,5,5);
- else
- AxisMovePosAccDec_LYQ(X_AXIS,HL_PARAM_HIGH_SPEED,HL_PARAM_DELAY_STOP,
- tXAxisStepper.cCurSpeed,4,5,5);
- // AxisChangeSpeed(X_AXIS,HL_PARAM_LOW_SPEED);
- //空位延时检测
- HL_MotorDelay = dwTickCount + HL_PARAM_DELAY_CHECK_TIME;
- HL_MotorStep = 6;
- save_buff = dwRealPos; //当位置保存
- }
- else //联网故障停时慢速停止
- {
- HL_MotorStep = 6;
- save_buff = dwRealPos; //当位置保存
- AxisMovePosAccDec_LYQ(X_AXIS,tXAxisStepper.cCurSpeed,HL_PARAM_ERROR_DELAY_STOP,
- tXAxisStepper.cCurSpeed,4,2,5);
- }
-
- }
- else if(dwTickCount >= HL_MotorDelay)//长时间没信号警告
- HL_SetAlarmCode(HL_GUOLIAN_ALARM);
- else //联机控制
- {
- if(HL_PARAM_CONNECT_MODE)
- {
-
- if(HL_LW_START_IN)
- {
- if(dwTickCount >= HL_MotorDelay)
- {
- if(!X_DRV)
- {
- HL_MotorStep = 2;
- HL_MotorDelay = dwTickCount;
- }
- }
- }
- else
- {
- if(HL_LW_STOP_IN)
- {
- HL_MotorStep = 50;
- AxisEgmStop(X_AXIS);
- HL_MotorDelay = dwTickCount + HL_PARAM_DELAY_START;
- }
-
- }
- }
- #if 0 //郑广程序
- if(work_flg)
- {
- if(!X_DRV)
- {
- HL_MotorStep = 2;
- HL_MotorDelay = dwTickCount;
- }
- }
- else if(HL_GUO_LIAN_IN)
- {
- if(X_DRV)AxisEgmStop(X_AXIS);
- }
- #endif
- }
- break;
- case 4:
- if(dwTickCount >= HL_MotorDelay)
- {
- HL_MotorStep = 5;
- HL_MotorDelay = dwTickCount + HL_PARAM_MOTOR_ALARM_TIME;
- }
- break;
- case 5:
- //过链上升沿
- if(HL_GUO_LIAN_IN_UP)
- {
- AxisChangeSpeed(X_AXIS,HL_PARAM_LOW_SPEED);
- save_buff = dwRealPos; //当位置保存
- HL_MotorStep = 6;
- }
- else if(dwTickCount >= HL_MotorDelay)//规定时间没到链上警告
- HL_SetAlarmCode(HL_GUOLIAN_ALARM);
-
- case 6: // 定位长度
- if(!X_DRV)
- {
- HL_MotorStep = 7;
- }
- if((dwRealPos + HL_PARAM_DELAY_STOP) <= save_buff)
- {
- // AxisEgmStop(X_AXIS);
- // HL_MotorStep = 7;
- }
- break;
- case 7://定位和合链完成
- if(!X_DRV && (HL_HLStep == 0))
- {
- HL_MotorStep = 0;
- HL_MotorDelay = dwTickCount;
- }
- break;
- case 50:
- if(HL_LW_START_IN)
- {
- if(dwTickCount >= HL_MotorDelay)
- {
- if(!X_DRV)
- {
- HL_MotorStep = 2;
- HL_MotorDelay = dwTickCount;
- dwZipCnt = 0;
- cErrorStop_Flg = 1;
- }
- }
- }
- else
- {
- if(HL_LW_STOP_IN)
- {
- AxisEgmStop(X_AXIS);
- }
- HL_MotorDelay = dwTickCount + HL_PARAM_DELAY_START;
- }
- break;
- /*
- case 20:
- // if(!X_DRV)
- {
- HL_MotorStep = 21;
- HL_HM_VAVLE = 0;
- HL_MotorDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- }
- break;
- case 21:
- if(!HL_SM_LIMIT_IN && !HL_XM_LIMIT_IN)
- {
- HL_MotorStep = 22;
- HL_MotorDelay = dwTickCount + HL_PARAM_DELAY_BB_BACK;
- }
- else if(dwTickCount >= HL_MotorDelay)
- {
- if(HL_SM_LIMIT_IN)HL_SetAlarmCode(HL_SM_LIMIT_ALARM);
- else HL_SetAlarmCode(HL_XM_LIMIT_ALARM);
- }
- break;
- case 22:
- if(dwTickCount >= HL_MotorDelay)
- {
- if(cHLflg)
- HL_MotorStep = 0;
- else
- HL_MotorStep = 23;
- HL_BB_VAVLE = 0;
-
- if(SingOneFlg)
- {
- SingOneFlg = 0;
- HL_MotorStep = 0;
- HL_AutoStep = 0;
- HL_bRunning = 0;
- }
- HL_MotorDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- }
- break;
- case 23:
- if(!HL_BB_LIMIT_IN)
- {
- HL_MotorStep = 0;
- // if(!X_DRV)AxisMovePosAccDec(X_AXIS,HL_PARAM_LOW_SPEED,HL_PARAM_DELAY_STOP2,1,5,5);
- }
- else if(dwTickCount >= HL_MotorDelay)
- {
- HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
- }
- break;
- case 24:
- if(!X_DRV)
- {
- HL_MotorStep = 0;
- HL_MotorDelay = dwTickCount;
- }
- break;
-
- */
- }
- }
- //自动运行动作
- void HL_AutoRunStep(void)
- {
- static long save_buff;
- static unsigned long yd_delay_back;
- static unsigned char yd_back_flg = 0;
- static unsigned long dk_up_delay;
- if((dwTickCount >= HL_YCXDelay) && HL_YCX_VAVLE)HL_YCX_VAVLE = 0;
- // if((dwTickCount >= HL_Y14Delay) && Y14)Y14 = 0;
- if(dwTickCount >= HL_Y15Delay) //工作完成输出信号延时关
- HL_OVEROUt_VAVLE = 0;
- if(HL_front_IN_DW)
- bCheckOK = 1;
- if(HL_bRunning)
- {
- if(yd_back_flg)
- {
- if(dwTickCount >= yd_delay_back)
- {
- yd_back_flg = 0;
- HL_YD_VAVLE = 0; //压带
- }
- }
- switch(HL_AutoStep)
- {
- case 1:
- HL_AutoStep = 2;
- SetEn(X_AXIS,HL_MOTOR_EN);
- HL_AutoDelay = dwTickCount + 300;
- break;
- case 2:
- if((dwTickCount >= HL_AutoDelay))
- {
- if(HL_MotorStep == 0)
- {////1为联机模式 //联网信号上 前机态拖带电机输出
- // if((!HL_PARAM_CONNECT_MODE))// || (!HL_STOP_IN && HL_front_IN && bCheckOK))//屏蔽部分为和前机有信号联动
- {
- HL_AutoStep = 3;
- HL_MotorStep = 1; //电机启动
- bCheckOK = 0;
- }
- // if((HL_front_IN_DW) && (work_Num == 0))
- // {
- // / work_Num++;
- // HL_OVEROUt_VAVLE = 1;
- // HL_Y15Delay = dwTickCount + 100;
- // }
- HL_CD_VAVLE = 0; //扯带电磁阀
- HL_SJ_VAVLE = 0; //松紧气缸
- }
- }
- break;
- case 3:
- if(HL_MotorStep == 0)
- {
- if(cDWflg | cHLflg)
- {
- HL_AutoDelay = dwTickCount + 150;
- HL_AutoStep =200;
-
- }
- else
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_TFK; // 延时推方块
- HL_AutoStep = 4;
- }
- }
- break;
- #if 0
- if((HL_front_IN_DW) && (work_Num == 0))
- {
- work_Num++;
- HL_OVEROUt_VAVLE = 1;
- HL_Y15Delay = dwTickCount + 100;
- }
- #endif
- case 4:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_TFK_VAVLE = 1; //推方块输出
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 5;
- }
- break;
- case 5:
- if(HL_TFK_LIMIT_IN) //推方块到位
- {
- HL_AutoStep = 6;
- //延时合模
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_HM;
- }
- else if(dwTickCount >= HL_AutoDelay)
- {
- HL_SetAlarmCode(HL_TFK_LIMIT_ALARM);
- }
- break;
- case 6:
-
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_HM_VAVLE = 1; //Y00 //合模
- HL_SJ_VAVLE = 1; //Y10 //松紧气缸
- HL_YD_VAVLE = 1; // 压带
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 7;
- }
- break;
- case 7:
- //上下模合模到位
- if(HL_SM_LIMIT_IN && HL_XM_LIMIT_IN)
- {
- HL_AutoStep = 8;
- //延时关推方块
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_TFK_BACK;
- }
- else if(dwTickCount >= HL_AutoDelay)
- {
- if(!HL_SM_LIMIT_IN)
- HL_SetAlarmCode(HL_SM_LIMIT_ALARM);
- else
- HL_SetAlarmCode(HL_XM_LIMIT_ALARM);
- }
- break;
- case 8:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_AutoStep = 9;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_TFK_VAVLE = 0;
- }
- break;
- case 9:
- if(!HL_TFK_LIMIT_IN)//HL_TFK_ORIGIN_IN) //推方块离开到位信号,回到原点
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_DK_UP;
- HL_AutoStep = 10;
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_TFK_ORIGIN_ALARM);
- break;
- case 10:
- if((dwTickCount >= HL_AutoDelay))
- {
- HL_DK_UP_VAVLE = 1; //Y03 //挡块上下
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 11;
- }
- break;
- case 11:
- // if(!HL_DK_UP_LIMIT_IN) //挡块上到位
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_DK_GO; //延时输出挡块前后
- HL_AutoStep = 100;
- }
- // else if(dwTickCount >= HL_AutoDelay)
- // HL_SetAlarmCode(HL_DK_UP_LIMIT_ALARM);
- break;
- case 100:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_DK_GO_VAVLE = 1; ////挡块前后输出
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 12;
- }
- break;
- case 12:
- if(HL_DK_LIMIT_IN && (!HL_DK_UP_LIMIT_IN) && HL_TFK_ORIGIN_IN)//挡块前后输出到位
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_BB;
- HL_YCX_VAVLE = 1; //压插销电磁阀
- // Y14 = 1;
- HL_YCXDelay = dwTickCount + HL_PARAM_YCX_TIME;
- HL_Y14Delay = dwTickCount + HL_PARAM_DELAY_Y14_BACK;
- HL_AutoStep = 13;
- }
- else if(dwTickCount >= HL_AutoDelay)
- {
- if(HL_DK_UP_LIMIT_IN)
- HL_SetAlarmCode(HL_DK_UP_LIMIT_ALARM);
- else if(!HL_TFK_ORIGIN_IN)
- HL_SetAlarmCode(HL_TFK_ORIGIN_ALARM);
- else
- HL_SetAlarmCode(HL_DK_LIMIT_ALARM);
- }
- break;
- case 13:
- if(dwTickCount >= HL_AutoDelay)
- {
- // if(HL_PARAM_BB_ENABLE == 0)
- HL_BB_VAVLE = 1; //摆臂输出
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 14;
- }
- break;
- case 14:
- // if(HL_PARAM_BB_ENABLE == 0)
- {
- if(HL_BB_LIMIT_IN)//摆臂到位
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
- HL_AutoStep = 15;
- if(HL_PARAM_CCX_MODE == 0) //气缸穿入
- {
- // AxisMovePosAccDec(X_AXIS,8,120,3,5,5);
- save_buff = dwRealPos;
- AxisMovePosAccDec(X_AXIS,HL_PARAM_CCX_SPEED,HL_PARAM_CCX_LENGTH,4,5,5);
- HL_AutoDelay = dwTickCount + 2;
- }
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
- }
- // else
- // {
- // HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_BB;
- // HL_AutoStep = 15;
- // }
- break;
- case 15:
- if(dwTickCount >= HL_AutoDelay)
- {
- if(HL_PARAM_CCX_MODE)////穿插销模式 1为电机穿 0为夹带气缸穿
- {
- if(HL_PARAM_BB_ENABLE) //后输出模式
- {
- HL_BB_VAVLE = 1;
- HL_AutoStep = 180;
- HL_AutoDelay = dwTickCount+HL_PARAM_DELAY_CCX;
- }
- else
- {
- if(!X_DRV)
- {
- AxisMovePosAccDec(X_AXIS,HL_PARAM_CCX_SPEED,HL_PARAM_CCX_LENGTH,1,5,5);
- HL_AutoDelay = dwTickCount;
- HL_AutoStep = 16;
- }
- }
- }
- else
- {
- if(HL_PARAM_BB_ENABLE)
- HL_BB_VAVLE = 1;
- //原来45
- if(((dwRealPos + 12) <= save_buff) || !X_DRV)
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
- HL_JD_VAVLE = 1;
- HL_AutoStep = 16;
- }
- }
- }
- break;
- case 180:
- if((dwTickCount >= HL_AutoDelay))
- {
- if(!X_DRV)
- AxisMovePosAccDec(X_AXIS,HL_PARAM_CCX_SPEED,HL_PARAM_CCX_LENGTH,1,5,5);
- HL_AutoDelay = dwTickCount;
- HL_AutoStep = 16;
- }
- break;
- case 16:
- if((dwTickCount >= HL_AutoDelay) && !HL_YCX_VAVLE)
- {
- if(HL_PARAM_CCX_MODE)
- {
- if(!X_DRV)
- {
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_CheckDelay = dwTickCount + HL_PARAM_DELAY_CHECK_CCX;
- HL_AutoStep = 17;
- if(HL_PARAM_CD_ENABLE) //1为带扯带功能
- HL_JD_VAVLE = 1;
- }
- }
- else
- {
- HL_CCX_VAVLE = 1;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_CheckDelay = dwTickCount + HL_PARAM_DELAY_CHECK_CCX;
- HL_AutoStep = 17;
- if(HL_PARAM_CD_ENABLE)
- HL_JD_VAVLE = 1;
- }
- }
- break;
- case 17:
- if((dwTickCount >= HL_CheckDelay))
- {
- if(HL_CCX_LIMIT_IN)
- {
- if(HL_PARAM_CCX_MODE)
- {
- HL_DK_UP_VAVLE = 0;
- HL_DK_GO_VAVLE = 0; ////挡块前后关
- // if(HL_PARAM_CD_ENABLE)
- // SetEn(X_AXIS,HL_MOTOR_DISEN);
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 18;
- }
- else
- {
- HL_DK_UP_VAVLE = 0;
- HL_DK_GO_VAVLE = 0; ////挡块前后关
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD_BACK;
- HL_AutoStep = 50;
- }
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_CCX_LIMIT_ALARM);
- }
- break;
- case 50:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_JD_VAVLE = 0;
- HL_AutoDelay = dwTickCount + 5;
- HL_AutoStep = 51;
- }
- break;
- case 51:
- if(dwTickCount >= HL_AutoDelay)
- {
- // if(!X_DRV)AxisMovePosAccDec(X_AXIS,HL_PARAM_CCX_SPEED,HL_PARAM_CCX_LENGTH,4,5,5);
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 18;
- }
- break;
- case 18:
- if(HL_DK_UP_LIMIT_IN && !X_DRV && ((HL_BB_LIMIT_IN && (HL_PARAM_BB_ENABLE == 0)) || (HL_PARAM_BB_ENABLE == 1)))
- {
- HL_CCX_VAVLE = 0;
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_BACK_DK_UP;
- HL_AutoStep = 19;
- }
- else if(dwTickCount >= HL_AutoDelay)
- {
- if(!HL_DK_UP_LIMIT_IN)HL_SetAlarmCode(HL_DK_UP_LIMIT_ALARM);
- else HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
- }
- break;
- case 19:
-
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_DK_GO_VAVLE = 0;
- if(!HL_PARAM_CCX_TIMES)
- {
- yd_back_flg = 1;
- yd_delay_back = dwTickCount + HL_PARAM_DELAY_YD_BACK;
- }
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 20;
- }
- break;
- case 20:
- if(HL_DK_ORIGIN_IN)
- {
- if(HL_PARAM_CCX_MODE)
- {
- HL_AutoDelay = dwTickCount;
-
- if(HL_PARAM_CD_ENABLE)
- HL_AutoStep = 21;
- else
- HL_AutoStep = 25;
- }
- else
- {
- if(!HL_PARAM_CCX_TIMES)
- {
- HL_AutoDelay = dwTickCount;
- HL_AutoStep = 25;
- }
- else
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD;
- HL_AutoStep = 21;
- }
- }
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_DK_ORIGIN_ALARM);
- break;
- case 21:
-
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_JD_VAVLE = 1;
- if(HL_PARAM_CD_ENABLE)
- {
- HL_AutoStep = 150;
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CD;
- }
- else
- {
- HL_AutoStep = 22;
- if(!HL_PARAM_CCX_MODE)HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
- }
- }
- break;
- case 150:
- if((dwTickCount >= HL_AutoDelay))
- {
- HL_CD_VAVLE = 1;
- if(!HL_PARAM_CCX_MODE)HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
- HL_AutoStep = 22;
- }
- break;
- case 22:
- if((dwTickCount >= HL_AutoDelay))
- {
- HL_CCX_VAVLE = 1;
- HL_AutoStep = 23;
- }
- break;
- case 23:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD_BACK;
- HL_AutoStep = 24;
- }
- break;
- case 24:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_JD_VAVLE = 0;
- // HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
- HL_AutoStep = 25;
- }
- break;
- case 25:
- if((dwTickCount >= HL_AutoDelay))
- {
- if(HL_PARAM_BB_ENABLE)HL_BB_VAVLE = 0;
- HL_CCX_VAVLE = 0;
- HL_JD_VAVLE = 0;
- yd_back_flg = 1;
- cErrorStop_Flg = 0;
- yd_delay_back = dwTickCount + HL_PARAM_DELAY_YD_BACK;
- if(cZCXflg)
- {
- cZCXflg = 0;
- HL_AutoStep = 0;
- HL_bRunning = 0;
- }
- else
- {
- HL_AutoStep = 26;
- }
- }
- break;
- case 26:
- if(HL_PARAM_CONNECT_MODE)
- {
- work_Num = 0;
- HL_OVEROUt_VAVLE = 1;
- HL_Y15Delay = dwTickCount + 100;
- }
- AddToTal(HL_TOTAL_ADDR);
- dwZipCnt++;
- if(GetTotal(HL_TOTAL_ADDR) >= HL_PARAM_SET_TOTAL)
- {
- HL_SetAlarmCode(HL_TOTAL_ALARM);
- }
- else
- {
- HL_AutoStep = 2;
- HL_AutoDelay = HL_PARAM_CYCLE_DELAY + dwTickCount;
- CalProSP(HL_PROSPEED_ADDR);
- }
- break;
- case 71:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_JD_VAVLE = 1;
- HL_DK_GO_VAVLE = 0;
- HL_AutoStep = 72;
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
- dk_up_delay = dwTickCount +HL_PARAM_DELAY_BACK_DK_UP;
- }
- break;
- case 72:
- if(dwTickCount >= HL_AutoDelay)
- {
- if(dwTickCount >= dk_up_delay)HL_DK_UP_VAVLE = 0;
- HL_CCX_VAVLE = 1;
- HL_AutoStep = 73;
- }
- break;
- case 73:
- if(dwTickCount >= HL_AutoDelay)
- {
- if(dwTickCount >= dk_up_delay)HL_DK_UP_VAVLE = 0;
- if(HL_CCX_LIMIT_IN)
- {
- HL_AutoDelay = dwTickCount;
- HL_AutoStep = 74;
- }
- }
- break;
- case 74:
- if(dwTickCount >= HL_AutoDelay)
- {
- if(dwTickCount >= dk_up_delay)HL_DK_UP_VAVLE = 0;
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD_BACK;
- HL_AutoStep = 75;
- }
- break;
- case 75:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_JD_VAVLE = 0;
- {
- HL_AutoStep = 76;
- HL_AutoDelay = dwTickCount;
- }
- }
- break;
- case 76:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
- HL_AutoStep = 77;
- }
- break;
- case 77:
- if(dwTickCount >= HL_AutoDelay)
- {
- HL_DK_UP_VAVLE = 0;
- HL_CCX_VAVLE = 0;
- yd_back_flg = 1;
- yd_delay_back = dwTickCount + HL_PARAM_DELAY_YD_BACK;
-
- if(HL_DK_UP_LIMIT_IN && (HL_DK_ORIGIN_IN))
- {
- if(cZCXflg)
- {
- cZCXflg = 0;
- HL_AutoStep = 0;
- HL_bRunning = 0;
- }
- else
- {
- HL_AutoStep = 26;
- }
- }
- }
- break;
- case 200:
-
- if(dwTickCount >= HL_AutoDelay)
- {
- cDWflg = 0;
- cHLflg = 0;
- HL_AutoStep = 0;
- HL_bRunning = 0;
- }
- break;
- }
- }
- }
- #endif
|