XYChuanTouJi.c 35 KB

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