123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- #include "global.h"
- #if TONG_YONG_MACHINE
- void DK_InitAction(void);
- void DK_ChuiQi(void);
- void DK_Action(void);
- void DK_XiaChong(void);
- void DK_SetAlarmCode(unsigned alarm_code);
- void DK_StartStopAction(void);
- void DK_AutoRunStep(void);
- void DK_Motor(void);
- unsigned char DK_SingOneFlg = 0;
- void DK_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(DK_ALARM_ADDR,alarm_code);
- DK_bAlarmStop = 1;
- }
- void DK_InitAction(void)
- {
- float buff_pulse,buff_dist;
-
- buff_pulse = DK_PARAM_CYCLE_PULSE;
- buff_dist = DK_PARAM_CYCLE_LENGTH;
- XGearRatio = buff_pulse/buff_dist;
- }
- void DK_ChuiQi(void)
- {
- if(DK_CQ_VAVLE && (dwTickCount>=DK_CQ_Delay)) DK_CQ_VAVLE = 0;
- }
- //手动动作
- void DK_ManualAction(void)
- {
- if(!DK_bRunning)
- {
- //警告跳出
- if(bClearTotal)
- {
- bClearTotal = 0;
- ClrcToTal(DK_TOTAL_ADDR);
- }
- if(DK_bMotor)
- {
- if(!X_DRV)AxisContinueMove(X_AXIS,10,DK_DIR_N);
- }
- if(DK_bBackMotor)
- {
- if(!X_DRV)AxisContinueMove(X_AXIS,10,DK_DIR_P);
- }
-
- if(!DK_bMotor && !DK_bBackMotor)
- {
- if(X_DRV)AxisDecStop(X_AXIS);
- }
-
- if(DK_bGZ)
- {
- DK_bGZ = 0;
- DK_GZ_VAVLE = ~DK_GZ_VAVLE;
- }
-
- if(DK_GZSwitch_IN_UP)DK_GZ_VAVLE = 1;
- if(DK_GZSwitch_IN_DW)DK_GZ_VAVLE = 0;
-
- if(DK_bCQ)
- {
- DK_bCQ = 0;
- DK_CQ_Delay = dwTickCount + DK_PARAM_CQ_TIME;
- DK_CQ_VAVLE = 1;
- }
-
- if(DK_bXM)
- {
- DK_bXM = 0;
- DK_XM_VAVLE = ~DK_XM_VAVLE;
- }
- if(DK_bSM)
- {
- DK_bSM = 0;
- DK_SM_VAVLE = ~DK_SM_VAVLE;
- }
-
- if(DK_bRJ || DK_RJSwitch_IN_UP)
- {
- DK_bRJ = 0;
- if(DK_XiaChongStep==0)DK_XiaChongStep=1;
- }
- }
- }
- //打孔动作
- void DK_Action(void)
- {
- DK_ManualAction();
- DK_ChuiQi();
- DK_XiaChong();
- DK_StartStopAction();
- DK_AutoRunStep();
- DK_Motor();
- }
- //下冲动作
- void DK_XiaChong(void)
- {
- if(DK_XiaChongStep == 1)
- {
- DK_XiaChongDelay = dwTickCount + DK_PARAM_SM_DELAY;
- DK_XiaChongStep = 2;
- }
- else if((DK_XiaChongStep == 2)&& (dwTickCount >= DK_XiaChongDelay))
- {
- DK_SM_VAVLE = 1;
- DK_XiaChongStep = 3;
- DK_XiaChongDelay = dwTickCount + DK_VAVLE_ALARM_TIME;
- }
- else if(DK_XiaChongStep == 3)
- {
- if(DK_SM_LIMIT_IN)
- {
- DK_XiaChongStep = 4;
- }
- else if(dwTickCount >= DK_XiaChongDelay)
- DK_SetAlarmCode(DK_SM_LIMIT_ALARM);
- }
- else if(DK_XiaChongStep == 4)
- {
- if(DK_PARAM_XM_ENABLE)
- {
- DK_XiaChongDelay = dwTickCount + DK_PARAM_XM_DELAY;
- DK_XiaChongStep = 5;
- }
- else
- DK_XiaChongStep = 7;
- }
- else if((DK_XiaChongStep == 5) && (dwTickCount >= DK_XiaChongDelay))
- {
- DK_XM_VAVLE = 1;
- DK_XiaChongDelay = dwTickCount + DK_VAVLE_ALARM_TIME;
- DK_XiaChongStep = 6;
- }
- else if(DK_XiaChongStep == 6)
- {
- if(DK_XM_LIMIT_IN)
- {
- DK_XiaChongStep = 7;
- }
- else if(dwTickCount >= DK_XiaChongDelay)
- DK_SetAlarmCode(DK_XM_LIMIT_ALARM);
- }
- else if(DK_XiaChongStep == 7)
- {
- DK_XiaChongDelay = dwTickCount + DK_PARAM_CS_DELAY;
- DK_XiaChongStep = 8;
- }
- else if((DK_XiaChongStep == 8) && (dwTickCount >= DK_XiaChongDelay))
- {
- if(!DK_PARAM_CS_ENABLE)DK_CS_OUT = 1;
- DK_XiaChongDelay = dwTickCount + DK_PARAM_CS_TIME;
- DK_XiaChongStep = 9;
- }
- else if((DK_XiaChongStep == 9) && (dwTickCount >= DK_XiaChongDelay))
- {
- if(!DK_PARAM_CS_ENABLE)DK_CS_OUT = 0;
- DK_XiaChongDelay = dwTickCount + DK_PARAM_CS_COLD_TIME;
- DK_XiaChongStep = 10;
- }
- else if((DK_XiaChongStep == 10) && (dwTickCount >= DK_XiaChongDelay))
- {
- DK_SM_VAVLE = 0;
- if(DK_PARAM_XM_ENABLE)DK_XM_VAVLE = 0;
- DK_GZ_VAVLE = 0;
- DK_XiaChongStep = 11;
- DK_XiaChongDelay = dwTickCount + DK_VAVLE_ALARM_TIME;
- }
- else if((DK_XiaChongStep == 11))
- {
- if(!DK_SM_LIMIT_IN && !DK_XM_LIMIT_IN)
- {
- DK_XiaChongStep = 0;
- DK_XiaChongDelay = dwTickCount;
- }
- else if(dwTickCount >= DK_XiaChongDelay)
- {
- if(DK_SM_LIMIT_IN)
- DK_SetAlarmCode(DK_SM_LIMIT_ALARM);
- else
- DK_SetAlarmCode(DK_XM_LIMIT_ALARM);
- }
- }
- }
- //启动停止故障停止动作
- void DK_StartStopAction(void)
- {
- if(DK_bRunning)
- DK_PARAM_RUN_STATE = 1;
- else
- DK_PARAM_RUN_STATE = 0;
-
- if((START_IN_UP || DK_bStart || DK_bSingle) && !DK_bRunning && (DK_AutoStep ==0))
- {
- if(DK_GZ_VAVLE || DK_GZ_IN)DK_SetAlarmCode(DK_START_GZ_ALARM);
- else if(DK_SM_VAVLE || DK_SM_LIMIT_IN)DK_SetAlarmCode(DK_START_SM_ALARM);
- else if(DK_XM_VAVLE || DK_XM_LIMIT_IN)DK_SetAlarmCode(DK_START_XM_ALARM);
- else
- {
- if(DK_bSingle)
- {
- DK_SingOneFlg = 1;
- DK_bSingle = 0;
- }
- DK_AutoStep = 1;
- DK_bRunning = 1;
- DK_PROSPEED = 0;
- }
- DK_bStart = 0;
- DK_bSingle = 0;
- }
-
- /* if(DK_KaDai_IN && (GetAlarmCode(DK_ALARM_ADDR) == 0))
- {
- DK_SetAlarmCode(DK_KADAI_ALARM);
- }
- */
-
- if(STOP_IN_UP || DK_bStop)
- {
- DK_bStop = 0;
- if(DK_bRunning)
- {
- DK_bRunning = 0;
- DK_SingOneFlg = 0;
- DK_AutoStep = 0;
- DK_MotorStep = 0;
- AxisEgmStop(X_AXIS);
- }
- else
- {
- DK_bRunning = 0;
- DK_AutoStep = 0;
- DK_MotorStep = 0;
- DK_XiaChongStep = 0;
- DK_GZ_VAVLE = 0;
- DK_CQ_VAVLE = 0;
- DK_SM_VAVLE = 0;
- DK_XM_VAVLE = 0;
- DK_SZ_OUT = 1;
- DK_CS_OUT = 0;
- DK_SingOneFlg = 0;
- AxisEgmStop(X_AXIS);
- }
- }
-
- if(DK_bAlarmStop)
- {
- DK_bAlarmStop = 0;
- DK_bRunning = 0;
- DK_AutoStep = 0;
- DK_MotorStep = 0;
- DK_XiaChongStep = 0;
- DK_GZ_VAVLE = 0;
- DK_CQ_VAVLE = 0;
- DK_SM_VAVLE = 0;
- DK_XM_VAVLE = 0;
- DK_SZ_OUT = 1;
- DK_CS_OUT = 0;
- DK_SingOneFlg = 0;
- DK_PROSPEED = 0;
- AxisEgmStop(X_AXIS);
- DISPLAY_DATA4++;
- }
- }
- //电机动作
- void DK_Motor(void) //
- {
- static long save_buff,length_buff;
- DISPLAY_DATA0 = dwRealPos;
- if(DK_bRunning)dwRealPos = GetPos(X_AXIS);
-
- switch(DK_MotorStep)
- {
- case 0:
- break;
- case 1:
- if(DK_SZ_OUT)
- {
- DK_SZ_OUT = 0;
- DK_MotorDelay = dwTickCount + 100;
- }
- DK_MotorStep = 2;
- break;
- case 2:
- if(dwTickCount >= DK_MotorDelay)
- {
- if(!X_DRV)AxisContinueMove(X_AXIS,DK_PARAM_HIGH_SPEED,DK_DIR_N);
- DK_MotorDelay = dwTickCount + DK_PARAM_NO_ZIPPER_TIME;
- DK_MotorStep = 3;
- }
- break;
- case 3:
- if(DK_GuoLian_IN_UP)
- {
- if(X_DRV)AxisChangeSpeed(X_AXIS,DK_PARAM_LOW_SPEED);
- DK_MotorStep = 4;
- DK_MotorDelay = dwTickCount + DK_PARAM_GZ_DELAY;
- }
- else if(dwTickCount >= DK_MotorDelay)
- DK_SetAlarmCode(DK_GUOLIAN_ALARM);
- break;
- case 4:
- if(dwTickCount >= DK_MotorDelay)
- {
- DK_GZ_VAVLE = 1;
- DK_CQ_Delay = dwTickCount + DK_PARAM_CQ_TIME;
- DK_CQ_VAVLE = 1;
- DK_MotorDelay = dwTickCount + DK_VAVLE_ALARM_TIME;
- DK_MotorStep = 5;
- }
- break;
- case 5:
- if(DK_GZ_IN)
- {
- save_buff = dwRealPos;
- DK_MotorStep = 6;
- }
- else if(dwTickCount >= DK_MotorDelay)
- DK_SetAlarmCode(DK_GZ_ALARM);
- break;
- case 6:
- if(dwRealPos >= (DK_PARAM_DELAY_STOP_MOTOR + save_buff))
- {
- AxisEgmStop(X_AXIS);
- DK_MotorStep = 7;
- }
- break;
- case 7:
- if(!X_DRV)
- {
- DK_MotorStep = 8;
- }
- break;
- case 8:
- {
- DK_MotorDelay = dwTickCount;
- DK_MotorStep = 0;
- }
- break;
- }
- }
- //自动运行动作
- void DK_AutoRunStep(void)
- {
- DISPLAY_DATA0 = DK_XiaChongStep;
- DISPLAY_DATA1 = DK_ManualStep;
- DISPLAY_DATA2 = DK_MotorStep;
- DISPLAY_DATA3 = DK_AutoStep;
- if(DK_bRunning)
- {
- if(DK_AutoStep == 1)
- {
- DK_AutoStep = 2;
- }
- else if((DK_AutoStep == 2) && (dwTickCount >= DK_AutoDelay))
- {
- if(DK_MotorStep == 0)
- {
- DK_MotorStep = 1;
- DK_AutoStep = 3;
- }
- }
- else if(DK_AutoStep == 3)
- {
- if(DK_MotorStep == 0)
- {
- DK_AutoStep = 4;
- }
- }
- else if(DK_AutoStep == 4)
- {
- DK_AutoStep = 5;
- }
- else if(DK_AutoStep == 5)
- {
- if(DK_MotorStep == 0)
- {
- if(DK_SingOneFlg)
- {
- DK_AutoStep = 0;
- DK_bRunning = 0;
- DK_SingOneFlg = 0;
- }
- else
- DK_AutoStep = 6;
- }
- }
- else if(DK_AutoStep == 6)
- {
- if(DK_XiaChongStep == 0)
- {
- DK_XiaChongStep = 1;
- DK_AutoStep = 7;
- }
- }
- else if(DK_AutoStep == 7)
- {
- if(DK_XiaChongStep == 0)
- {
- DK_AutoStep = 8;
- }
- }
- else if(DK_AutoStep == 8)
- {
- AddToTal(DK_TOTAL_ADDR);
- AddToTal(DK_ALLTOTAL_ADDR);
- {
- DK_AutoStep = 2;
- DK_AutoDelay = DK_PARAM_CYCLE_DELAY + dwTickCount;
- CalProSP(DK_PROSPEED_ADDR);
- }
- }
- }
- }
- #endif
|