123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- #include "global.h"
- #if XI_DONG_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);
- unsigned char cDWflg=0,cZCXflg=0,cHLflg=0,HL_StopFlg;
- short *offset_length_buff;
- unsigned char HL_X02_IN_FLAG,HL_X02_IN_FLAG_OLD;
- unsigned short HL_X02_FILTER;
- void HL_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(HL_ALARM_ADDR,alarm_code);
- HL_bAlarmStop = 1;
- }
- void HL_InitAction(void)
- {
- CalFreqTab_X_Free(14);
- XGearRatio = 1;
- HL_X02_IN_FLAG = HL_GUO_LIAN_IN;
- HL_X02_IN_FLAG_OLD = HL_X02_IN_FLAG;
- }
- //手动动作
- 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;
- HL_HM_VAVLE = ~HL_HM_VAVLE;
- }
- 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_bJD)
- {
- HL_bJD = 0;
- HL_JD_VAVLE = ~HL_JD_VAVLE;
- }
- if(HL_bCCX)
- {
- HL_bCCX = 0;
- HL_CCX_VAVLE = ~HL_CCX_VAVLE;
- }
-
- if(HL_bSL)
- {
- HL_bSL = 0;
- HL_SL_MOTOR = ~HL_SL_MOTOR;
- }
-
- if(HL_bDK)
- {
- HL_bDK = 0;
- HL_DK_VAVLE = ~HL_DK_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)
- {
- HL_ManualAction();
- HL_StartStopAction();
- HL_Motor();
- HL_Step();
- HL_AutoRunStep();
- }
- //启动停止故障停止动作
- void HL_StartStopAction(void)
- {
- static unsigned long dwstop_cnt = 0;
- if((START_IN_UP || HL_bStart || HL_bSingStart || HL_bDW || HL_bZCX || HL_bHL) && !HL_bRunning && (HL_AutoStep ==0))
- {
- if(!HL_CCX_LIMIT_IN)HL_SetAlarmCode(HL_CCX_LIMIT_ALARM);
- else if(!HL_CCX_ORIGIN_IN)HL_SetAlarmCode(HL_CCX_ORIGIN_ALARM);
- else
- {
- SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- HL_bRunning = 1;
- HL_StopFlg = 0;
- dwZipCnt = 0;
- if(HL_bSingStart)
- {
- HL_bSingStart = 0;
- SingOneFlg = 1;
- }
-
- if(HL_bDW)
- {
- cDWflg = 1;
- dwZipCnt = 1;
- }
- if(HL_bZCX)cZCXflg = 1;
- if(HL_bHL)cHLflg = 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_JD_VAVLE = 0;
- HL_CCX_VAVLE = 0;
- HL_DK_VAVLE = 0;
- HL_SL_MOTOR = 0;
- HL_bRunning = 0;
- HL_AutoStep = 0;
- HL_MotorStep = 0;
- SingOneFlg = 0;
- HL_bMotor = 0;
- cDWflg = 0;
- cZCXflg = 0;
- cHLflg = 0;
- AxisEgmStop(X_AXIS);
- SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- HL_StopFlg = 1;
- }
- }
-
- if(STOP_IN_UP)
- {
- if(HL_bRunning)
- {
- HL_bStop = 0;
- HL_DK_VAVLE = 0;
- HL_JD_VAVLE = 0;
- HL_CCX_VAVLE = 0;
- HL_SL_MOTOR = 0;
- HL_bRunning = 0;
- HL_AutoStep = 0;
- HL_MotorStep = 0;
- HL_HLStep = 0;
- SingOneFlg = 0;
- HL_bMotor = 0;
- cDWflg = 0;
- cZCXflg = 0;
- cHLflg = 0;
- SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- AxisEgmStop(X_AXIS);
- }
- else
- {
- HL_bStop = 0;
- HL_DK_VAVLE = 0;
- HL_JD_VAVLE = 0;
- HL_CCX_VAVLE = 0;
- HL_SL_MOTOR = 0;
- HL_bRunning = 0;
- HL_AutoStep = 0;
- HL_MotorStep = 0;
- HL_HLStep = 0;
- SingOneFlg = 0;
- HL_bMotor = 0;
- cDWflg = 0;
- cZCXflg = 0;
- cHLflg = 0;
- SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- AxisEgmStop(X_AXIS);
- HL_HM_VAVLE = 0;
- HL_StopFlg = 1;
- }
- }
-
- if(HL_StopFlg)
- {
- if(!HL_SM_LIMIT_IN && !HL_XM_LIMIT_IN)
- {
- HL_BB_VAVLE = 0;
- HL_TFK_VAVLE = 0;
- HL_StopFlg = 0;
- }
- }
- if(HL_bAlarmStop)
- {
- 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;
- }
-
- if(HL_KA_DAI_IN)
- {
- HL_SetAlarmCode(HL_KD_ALARM);
- }
- else
- {
- // if(GetAlarmCode(HL_ALARM_ADDR) == HL_KD_ALARM)SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
- }
- }
- 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((dwRealPos + HL_PARAM_DELAY_HM_BACK) <= hm_save_buff)
- {
- HL_HM_VAVLE = 0;
- HL_HLDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_HLStep = 3;
- }
- else if(!X_DRV)HL_SetAlarmCode(HL_HM_BACK_ALARM);
- 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;
- }
- 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_Motor(void) //
- {
- static long save_buff,hm_save_buff;
-
- DISPLAY_DATA0 = dwRealPos;
- DISPLAY_DATA1 = HL_AutoStep;
- DISPLAY_DATA2 = HL_MotorStep;
- DISPLAY_DATA3 = HL_HLStep;
-
- HL_X02_IN_FLAG_OLD = HL_X02_IN_FLAG;
-
- if(HL_GUO_LIAN_IN)
- {
- if(HL_X02_FILTER < HL_PARAM_FILTER_TIMES)
- {
- HL_X02_FILTER++;
- }
- else
- HL_X02_IN_FLAG = 1;
- }
- else if(HL_X02_FILTER > (HL_PARAM_FILTER_TIMES/2))
- {
- HL_X02_FILTER--;
- }
- else
- HL_X02_IN_FLAG = 0;
-
- dwRealPos = GetPos(X_AXIS);
- switch(HL_MotorStep)
- {
- case 0:break;
- case 1:
- if(GetEn(X_AXIS) == 0)
- {
- SetEn(X_AXIS,HL_MOTOR_EN);
- HL_MotorDelay = dwTickCount + 100;
- }
- HL_MotorStep = 2;
- break;
- case 2:
- if(dwTickCount >= HL_MotorDelay)
- {
- HL_MotorDelay = dwTickCount + HL_PARAM_MOTOR_ALARM_TIME;
-
- if(!HL_GUO_LIAN_IN)
- {
- MoveAction_Const_AccDec(X_AXIS,HL_DIR_P,HL_PARAM_LOW_SPEED,1,5,1);
- HL_MotorStep = 4;
- }
- else
- {
- if(dwZipCnt == 0)
- MoveAction_Const_AccDec(X_AXIS,HL_DIR_P,HL_PARAM_HIGH_SPEED/2,1,5,1);
- else
- MoveAction_Const_AccDec(X_AXIS,HL_DIR_P,HL_PARAM_HIGH_SPEED,1,5,1);
- HL_MotorStep = 3;
- }
-
- if(HL_HM_VAVLE)
- {
- *offset_length_buff = 0;
- if(HL_HLStep == 0)HL_HLStep = 1;
- }
- else
- {
- *offset_length_buff = 0;
- // offset_length_buff = &user_datas[22];
- }
- }
- break;
- case 3:
- if(HL_GUO_LIAN_IN_DW)
- {
- AxisChangeSpeed(X_AXIS,HL_PARAM_LOW_SPEED);
- HL_MotorDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_MotorStep = 4;
- }
- else if((dwTickCount >= HL_MotorDelay) || HL_GUO_LIAN_IN_UP)
- HL_SetAlarmCode(HL_GUOLIAN_ALARM);
- break;
- case 4:
- if((HL_X02_IN_FLAG && !HL_X02_IN_FLAG_OLD))
- {
- save_buff = dwRealPos;
- HL_MotorStep = 5;
- }
- else if(dwTickCount >= HL_MotorDelay)
- HL_SetAlarmCode(HL_GUOLIAN_ALARM);
- break;
- case 5:
- if((dwRealPos + HL_PARAM_DELAY_STOP) <= save_buff)
- {
- AxisEgmStop(X_AXIS);
- HL_MotorStep = 6;
- }
- break;
- case 6:
- if(!X_DRV && (HL_HLStep == 0))
- {
- HL_MotorStep = 0;
- HL_MotorDelay = dwTickCount;
- }
- break;
- }
- }
- //自动运行动作
- void HL_AutoRunStep(void)
- {
- if(HL_bRunning)
- {
- if(HL_AutoStep == 1)
- {
- HL_AutoStep = 2;
- }
- else if((HL_AutoStep == 2) && (dwTickCount >= HL_AutoDelay))
- {
- if(HL_MotorStep == 0)
- {
- HL_AutoStep = 3;
- HL_MotorStep = 1;
- }
- }
- else if(HL_AutoStep == 3)
- {
- if(HL_MotorStep == 0)
- {
- if(cDWflg | cHLflg)
- {
- cDWflg = 0;
- cHLflg = 0;
- HL_AutoStep = 0;
- HL_bRunning = 0;
- }
- else
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_TFK;
- HL_AutoStep = 4;
- }
- }
- }
- else if((HL_AutoStep == 4) && (dwTickCount >= HL_AutoDelay))
- {
- HL_TFK_VAVLE = 0;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 5;
- }
- else if(HL_AutoStep == 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);
- }
- }
- else if((HL_AutoStep == 6) && (dwTickCount >= HL_AutoDelay))
- {
- HL_HM_VAVLE = 1;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 7;
- }
- else if(HL_AutoStep == 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);
- }
- }
- else if((HL_AutoStep == 8) && (dwTickCount >= HL_AutoDelay))
- {
- HL_AutoStep = 9;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_TFK_VAVLE = 1;
- }
- else if(HL_AutoStep == 9)
- {
- if(HL_TFK_ORIGIN_IN)
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_DK;
- HL_AutoStep = 10;
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_TFK_ORIGIN_ALARM);
- }
- else if((HL_AutoStep == 10) && (dwTickCount >= HL_AutoDelay))
- {
- HL_AutoStep = 11;
- }
- else if(HL_AutoStep == 11)
- {
- HL_DK_VAVLE = 1;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 12;
- }
- else if(HL_AutoStep == 12)
- {
- if(HL_DK_LIMIT_IN)
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_BB;
- HL_AutoStep = 13;
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_DK_LIMIT_ALARM);
- }
- else if((HL_AutoStep == 13) && (dwTickCount >= HL_AutoDelay))
- {
- HL_BB_VAVLE = 1;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 14;
- }
- else if(HL_AutoStep == 14)
- {
- if(HL_BB_LIMIT_IN)
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD;
- HL_AutoStep = 15;
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
- }
- else if((HL_AutoStep == 15) && (dwTickCount >= HL_AutoDelay))
- {
- HL_JD_VAVLE = 1;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 16;
- }
- else if(HL_AutoStep == 16)
- {
- if(HL_JD_LIMIT_IN)
- {
- HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
- HL_AutoStep = 17;
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_JD_LIMIT_ALARM);
- }
- else if((HL_AutoStep == 17) && (dwTickCount >= HL_AutoDelay))
- {
- HL_CCX_VAVLE = 1;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_CheckDelay = dwTickCount + HL_PARAM_DELAY_CHECK_CCX;
- HL_AutoStep = 18;
- }
- else if((HL_AutoStep == 18) && (dwTickCount >= HL_CheckDelay))
- {
- if(HL_CCX_LIMIT_IN)
- {
- if(!X_DRV)AxisMovePosAccDec(X_AXIS,HL_PARAM_LOW_SPEED,HL_PARAM_CCX_LENGTH,1,5,5);
- HL_JD_VAVLE = 0;
- HL_DK_VAVLE = 0;
- HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
- HL_AutoStep = 19;
- }
- else if(dwTickCount >= HL_AutoDelay)
- HL_SetAlarmCode(HL_CCX_LIMIT_ALARM);
- }
- else if(HL_AutoStep == 19)
- {
- if(HL_DK_ORIGIN_IN && !HL_JD_LIMIT_IN && !X_DRV)
- {
- HL_CCX_VAVLE = 0;
- HL_AutoStep = 20;
- }
- else if(dwTickCount >= HL_AutoDelay)
- {
- if(!HL_DK_ORIGIN_IN)
- HL_SetAlarmCode(HL_DK_ORIGIN_ALARM);
- else
- HL_SetAlarmCode(HL_CCX_ORIGIN_ALARM);
- }
- }
- else if(HL_AutoStep == 20)
- {
- HL_AutoStep = 21;
- }
- else if(HL_AutoStep == 21)
- {
- HL_AutoStep = 22;
- }
- else if(HL_AutoStep == 22)
- {
- HL_AutoStep = 23;
- }
- else if(HL_AutoStep == 23)
- {
- HL_AutoDelay = dwTickCount;
- HL_AutoStep = 24;
- }
- else if(HL_AutoStep == 24)
- {
- if(cZCXflg)
- {
- cZCXflg = 0;
- HL_AutoStep = 0;
- HL_bRunning = 0;
- }
- else
- {
- HL_AutoStep = 25;
- }
- }
- else if(HL_AutoStep == 25)
- {
- AddToTal(HL_TOTAL_ADDR);
- dwZipCnt++;
- HL_AutoStep = 2;
- HL_AutoDelay = HL_PARAM_CYCLE_DELAY + dwTickCount;
- CalProSP(HL_PROSPEED_ADDR);
- }
- }
- }
- #endif
|