1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117 |
- #include "global.h"
- #if YU_WEN_XUAN_MACHINE
- extern char ReadTimeData(unsigned short ReadMode);
- /**************************************
- ** 函数名称:void ChuanTouJi(void)
- ** 函数功能:穿头机动作函数
- ** 穿头机输入输出说明:
- 全自动步进穿头机 C02
- X00 起动(全自动) M48
- X01 停止 M49
- X02 手动分带(半自动) M50
- X03 穿入特短链选择(先不用接) M51
- X04 故障输入 M52
- X05 分带磁感 M53
- X06 顶针(有料感应) M54
- X07 下模(下止模)感应 M55
- X10 送料复位(后)感应 M56
- X11 送料到位(前)感应 M57
- X12 护链磁感 M58
- X13 护链选择 M59
- X14 振动盘 M60
- X15 过链感应 M61
- X16 推料 M62
- X17 钩针定位 M63
- X20 单次动作 M64
- X21 过链杆下限位 M65
- 输出
- Y11 振动盘 M41
- Y10 停止灯 M40
- Y07 计数器输出(运行) M39
- Y06 夹链电磁阀(勾针旁)(警告灯)M38
- Y05 打片电磁阀(伸缩杠) M37
- Y04 护链电磁阀 M36
- Y03 勾针电磁阀 M35
- Y02 送料电磁阀(给料) M34
- Y01 下模电磁阀(送料电磁) M33
- Y00 分带电磁阀 M32
- PU+ 步进脉冲+
- PU- 步进脉冲-
- DR+ 松步进+
- DR- 松步进-
- P00 穿入后速度 (6)
- P01 加速度 (12)
- P02 起动速度 (10)
- P03 最高速度 (35)
- P04 空位速度 (6)
- P05 延时下勾针 (50)
- P06 延时拖带 (4)
- P07 延时退护链 (3)
- P08 延时退下模(先退分带模式)或延时退分带(先退下模方式) (50)
- P09 给料到位延时返回 (2)
- P10 分带下模分开方式(0 先退分带,1先退下模) (0)
- P11 振动盘延时停 (100)
- P12 振动盘重启动个数 (6)
- P13 延时分带 (3)
- P14 0 拖带延时退护链(护下止),1 分带后延时退护链(合链功能) (0)
- P15 伸缩杆的时间间隔
- P16 延时给料 (3)
- P17 延时夹链 (4)
- P18 合链时间 (10)
- P19 拉链长度(不为0时高速走链长度) (0)
- P20 启动开关方式(0 拔动式,1 按钮式)
- P21 勾针选择(0 不用,1 有勾`针)
- P22 护链磁感选择(0 不用 1 要有磁感)不用磁感时X12用作定位用
- P23 护链选择(0 用 1 不用护链) 只是在用触摸屏通信才有效,用屏的情况下X13接电源的GND
- P24 Y06用途(0 夹链 1 停止指示灯)只是在用触摸屏通信才有效
- P25 振动盘自动停选择(0 只有满料才停 1 两分钟内没料到也停止)
- P26 伸缩杆的工作方式(0 不停止的动作,1给料一次输出一次)()
- P30 拖带的最长脉冲
- P31 0, 分带正常退, 1,有合链时穿入后就退 (0)
- P32 穿拉头的最高速
- P33 联机方式(1,联机,其它,单机)
- P34 重送拉头次数
- P35
- P36
- P37 Y10的用途()
- P38 钢片动作时间
- P39 空位延时停止
- P40 0 无下止合链, 1 有下止合链
- P60 定位长度 (100)
- P61 穿入长度 ()
- P63 3 (7)
- P64 超声时间参数方式选择,,0老款拔码,1编码,2内部按键设(或通信设定),3 输入点方式 新编码采集方式 (1)
- M00 手动给料
- M01 手动并链
- M02 手动钩针
- M03 振动盘
- M04 手动分带
- M06 手动下模
- M07 手动合模动作
- M08 手动拖带
- M09 启动
- M10 自动启动
- M11 单次启动
- M13 停止
- M14 产量清零
- M16 给料启动条件不满足
- M17 合模启动条件不满足
- M18 拖带启动条件不满足
- M19 启动条件不满足
- M20 给料不到位置
- M21 分带不到位
- M22 下模送料不到位
- M23 接头故障输入
- M24 没拉链警告
- E01
- E02
- E03
- E04 给料不到位置 M20
- E05 分带不到位 M21
- E06 下模送料不到位 M22
- E07 接头故障输入 M23
- E08 没拉链警告 M24
- E09
- E10
- E11
- E12
- E30 启动条件不满足 M19
- E31 手动给料条件不满足 M16
- E32 手动下模条件不满足 送料退回开关要亮 M17
- E33 勾针不起来不能启动电机 M18
- ***************************************/
- #define BoDong 0
- #define AnNiu 1
- void ZhenDongCTR(unsigned char flag);
- void HeMo(void);
- extern unsigned char ManualMotor;
- unsigned char CT_cOneTimes,CT_bRunning,CT_bStop;
- unsigned long CT_cAutoStopTime;
- long CT_cDinWeiTime;
- unsigned short CT_cLaTuoNum;
- static long save_dist_buff;
- //清警告
- void Clr_Warning(unsigned char W_Page)
- {
- user_datas[75] = W_Page;
- user_datas[100] = 0; //检查过链接近开关或没有拉链
- user_datas[101] = 0;
- }
- void ChuanTou_InitAction(void)
- {
- XGearRatio = 1;
- ZhenDongCTR(1);
- if(user_datas[15] < 35)user_datas[15] = 35;
- user_datas[100] = 0;
- user_datas[101] = 0;
- user_datas[75] = 0;
- }
- void ChuanTou_Action(void)
- {
- static unsigned long GuZhangInputTime;
- static unsigned char cJiaLian = 0;
- unsigned short ch, j;
- {
- user_datas[121] = dwRealPos;
- user_datas[122] = cStepMByte;
- user_datas[123] = cStepMByte1;
- user_datas[124] = cStepMByte2;
- user_datas[125] = cStepMByte3;
- user_datas[126] = cStepMByte4;
-
- dwRealPos = GetPos(X_AXIS);
- //输出运行状态
- if(user_datas[100])
- {
- if(user_datas[24] == 1)
- Y06 = 1;
- if(user_datas[35] == 0)
- Y07 = 0;
- if(user_datas[37] == 0)
- Y10 = 0;
- }
- else if(CT_bRunning)
- {
- if(user_datas[24] == 1)
- Y06 = 0;
- if(user_datas[35] == 0)
- Y07 = 1;
- if(user_datas[37] == 0)
- Y10 = 0;
- }
- else
- {
- if(user_datas[24] == 1)
- Y06 = 0;
- if(user_datas[35] == 0)
- Y07 = 0;
- if(user_datas[37] == 0)
- Y10 = 1;
- }
- HeMo();
- ZhenDongCTR(0);
- if(M14) //产量清零
- {
- M14 = 0;
- ClrcToTal(76);
- }
- if(X15) //空位时的自动停机时间
- {
- if(user_datas[39] == 0)
- CT_cAutoStopTime = dwTickCount + 3500;
- else
- CT_cAutoStopTime = dwTickCount + (unsigned long) 100 * user_datas[39];
- }
- //停止 故障输入 //拔动式开关
- if (X01 || X04 || M13 || (X00_DW && (user_datas[20] == BoDong) && (dwTickCount >= cDelayTime5)) || ((dwTickCount >= CT_cAutoStopTime) && (!X15) && X_DRV))
- {
- M10 = 0;
- M12 = 0;
- if(X04)
- {
- M23 = 1;
- user_datas[100] = 7;
- }
- else if ((dwTickCount >= CT_cAutoStopTime) && X_DRV && !X15)
- {
- M24 = 1;
- user_datas[100] = 8;
- }
- else if(X01)
- {
- M16 = 0;
- M17 = 0;
- M18 = 0;
- M19 = 0;
- M20 = 0;
- M21 = 0;
- M22 = 0;
- M23 = 0;
- M24 = 0;
- M25 = 0;
- Clr_Warning(1);
- if(X01_UP && !CT_bRunning) Y03 = 1; //勾针
- }
- if(CT_bRunning)ZhenDongCTR(1);
- if(!M13 || !CT_bRunning)
- {
- AxisEgmStop(X_AXIS);
- cStepMByte = 0;
- cStepMByte1 = 0;
- cStepMByte2 = 0;
- cStepMByte3 = 0;
- cStepMByte4 = 0;
- if(user_datas[24] == 0)Y06 = 0; //夹链电磁阀(勾针旁)
-
- Y04 = 0; //护链电磁阀
- Y02 = 0; // 拉头定位电磁阀(给料)
- Y01 = 0; // 下模电磁阀
- Y00 = 0; // 分带电磁阀
- cDelayTime5 = dwTickCount + 60;
- if(user_datas[37] == 1)Y10 = 0;
- SETDR(); //松电机
- CT_bRunning = 0;
- }
- else
- {
- CT_cOneTimes = 1;
- }
- M13 = 0;
- }
- //手动
- if ((CT_bRunning == 0) && !X01)
- {
- //起动
- if ((X00_UP || M09 || M11 || (X20_UP && (user_datas[64] != 3)) || (X00 && X06_UP)) && (dwTickCount >= cDelayTime5) && (CT_bRunning == 0))
- {
- //过链感应 送料后 送料前 故障输入
- if (X15 && X10 && !X11 && !X04)
- {
- //第一条认为给料已完成
- CLRDR(); // 松步进
- CT_bRunning = 1;
- CT_cOneTimes = 0;
- M03 = 0;
- M16 = 0;
- M17 = 0;
- M18 = 0;
- M19 = 0;
- M20 = 0;
- M21 = 0;
- M22 = 0;
- M23 = 0;
- M24 = 0;
- M25 = 0;
- Clr_Warning(1);
- if(M11 || (X20 && (user_datas[64] != 3)))
- { //单次动作
- CT_cOneTimes = 1;
- M12 = 1;
- }
- else //自动动作
- {
- M10 = 1;
- }
- cStepMByte1 = 0;
- cStepMByte2 = 10; //给料已经完成
- cStepMByte4 = 0;
- CT_cAutoStopTime = dwTickCount + 12000;
- CT_bStop = 0;
- if(user_datas[24] == 0)Y06 = 1; //夹紧(勾针旁)
-
- if((!X13) || ((user_datas[23] == 0) && (user_datas[40] == 0))) Y04 = 1; //护链
- //延时分带
- cStepMByte = 4;
- cDelayTime5 = dwTickCount + 60;
- cDelayTime1 = dwTickCount + (unsigned long)user_datas[13]*10 + 60;
- ZhenDongCTR(1);
- }
- else
- {
- if (X00_UP || M09 || M11 || (X00 && X06_UP) || (X20_UP && (user_datas[64] != 3)))
- {
- //启动条件不满足报警
-
- if(!X15)
- {
- M19 = 1;
- user_datas[100] = 30;
- }
- else if(!X10)
- {
- M19 = 1;
- user_datas[100] = 34;
- }
- else if(X11)
- {
- M19 = 1;
- user_datas[100] = 35;
- }
- else if(X04)
- {
- M19 = 1;
- user_datas[100] = 36;
- }
- else
- {
- M19 = 1;
- user_datas[100] = 37;
- }
- }
- }
- M09 = 0;M11 = 0;
- }
-
- //手动分带(半自动)
- if(X02_UP)
- {
- if (X10 && !X11 && !Y02 && !M30) //给料不能有输出
- {
- cStepMByte4 = 1; //合模变为单独动作
- }
- else
- { //条件不满足警告
- M17 = 1;
- user_datas[100] = 32;
- }
- }
- else if(X02_DW) //半自动放开
- {
- if(user_datas[24] == 0)Y06 = 0; //夹紧
- Y04 = 0; //护链
- Y01 = 0; //下模
- Y00 = 0; //分带
- cStepMByte4 = 0;
- }
- //手动给料
- if(M00)
- {
- M00 = 0;
- if(Y02)
- {
- Y02 = 0;
- M30 = 0;
- if(user_datas[37] == 1)Y10 = 0;
- }
- else if(!Y01 && X07)
- {
- if(user_datas[37] == 0)Y02 = 1;
- else
- {
- Y10 = 1;
- M30 = 1;
- cDelayTime9 = dwTickCount + (unsigned long)user_datas[38] + 20;
- }
- }
- else //条件不满足警告
- {
- M16 = 1;
- user_datas[100] = 31;
- }
- }
- if(M30 && (dwTickCount >= cDelayTime9))
- {
- Y02 = 1;
- M30 = 0;
- }
- //手动拼链
- if(M01)
- {
- M01 = 0;
- if(Y04)
- Y04 = 0;
- else
- Y04 = 1;
- }
- //手动分带和下模动作
- if(M04)
- {
- M04 = 0;
- Y00 = ~Y00; //分带输出
-
- if(!Y00)cStepMByte4 = 0;
- }
- if(M06)
- {
- M06 = 0;
- if (Y01)
- {
- Y01 = 0;
- cStepMByte4 = 0;
- }
- // 给料后限位 前限位
- else if (X10 && !X11 && !(Y02 && !M30)) //给料不能有输出
- {
- Y01 = 1;
- }
- else
- { //条件不满足警告
- M17 = 1;
- user_datas[100] = 32;
- }
- }
- if(M07)
- {
- M07 = 0;
- if(cStepMByte4 != 0)
- {
- if(user_datas[24] == 0)Y06 = 0; //夹紧
- Y04 = 0; //护链
- Y01 = 0; //下模
- Y00 = 0; //分带
- cStepMByte4 = 0;
- }
- else
- cStepMByte4 = 1;
- }
- if(!X04)GuZhangInputTime = dwTickCount + (unsigned long)120 * 10;
-
- //顶针 故障开关
- if (X06 || (X04 && (dwTickCount >= GuZhangInputTime)))Y03 = 1; //勾针
- else if (X15_UP || M02) //过链
- {
- if(M02)
- {
- Y03 = ~Y03;
- M02 = 0;
- }
- else
- {
- Y03 = 0;
- cJiaLian = 1;
- }
-
- }
- else if(X15_DW)
- {
- cDelayTime1 = dwTickCount + (unsigned long)user_datas[17];
- }
- if(cJiaLian && dwTickCount >= cDelayTime1)
- {
- cJiaLian = 0;
- if(user_datas[24] == 0)Y06 = 1; //夹紧
- }
- //手动拖带
- if (M08 || (X12_UP && (user_datas[22] == 0)))
- { // 勾针选择
- M08 = 0;
- if(!X_DRV && !Y00 && !Y01)
- {
- Y03 = 1;
- cJiaLian = 0;
- CLRDR();
- CT_cDinWeiTime = user_datas[60];
- if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,CT_DIR_P,user_datas[3],user_datas[4],15,5);
-
- cDelayTime8 = dwTickCount + (unsigned long)650 * 10; //160ms
- CT_cAutoStopTime = dwTickCount + 14000;
- Y04 = 0;
- if(user_datas[24] == 0) Y06 = 0; //夹链电磁阀(勾针旁) //夹紧
- }
- }
- if (X15_DW) cDelayTime3 = dwTickCount + 2;
-
- if(X_DRV)
- {
- //判断过链是不是真的松开
- if(!X15) //计数器
- {
- AxisChangeSpeed(X_AXIS,user_datas[4]);
- cDelayTime8 = dwTickCount + (unsigned long)35 * 10; //160ms
- }
- if(X15_UP)
- {
- Y03 = 0;
- if(user_datas[24] == 0)Y06 = 1; //夹链电磁阀(勾针旁) //夹紧
- }
- }
- else if((dwTickCount >= cDelayTime8) && (CT_bRunning == 0))
- {
- SETDR(); //松电机
- }
- }
- else if (CT_bRunning)
- { //
- switch (cStepMByte)
- {
- case 2: //过链检测
- if((dwRealPos+180) >= (user_datas[61]))AxisChangeSpeed(X_AXIS,user_datas[4]);
-
- if((user_datas[33] != 1) && (user_datas[35] == 1));
- //判断过链是不是真的松开
- else if(!X15 && (user_datas[19] <= 300))
- {
- cStepMByte = 30;
- //夹紧
- Y04 = 0;
- AxisChangeSpeed(X_AXIS,user_datas[4]);
- cDelayTime1 = dwTickCount + (unsigned long)user_datas[17];
-
- }
- else
- {
-
- if(user_datas[30] > 80)
- {
- if(dwRealPos > (user_datas[30] * 20))
- {
- M13 = 1;
- CT_bRunning = 0;
- AxisEgmStop(X_AXIS);
- }
- }
- }
- break;
- case 30:
- // 勾针选择
- if((dwRealPos - save_dist_buff) >= user_datas[5])
- {
- if(user_datas[21] == 1)Y03 = 0;
- }
- if(dwTickCount >= cDelayTime1)
- {
- if(user_datas[24] == 0)Y06 = 1; //夹链电磁阀(勾针旁)
- }
-
- if(X15_UP)
- {
- save_dist_buff = dwRealPos;
- cStepMByte = 31;
- }
- break;
- case 31:
- if((dwRealPos - save_dist_buff) >= user_datas[5])
- {
- if(user_datas[21] == 1)Y03 = 0;
- }
- if(dwTickCount >= cDelayTime1)
- {
- if(user_datas[24] == 0)Y06 = 1; //夹链电磁阀(勾针旁)
- }
- if((dwRealPos - save_dist_buff) >= CT_cDinWeiTime)
- {
- cStepMByte = 3;
- AxisEgmStop(X_AXIS);
- }
- break;
- case 3:
- // 勾针选择
- if((dwRealPos - save_dist_buff) >= user_datas[5])
- {
- if(user_datas[21] == 1)Y03 = 0;
- }
- if(dwTickCount >= cDelayTime1)
- {
- if(user_datas[24] == 0)Y06 = 1; //夹链电磁阀(勾针旁)
- }
- if (!X_DRV)
- {
- if(user_datas[24] == 0)Y06 = 1; //夹牙
-
- cStepMByte = 4;
- if (user_datas[21] == 1)Y03 = 0; //勾针
-
- if ((X02 && (user_datas[20] == BoDong)) || (CT_cOneTimes != 0))
- { //单条停止
- cStepMByte = 3;
- CT_cAutoStopTime = dwTickCount + 250;
- if ((cStepMByte2 == 10))
- {
- cDelayTime8 = dwTickCount + (unsigned long)30 * 10; //延时松电机 //300ms
- cStepMByte = 0;
- CT_bRunning = 0;
- CT_bStop = 0;
- CT_cOneTimes = 0;
- M10 = 0;
- M12 = 0;
- ZhenDongCTR(1);
- }
- }
- else
- {
- if(user_datas[24] == 0)Y06 = 1; //夹牙 带下止合链选择
- if((!X13) ||((user_datas[23] == 0) && (user_datas[40] == 0)))
- { //护链选择
- cStepMByte3 = 0;
- Y04 = 1; //护链输出
- //延时分带
- if (user_datas[22] == 0) //不用磁感
- cDelayTime1 = dwTickCount + (unsigned long)user_datas[13]*10 + 60;
- else
- cDelayTime1 = dwTickCount;
- }
- else //不用护带
- cDelayTime1 = dwTickCount;
- }
- }
- break;
- case 4: //在过链 不用护链或不用磁感 延时分带 给料
- if (X15 && ((( ((user_datas[23] == 1) || (user_datas[40] == 1))|| (user_datas[22] == 0)) && (dwTickCount >= cDelayTime1)) || (X12 && (user_datas[22] == 1)))
- //给料 //给料到位
- && !Y02 && !X11 && (cStepMByte2 == 10))
- {
- cStepMByte = 5;
- Y00 = 1; //分带输出
- cDelayTime1 = dwTickCount + (unsigned long)2000; //给料到位的最长时间 }
- }
- else if(X01 || M13)
- {
- if(cStepMByte2 == 10)
- {
- cDelayTime8 = dwTickCount + (unsigned long)30 * 10; //延时松电机 //300ms
- cStepMByte = 0;
- CT_bRunning = 0;
- CT_bStop = 0;
- CT_cOneTimes = 0;
- M10 = 0;
- M12 = 0;
- ZhenDongCTR(1);
- }
- }
- break;
- //判断分带到位
- case 5: //分带到位 给料已给完成 送料前 送料后
- if(X05)
- {
- if ((cStepMByte2 == 10) && !X11 && X10 && !Y02)
- {
- cStepMByte = 6;
- cStepMByte2 = 0;
- cDelayTime1 = dwTickCount + (unsigned long)5; //25ms
- }
- }
- else if (dwTickCount >= cDelayTime1) //加上分带不到位警告代码
- {
- ZhenDongCTR(1);
- CT_bRunning = 0;
- M21 = 1;
- M10 = 0;
- M12 = 0;
- user_datas[100] = 5;
- }
- break;
- case 6:
- if (dwTickCount >= cDelayTime1)
- {
- cStepMByte = 7;
- Y01 = 1; //下模输出
- cDelayTime1 = dwTickCount + (unsigned long)600; //2.5s
- }
- break;
- //下模气缸上到位
- case 7:
- if (!X07) //下模感应
- {
- if(X06) //送料到
- {
- cStepMByte = 8;
- //延时退勾针
- cDelayTime1 = dwTickCount + (unsigned long)2; //50ms
- if(user_datas[24] == 0)Y06 = 1; //夹紧(护牙)
- }
- else if ((dwTickCount >= cDelayTime1)) // 一定时间不到位就看作没料或卡住
- {
- if(++CT_cLaTuoNum >= user_datas[34])
- {
- CT_cLaTuoNum = 0;
- ZhenDongCTR(1);
- CT_bRunning = 0;
- Y00 = 0; //下模下去
- Y01 = 0; //分带
- M22 = 1;
- M10 = 0;
- M12 = 0;
- M13 = 1;
- user_datas[100] = 6;
- }
- else
- {
- cStepMByte = 4;
- cStepMByte2 = 1;
- Y00 = 0; //分针下去
- Y01 = 0; //下模输出
- }
- }
- }
- break;
- // 延时松勾针
- case 8:
- if(dwTickCount >= cDelayTime1)
- {
- CT_cLaTuoNum = 0;
- cStepMByte = 9;
- Y03 = 1; // 勾针退
- cDelayTime1 = dwTickCount + (unsigned long)user_datas[6] * 10; //70ms
- }
- break;
- // 延时穿入
- case 9:
- if(dwTickCount >= cDelayTime1)
- {
- cStepMByte = 2; //回到空位检测
- MV_Set_Command_Pos_CPU(X_AXIS,0);
- CT_cDinWeiTime = user_datas[60];
-
- if(X03)
- MoveAction_Const_AccDec(X_AXIS,CT_DIR_P,user_datas[32],user_datas[0],user_datas[1],user_datas[1]/2);
- else
- MoveAction_Const_AccDec(X_AXIS,CT_DIR_P,user_datas[32],user_datas[2],user_datas[1],user_datas[1]/2);
- cStepMByte1 = 1; //延时松分带 和 延时松下模动作
- if(user_datas[24] == 0) //夹牙退
- {
- cStepMByte5 = 1; //延时退护链
- cDelayTime4 = dwTickCount + (unsigned long)user_datas[7] * 3;
- }
- if(user_datas[14] == 0)
- {
- cStepMByte3 = 1; //延时退护链
- cDelayTime6 = dwTickCount + (unsigned long)user_datas[7] * 3;
- }
- cStepMByte2 = 0;
- AddToTal(76);
- CalProSP(78);
- }
- break;
- }
- //延时退夹链 退护链的脉冲数
- if(cStepMByte5 && (Y06) && (dwTickCount >= cDelayTime4))
- {
- cStepMByte5 = 0;
- Y06 = 0;
- }
- //延时退护链 退护链的脉冲数
- if(cStepMByte3 && (dwTickCount >= cDelayTime6))
- {
- cStepMByte3 = 0;
- Y04 = 0;
- }
- //延时松分带 和 延时松下模动作
- switch (cStepMByte1)
- {
- case 1:
- if(user_datas[10] == 0)
- {
- cStepMByte1 = 2;
- if(user_datas[40] == 1)cDelayTime6 = dwTickCount + (unsigned long)user_datas[7];
- }
- else
- cStepMByte1 = 10;
- break;
- //先退分带
- case 2:
- if(user_datas[40] == 1)
- {
- if((cStepMByte3 == 0) && (dwTickCount >= cDelayTime6))
- {
- Y04 = 1;
- }
- }
- if((user_datas[31] == 1) && (user_datas[23] == 0))
- {
- if(dwRealPos >= 60)Y00 = 0;
- }
- if((dwRealPos >= user_datas[61]) || (cStepMByte == 31))
- {
- //退分带
- Y00 = 0;
- cStepMByte1 = 3;
- //70ms 合链功能
- if(user_datas[14] != 0)
- {
- cStepMByte3 = 1; //延时退护链
- cDelayTime6 = dwTickCount + (unsigned long)user_datas[18];
- }
- else
- {
- Y04 = 0;
- cStepMByte3 = 0;
- }
- }
- break;
- case 3:
- cDelayTime2 = dwTickCount + (unsigned long)user_datas[8];
- cStepMByte1 = 4;
- break;
- case 4:
- if ((dwTickCount >= cDelayTime2))
- {
- Y01 = 0;
- cStepMByte1 = 5;
- }
- break;
- case 5:
- if(!X06 && !Y00 && !Y01)
- {
- cStepMByte1 = 6;
- cDelayTime2 = dwTickCount + (unsigned long)25; //70ms
- if(user_datas[14] != 0)cDelayTime2 = dwTickCount + (unsigned long)user_datas[50];
- }
- break;
- case 6:
- if(dwTickCount >= cDelayTime2)
- {
- cStepMByte1 = 0;
- cStepMByte2 = 1;
- cDelayTime3 = dwTickCount + (unsigned long)4 * 10;
- //没有长度之前检测到下一条链
- if((cStepMByte == 9) || (cStepMByte == 2))
- {
- AxisChangeSpeed(X_AXIS,user_datas[3]); //最高速
- if(user_datas[19] > 300)
- {
- /* (unsigned long)2000 * user_datas[19]/300
- if(cWorkPulseNum > dwRealPos)
- {
- cWorkPulseNum -= dwRealPos;
- cStepMByte1 = 7;
- cStepMode = 4;
- } */
- }
- }
- }
- break;
- case 7:
- if(dwRealPos >= ((unsigned long)2000 * user_datas[19]/300))
- {
- cStepMByte1 = 0;
-
- }
- break;
- //先退下模
- case 10:
- if ((dwRealPos >= ((unsigned long)2000 * user_datas[19]/300)) || (cStepMByte == 31))
- {
- //退下模
- Y01 = 0;
- cStepMByte1 = 11;
- cDelayTime2 = dwTickCount + (unsigned long)user_datas[8]; //70ms
- Y07 = 0; //退夹链
- if(user_datas[14] != 0)
- {
- cStepMByte3 = 1; //延时退护链
- cDelayTime6 = dwTickCount + (unsigned long)user_datas[18];
- }
- else
- {
- Y04 = 0; //退护链
- cStepMByte3 = 0;
- }
- cDelayTime3 = dwTickCount + (unsigned long)3 * 100; //没法开模
- }
- break;
- case 11:
- if((dwTickCount >= cDelayTime2) || !X06)
- {
- Y00 = 0; //退分带
- cStepMByte1 = 12;
- cDelayTime2 = dwTickCount + (unsigned long)250; //70ms
- }
- break;
- case 12:
- if (!X05 && !Y00 && !Y01)
- {
- cDelayTime2 = dwTickCount + (unsigned long)15;
- cStepMByte1 = 13;
- }
- break;
- case 13:
- if (dwTickCount >= cDelayTime2)
- {
- //没有长度之前检测到下一条链
- /* if ((cStepMode == 4) || (cStepMode == 0))
- {
- cStepMode = 1;
- cLowSpeadLimit = user_datas[4];
- }*/
- cStepMByte2 = 1; //给料启动
- cStepMByte1 = 0;
- }
- break;
-
- }
- //给料动作
- switch (cStepMByte2)
- {
- case 1:
- //分带感应 有料感应 下模感应 分带 下模
- if (!X05 && !X06 && X07 && !Y00 && !Y01)
- {
- cStepMByte2 = 2;
- cDelayTime3 = dwTickCount + (unsigned long)10 * (4 + user_datas[16]);
- if(user_datas[37] == 1)
- {
- Y10 = 1;
- cDelayTime3 = dwTickCount + (unsigned long)user_datas[38] + 20;
- }
- }
- break;
- case 2: //延时给料
- if ((dwTickCount >= cDelayTime3) && X07)
- {
- Y02 = 1; //给料输出
- cStepMByte2 = 3;
- //不知道加多少时候才够,只能定成1秒
- cDelayTime3 = dwTickCount + 2000;
- }
- break;
- case 3: //判断给料到位
- if(X11)
- {
- cStepMByte2 = 4;
- cDelayTime3 = dwTickCount + user_datas[9]; //给料到位延时返回
- }
- else if ((dwTickCount >= cDelayTime3) && X07)
- { //下模上升超时
- ZhenDongCTR(1);
- CT_bRunning = 0;
- M20 = 1;
- M10 = 0;
- M12 = 0;
- user_datas[100] = 4;
- }
- break;
- case 4:
- if (dwTickCount >= cDelayTime3)
- {
- Y02 = 0; //给料关
- cStepMByte2 = 5;
- }
- break;
- case 5:
- if (!X11)
- {
- cStepMByte2 = 6;
- cDelayTime3 = dwTickCount + 30; //给料到位延时返回
- if(user_datas[37] == 1)Y10 = 0;
- }
- break;
- case 6:
- if (X10 && (dwTickCount >= cDelayTime3)) cStepMByte2 = 10;
- break;
- }
- }
- }
- }
- //合模动作
- void HeMo(void)
- {
- switch(cStepMByte4)
- {
- case 0:
- return;
- case 1:
- if(user_datas[24] == 0)Y06 = 1; ////夹紧
- //护链选择
- if(!X13 ||(user_datas[23] == 0)) Y04 = 1; //护链输出
-
- cDelayTime7 = dwTickCount + (unsigned long)user_datas[13]*10 + 60; //160ms
- cStepMByte4 = 2;
- if(user_datas[37] == 1)Y10 = 0;
- break;
- case 2: //护链输出后分带输出
- if(X10 && !X11 && (Y06 || (user_datas[24] == 1)))
- {
- //护链磁感 不用护链磁感时用延时
- if ((((X12 && (user_datas[22] == 1))) || ((user_datas[23] == 1) && (dwTickCount >= cDelayTime7)) ||
- // 护链磁感选择
- (!X13 && (dwTickCount >= cDelayTime7) && (user_datas[22] == 0))) //要护链 不用磁感
- && !Y00 && !X05) //分带电磁阀 分带到位
- {
- Y00 = 1; //分带
- cDelayTime7 = dwTickCount + (unsigned long)10 * 10; //160ms
- }
- if(X05_UP && Y00) Y01 = 1; //下模输出
- //分带到位 分带电磁阀
- //有料感应 下模输出
- if (X06 && Y01)Y03 = 1;
- }
- }
- }
- //振盘控制
- void ZhenDongCTR(unsigned char flag)
- {
- static unsigned long cStopZDTime, cTuiPianTime,cSongLiaoQianTime;
- static unsigned short cStartTimes;
- if(flag == 1)
- {
- if(!X14)
- {
- Y11 = 1;
- cStopZDTime = dwTickCount + (unsigned long)1000 * 120;
- }
- }
- else
- {
- //振动盘 振动检测 手动给料
- if(Y11)
- {
- if((X14_UP || ((user_datas[25] == 0) && !X14)) && !M15) // || (X03_DW))
- {
- cStopZDTime = dwTickCount + (unsigned long)1000 * user_datas[11];
- }
- else if (M15 || ((X14 || (!CT_bRunning && (user_datas[25] == 1))) && (dwTickCount >= cStopZDTime)))
- {
- M15 = 0;
- Y11 = 0;
- cStartTimes = 0;
- }
- else if(X14_DW)
- {
- cStopZDTime = dwTickCount + (unsigned long)1000 * 40;
- }
- }
- else if ((!Y11) && (((cStartTimes >= user_datas[12]) && (!X14))|| M15))
- {
- M15 = 0;
- Y11 = 1;
- cStopZDTime = dwTickCount + (unsigned long)1000 * 40;
- if(X14)cStopZDTime = dwTickCount + (unsigned long)1000 * 4;
- cStartTimes = 0;
- }
- }
- // 送料前
- if (X11_UP && (dwTickCount >= cSongLiaoQianTime))
- {
- cStartTimes++;
- cSongLiaoQianTime = dwTickCount + 100;
- }
- //拉头检测
- if (X14) cStartTimes = 0;
- //推拉片动作(弹簧头)
- if(flag == 0)
- {
- if((user_datas[26] == 0) || M03)
- {
- if(Y11 && !X04 && (M03 || CT_bRunning))
- {
- if (dwTickCount >= cTuiPianTime)
- {
- cTuiPianTime = dwTickCount + (unsigned long)10 * user_datas[15];
- Y05 = ~Y05;
- }
- }
- else Y05 = 0;
- }
- else if(Y11 && !X04)
- Y05 = Y02;
- }
- }
- #endif
|