123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- #include "global.h"
- #if YOU_GUAN_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);
- 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_XC_ORIGIN_IN_UP)
- {
- DK_CQ_VAVLE = 1;
- DK_CQ_Delay = dwTickCount + DK_PARAM_CQ_TIME;
- }
-
- 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,DK_PARAM_HIGH_SPEED,DK_DIR_N);
- }
- if(DK_bBackMotor)
- {
- if(!X_DRV)AxisContinueMove(X_AXIS,DK_PARAM_HIGH_SPEED,DK_DIR_P);
- }
-
- if(!DK_bMotor && !DK_bBackMotor)
- {
- if(X_DRV)AxisDecStop(X_AXIS);
- }
-
- if(DK_bCQ)
- {
- DK_bCQ = 0;
- DK_CQ_VAVLE = 1;
- DK_CQ_Delay = dwTickCount + DK_PARAM_CQ_TIME;
- }
-
-
- if(DK_bManXiaChong || (DK_MANAL_XC_IN && !DK_MANAL_XC_IN_UP))
- {
- DK_bManXiaChong = 0;
-
- if(DK_XiaChongStep == 0)
- {
- DK_XiaChongStep = 1;
- }
- }
-
-
- }
- }
- //打孔动作
- void DK_Action(void)
- {
- DISPLAY_DATA0 = GetEncodeCount();
- DK_ManualAction();
- DK_ChuiQi();
- DK_XiaChong();
- DK_StartStopAction();
- DK_AutoRunStep();
- DK_Motor();
- }
- //下冲动作
- void DK_XiaChong(void)
- {
- if(DK_XiaChongStep == 1)
- {
- if(DK_bRunning)DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_DELAY + 50;
- else
- DK_XiaChongDelay = dwTickCount + 50;
-
- DK_SC_VAVLE = 0;
- DK_XiaChongStep = 2;
- }
- else if((DK_XiaChongStep == 2) && (dwTickCount >= DK_XiaChongDelay))
- {
- DK_XC_MOTOR = 1;
- if(DK_bRunning)DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_ALARM_TIME;
- else
- DK_XiaChongDelay = dwTickCount + 5000;
-
- DK_XiaChongStep = 3;
- }
- else if(DK_XiaChongStep == 3)
- {
- if(DK_XC_ORIGIN_IN_UP)
- {
- DK_XC_MOTOR = 0;
- if(DK_bRunning)DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_DELAY_STOP_TIME;
- else
- DK_XiaChongDelay = dwTickCount + 10;
- DK_XiaChongStep = 4;
- }
- else if(dwTickCount >= DK_XiaChongDelay)
- {
- DK_SC_VAVLE = 1;
- DK_XC_MOTOR = 0;
- DK_SetAlarmCode(DK_XM_LIMIT_ALARM);
- }
- }
- else if((DK_XiaChongStep == 4) && (dwTickCount >= DK_XiaChongDelay))
- {
- DK_SC_VAVLE = 1;
- DK_XiaChongStep = 0;
- }
- else if((DK_XiaChongStep == 5) && (dwTickCount >= DK_XiaChongDelay))
- {
- DK_SC_VAVLE = 0;
- DK_XiaChongStep = 0;
- }
- }
- //启动停止故障停止动作
- void DK_StartStopAction(void)
- {
- if((START_IN_UP || DK_bStart) && !DK_bRunning && (DK_AutoStep ==0))
- {
- if(GetTotal(DK_TOTAL_ADDR) >= SET_TOTAL)DK_SetAlarmCode(DK_TOTAL_ALARM);
- else
- {
- DK_AutoStep = 1;
- DK_bRunning = 1;
- DK_AutoDelay = 0;
- }
- DK_bStart = 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 && (SingOneFlg == 0))
- {
- SingOneFlg = 1;
- }
- else
- {
- DK_CQ_VAVLE = 0;
- DK_bRunning = 0;
- DK_AutoStep = 0;
- AxisEgmStop(X_AXIS);
- }
- }
-
- if(DK_bAlarmStop)
- {
- DK_bAlarmStop = 0;
- AxisEgmStop(X_AXIS);
- DK_AutoStep = 0;
- DK_XiaChongStep = 0;
- DK_bRunning = 0;
- SingOneFlg = 0;
- }
- }
- //电机动作
- void DK_Motor(void) //
- {
- static long save_buff,length_buff;
-
- switch(DK_MotorStep)
- {
- case 0:
- break;
- case 1:
- QD_MotorStep = 2;
- break;
- case 2:
- if(!X_DRV)AxisMoveTwoPos(X_AXIS,DK_PARAM_HIGH_SPEED,(DK_PARAM_ZIPRER_LENGTH - DK_PARAM_LOWSPEED_LENGTH),DK_PARAM_LOW_SPEED,DK_PARAM_LOWSPEED_LENGTH,DK_DIR_N);
- QD_MotorStep = 3;
- break;
- case 3:
- if(!X_DRV)
- {
- QD_MotorStep = 0;
- }
- break;
- case 10:
- QD_MotorStep = 11;
- break;
- case 11:
- QD_MotorStep = 12;
- if(!X_DRV)AxisMovePos(X_AXIS,DK_PARAM_HIGH_SPEED,-DK_PARAM_BACK_LENGTH);
- break;
- case 12:
- if(!X_DRV)
- {
- QD_MotorStep = 0;
- }
- break;
- }
- }
- //自动运行动作
- void DK_AutoRunStep(void)
- {
- if(DK_bRunning)
- {
- if(DK_AutoStep == 1)
- {
- DK_AutoStep = 2;
- }
- else if((DK_AutoStep == 2) && (dwTickCount >= DK_AutoDelay))
- {
- if(QD_MotorStep == 0)QD_MotorStep = 1;
- DK_AutoStep = 3;
- }
- else if(DK_AutoStep == 3)
- {
- if(QD_MotorStep == 0)
- {
- DK_AutoStep = 4;
- }
- }
- else if(DK_AutoStep == 4)
- {
- if(QD_MotorStep == 0)QD_MotorStep = 10;
- DK_AutoStep = 5;
- }
- else if(DK_AutoStep == 5)
- {
- if(QD_MotorStep == 0)
- {
- DK_AutoStep = 6;
- }
- }
- else if(DK_AutoStep == 6)
- {
- if(DK_XiaChongStep == 0)
- {
- DK_XiaChongStep = 1;
- DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_DELAY;
- }
- DK_AutoStep = 7;
- }
- else if(DK_AutoStep == 7)
- {
- if(DK_XiaChongStep == 0)
- {
- DK_AutoStep = 8;
- }
- }
- else if(DK_AutoStep == 8)
- {
- AddToTal(DK_TOTAL_ADDR);
- if((GetTotal(DK_TOTAL_ADDR) >= DK_PARAM_SET_TOTAL) || SingOneFlg)
- {
- if(SingOneFlg)
- {
- DK_AutoStep = 0;
- DK_bRunning = 0;
- SingOneFlg = 0;
- }
- else
- {
- DK_SetAlarmCode(DK_TOTAL_ALARM);
- }
- }
- else
- {
- DK_AutoStep = 2;
- DK_AutoDelay = DK_PARAM_CYCLE_DELAY + dwTickCount;
- CalProSP(DK_PROSPEED_ADDR);
- }
- }
- }
- }
- #endif
|