YWXChuanTouJi.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. #include "global.h"
  2. #if YU_WEN_XUAN_MACHINE
  3. extern char ReadTimeData(unsigned short ReadMode);
  4. /**************************************
  5. ** 函数名称:void ChuanTouJi(void)
  6. ** 函数功能:穿头机动作函数
  7. ** 穿头机输入输出说明:
  8. 全自动步进穿头机 C02
  9. X00 起动(全自动) M48
  10. X01 停止 M49
  11. X02 手动分带(半自动) M50
  12. X03 穿入特短链选择(先不用接) M51
  13. X04 故障输入 M52
  14. X05 分带磁感 M53
  15. X06 顶针(有料感应) M54
  16. X07 下模(下止模)感应 M55
  17. X10 送料复位(后)感应 M56
  18. X11 送料到位(前)感应 M57
  19. X12 护链磁感 M58
  20. X13 护链选择 M59
  21. X14 振动盘 M60
  22. X15 过链感应 M61
  23. X16 推料 M62
  24. X17 钩针定位 M63
  25. X20 单次动作 M64
  26. X21 过链杆下限位 M65
  27. 输出
  28. Y11 振动盘 M41
  29. Y10 停止灯 M40
  30. Y07 计数器输出(运行) M39
  31. Y06 夹链电磁阀(勾针旁)(警告灯)M38
  32. Y05 打片电磁阀(伸缩杠) M37
  33. Y04 护链电磁阀 M36
  34. Y03 勾针电磁阀 M35
  35. Y02 送料电磁阀(给料) M34
  36. Y01 下模电磁阀(送料电磁) M33
  37. Y00 分带电磁阀 M32
  38. PU+ 步进脉冲+
  39. PU- 步进脉冲-
  40. DR+ 松步进+
  41. DR- 松步进-
  42. P00 穿入后速度 (6)
  43. P01 加速度 (12)
  44. P02 起动速度 (10)
  45. P03 最高速度 (35)
  46. P04 空位速度 (6)
  47. P05 延时下勾针 (50)
  48. P06 延时拖带 (4)
  49. P07 延时退护链 (3)
  50. P08 延时退下模(先退分带模式)或延时退分带(先退下模方式) (50)
  51. P09 给料到位延时返回 (2)
  52. P10 分带下模分开方式(0 先退分带,1先退下模) (0)
  53. P11 振动盘延时停 (100)
  54. P12 振动盘重启动个数 (6)
  55. P13 延时分带 (3)
  56. P14 0 拖带延时退护链(护下止),1 分带后延时退护链(合链功能) (0)
  57. P15 伸缩杆的时间间隔
  58. P16 延时给料 (3)
  59. P17 延时夹链 (4)
  60. P18 合链时间 (10)
  61. P19 拉链长度(不为0时高速走链长度) (0)
  62. P20 启动开关方式(0 拔动式,1 按钮式)
  63. P21 勾针选择(0 不用,1 有勾`针)
  64. P22 护链磁感选择(0 不用 1 要有磁感)不用磁感时X12用作定位用
  65. P23 护链选择(0 用 1 不用护链) 只是在用触摸屏通信才有效,用屏的情况下X13接电源的GND
  66. P24 Y06用途(0 夹链 1 停止指示灯)只是在用触摸屏通信才有效
  67. P25 振动盘自动停选择(0 只有满料才停 1 两分钟内没料到也停止)
  68. P26 伸缩杆的工作方式(0 不停止的动作,1给料一次输出一次)()
  69. P30 拖带的最长脉冲
  70. P31 0, 分带正常退, 1,有合链时穿入后就退 (0)
  71. P32 穿拉头的最高速
  72. P33 联机方式(1,联机,其它,单机)
  73. P34 重送拉头次数
  74. P35
  75. P36
  76. P37 Y10的用途()
  77. P38 钢片动作时间
  78. P39 空位延时停止
  79. P40 0 无下止合链, 1 有下止合链
  80. P60 定位长度 (100)
  81. P61 穿入长度 ()
  82. P63 3 (7)
  83. P64 超声时间参数方式选择,,0老款拔码,1编码,2内部按键设(或通信设定),3 输入点方式 新编码采集方式 (1)
  84. M00 手动给料
  85. M01 手动并链
  86. M02 手动钩针
  87. M03 振动盘
  88. M04 手动分带
  89. M06 手动下模
  90. M07 手动合模动作
  91. M08 手动拖带
  92. M09 启动
  93. M10 自动启动
  94. M11 单次启动
  95. M13 停止
  96. M14 产量清零
  97. M16 给料启动条件不满足
  98. M17 合模启动条件不满足
  99. M18 拖带启动条件不满足
  100. M19 启动条件不满足
  101. M20 给料不到位置
  102. M21 分带不到位
  103. M22 下模送料不到位
  104. M23 接头故障输入
  105. M24 没拉链警告
  106. E01
  107. E02
  108. E03
  109. E04 给料不到位置 M20
  110. E05 分带不到位 M21
  111. E06 下模送料不到位 M22
  112. E07 接头故障输入 M23
  113. E08 没拉链警告 M24
  114. E09
  115. E10
  116. E11
  117. E12
  118. E30 启动条件不满足 M19
  119. E31 手动给料条件不满足 M16
  120. E32 手动下模条件不满足 送料退回开关要亮 M17
  121. E33 勾针不起来不能启动电机 M18
  122. ***************************************/
  123. #define BoDong 0
  124. #define AnNiu 1
  125. void ZhenDongCTR(unsigned char flag);
  126. void HeMo(void);
  127. extern unsigned char ManualMotor;
  128. unsigned char CT_cOneTimes,CT_bRunning,CT_bStop;
  129. unsigned long CT_cAutoStopTime;
  130. long CT_cDinWeiTime;
  131. unsigned short CT_cLaTuoNum;
  132. static long save_dist_buff;
  133. //清警告
  134. void Clr_Warning(unsigned char W_Page)
  135. {
  136. user_datas[75] = W_Page;
  137. user_datas[100] = 0; //检查过链接近开关或没有拉链
  138. user_datas[101] = 0;
  139. }
  140. void ChuanTou_InitAction(void)
  141. {
  142. XGearRatio = 1;
  143. ZhenDongCTR(1);
  144. if(user_datas[15] < 35)user_datas[15] = 35;
  145. user_datas[100] = 0;
  146. user_datas[101] = 0;
  147. user_datas[75] = 0;
  148. }
  149. void ChuanTou_Action(void)
  150. {
  151. static unsigned long GuZhangInputTime;
  152. static unsigned char cJiaLian = 0;
  153. unsigned short ch, j;
  154. {
  155. user_datas[121] = dwRealPos;
  156. user_datas[122] = cStepMByte;
  157. user_datas[123] = cStepMByte1;
  158. user_datas[124] = cStepMByte2;
  159. user_datas[125] = cStepMByte3;
  160. user_datas[126] = cStepMByte4;
  161. dwRealPos = GetPos(X_AXIS);
  162. //输出运行状态
  163. if(user_datas[100])
  164. {
  165. if(user_datas[24] == 1)
  166. Y06 = 1;
  167. if(user_datas[35] == 0)
  168. Y07 = 0;
  169. if(user_datas[37] == 0)
  170. Y10 = 0;
  171. }
  172. else if(CT_bRunning)
  173. {
  174. if(user_datas[24] == 1)
  175. Y06 = 0;
  176. if(user_datas[35] == 0)
  177. Y07 = 1;
  178. if(user_datas[37] == 0)
  179. Y10 = 0;
  180. }
  181. else
  182. {
  183. if(user_datas[24] == 1)
  184. Y06 = 0;
  185. if(user_datas[35] == 0)
  186. Y07 = 0;
  187. if(user_datas[37] == 0)
  188. Y10 = 1;
  189. }
  190. HeMo();
  191. ZhenDongCTR(0);
  192. if(M14) //产量清零
  193. {
  194. M14 = 0;
  195. ClrcToTal(76);
  196. }
  197. if(X15) //空位时的自动停机时间
  198. {
  199. if(user_datas[39] == 0)
  200. CT_cAutoStopTime = dwTickCount + 3500;
  201. else
  202. CT_cAutoStopTime = dwTickCount + (unsigned long) 100 * user_datas[39];
  203. }
  204. //停止 故障输入 //拔动式开关
  205. if (X01 || X04 || M13 || (X00_DW && (user_datas[20] == BoDong) && (dwTickCount >= cDelayTime5)) || ((dwTickCount >= CT_cAutoStopTime) && (!X15) && X_DRV))
  206. {
  207. M10 = 0;
  208. M12 = 0;
  209. if(X04)
  210. {
  211. M23 = 1;
  212. user_datas[100] = 7;
  213. }
  214. else if ((dwTickCount >= CT_cAutoStopTime) && X_DRV && !X15)
  215. {
  216. M24 = 1;
  217. user_datas[100] = 8;
  218. }
  219. else if(X01)
  220. {
  221. M16 = 0;
  222. M17 = 0;
  223. M18 = 0;
  224. M19 = 0;
  225. M20 = 0;
  226. M21 = 0;
  227. M22 = 0;
  228. M23 = 0;
  229. M24 = 0;
  230. M25 = 0;
  231. Clr_Warning(1);
  232. if(X01_UP && !CT_bRunning) Y03 = 1; //勾针
  233. }
  234. if(CT_bRunning)ZhenDongCTR(1);
  235. if(!M13 || !CT_bRunning)
  236. {
  237. AxisEgmStop(X_AXIS);
  238. cStepMByte = 0;
  239. cStepMByte1 = 0;
  240. cStepMByte2 = 0;
  241. cStepMByte3 = 0;
  242. cStepMByte4 = 0;
  243. if(user_datas[24] == 0)Y06 = 0; //夹链电磁阀(勾针旁)
  244. Y04 = 0; //护链电磁阀
  245. Y02 = 0; // 拉头定位电磁阀(给料)
  246. Y01 = 0; // 下模电磁阀
  247. Y00 = 0; // 分带电磁阀
  248. cDelayTime5 = dwTickCount + 60;
  249. if(user_datas[37] == 1)Y10 = 0;
  250. SETDR(); //松电机
  251. CT_bRunning = 0;
  252. }
  253. else
  254. {
  255. CT_cOneTimes = 1;
  256. }
  257. M13 = 0;
  258. }
  259. //手动
  260. if ((CT_bRunning == 0) && !X01)
  261. {
  262. //起动
  263. if ((X00_UP || M09 || M11 || (X20_UP && (user_datas[64] != 3)) || (X00 && X06_UP)) && (dwTickCount >= cDelayTime5) && (CT_bRunning == 0))
  264. {
  265. //过链感应 送料后 送料前 故障输入
  266. if (X15 && X10 && !X11 && !X04)
  267. {
  268. //第一条认为给料已完成
  269. CLRDR(); // 松步进
  270. CT_bRunning = 1;
  271. CT_cOneTimes = 0;
  272. M03 = 0;
  273. M16 = 0;
  274. M17 = 0;
  275. M18 = 0;
  276. M19 = 0;
  277. M20 = 0;
  278. M21 = 0;
  279. M22 = 0;
  280. M23 = 0;
  281. M24 = 0;
  282. M25 = 0;
  283. Clr_Warning(1);
  284. if(M11 || (X20 && (user_datas[64] != 3)))
  285. { //单次动作
  286. CT_cOneTimes = 1;
  287. M12 = 1;
  288. }
  289. else //自动动作
  290. {
  291. M10 = 1;
  292. }
  293. cStepMByte1 = 0;
  294. cStepMByte2 = 10; //给料已经完成
  295. cStepMByte4 = 0;
  296. CT_cAutoStopTime = dwTickCount + 12000;
  297. CT_bStop = 0;
  298. if(user_datas[24] == 0)Y06 = 1; //夹紧(勾针旁)
  299. if((!X13) || ((user_datas[23] == 0) && (user_datas[40] == 0))) Y04 = 1; //护链
  300. //延时分带
  301. cStepMByte = 4;
  302. cDelayTime5 = dwTickCount + 60;
  303. cDelayTime1 = dwTickCount + (unsigned long)user_datas[13]*10 + 60;
  304. ZhenDongCTR(1);
  305. }
  306. else
  307. {
  308. if (X00_UP || M09 || M11 || (X00 && X06_UP) || (X20_UP && (user_datas[64] != 3)))
  309. {
  310. //启动条件不满足报警
  311. if(!X15)
  312. {
  313. M19 = 1;
  314. user_datas[100] = 30;
  315. }
  316. else if(!X10)
  317. {
  318. M19 = 1;
  319. user_datas[100] = 34;
  320. }
  321. else if(X11)
  322. {
  323. M19 = 1;
  324. user_datas[100] = 35;
  325. }
  326. else if(X04)
  327. {
  328. M19 = 1;
  329. user_datas[100] = 36;
  330. }
  331. else
  332. {
  333. M19 = 1;
  334. user_datas[100] = 37;
  335. }
  336. }
  337. }
  338. M09 = 0;M11 = 0;
  339. }
  340. //手动分带(半自动)
  341. if(X02_UP)
  342. {
  343. if (X10 && !X11 && !Y02 && !M30) //给料不能有输出
  344. {
  345. cStepMByte4 = 1; //合模变为单独动作
  346. }
  347. else
  348. { //条件不满足警告
  349. M17 = 1;
  350. user_datas[100] = 32;
  351. }
  352. }
  353. else if(X02_DW) //半自动放开
  354. {
  355. if(user_datas[24] == 0)Y06 = 0; //夹紧
  356. Y04 = 0; //护链
  357. Y01 = 0; //下模
  358. Y00 = 0; //分带
  359. cStepMByte4 = 0;
  360. }
  361. //手动给料
  362. if(M00)
  363. {
  364. M00 = 0;
  365. if(Y02)
  366. {
  367. Y02 = 0;
  368. M30 = 0;
  369. if(user_datas[37] == 1)Y10 = 0;
  370. }
  371. else if(!Y01 && X07)
  372. {
  373. if(user_datas[37] == 0)Y02 = 1;
  374. else
  375. {
  376. Y10 = 1;
  377. M30 = 1;
  378. cDelayTime9 = dwTickCount + (unsigned long)user_datas[38] + 20;
  379. }
  380. }
  381. else //条件不满足警告
  382. {
  383. M16 = 1;
  384. user_datas[100] = 31;
  385. }
  386. }
  387. if(M30 && (dwTickCount >= cDelayTime9))
  388. {
  389. Y02 = 1;
  390. M30 = 0;
  391. }
  392. //手动拼链
  393. if(M01)
  394. {
  395. M01 = 0;
  396. if(Y04)
  397. Y04 = 0;
  398. else
  399. Y04 = 1;
  400. }
  401. //手动分带和下模动作
  402. if(M04)
  403. {
  404. M04 = 0;
  405. Y00 = ~Y00; //分带输出
  406. if(!Y00)cStepMByte4 = 0;
  407. }
  408. if(M06)
  409. {
  410. M06 = 0;
  411. if (Y01)
  412. {
  413. Y01 = 0;
  414. cStepMByte4 = 0;
  415. }
  416. // 给料后限位 前限位
  417. else if (X10 && !X11 && !(Y02 && !M30)) //给料不能有输出
  418. {
  419. Y01 = 1;
  420. }
  421. else
  422. { //条件不满足警告
  423. M17 = 1;
  424. user_datas[100] = 32;
  425. }
  426. }
  427. if(M07)
  428. {
  429. M07 = 0;
  430. if(cStepMByte4 != 0)
  431. {
  432. if(user_datas[24] == 0)Y06 = 0; //夹紧
  433. Y04 = 0; //护链
  434. Y01 = 0; //下模
  435. Y00 = 0; //分带
  436. cStepMByte4 = 0;
  437. }
  438. else
  439. cStepMByte4 = 1;
  440. }
  441. if(!X04)GuZhangInputTime = dwTickCount + (unsigned long)120 * 10;
  442. //顶针 故障开关
  443. if (X06 || (X04 && (dwTickCount >= GuZhangInputTime)))Y03 = 1; //勾针
  444. else if (X15_UP || M02) //过链
  445. {
  446. if(M02)
  447. {
  448. Y03 = ~Y03;
  449. M02 = 0;
  450. }
  451. else
  452. {
  453. Y03 = 0;
  454. cJiaLian = 1;
  455. }
  456. }
  457. else if(X15_DW)
  458. {
  459. cDelayTime1 = dwTickCount + (unsigned long)user_datas[17];
  460. }
  461. if(cJiaLian && dwTickCount >= cDelayTime1)
  462. {
  463. cJiaLian = 0;
  464. if(user_datas[24] == 0)Y06 = 1; //夹紧
  465. }
  466. //手动拖带
  467. if (M08 || (X12_UP && (user_datas[22] == 0)))
  468. { // 勾针选择
  469. M08 = 0;
  470. if(!X_DRV && !Y00 && !Y01)
  471. {
  472. Y03 = 1;
  473. cJiaLian = 0;
  474. CLRDR();
  475. CT_cDinWeiTime = user_datas[60];
  476. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,CT_DIR_P,user_datas[3],user_datas[4],15,5);
  477. cDelayTime8 = dwTickCount + (unsigned long)650 * 10; //160ms
  478. CT_cAutoStopTime = dwTickCount + 14000;
  479. Y04 = 0;
  480. if(user_datas[24] == 0) Y06 = 0; //夹链电磁阀(勾针旁) //夹紧
  481. }
  482. }
  483. if (X15_DW) cDelayTime3 = dwTickCount + 2;
  484. if(X_DRV)
  485. {
  486. //判断过链是不是真的松开
  487. if(!X15) //计数器
  488. {
  489. AxisChangeSpeed(X_AXIS,user_datas[4]);
  490. cDelayTime8 = dwTickCount + (unsigned long)35 * 10; //160ms
  491. }
  492. if(X15_UP)
  493. {
  494. Y03 = 0;
  495. if(user_datas[24] == 0)Y06 = 1; //夹链电磁阀(勾针旁) //夹紧
  496. }
  497. }
  498. else if((dwTickCount >= cDelayTime8) && (CT_bRunning == 0))
  499. {
  500. SETDR(); //松电机
  501. }
  502. }
  503. else if (CT_bRunning)
  504. { //
  505. switch (cStepMByte)
  506. {
  507. case 2: //过链检测
  508. if((dwRealPos+180) >= (user_datas[61]))AxisChangeSpeed(X_AXIS,user_datas[4]);
  509. if((user_datas[33] != 1) && (user_datas[35] == 1));
  510. //判断过链是不是真的松开
  511. else if(!X15 && (user_datas[19] <= 300))
  512. {
  513. cStepMByte = 30;
  514. //夹紧
  515. Y04 = 0;
  516. AxisChangeSpeed(X_AXIS,user_datas[4]);
  517. cDelayTime1 = dwTickCount + (unsigned long)user_datas[17];
  518. }
  519. else
  520. {
  521. if(user_datas[30] > 80)
  522. {
  523. if(dwRealPos > (user_datas[30] * 20))
  524. {
  525. M13 = 1;
  526. CT_bRunning = 0;
  527. AxisEgmStop(X_AXIS);
  528. }
  529. }
  530. }
  531. break;
  532. case 30:
  533. // 勾针选择
  534. if((dwRealPos - save_dist_buff) >= user_datas[5])
  535. {
  536. if(user_datas[21] == 1)Y03 = 0;
  537. }
  538. if(dwTickCount >= cDelayTime1)
  539. {
  540. if(user_datas[24] == 0)Y06 = 1; //夹链电磁阀(勾针旁)
  541. }
  542. if(X15_UP)
  543. {
  544. save_dist_buff = dwRealPos;
  545. cStepMByte = 31;
  546. }
  547. break;
  548. case 31:
  549. if((dwRealPos - save_dist_buff) >= user_datas[5])
  550. {
  551. if(user_datas[21] == 1)Y03 = 0;
  552. }
  553. if(dwTickCount >= cDelayTime1)
  554. {
  555. if(user_datas[24] == 0)Y06 = 1; //夹链电磁阀(勾针旁)
  556. }
  557. if((dwRealPos - save_dist_buff) >= CT_cDinWeiTime)
  558. {
  559. cStepMByte = 3;
  560. AxisEgmStop(X_AXIS);
  561. }
  562. break;
  563. case 3:
  564. // 勾针选择
  565. if((dwRealPos - save_dist_buff) >= user_datas[5])
  566. {
  567. if(user_datas[21] == 1)Y03 = 0;
  568. }
  569. if(dwTickCount >= cDelayTime1)
  570. {
  571. if(user_datas[24] == 0)Y06 = 1; //夹链电磁阀(勾针旁)
  572. }
  573. if (!X_DRV)
  574. {
  575. if(user_datas[24] == 0)Y06 = 1; //夹牙
  576. cStepMByte = 4;
  577. if (user_datas[21] == 1)Y03 = 0; //勾针
  578. if ((X02 && (user_datas[20] == BoDong)) || (CT_cOneTimes != 0))
  579. { //单条停止
  580. cStepMByte = 3;
  581. CT_cAutoStopTime = dwTickCount + 250;
  582. if ((cStepMByte2 == 10))
  583. {
  584. cDelayTime8 = dwTickCount + (unsigned long)30 * 10; //延时松电机 //300ms
  585. cStepMByte = 0;
  586. CT_bRunning = 0;
  587. CT_bStop = 0;
  588. CT_cOneTimes = 0;
  589. M10 = 0;
  590. M12 = 0;
  591. ZhenDongCTR(1);
  592. }
  593. }
  594. else
  595. {
  596. if(user_datas[24] == 0)Y06 = 1; //夹牙 带下止合链选择
  597. if((!X13) ||((user_datas[23] == 0) && (user_datas[40] == 0)))
  598. { //护链选择
  599. cStepMByte3 = 0;
  600. Y04 = 1; //护链输出
  601. //延时分带
  602. if (user_datas[22] == 0) //不用磁感
  603. cDelayTime1 = dwTickCount + (unsigned long)user_datas[13]*10 + 60;
  604. else
  605. cDelayTime1 = dwTickCount;
  606. }
  607. else //不用护带
  608. cDelayTime1 = dwTickCount;
  609. }
  610. }
  611. break;
  612. case 4: //在过链 不用护链或不用磁感       延时分带  给料
  613. if (X15 && ((( ((user_datas[23] == 1) || (user_datas[40] == 1))|| (user_datas[22] == 0)) && (dwTickCount >= cDelayTime1)) || (X12 && (user_datas[22] == 1)))
  614. //给料 //给料到位
  615. && !Y02 && !X11 && (cStepMByte2 == 10))
  616. {
  617. cStepMByte = 5;
  618. Y00 = 1; //分带输出
  619. cDelayTime1 = dwTickCount + (unsigned long)2000; //给料到位的最长时间 }
  620. }
  621. else if(X01 || M13)
  622. {
  623. if(cStepMByte2 == 10)
  624. {
  625. cDelayTime8 = dwTickCount + (unsigned long)30 * 10; //延时松电机 //300ms
  626. cStepMByte = 0;
  627. CT_bRunning = 0;
  628. CT_bStop = 0;
  629. CT_cOneTimes = 0;
  630. M10 = 0;
  631. M12 = 0;
  632. ZhenDongCTR(1);
  633. }
  634. }
  635. break;
  636. //判断分带到位
  637. case 5: //分带到位 给料已给完成 送料前 送料后
  638. if(X05)
  639. {
  640. if ((cStepMByte2 == 10) && !X11 && X10 && !Y02)
  641. {
  642. cStepMByte = 6;
  643. cStepMByte2 = 0;
  644. cDelayTime1 = dwTickCount + (unsigned long)5; //25ms
  645. }
  646. }
  647. else if (dwTickCount >= cDelayTime1) //加上分带不到位警告代码
  648. {
  649. ZhenDongCTR(1);
  650. CT_bRunning = 0;
  651. M21 = 1;
  652. M10 = 0;
  653. M12 = 0;
  654. user_datas[100] = 5;
  655. }
  656. break;
  657. case 6:
  658. if (dwTickCount >= cDelayTime1)
  659. {
  660. cStepMByte = 7;
  661. Y01 = 1; //下模输出
  662. cDelayTime1 = dwTickCount + (unsigned long)600; //2.5s
  663. }
  664. break;
  665. //下模气缸上到位
  666. case 7:
  667. if (!X07) //下模感应
  668. {
  669. if(X06) //送料到
  670. {
  671. cStepMByte = 8;
  672. //延时退勾针
  673. cDelayTime1 = dwTickCount + (unsigned long)2; //50ms
  674. if(user_datas[24] == 0)Y06 = 1; //夹紧(护牙)
  675. }
  676. else if ((dwTickCount >= cDelayTime1)) // 一定时间不到位就看作没料或卡住
  677. {
  678. if(++CT_cLaTuoNum >= user_datas[34])
  679. {
  680. CT_cLaTuoNum = 0;
  681. ZhenDongCTR(1);
  682. CT_bRunning = 0;
  683. Y00 = 0; //下模下去
  684. Y01 = 0; //分带
  685. M22 = 1;
  686. M10 = 0;
  687. M12 = 0;
  688. M13 = 1;
  689. user_datas[100] = 6;
  690. }
  691. else
  692. {
  693. cStepMByte = 4;
  694. cStepMByte2 = 1;
  695. Y00 = 0; //分针下去
  696. Y01 = 0; //下模输出
  697. }
  698. }
  699. }
  700. break;
  701. // 延时松勾针
  702. case 8:
  703. if(dwTickCount >= cDelayTime1)
  704. {
  705. CT_cLaTuoNum = 0;
  706. cStepMByte = 9;
  707. Y03 = 1; // 勾针退
  708. cDelayTime1 = dwTickCount + (unsigned long)user_datas[6] * 10; //70ms
  709. }
  710. break;
  711. // 延时穿入
  712. case 9:
  713. if(dwTickCount >= cDelayTime1)
  714. {
  715. cStepMByte = 2; //回到空位检测
  716. MV_Set_Command_Pos_CPU(X_AXIS,0);
  717. CT_cDinWeiTime = user_datas[60];
  718. if(X03)
  719. MoveAction_Const_AccDec(X_AXIS,CT_DIR_P,user_datas[32],user_datas[0],user_datas[1],user_datas[1]/2);
  720. else
  721. MoveAction_Const_AccDec(X_AXIS,CT_DIR_P,user_datas[32],user_datas[2],user_datas[1],user_datas[1]/2);
  722. cStepMByte1 = 1; //延时松分带 和 延时松下模动作
  723. if(user_datas[24] == 0) //夹牙退
  724. {
  725. cStepMByte5 = 1; //延时退护链
  726. cDelayTime4 = dwTickCount + (unsigned long)user_datas[7] * 3;
  727. }
  728. if(user_datas[14] == 0)
  729. {
  730. cStepMByte3 = 1; //延时退护链
  731. cDelayTime6 = dwTickCount + (unsigned long)user_datas[7] * 3;
  732. }
  733. cStepMByte2 = 0;
  734. AddToTal(76);
  735. CalProSP(78);
  736. }
  737. break;
  738. }
  739. //延时退夹链 退护链的脉冲数
  740. if(cStepMByte5 && (Y06) && (dwTickCount >= cDelayTime4))
  741. {
  742. cStepMByte5 = 0;
  743. Y06 = 0;
  744. }
  745. //延时退护链 退护链的脉冲数
  746. if(cStepMByte3 && (dwTickCount >= cDelayTime6))
  747. {
  748. cStepMByte3 = 0;
  749. Y04 = 0;
  750. }
  751. //延时松分带 和 延时松下模动作
  752. switch (cStepMByte1)
  753. {
  754. case 1:
  755. if(user_datas[10] == 0)
  756. {
  757. cStepMByte1 = 2;
  758. if(user_datas[40] == 1)cDelayTime6 = dwTickCount + (unsigned long)user_datas[7];
  759. }
  760. else
  761. cStepMByte1 = 10;
  762. break;
  763. //先退分带
  764. case 2:
  765. if(user_datas[40] == 1)
  766. {
  767. if((cStepMByte3 == 0) && (dwTickCount >= cDelayTime6))
  768. {
  769. Y04 = 1;
  770. }
  771. }
  772. if((user_datas[31] == 1) && (user_datas[23] == 0))
  773. {
  774. if(dwRealPos >= 60)Y00 = 0;
  775. }
  776. if((dwRealPos >= user_datas[61]) || (cStepMByte == 31))
  777. {
  778. //退分带
  779. Y00 = 0;
  780. cStepMByte1 = 3;
  781. //70ms 合链功能
  782. if(user_datas[14] != 0)
  783. {
  784. cStepMByte3 = 1; //延时退护链
  785. cDelayTime6 = dwTickCount + (unsigned long)user_datas[18];
  786. }
  787. else
  788. {
  789. Y04 = 0;
  790. cStepMByte3 = 0;
  791. }
  792. }
  793. break;
  794. case 3:
  795. cDelayTime2 = dwTickCount + (unsigned long)user_datas[8];
  796. cStepMByte1 = 4;
  797. break;
  798. case 4:
  799. if ((dwTickCount >= cDelayTime2))
  800. {
  801. Y01 = 0;
  802. cStepMByte1 = 5;
  803. }
  804. break;
  805. case 5:
  806. if(!X06 && !Y00 && !Y01)
  807. {
  808. cStepMByte1 = 6;
  809. cDelayTime2 = dwTickCount + (unsigned long)25; //70ms
  810. if(user_datas[14] != 0)cDelayTime2 = dwTickCount + (unsigned long)user_datas[50];
  811. }
  812. break;
  813. case 6:
  814. if(dwTickCount >= cDelayTime2)
  815. {
  816. cStepMByte1 = 0;
  817. cStepMByte2 = 1;
  818. cDelayTime3 = dwTickCount + (unsigned long)4 * 10;
  819. //没有长度之前检测到下一条链
  820. if((cStepMByte == 9) || (cStepMByte == 2))
  821. {
  822. AxisChangeSpeed(X_AXIS,user_datas[3]); //最高速
  823. if(user_datas[19] > 300)
  824. {
  825. /* (unsigned long)2000 * user_datas[19]/300
  826. if(cWorkPulseNum > dwRealPos)
  827. {
  828. cWorkPulseNum -= dwRealPos;
  829. cStepMByte1 = 7;
  830. cStepMode = 4;
  831. } */
  832. }
  833. }
  834. }
  835. break;
  836. case 7:
  837. if(dwRealPos >= ((unsigned long)2000 * user_datas[19]/300))
  838. {
  839. cStepMByte1 = 0;
  840. }
  841. break;
  842. //先退下模
  843. case 10:
  844. if ((dwRealPos >= ((unsigned long)2000 * user_datas[19]/300)) || (cStepMByte == 31))
  845. {
  846. //退下模
  847. Y01 = 0;
  848. cStepMByte1 = 11;
  849. cDelayTime2 = dwTickCount + (unsigned long)user_datas[8]; //70ms
  850. Y07 = 0; //退夹链
  851. if(user_datas[14] != 0)
  852. {
  853. cStepMByte3 = 1; //延时退护链
  854. cDelayTime6 = dwTickCount + (unsigned long)user_datas[18];
  855. }
  856. else
  857. {
  858. Y04 = 0; //退护链
  859. cStepMByte3 = 0;
  860. }
  861. cDelayTime3 = dwTickCount + (unsigned long)3 * 100; //没法开模
  862. }
  863. break;
  864. case 11:
  865. if((dwTickCount >= cDelayTime2) || !X06)
  866. {
  867. Y00 = 0; //退分带
  868. cStepMByte1 = 12;
  869. cDelayTime2 = dwTickCount + (unsigned long)250; //70ms
  870. }
  871. break;
  872. case 12:
  873. if (!X05 && !Y00 && !Y01)
  874. {
  875. cDelayTime2 = dwTickCount + (unsigned long)15;
  876. cStepMByte1 = 13;
  877. }
  878. break;
  879. case 13:
  880. if (dwTickCount >= cDelayTime2)
  881. {
  882. //没有长度之前检测到下一条链
  883. /* if ((cStepMode == 4) || (cStepMode == 0))
  884. {
  885. cStepMode = 1;
  886. cLowSpeadLimit = user_datas[4];
  887. }*/
  888. cStepMByte2 = 1; //给料启动
  889. cStepMByte1 = 0;
  890. }
  891. break;
  892. }
  893. //给料动作
  894. switch (cStepMByte2)
  895. {
  896. case 1:
  897. //分带感应 有料感应 下模感应 分带 下模
  898. if (!X05 && !X06 && X07 && !Y00 && !Y01)
  899. {
  900. cStepMByte2 = 2;
  901. cDelayTime3 = dwTickCount + (unsigned long)10 * (4 + user_datas[16]);
  902. if(user_datas[37] == 1)
  903. {
  904. Y10 = 1;
  905. cDelayTime3 = dwTickCount + (unsigned long)user_datas[38] + 20;
  906. }
  907. }
  908. break;
  909. case 2: //延时给料
  910. if ((dwTickCount >= cDelayTime3) && X07)
  911. {
  912. Y02 = 1; //给料输出
  913. cStepMByte2 = 3;
  914. //不知道加多少时候才够,只能定成1秒
  915. cDelayTime3 = dwTickCount + 2000;
  916. }
  917. break;
  918. case 3: //判断给料到位
  919. if(X11)
  920. {
  921. cStepMByte2 = 4;
  922. cDelayTime3 = dwTickCount + user_datas[9]; //给料到位延时返回
  923. }
  924. else if ((dwTickCount >= cDelayTime3) && X07)
  925. { //下模上升超时
  926. ZhenDongCTR(1);
  927. CT_bRunning = 0;
  928. M20 = 1;
  929. M10 = 0;
  930. M12 = 0;
  931. user_datas[100] = 4;
  932. }
  933. break;
  934. case 4:
  935. if (dwTickCount >= cDelayTime3)
  936. {
  937. Y02 = 0; //给料关
  938. cStepMByte2 = 5;
  939. }
  940. break;
  941. case 5:
  942. if (!X11)
  943. {
  944. cStepMByte2 = 6;
  945. cDelayTime3 = dwTickCount + 30; //给料到位延时返回
  946. if(user_datas[37] == 1)Y10 = 0;
  947. }
  948. break;
  949. case 6:
  950. if (X10 && (dwTickCount >= cDelayTime3)) cStepMByte2 = 10;
  951. break;
  952. }
  953. }
  954. }
  955. }
  956. //合模动作
  957. void HeMo(void)
  958. {
  959. switch(cStepMByte4)
  960. {
  961. case 0:
  962. return;
  963. case 1:
  964. if(user_datas[24] == 0)Y06 = 1; ////夹紧
  965. //护链选择
  966. if(!X13 ||(user_datas[23] == 0)) Y04 = 1; //护链输出
  967. cDelayTime7 = dwTickCount + (unsigned long)user_datas[13]*10 + 60; //160ms
  968. cStepMByte4 = 2;
  969. if(user_datas[37] == 1)Y10 = 0;
  970. break;
  971. case 2: //护链输出后分带输出
  972. if(X10 && !X11 && (Y06 || (user_datas[24] == 1)))
  973. {
  974. //护链磁感 不用护链磁感时用延时
  975. if ((((X12 && (user_datas[22] == 1))) || ((user_datas[23] == 1) && (dwTickCount >= cDelayTime7)) ||
  976. // 护链磁感选择
  977. (!X13 && (dwTickCount >= cDelayTime7) && (user_datas[22] == 0))) //要护链 不用磁感
  978. && !Y00 && !X05) //分带电磁阀 分带到位
  979. {
  980. Y00 = 1; //分带
  981. cDelayTime7 = dwTickCount + (unsigned long)10 * 10; //160ms
  982. }
  983. if(X05_UP && Y00) Y01 = 1; //下模输出
  984. //分带到位 分带电磁阀 
  985. //有料感应 下模输出
  986. if (X06 && Y01)Y03 = 1;
  987. }
  988. }
  989. }
  990. //振盘控制
  991. void ZhenDongCTR(unsigned char flag)
  992. {
  993. static unsigned long cStopZDTime, cTuiPianTime,cSongLiaoQianTime;
  994. static unsigned short cStartTimes;
  995. if(flag == 1)
  996. {
  997. if(!X14)
  998. {
  999. Y11 = 1;
  1000. cStopZDTime = dwTickCount + (unsigned long)1000 * 120;
  1001. }
  1002. }
  1003. else
  1004. {
  1005. //振动盘 振动检测 手动给料
  1006. if(Y11)
  1007. {
  1008. if((X14_UP || ((user_datas[25] == 0) && !X14)) && !M15) // || (X03_DW))
  1009. {
  1010. cStopZDTime = dwTickCount + (unsigned long)1000 * user_datas[11];
  1011. }
  1012. else if (M15 || ((X14 || (!CT_bRunning && (user_datas[25] == 1))) && (dwTickCount >= cStopZDTime)))
  1013. {
  1014. M15 = 0;
  1015. Y11 = 0;
  1016. cStartTimes = 0;
  1017. }
  1018. else if(X14_DW)
  1019. {
  1020. cStopZDTime = dwTickCount + (unsigned long)1000 * 40;
  1021. }
  1022. }
  1023. else if ((!Y11) && (((cStartTimes >= user_datas[12]) && (!X14))|| M15))
  1024. {
  1025. M15 = 0;
  1026. Y11 = 1;
  1027. cStopZDTime = dwTickCount + (unsigned long)1000 * 40;
  1028. if(X14)cStopZDTime = dwTickCount + (unsigned long)1000 * 4;
  1029. cStartTimes = 0;
  1030. }
  1031. }
  1032. // 送料前
  1033. if (X11_UP && (dwTickCount >= cSongLiaoQianTime))
  1034. {
  1035. cStartTimes++;
  1036. cSongLiaoQianTime = dwTickCount + 100;
  1037. }
  1038. //拉头检测
  1039. if (X14) cStartTimes = 0;
  1040. //推拉片动作(弹簧头)
  1041. if(flag == 0)
  1042. {
  1043. if((user_datas[26] == 0) || M03)
  1044. {
  1045. if(Y11 && !X04 && (M03 || CT_bRunning))
  1046. {
  1047. if (dwTickCount >= cTuiPianTime)
  1048. {
  1049. cTuiPianTime = dwTickCount + (unsigned long)10 * user_datas[15];
  1050. Y05 = ~Y05;
  1051. }
  1052. }
  1053. else Y05 = 0;
  1054. }
  1055. else if(Y11 && !X04)
  1056. Y05 = Y02;
  1057. }
  1058. }
  1059. #endif