123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- #include "global.h"
- #if JIA_CHENG_WEI_YE_MACHINE
- void HuaXian_AlarmProtect(void);
- void HuaXian_ManualAction(void);
- void HuaXian_AutoAction(void);
- void HuaXian_StepCheckStart(void);
- void HuaXian_Motor(void);
- void HuaXian_ActionStep(void);
- static unsigned long cZipCnt = 0;
- static unsigned short cHuaXianTimesCnt = 0;
-
- void HX_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(HX_ALARM_ADDR,alarm_code);
- bAlarmStop = 1;
- }
- void HuaXian_InitAction(void)
- {
- float length_buff,pulse_buff;
-
- length_buff = HX_PARAM_CYCLE_LENGTH;
- pulse_buff = HX_PARAM_CYCLE_PULSE;
- XGearRatio = pulse_buff/length_buff;
-
- CalFreqTab_X_Free(15);
- HX_SZ_OUT = 1;
- }
- void HuaXian_Action(void)
- {
- HuaXian_AlarmProtect();
- HuaXian_Motor();
- HuaXian_ManualAction();
- HuaXian_ActionStep();
- HuaXian_AutoAction();
- HuaXian_StepCheckStart(); // 调用脚踏开关检测程序
- }
- //手动动作
- void HuaXian_ManualAction(void)
- {
- if(bRunning == 0)
- {
- if(HX_bClearTotal) //切断计数清零
- {
- HX_bClearTotal = 0;
- ClrcToTal(HX_TOTAL_ADDR);
- }
-
- if(HX_bDown)
- {
- HX_bDown = 0;
- HX_DOWN_VAVLE = ~HX_DOWN_VAVLE;
- }
-
- if(HX_bHX)
- {
- HX_bHX = 0;
- HX_HX_VAVLE = ~HX_HX_VAVLE;
- }
-
- if(HX_bGZ)
- {
- HX_bGZ = 0;
- HX_GZ_VAVLE = ~HX_GZ_VAVLE;
- }
-
- if(HX_bHXRun)
- {
- HX_bHXRun = 0;
- if(HX_HuaXianStep==0)HX_HuaXianStep=1;
- }
-
- //电机控制
- if(HX_bGoMotor)
- {
- HX_SZ_OUT = 0;
- if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, HX_DIR_N, 5,1,5,30);
- }
-
- if(HX_bBackMotor)
- {
- HX_SZ_OUT = 0;
- if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, HX_DIR_P, 5,1,5,30);
- }
-
- if(!HX_bGoMotor && !HX_bBackMotor && (HX_MotorStep == 0))
- {
- if(X_DRV)AxisDecStop(X_AXIS);
- }
-
- }
- }
- void HuaXian_AlarmProtect(void)
- {
- dwRealPos = GetPos(X_AXIS);
- }
- void HuaXian_ActionStep(void)
- {
- switch(HX_HuaXianStep)
- {
- case 0:break;
- case 1:
- HX_HuaXianStep = 2;
- HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
- break;
- case 2:
- if(HX_DOWN_UP_IN)
- {
- HX_HuaXianStep = 3;
- HX_HXDelay = dwTickCount+HX_PARAM_DELAY_DOWN;
- }
- else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_UP_ALARM);
- break;
- case 3:
- if(dwTickCount >= HX_HXDelay)
- {
- HX_DOWN_VAVLE = 1;
- HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
- HX_HuaXianStep = 4;
- }
- break;
- case 4:
- if(HX_DOWN_DOWN_IN)
- {
- HX_HuaXianStep = 5;
- HX_HXDelay = dwTickCount+HX_PARAM_DELAY_HX;
- }
- else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_DOWN_ALARM);
- break;
- case 5:
- if(dwTickCount >= HX_HXDelay)
- {
- HX_HX_VAVLE = 1;
- HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
- HX_HuaXianStep = 6;
- }
- break;
- case 6:
- if(HX_HX_LIMIT_IN)
- {
- HX_HuaXianStep = 7;
- HX_HXDelay = dwTickCount+HX_PARAM_DELAY_DOWNBACK;
- }
- else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_HX_LIMIT);
- break;
- case 7:
- if(dwTickCount >= HX_HXDelay)
- {
- HX_DOWN_VAVLE = 0;
- HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
- HX_HuaXianStep = 8;
- }
- break;
- case 8:
- if(!HX_DOWN_DOWN_IN)
- {
- HX_HuaXianStep = 9;
- HX_HXDelay = dwTickCount+HX_PARAM_DELAY_HXBACK;
- }
- else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_DOWN_ALARM);
- break;
- case 9:
- if(dwTickCount >= HX_HXDelay)
- {
- HX_HX_VAVLE = 0;
- cHuaXianTimesCnt++;
- if((cHuaXianTimesCnt >= HX_PARAM_HX_TIMES) || !bRunning)HX_GZ_VAVLE = 0;
-
- HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
- HX_HuaXianStep = 10;
- }
- else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_HX_LIMIT);
- break;
- case 10:
- if(HX_DOWN_UP_IN && HX_HX_ORIGIN_IN)
- {
- if((cHuaXianTimesCnt >= HX_PARAM_HX_TIMES) || !bRunning)
- {
- HX_HuaXianStep = 0;
- HX_HXDelay = dwTickCount;
- }
- else
- {
- HX_HuaXianStep = 1;
- HX_HXDelay = dwTickCount;
- }
- }
- else if(dwTickCount >= HX_HXDelay)
- {
- if(!HX_DOWN_UP_IN)
- HX_SetAlarmCode(HX_DW_UP_ALARM);
- else
- HX_SetAlarmCode(HX_HX_ORIGIN);
- }
- break;
- default:;
- }
- }
- void HuaXian_AutoAction(void)
- {
- if(bRunning)
- {
- switch(HX_AutoStep)
- {
- case 1:
- if(dwTickCount >= HX_AutoDelay)
- {
- if(HX_MotorStep == 0)
- {
- HX_MotorStep = 30;
- HX_AutoStep = 2;
- }
- }
- break;
- case 2:
- if(HX_MotorStep == 0)
- {
- HX_AutoStep = 3;
- }
- break;
- case 3:
- if(HX_HuaXianStep == 0)
- {
- cHuaXianTimesCnt = 0;
- HX_HuaXianStep = 1;
- HX_AutoStep = 4;
- }
- break;
- case 4:
- if(HX_HuaXianStep == 0)
- {
- HX_AutoStep = 5;
- }
- break;
- case 5:
- cZipCnt++;
- AddToTal(HX_TOTAL_ADDR);
- CalProSP(HX_PROSPEED_ADDR);
-
-
- if((GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) || SingOneFlg)
- {
- bRunning = 0;
- HX_AutoStep = 0;
- SingOneFlg = 0;
-
- if(GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) HX_SetAlarmCode(HX_TOTAL_ALARM);
- }
- else
- {
- HX_AutoStep = 1;
- HX_AutoDelay = dwTickCount + HX_PARAM_DELAY_DELAY_START;
- }
- break;
- }
- }
- }
- void HuaXian_StepCheckStart(void)
- {
- // 启动
- if((START_IN_UP) || bStart || HX_bSingle)
- {
- bStart = 0;
-
- if(!bRunning && (HX_AutoStep == 0))
- {
- if(!HX_DOWN_UP_IN)HX_SetAlarmCode(HX_DW_UP_ALARM);
- else if(!HX_HX_ORIGIN_IN)HX_SetAlarmCode(HX_HX_ORIGIN);
- else if(HX_GOUZHEN_IN)HX_SetAlarmCode(HX_GZ_ALARM);
- else if(HX_GZ_VAVLE)HX_SetAlarmCode(HX_GZ_OUT_ALARM);
- else if(GetAlarmCode(HX_ALARM_ADDR) != 0);
- else if(GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) HX_SetAlarmCode(HX_TOTAL_ALARM);
- else
- {
- bRunning = 1;
- HX_AutoStep = 1;
- if(HX_bSingle) SingOneFlg= 1;
- cZipCnt = 0;
- }
- }
- HX_bSingle = 0;
- }
- //停止
- if(STOP_IN_UP || bStop)
- {
- bStop = 0;
-
- if(bRunning)
- {
- bRunning = 0;
- HX_AutoStep = 0;
- HX_MotorStep = 0;
- HX_HuaXianStep=0;
-
- HX_AutoDelay = dwTickCount;
- HX_MotorDelay = dwTickCount;
- HX_HXDelay = dwTickCount;
- SingOneFlg = 0;
- AxisDecStop(X_AXIS);
- }
- else
- {
- bRunning = 0;
- HX_AutoStep = 0;
- HX_MotorStep = 0;
- HX_HuaXianStep=0;
-
- HX_AutoDelay = dwTickCount;
- HX_MotorDelay = dwTickCount;
- HX_HXDelay = dwTickCount;
- SingOneFlg = 0;
- HX_GZ_VAVLE = 0;
- HX_DOWN_VAVLE = 0;
- HX_HX_VAVLE = 0;
- HX_SZ_OUT = 1;
- AxisDecStop(X_AXIS);
- if(GetAlarmCode(HX_ALARM_ADDR) != 0)SetAlarmCode(HX_ALARM_ADDR,0);
- }
- }
-
- if(bAlarmStop)
- {
- bAlarmStop = 0;
- bRunning = 0;
- HX_AutoStep = 0;
- HX_MotorStep = 0;
- HX_HuaXianStep=0;
-
- HX_AutoDelay = dwTickCount;
- HX_MotorDelay = dwTickCount;
- HX_HXDelay = dwTickCount;
- SingOneFlg = 0;
- AxisDecStop(X_AXIS);
- }
-
- }
- //电机动作
- void HuaXian_Motor(void) //
- {
- switch(HX_MotorStep)
- {
- case 30:
- if(HX_SZ_OUT)
- {
- HX_SZ_OUT = 0;
- HX_MotorDelay = dwTickCount + 50;
- }
- HX_MotorStep = 31;
- break;
- case 31:
- if(dwTickCount>=HX_MotorDelay)
- {
- MoveAction_Const_AccDec(X_AXIS, HX_DIR_P,HX_PARAM_HIGH_SPEED,1,5,30);
- HX_MotorDelay = dwTickCount + HX_PARAM_MOTOR_ALARM_TIME;
- HX_MotorStep = 32;
- }
- break;
- case 32:
- if(HX_GOUZHEN_IN)
- {
- AxisEgmStop(X_AXIS);
- HX_MotorStep = 35;
- }
- if(HX_GUO_LIAN_IN_UP)
- {
- if(X_DRV)MoveChangSpeed(X_AXIS,HX_PARAM_LOW_SPEED);
- HX_MotorDelay = dwTickCount + HX_PARAM_DELAY_GZ;
- HX_MotorStep = 33;
- }
- else if(dwTickCount>=HX_MotorDelay)HX_SetAlarmCode(HX_NO_ZIPPER_ALARM);
- break;
- case 33:
- if(dwTickCount>=HX_MotorDelay)
- {
- HX_GZ_VAVLE = 1;
- HX_MotorDelay = dwTickCount + HX_PARAM_MOTOR_ALARM_TIME;
- HX_MotorStep = 34;
- }
- break;
- case 34:
- if(HX_GOUZHEN_IN)
- {
- AxisEgmStop(X_AXIS);
- HX_MotorStep = 35;
- }
- else if(dwTickCount>=HX_MotorDelay)HX_SetAlarmCode(HX_GZ_ALARM);
- break;
- case 35:
- if(!X_DRV)
- {
- AxisMovePos(X_AXIS,HX_PARAM_LOW_SPEED,QD_PARAM_FZ_LENGTH);
- HX_MotorStep = 36;
- }
- break;
- case 36:
- if(!X_DRV)
- {
- HX_MotorDelay = dwTickCount;
- HX_MotorStep = 0;
- }
- break;
-
- }
- }
- #endif
|