YXGongZiMa.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. #include "global.h"
  2. #if XI_DONG_MACHINE
  3. /******输入输出说明******
  4. 输入监控页
  5. M48 X00 启动开关
  6. M49 X01 停止开关
  7. M50 X02 送料开关
  8. M51 X03 分带开关
  9. M52 X04 装料开关
  10. M53 X05 锁带开关
  11. M54 X06 夹料开关
  12. M55 X07 迫紧开关
  13. M56 X10 推料到位感应
  14. M57 X11 推料退到位感应
  15. M58 X12 送料到位感应
  16. M59 X13 送料退到位接近开关
  17. M60 X14 缺料感应
  18. M61 X15 过链接近开关
  19. M62 X16 迫紧接近开关
  20. M63 X17 卡带故障开关
  21. M64 X20 分带到位感应
  22. M65 X21 反推带到位感应
  23. M66 X22 工字码接近开关
  24. M67 X23 拨码片8脚
  25. M68 X24 拨码片4脚
  26. M69 X25 拨码片2脚
  27. M70 X26 模式转换 0 老款工作方式 1 新装饰链
  28. M71 X27 拨码片1脚
  29. 输出监控页
  30. M32 Y00 工字码数个位
  31. M33 Y01 工字码数十位
  32. M34 Y02 工字码间隙个位
  33. M35 Y03 振动盘
  34. M36 Y04 锁带电磁阀
  35. M37 Y05 送料电磁阀
  36. M38 Y06 夹料电磁阀
  37. M39 Y07 分带电磁阀
  38. M40 Y10 工字码间隙十位
  39. M41 Y11 工字码位置个位
  40. M42 Y12 工字码位置十位
  41. M43 Y13 蜂鸣器/计数表
  42. M44 Y14 装料电磁阀
  43. M45 Y15 迫紧电磁阀
  44. M46 Y16 反锁带电磁阀
  45. M47 Y017 反推带电磁阀
  46. ********************/
  47. extern unsigned long GZM_cCountTime;
  48. extern unsigned char GZM_cGeiLiaoNum;
  49. #define AddPuls 55
  50. //警告
  51. #define GZM_TuiLiaoDW_W 1 //推料到位(前)磁感开关异常
  52. #define GZM_TuiLiaoTDW_W 2 //推料退到位磁感开关异常
  53. #define GZM_SongLiaoDW_W 3 //送料到位磁感开关异常
  54. #define GZM_SongLiaoTDW_W 4 //送料退到位接近开关异常
  55. #define GZM_QueLiao_W 5 //缺料磁感开关异常
  56. #define GZM_NoZip_W 6 //过链接近开关异常
  57. #define GZM_PoJin_W 7 //迫紧接近开关异常
  58. #define GZM_KaDai_W 8 //卡带故障开关异常
  59. #define GZM_FengDaiDW_W 9 //分带到位磁感开关异常
  60. #define GZM_FanTiuDaiDW_W 10 //反推带到位磁感开关异常
  61. void GZM_TuiLiao(void);
  62. void GZM_PoJin(void);
  63. void GZM_Motor(void);
  64. unsigned char GZM_cOneTime,GZM_cWorkNum = 0,GZM_cBuMa,GZM_bStop,GZM_bRunning,GZM_cFirst,GZM_cGeiLiaoNum;
  65. long GZM_cPulseCount,GZM_dwSavePosBuff;
  66. void GZM_SetAlarmCode(unsigned alarm_code)
  67. {
  68. SetAlarmCode(GZM_ALARM_ADDR,alarm_code);
  69. GZM_bStop = 1;
  70. }
  71. void GZM_InitAction(void)
  72. {
  73. XGearRatio = 1;
  74. YGearRatio = 1;
  75. }
  76. void GZM_Action(void)
  77. {
  78. GZM_PoJin();
  79. if(M15)
  80. {
  81. M15 = 0;
  82. SetAlarmCode(GZM_ALARM_ADDR,0);
  83. }
  84. //下止位减1
  85. if(M12)
  86. {
  87. M12 = 0;
  88. if(user_datas[41] > 0)user_datas[41] -= 1;
  89. }
  90. //下止位加1
  91. else if(M11)
  92. {
  93. M11 = 0;
  94. if((user_datas[41] < 500) || (X026 && (user_datas[41] < 9999)))user_datas[41]++;
  95. }
  96. //间隙位减1
  97. if(M17)
  98. {
  99. M17 = 0;
  100. if(user_datas[42] > 0)user_datas[42] -= 1;
  101. }
  102. //间隙位加1
  103. else if(M16)
  104. {
  105. M16 = 0;
  106. if(user_datas[42] < 500)user_datas[42]++;
  107. }
  108. //振动盘控制
  109. if(user_datas[71] != 0)
  110. SETY003();
  111. else
  112. CLRY003();
  113. //停止
  114. if(X001 || M1 || (GZM_bStop != 0) || X017)
  115. {
  116. if(X01_UP)
  117. {
  118. if(GZM_bRunning == 0)
  119. GZM_cWorkNum = 0;
  120. }
  121. GZM_bStop = 0;
  122. GZM_bRunning = 0;
  123. M1 = 0;
  124. AxisEgmStop(X_AXIS);
  125. cStepMByte = 0;
  126. cStepMByte1 = 0;
  127. cStepMByte2 = 0;
  128. cStepMByte3 = 0;
  129. cStepMByte4 = 0;
  130. cStepMByte5 = 0;
  131. cStepMByte6 = 0;
  132. AxisEgmStop(X_AXIS);
  133. Y00 = 0;
  134. Y01 = 0;
  135. Y02 = 0;
  136. Y04 = 0;
  137. Y05 = 0;
  138. Y06 = 0;
  139. Y07 = 0;
  140. Y10 = 0;
  141. Y11 = 0;
  142. Y12 = 0;
  143. Y13 = 0;
  144. Y14 = 0;
  145. Y15 = 0;
  146. Y16 = 0;
  147. if(X17_UP)
  148. {
  149. GZM_SetAlarmCode(GZM_KaDai_W) ;
  150. }
  151. }
  152. //手动
  153. if((GZM_bRunning==0) && (X001 == 0))
  154. {
  155. SETDR();
  156. //下止数量减1
  157. if(M19)
  158. {
  159. M19 = 0;
  160. if(user_datas[43] > 0)user_datas[43] -= 1;
  161. }
  162. //下止数量减1
  163. else if(M18)
  164. {
  165. M18 = 0;
  166. if(user_datas[43] < 500)user_datas[43]++;
  167. }
  168. //清产量
  169. if(M9)
  170. {
  171. M9 = 0;
  172. ClrcToTal(78);
  173. }
  174. //起动
  175. if((X00_UP|| M0 || M10) && (GZM_bRunning == 0))
  176. { // 分针 送料 迫紧 不良链
  177. if((X020 == 0) && (X013 != 0) && (X011 != 0) && (X017==0) && (X010 == 0) && (X016 != 0) //各限位
  178. //各手动 手动锁带 手动分带 夹码 上升(送料) 推料
  179. && (X005 == 0) && (X003 == 0) && (X006 == 0) && (X004 == 0) && (X002 == 0))
  180. {
  181. cStepMByte = 1; //
  182. GZM_bRunning = 1;
  183. CLRDR();
  184. if(M10)
  185. GZM_cOneTime = 1;
  186. else
  187. GZM_cOneTime = 0;
  188. if(M8)
  189. GZM_cBuMa = 1;
  190. else
  191. GZM_cBuMa = 0;
  192. M0 = 0;
  193. M10 = 0;
  194. }
  195. }
  196. //动作程序 起动
  197. //推料动作
  198. if((X02_UP || M4))
  199. {
  200. M4 = 0;
  201. if((Y005 == 0) || X002)
  202. {
  203. if((X013 != 0) && (X016 != 0) && (X012 == 0) && (Y014 == 0) && (Y015 == 0))
  204. {
  205. SETY005();
  206. SETY006();
  207. }
  208. else //条件不满足警告
  209. {
  210. }
  211. }
  212. else
  213. {
  214. CLRY005();
  215. CLRY006();
  216. }
  217. }
  218. //夹料动作
  219. if(X06_UP || M3)
  220. {
  221. M3 = 0;
  222. if((Y006 == 0) || (X006))
  223. SETY006();
  224. else
  225. CLRY006();
  226. }
  227. //分带手动
  228. if(X03_UP || M5)
  229. {
  230. M5 = 0;
  231. if((Y007 == 0) || X003)
  232. {
  233. if(Y015 == 0)SETY007();
  234. }
  235. else
  236. CLRY007();
  237. }
  238. //手动送料(装料)
  239. if(X04_UP || M6)
  240. {
  241. M6 = 0;
  242. if((Y014 == 0) || X004)
  243. {
  244. if((X011 != 0) && (X010 == 0) && (Y005 == 0) && (X016 != 0) && (X020 != 0) && (Y015 == 0))SETY014();
  245. }
  246. else
  247. CLRY014();
  248. }
  249. //锁带动作
  250. if(X05_UP || M2)
  251. {
  252. M2 = 0;
  253. if((Y004 == 0) || X005)
  254. SETY004();
  255. else
  256. CLRY004();
  257. }
  258. //迫紧动作
  259. if(X07_UP || M7)
  260. {
  261. M7 = 0;
  262. if((X010 == 0) && (X011 != 0) && (Y005 == 0) && (X012!=0) && (X013 == 0) && (Y014 != 0) && (X020 == 0) && (X016 != 0) && !Y015)cStepMByte2 = 1;
  263. }
  264. }
  265. else if((GZM_bRunning != 0))
  266. {
  267. GZM_TuiLiao(); //推料
  268. GZM_Motor();
  269. if(!X026)
  270. {
  271. switch(cStepMByte)
  272. {
  273. case 0:
  274. break;
  275. case 1:
  276. cStepMByte = 2;
  277. cDelayTime1 = dwTickCount + 220; //先等待电机锁轴
  278. GZM_cFirst = 0;
  279. break;
  280. case 2:
  281. if(dwTickCount >= cDelayTime1)
  282. {
  283. GZM_cGeiLiaoNum = 0; //推料次数清零
  284. cStepMByte1 = 1; //推料启动
  285. cStepMByte3 = 1; //拖带电机启动
  286. cStepMByte = 3;
  287. }
  288. break;
  289. case 3:
  290. //  一次拖带完成
  291. if((cStepMByte3 == 0))
  292. {
  293. //第一条处理,判断是否为补码
  294. if(((X022 != 0) || M8) && (GZM_cFirst == 0))
  295. {
  296. cStepMByte = 50;
  297. }
  298. else
  299. {
  300. cStepMByte = 4;
  301. SETY007(); //分带输出
  302. cDelayTime1 = dwTickCount + GZM_ERRORTIME; //先等待电机锁轴
  303. }
  304. }
  305. break;
  306. case 4:
  307. //分带到位
  308. if(X020)
  309. { //保证给料回到原位 推料完成
  310. if((X011 != 0) && (X010 == 0) && (Y005 == 0) && (cStepMByte1 == 0))
  311. {
  312. SETY014(); //装料输出
  313. cStepMByte = 5;
  314. cDelayTime1 = dwTickCount + GZM_ERRORTIME;
  315. }
  316. }
  317. else if(dwTickCount >= cDelayTime1)
  318. {
  319. GZM_SetAlarmCode(GZM_FengDaiDW_W);
  320. }
  321. break;
  322. case 5: //装到位
  323. if((X012 != 0) && (X013 == 0))
  324. {
  325. cStepMByte = 6;
  326. cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[10]; //延时退分带
  327. }
  328. else if(dwTickCount >= cDelayTime1)
  329. {
  330. GZM_SetAlarmCode(GZM_SongLiaoDW_W);
  331. }
  332. break;
  333. case 6:
  334. if(dwTickCount >= cDelayTime1)
  335. {
  336. cStepMByte = 7;
  337. CLRY007();
  338. }
  339. break;
  340. case 7:
  341. if(X020 == 0)
  342. {
  343. cStepMByte = 8;
  344. cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[11]; //分带信号离开二次拖带
  345. }
  346. break;
  347. case 8:
  348. if(dwTickCount >= cDelayTime1)
  349. {
  350. cStepMByte = 9;
  351. cStepMByte3 = 10; //电机二次拖带
  352. if((GZM_cWorkNum > 0) || (X022 != 0) || M8)//第二次为间隙
  353. {
  354. GZM_cPulseCount = user_datas[42] + user_datas[16] + user_datas[1];
  355. }
  356. else
  357. {
  358. // 第一次长度脉冲 + 修正值
  359. GZM_cPulseCount = user_datas[41] + user_datas[15];
  360. }
  361. }
  362. break;
  363. case 9:
  364. if(cStepMByte3 == 0)
  365. {
  366. if(Y004 && (GZM_cWorkNum == 0) && (M8 == 0))
  367. {
  368. CLRY004();
  369. cDelayTime1 = dwTickCount + (unsigned long)10 * 3; //二次拖带停止后延时迫紧
  370. }
  371. else if(dwTickCount >= cDelayTime1)
  372. {
  373. cStepMByte = 10;
  374. cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[12]; //二次拖带停止后延时迫紧
  375. if((GZM_cWorkNum == 0) && (M8 == 0)) //第一颗时反转一下
  376. {
  377. SETY010();
  378. if(user_datas[22] != 0)
  379. {
  380. AxisMovePos(X_AXIS,5,-GZM_cPulseCount);
  381. cStepMByte3 = 500;
  382. }
  383. }
  384. else
  385. GZM_cPulseCount = 0;
  386. }
  387. }
  388. break;
  389. case 10: // 单一自动   迫紧
  390. if((dwTickCount >= cDelayTime1) && ((GZM_cOneTime == 0) || M7) && (GZM_cPulseCount == 0))
  391. {
  392. cStepMByte3 = 0;
  393. M7 = 0;
  394. cStepMByte = 11;
  395. cStepMByte2 = 1; //迫紧开始
  396. CLRY010();
  397. if(user_datas[5] == 0)CLRY004();
  398. }
  399. break;
  400. case 11:
  401. if(cStepMByte2 == 0)
  402. {
  403. cStepMByte = 12;
  404. CLRY014(); //装料下
  405. M8 = 0;
  406. GZM_cWorkNum++;
  407. if(GZM_cWorkNum >= user_datas[43]) //当条打完
  408. {
  409. CLRY004(); //夹带松开
  410. }
  411. else //打下一颗
  412. {
  413. //输出电机反转和反向锁定电磁阀
  414. SETY010();
  415. }
  416. cDelayTime1 = dwTickCount + GZM_ERRORTIME;
  417. }
  418. break;
  419. case 12: //装料下到位
  420. if((X012 == 0) && (X013 != 0))
  421. {
  422. if(GZM_cWorkNum >= user_datas[43]) //当条打完
  423. {
  424. if((GZM_cOneTime != 0) || (GZM_cBuMa != 0))
  425. {
  426. cStepMByte = 0;
  427. GZM_bRunning = 0;
  428. }
  429. else
  430. cStepMByte = 2;
  431. //产量加一保存
  432. AddToTal(76);
  433. //计算生产速度
  434. CalProSP(78);
  435. cDelayTime1 = dwTickCount;
  436. GZM_cWorkNum = 0;
  437. }
  438. else
  439. {
  440. cStepMByte = 30;
  441. cDelayTime1 = dwTickCount + 15;
  442. }
  443. }
  444. else if(dwTickCount >= cDelayTime1)GZM_SetAlarmCode(GZM_SongLiaoTDW_W);
  445. break;
  446. //以下为反转电机
  447. case 30:
  448. if(dwTickCount >= cDelayTime1) //后锁带时间到
  449. {
  450. cDelayTime1 = dwTickCount + 25; //25
  451. //松开前锁带
  452. CLRY004();
  453. cStepMByte = 31;
  454. }
  455. break;
  456. case 31:
  457. if(dwTickCount >= cDelayTime1)
  458. {
  459. cDelayTime1 = dwTickCount + 30; //25
  460. //反向电磁阀
  461. SETY011();
  462. cStepMByte = 32;
  463. }
  464. break;
  465. case 32:
  466. if(dwTickCount >= cDelayTime1)
  467. {
  468. cStepMByte = 33;
  469. GZM_cPulseCount = user_datas[41] + AddPuls + user_datas[9];
  470. //重新推料
  471. if((GZM_cWorkNum > 0) && (M8 == 0))
  472. {
  473. GZM_cGeiLiaoNum = 0; //推料次数清零
  474. cStepMByte1 = 1; //推料启动
  475. }
  476. cStepMByte3 = 15;
  477. cDelayTime1 = dwTickCount + (unsigned long)350;
  478. }
  479. break;
  480. case 33://退到位
  481. if(X021 != 0)
  482. {
  483. AxisEgmStop(X_AXIS);
  484. if(X21_UP)
  485. {
  486. cDelayTime1 = dwTickCount + (unsigned long)35;
  487. }
  488. if(dwTickCount >= cDelayTime1)
  489. {
  490. cDelayTime1 = dwTickCount + (unsigned long)user_datas[14]*10; //锁带时间
  491. SETY004(); //锁带
  492. cStepMByte = 34;
  493. }
  494. }
  495. else if(((dwRealPos -GZM_dwSavePosBuff)>300) && (dwTickCount >= cDelayTime1))
  496. {
  497. GZM_SetAlarmCode(GZM_FanTiuDaiDW_W); //
  498. }
  499. break;
  500. case 34:
  501. if(dwTickCount >= cDelayTime1)
  502. {
  503. //输出电机正转,关反向电磁阀
  504. CLRY010();
  505. CLRY011();
  506. //分带
  507. cStepMByte = 4;
  508. SETY007(); //分带输出
  509. cDelayTime1 = dwTickCount + GZM_ERRORTIME;
  510. }
  511. break;
  512. //50-52步为第一条补带的先往前
  513. case 50:
  514. cStepMByte = 51;
  515. // 第一次长度脉冲 + 修正值
  516. GZM_cPulseCount = user_datas[41] + user_datas[15] + user_datas[17];
  517. cStepMByte3 = 10;
  518. GZM_cFirst = 1;
  519. break;
  520. case 51:
  521. if(cStepMByte3 == 0)
  522. {
  523. cStepMByte = 52;
  524. cDelayTime1 = dwTickCount + (unsigned long)35;
  525. }
  526. break;
  527. case 52: //返向转动
  528. if(dwTickCount >= cDelayTime1)
  529. {
  530. cStepMByte = 30;
  531. //输出电机反转和反向锁定电磁阀
  532. SETY010();
  533. cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[14]; //50
  534. }
  535. }
  536. }
  537. else //第二种机械,只有打码
  538. {
  539. switch(cStepMByte)
  540. {
  541. case 0:
  542. break;
  543. case 1: //先锁轴
  544. CLRDR();
  545. cDelayTime1 = dwTickCount + (unsigned long)10 * 20;
  546. cStepMByte = 2;
  547. break;
  548. case 2:
  549. if(dwTickCount >= cDelayTime1)
  550. {
  551. if(M8 == 0) //不是补码状态下先拖空柆
  552. {
  553. cStepMByte = 3;
  554. cStepMByte3 = 20; //第一条 先走空位长度
  555. }
  556. else //走补码程序
  557. {
  558. }
  559. cStepMByte1 = 1; //推料开始
  560. }
  561. break;
  562. case 3: //第一次拉带完成
  563. if((cStepMByte3 == 0))
  564. {
  565. cStepMByte = 4;
  566. SETY007(); //分带输出
  567. cDelayTime1 = dwTickCount + GZM_ERRORTIME; //判断分带是否到位
  568. }
  569. break;
  570. case 4:
  571. //分带到位
  572. if(X020)
  573. { //保证给料回到原位 推料完成
  574. if((X011 != 0) && (X010 == 0) && (Y005 == 0) && (cStepMByte1 == 0))
  575. {
  576. SETY014(); //装料输出
  577. cStepMByte = 5;
  578. cDelayTime1 = dwTickCount + GZM_ERRORTIME;
  579. //反锁就先输出
  580. SETY010();
  581. }
  582. }
  583. else if(dwTickCount >= cDelayTime1)GZM_SetAlarmCode(GZM_FengDaiDW_W);
  584. break;
  585. case 5: //装到位
  586. if((X012 != 0) && (X013 == 0))
  587. {
  588. cStepMByte = 6;
  589. cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[10]; //延时退分带
  590. }
  591. else if(dwTickCount >= cDelayTime1)GZM_SetAlarmCode(GZM_SongLiaoDW_W);
  592. break;
  593. case 6:
  594. if(dwTickCount >= cDelayTime1)
  595. {
  596. cStepMByte = 7;
  597. //分带关闭
  598. CLRY007();
  599. //反推电磁阀输出
  600. SETY011();
  601. //前锁带关闭
  602. CLRY004();
  603. }
  604. break;
  605. case 7:
  606. if(X020 == 0)
  607. {
  608. cStepMByte = 8;
  609. cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[11]; //分带信号离开二次拖带
  610. }
  611. break;
  612. case 8:
  613. if(dwTickCount >= cDelayTime1)
  614. {
  615. //计算脉冲数 细分*空位长度/周长,第一次的长度+第二次间隙长度+加上补尝
  616. GZM_cPulseCount = user_datas[42] + user_datas[16] + user_datas[1]; //加上公式
  617. cStepMByte = 9;
  618. //电机反转
  619. cStepMByte3 = 15;
  620. }
  621. break;
  622. case 9:
  623. if(cStepMByte3 == 0)
  624. {
  625. cStepMByte = 10;
  626. cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[12]; //二次拖带停止后延时迫紧
  627. }
  628. else if(X021 != 0) //退回脉冲没到之前,到达反限位时出错
  629. {
  630. }
  631. break;
  632. case 10: // 单一自动   迫紧
  633. if((dwTickCount >= cDelayTime1) && ((GZM_cOneTime == 0) || M7))
  634. {
  635. M7 = 0;
  636. cStepMByte = 11;
  637. cStepMByte2 = 1; //迫紧开始
  638. }
  639. break;
  640. case 11:
  641. if(cStepMByte2 == 0) //迫紧完成
  642. {
  643. cStepMByte = 12;
  644. CLRY014(); //装料下
  645. M8 = 0;
  646. GZM_cWorkNum++;
  647. if(GZM_cWorkNum >= user_datas[43]) //当条打完
  648. {
  649. CLRY010(); //反转锁带松开
  650. CLRY011(); //反推电磁阀松开
  651. }
  652. else //打下一颗
  653. {
  654. //前锁带输出
  655. SETY004();
  656. }
  657. cDelayTime1 = dwTickCount + GZM_ERRORTIME;
  658. }
  659. break;
  660. case 12: //装料下到位
  661. if((X012 == 0) && (X013 != 0))
  662. {
  663. if(GZM_cWorkNum >= user_datas[43]) //当条打完
  664. {
  665. if(GZM_cOneTime != 0)
  666. {
  667. cStepMByte = 0;
  668. GZM_bRunning = 0;
  669. }
  670. else
  671. cStepMByte = 99;
  672. //产量加一保存
  673. AddToTal(76);
  674. //计算生产速度
  675. CalProSP(78);
  676. cDelayTime1 = dwTickCount;
  677. GZM_cWorkNum = 0;
  678. }
  679. }
  680. else if(dwTickCount >= cDelayTime1)GZM_SetAlarmCode(GZM_SongLiaoTDW_W);
  681. break;
  682. }
  683. }
  684. }
  685. }
  686. //夹码.推码动作
  687. void GZM_TuiLiao(void)
  688. {
  689. switch(cStepMByte1)
  690. {
  691. case 0:
  692. break;
  693. case 1:
  694. // 推料后     推料前    主轴  送料前 送料后
  695. if((X011 != 0) && (X010 == 0) && X016 && !X012 && X013) //推料电磁阀在原点
  696. {
  697. cStepMByte1 = 2;
  698. SETY006();
  699. cDelayTime2 = dwTickCount + (unsigned long)10 * user_datas[7];
  700. }
  701. else //先退推料电磁阀
  702. {
  703. CLRY005();
  704. CLRY006();
  705. }
  706. break;
  707. case 2://等夹料时间
  708. if(dwTickCount >= cDelayTime2)
  709. {
  710. cStepMByte1 = 3;
  711. SETY005();
  712. cDelayTime2 = dwTickCount + (unsigned long)10 * user_datas[0];
  713. }
  714. break;
  715. case 3:
  716. if((X010 != 0) && (X011 == 0)) //送到前面
  717. {
  718. cStepMByte1 = 4;
  719. cDelayTime2 = dwTickCount + (unsigned long)10*user_datas[6]; //延时检测
  720. }
  721. else if(dwTickCount >= cDelayTime2)
  722. {
  723. CLRY005();
  724. CLRY006();
  725. GZM_cGeiLiaoNum++;
  726. if(GZM_cGeiLiaoNum >= user_datas[3]) //3次就结束警告
  727. {
  728. GZM_SetAlarmCode(GZM_TuiLiaoDW_W);
  729. }
  730. else
  731. {
  732. cStepMByte1 = 10;
  733. cDelayTime2 = dwTickCount + GZM_ERRORTIME;
  734. }
  735. }
  736. break;
  737. case 4: //延时检测是否有料
  738. if(dwTickCount >= cDelayTime2)
  739. {
  740. CLRY006(); //松开夹
  741. if(!X014)
  742. {
  743. cDelayTime2 = dwTickCount + (unsigned long)10*user_datas[8]; //150ms
  744. cStepMByte1 = 5;
  745. }
  746. else
  747. {
  748. CLRY005(); //退料同时退
  749. GZM_cGeiLiaoNum++;
  750. if(GZM_cGeiLiaoNum >= user_datas[3]) //3次就结束
  751. {
  752. GZM_SetAlarmCode(GZM_QueLiao_W);
  753. }
  754. else
  755. {
  756. cStepMByte1 = 10;
  757. cDelayTime2 = dwTickCount + GZM_ERRORTIME;
  758. }
  759. }
  760. }
  761. break;
  762. case 5:
  763. if(dwTickCount >= cDelayTime2) //松开夹料后退推料
  764. {
  765. cStepMByte1 = 6;
  766. CLRY005();
  767. cDelayTime2 = dwTickCount + GZM_ERRORTIME;
  768. }
  769. break;
  770. case 6:
  771. if(!X010 && X011) //退料到位
  772. {
  773. cStepMByte1 = 0; //
  774. }
  775. else if(dwTickCount >= cDelayTime2) //退推料到位出错
  776. {
  777. GZM_SetAlarmCode(GZM_TuiLiaoTDW_W);
  778. }
  779. break;
  780. case 10:
  781. if(!X010 && X011) //出错后退料到位
  782. {
  783. cStepMByte1 = 11;
  784. cDelayTime2 = dwTickCount + (unsigned long)100*user_datas[4]; //延时重新推料
  785. }
  786. else if(dwTickCount >= cDelayTime2) //退推料到位出错
  787. {
  788. GZM_SetAlarmCode(GZM_TuiLiaoTDW_W);
  789. }
  790. break;
  791. case 11:
  792. if(dwTickCount >= cDelayTime2)
  793. {
  794. cStepMByte1 = 1;
  795. }
  796. break;
  797. }
  798. }
  799. //迫紧动作
  800. void GZM_PoJin(void)
  801. {
  802. switch(cStepMByte2)
  803. {
  804. case 0:
  805. break;
  806. case 1:
  807. cStepMByte2 = 2;
  808. SETY012(); //迫紧输出
  809. cDelayTime3 = dwTickCount + GZM_ERRORTIME;
  810. break;
  811. case 2:
  812. if(!X016)
  813. {
  814. cStepMByte2 = 3;
  815. CLRY012();
  816. cDelayTime3 = dwTickCount + (unsigned long)75;
  817. }
  818. else if(dwTickCount >= cDelayTime3) //主轴没法转动
  819. {
  820. GZM_SetAlarmCode(GZM_PoJin_W);
  821. }
  822. break;
  823. case 3:
  824. if(dwTickCount >= cDelayTime3)
  825. {
  826. cStepMByte2 = 4;
  827. cDelayTime3 = dwTickCount + GZM_ERRORTIME;
  828. }
  829. break;
  830. case 4:
  831. if(X016)
  832. {
  833. cStepMByte2 = 0;
  834. }
  835. else if(dwTickCount >= cDelayTime3) //主轴没法转动一周
  836. {
  837. GZM_SetAlarmCode(GZM_PoJin_W);
  838. }
  839. break;
  840. }
  841. }
  842. //拖带电机
  843. void GZM_Motor(void)
  844. {
  845. static long save_pos;
  846. switch(cStepMByte3)
  847. {
  848. case 1:
  849. if(X015 == 0)
  850. {
  851. cStepMByte3 = 2;
  852. cDelayTime4 = dwTickCount + 5;
  853. MoveAction_Const_AccDec(X_AXIS, GZM_DIR_P,user_datas[2],user_datas[19],5,1);
  854. }
  855. else //在空位慢速
  856. {
  857. cStepMByte3 = 3;
  858. cDelayTime4 = dwTickCount + (unsigned long)1000 * user_datas[13];
  859. MoveAction_Const_AccDec(X_AXIS, GZM_DIR_P,user_datas[19],user_datas[19],5,1);
  860. }
  861. break;
  862. case 2:
  863. if((dwTickCount >= cDelayTime4) && X15_UP)
  864. {
  865. MoveChangSpeed(X_AXIS,user_datas[19]);
  866. cStepMByte3 = 3;
  867. cDelayTime4 = dwTickCount + (unsigned long)1000 * user_datas[13];
  868. }
  869. break;
  870. case 3:
  871. if(X15_DW)
  872. {
  873. AxisEgmStop(X_AXIS);
  874. cStepMByte3 = 0;
  875. }
  876. else if(dwTickCount >= cDelayTime4)//没链停机
  877. {
  878. GZM_SetAlarmCode(GZM_NoZip_W);
  879. }
  880. break;
  881. //以上为前检测拖带
  882. //下面是二次拖带
  883. case 10:
  884. cStepMByte3 = 11;
  885. MoveAction_Const_AccDec(X_AXIS, GZM_DIR_P,user_datas[20],1,5,1);
  886. break;
  887. case 11:
  888. if(X15_DW)
  889. {
  890. AxisEgmStop(X_AXIS);
  891. cStepMByte3 = 0;
  892. }
  893. break;
  894. //反推时快速返回
  895. case 15:
  896. cStepMByte3 = 11;
  897. GZM_dwSavePosBuff = dwRealPos;
  898. MoveAction_Const_AccDec(X_AXIS, GZM_DIR_P,user_datas[20],1,5,1);
  899. break;
  900. //走拖带轮的拉链长度
  901. case 20:
  902. cStepMByte3 = 21;
  903. //计算脉冲数 细分*空位长度/周长,第一次的长度+第二次间隙长度
  904. GZM_cPulseCount = 1600 * user_datas[41]/user_datas[21] + user_datas[42] + user_datas[16] + user_datas[1]; //加上公式
  905. save_pos = dwRealPos;
  906. AxisMovePos(X_AXIS,user_datas[19],GZM_cPulseCount);
  907. break;
  908. //等待走拉链长度走完
  909. case 21:
  910. if((dwRealPos - save_pos) < 200) //前锁带先锁
  911. {
  912. SETY004(); //前锁带输出
  913. }
  914. if(!X_DRV)
  915. {
  916. cStepMByte3 = 0;
  917. }
  918. break;
  919. }
  920. }
  921. #endif