XDLaSiJi.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. #include "global.h"
  2. #if XI_DONG_MACHINE
  3. /**************************************
  4. //X000 正转启动
  5. //X001 反转启动
  6. //X002 停止
  7. //X003 步进电机点动
  8. //X004 电机正、反转开关
  9. //X005 摆丝电机计数下反转
  10. //X006 摆丝电机右接近开关
  11. //X007 摆丝电机左接近开关
  12. //X010 摆丝电机暂停正、反转开关
  13. //X011 摆丝电机加速开关
  14. //X012 摆丝电机点动正、反转
  15. //X013 卷丝电机点动正、反转
  16. //X014 1号压丝电机点动正、反转
  17. //X015 2号压丝电机点动正、反转
  18. //X016 3号压丝电机点动正、反转
  19. //X017 4号压丝电机点动正、反转
  20. //X020 5号压丝电机点动正、反转
  21. //X021 变频器异常
  22. //X022 摆丝电机到位接近开关
  23. //X023 6号压丝电机点动正、反转
  24. //X024 7号压丝电机点动正、反转
  25. //X025 8号压丝电机点动正、反转
  26. //X026 9号压丝电机点动正、反转
  27. //X027
  28. //Y000 启动
  29. //Y001 摆丝电机加速
  30. //Y002 摆丝电机正转
  31. //Y003 摆丝电机反转
  32. //Y004 卷丝电机正转
  33. //Y005 卷丝电机反转
  34. //Y006 1号压丝电机正转
  35. //Y007 1号压丝电机反转
  36. //Y010 2号压丝电机正转
  37. //Y011 2号压丝电机反转
  38. //Y012 3号压丝电机正转
  39. //Y013 3号压丝电机反转
  40. //Y014 4号压丝电机正转
  41. //Y015 4号压丝电机反转
  42. //Y016 5号压丝电机正转
  43. //Y017 5号压丝电机反转
  44. ***************************************/
  45. #define LS_SETCSB_DIS() SETY015()
  46. #define LS_SETCSB_EN() CLRY015()
  47. unsigned char LS_Y02_EN,LS_Y03_EN,LS_bRunning;
  48. unsigned long LS_cTotal;
  49. void LS_InitAction(void)
  50. {
  51. XGearRatio = 1;
  52. YGearRatio = 1;
  53. }
  54. void LS_Action(void)
  55. {
  56. //正转启动 反转启动 变频器异常 停止
  57. if((X00_UP || X01_UP) && X21 && (X02 == 0) && (LS_bRunning == 0))
  58. {
  59. LS_bRunning = 1;
  60. cStepMByte = 1;
  61. LS_cTotal = 0;
  62. SETY000();
  63. SETY004();
  64. SETY010();
  65. SETY012();
  66. SETY014();
  67. SETY016();
  68. SETY020();
  69. SETY022();
  70. SETY024();
  71. SETY026();
  72. SETY006();
  73. LS_Y02_EN = 0;
  74. LS_Y03_EN = 0;
  75. cDelayTime1 = dwTickCount + (unsigned long)user_datas[3] * 10;
  76. SETDR();
  77. LS_SETCSB_DIS();
  78. if(X01_UP)
  79. {
  80. cStepMByte = 11;
  81. SETY003();
  82. LS_Y03_EN = 1;
  83. }
  84. else
  85. {
  86. SETY002();
  87. LS_Y02_EN = 1;
  88. }
  89. }
  90. if(X011)
  91. {
  92. SETY001();
  93. }
  94. else if(X11_DW)
  95. CLRY001();
  96. //手动状态 
  97. if((LS_bRunning == 0) && (X002 == 0) && (dwTickCount >= cDelayTime2))
  98. {
  99. if(X003) //
  100. {
  101. if(!X_DRV && X03_UP)
  102. {
  103. LS_SETCSB_DIS();
  104. if(X004 == 0) //正转
  105. {
  106. SETDR();
  107. AxisMovePosAccDec(X_AXIS, 5, 10 * user_datas[5],user_datas[4],1,1);
  108. }
  109. else if(!X022)
  110. {
  111. CLRDR(); //反转
  112. MoveAction_Const_AccDec(X_AXIS,LS_DIR_P,user_datas[4],user_datas[4],1,1);
  113. }
  114. }
  115. if(X004 != 0) //反转回原点
  116. {
  117. if(X022 && (user_datas[6] == 1))AxisEgmStop(X_AXIS);
  118. }
  119. }
  120. else if(X03_DW)
  121. {
  122. if(X004 != 0) AxisEgmStop(X_AXIS);
  123. }
  124. if(X12_UP) //摆丝机点动
  125. {
  126. if(X004 == 0) //正转
  127. {
  128. SETY002();
  129. CLRY003();
  130. }
  131. else //反转
  132. {
  133. CLRY002();
  134. SETY003();
  135. }
  136. }
  137. else if(X012 == 0)
  138. {
  139. CLRY002();
  140. CLRY003();
  141. }
  142. if(X13_UP) //卷丝机点动
  143. {
  144. if(X004 == 0) //正转
  145. {
  146. SETY004();
  147. CLRY005();
  148. }
  149. else //反转
  150. {
  151. CLRY004();
  152. SETY005();
  153. }
  154. }
  155. else if(X013 == 0)
  156. {
  157. CLRY004();
  158. CLRY005();
  159. }
  160. if(X14_UP) //1号压丝机
  161. {
  162. if(X004 == 0)
  163. {
  164. SETY006();
  165. CLRY007();
  166. }
  167. else
  168. {
  169. CLRY006();
  170. SETY007();
  171. }
  172. }
  173. else if(X014 == 0)
  174. {
  175. CLRY006();
  176. CLRY007();
  177. }
  178. if(X15_UP) //2号压丝机
  179. {
  180. if(X004 == 0)
  181. {
  182. SETY010();
  183. CLRY011();
  184. }
  185. else
  186. {
  187. CLRY010();
  188. SETY011();
  189. }
  190. }
  191. else if(X015 == 0)
  192. {
  193. CLRY010();
  194. CLRY011();
  195. }
  196. if(X16_UP) //3号压丝机
  197. {
  198. if(X004 == 0)
  199. {
  200. SETY012();
  201. CLRY013();
  202. }
  203. else
  204. {
  205. CLRY012();
  206. SETY013();
  207. }
  208. }
  209. else if(X016 == 0)
  210. {
  211. CLRY012();
  212. CLRY013();
  213. }
  214. if(X17_UP) //4号压丝机
  215. {
  216. if(X004 == 0)
  217. {
  218. SETY014();
  219. CLRY015();
  220. }
  221. else
  222. {
  223. CLRY014();
  224. SETY015();
  225. }
  226. }
  227. else if(X017 == 0)
  228. {
  229. CLRY014();
  230. CLRY015();
  231. }
  232. if(X20_UP) //5号压丝机
  233. {
  234. if(X004 == 0)
  235. {
  236. SETY016();
  237. CLRY017();
  238. }
  239. else
  240. {
  241. CLRY016();
  242. SETY017();
  243. }
  244. }
  245. else if(X020 == 0)
  246. {
  247. CLRY016();
  248. CLRY017();
  249. }
  250. if(X23_UP) //6号压丝机
  251. {
  252. if(X004 == 0)
  253. {
  254. SETY020();
  255. CLRY021();
  256. }
  257. else
  258. {
  259. CLRY020();
  260. SETY021();
  261. }
  262. }
  263. else if(X023 == 0)
  264. {
  265. CLRY020();
  266. CLRY021();
  267. }
  268. if(X24_UP) //7号压丝机
  269. {
  270. if(X004 == 0)
  271. {
  272. SETY022();
  273. CLRY023();
  274. }
  275. else
  276. {
  277. CLRY022();
  278. SETY023();
  279. }
  280. }
  281. else if(X024 == 0)
  282. {
  283. CLRY022();
  284. CLRY023();
  285. }
  286. if(X25_UP) //8号压丝机
  287. {
  288. if(X004 == 0)
  289. {
  290. SETY024();
  291. CLRY025();
  292. }
  293. else
  294. {
  295. CLRY024();
  296. SETY025();
  297. }
  298. }
  299. else if(X025 == 0)
  300. {
  301. CLRY024();
  302. CLRY025();
  303. }
  304. if(X26_UP) //9号压丝机
  305. {
  306. if(X004 == 0)
  307. {
  308. SETY026();
  309. CLRY027();
  310. }
  311. else
  312. {
  313. CLRY026();
  314. SETY027();
  315. }
  316. }
  317. else if(X026 == 0)
  318. {
  319. CLRY026();
  320. CLRY027();
  321. }
  322. }
  323. else if(LS_bRunning) //自动运行
  324. {
  325. switch(cStepMByte)
  326. {
  327. case 1:
  328. if((X006 || (X022 && (user_datas[6] == 0)))&& (dwTickCount >= cDelayTime1))
  329. {
  330. cStepMByte = 2;
  331. cDelayTime1 = dwTickCount + 1;
  332. LS_cTotal = 0;
  333. }
  334. else if(!X006 && ((!X022 && (user_datas[6] == 0)) || (user_datas[6] == 1)))
  335. {
  336. cDelayTime1 = dwTickCount + (unsigned long)user_datas[3] * 10;
  337. }
  338. break;
  339. case 2:
  340. if((X05_UP || (user_datas[0] == 0)) && (dwTickCount >= cDelayTime1))
  341. {
  342. cDelayTime1 = dwTickCount + 15;
  343. LS_cTotal++;
  344. if(LS_cTotal >= user_datas[0])
  345. {
  346. LS_cTotal = 0;
  347. cStepMByte = 3;
  348. }
  349. }
  350. break;
  351. case 3:
  352. CLRY002();
  353. CLRY003();
  354. LS_Y02_EN = 0;
  355. LS_Y03_EN = 0;
  356. cStepMByte = 4;
  357. cDelayTime1 = dwTickCount + 1;
  358. break;
  359. case 4:
  360. if((X05_UP || (user_datas[1] == 0)) && (dwTickCount >= cDelayTime1))
  361. {
  362. cDelayTime1 = dwTickCount + 15;
  363. LS_cTotal++;
  364. if(LS_cTotal >= user_datas[1])
  365. {
  366. LS_cTotal = 0;
  367. cStepMByte = 5;
  368. }
  369. }
  370. break;
  371. case 5:
  372. CLRY002();
  373. SETY003();
  374. LS_Y03_EN = 1;
  375. SETY001();
  376. cStepMByte = 6;
  377. cDelayTime1 = dwTickCount + (unsigned long)user_datas[3] * 10;
  378. break;
  379. case 6:
  380. CLRY002();
  381. SETY003();
  382. SETY001();
  383. if(!X006 && ((!X022 && (user_datas[6] == 0)) || (user_datas[6] == 1)) && (dwTickCount >= cDelayTime1))
  384. {
  385. cStepMByte = 7;
  386. cDelayTime1 = dwTickCount + 1;
  387. LS_cTotal = 0;
  388. }
  389. else if(X006 || (X022 && (user_datas[6] == 0)))
  390. {
  391. cDelayTime1 = dwTickCount + (unsigned long)user_datas[3] * 10;
  392. }
  393. break;
  394. case 7:
  395. if((X05_UP || (user_datas[2] == 0))&& (dwTickCount >= cDelayTime1))
  396. {
  397. cDelayTime1 = dwTickCount + 15;
  398. LS_cTotal++;
  399. if(LS_cTotal >= user_datas[2])
  400. {
  401. LS_cTotal = 0;
  402. cStepMByte = 8;
  403. }
  404. }
  405. break;
  406. case 8:
  407. CLRY001();
  408. cStepMByte = 9;
  409. AxisMovePosAccDec(X_AXIS, 5, 10 * user_datas[5],user_datas[4],1,1);
  410. break;
  411. case 9:
  412. cStepMByte = 11;
  413. cDelayTime1 = dwTickCount + (unsigned long)user_datas[3] * 10;
  414. break;
  415. case 11:
  416. if((X007 || (X022 && (user_datas[6] == 0))) && (dwTickCount >= cDelayTime1))
  417. {
  418. cStepMByte = 12;
  419. cDelayTime1 = dwTickCount + 1;
  420. LS_cTotal = 0;
  421. }
  422. else if(!X007 && ((!X022 && (user_datas[6] == 0)) || (user_datas[6] == 1)))
  423. {
  424. cDelayTime1 = dwTickCount + (unsigned long)user_datas[3] * 10;
  425. }
  426. break;
  427. case 12:
  428. if((X05_UP || (user_datas[0] == 0)) && (dwTickCount >= cDelayTime1))
  429. {
  430. cDelayTime1 = dwTickCount + 15;
  431. LS_cTotal++;
  432. if(LS_cTotal >= user_datas[0])
  433. {
  434. LS_cTotal = 0;
  435. cStepMByte = 13;
  436. }
  437. }
  438. break;
  439. case 13:
  440. CLRY002();
  441. CLRY003();
  442. LS_Y02_EN = 0;
  443. LS_Y03_EN = 0;
  444. cStepMByte = 14;
  445. cDelayTime1 = dwTickCount + 1;
  446. break;
  447. case 14:
  448. if((X05_UP || (user_datas[1] == 0)) && (dwTickCount >= cDelayTime1))
  449. {
  450. cDelayTime1 = dwTickCount + 15;
  451. LS_cTotal++;
  452. if(LS_cTotal >= user_datas[1])
  453. {
  454. LS_cTotal = 0;
  455. cStepMByte = 15;
  456. }
  457. }
  458. break;
  459. case 15:
  460. SETY002();
  461. LS_Y02_EN = 1;
  462. CLRY003();
  463. SETY001();
  464. cStepMByte = 16;
  465. cDelayTime1 = dwTickCount + (unsigned long)user_datas[3] * 10;
  466. break;
  467. case 16:
  468. SETY002();
  469. CLRY003();
  470. SETY001();
  471. if(!X007 && ((!X022 && (user_datas[6] == 0)) || (user_datas[6] == 1)) && (dwTickCount >= cDelayTime1))
  472. {
  473. cStepMByte = 17;
  474. cDelayTime1 = dwTickCount + 1;
  475. LS_cTotal = 0;
  476. }
  477. else if(X007 || (X022 && (user_datas[6] == 0)))
  478. {
  479. cDelayTime1 = dwTickCount + (unsigned long)user_datas[3] * 10;
  480. }
  481. break;
  482. case 17:
  483. if((X05_UP || (user_datas[2] == 0)) && (dwTickCount >= cDelayTime1))
  484. {
  485. cDelayTime1 = dwTickCount + 15;
  486. LS_cTotal++;
  487. if(LS_cTotal >= user_datas[2])
  488. {
  489. LS_cTotal = 0;
  490. cStepMByte = 18;
  491. }
  492. }
  493. break;
  494. case 18:
  495. CLRY001();
  496. cStepMByte = 19;
  497. AxisMovePosAccDec(X_AXIS, 5, 10 * user_datas[5],user_datas[4],1,1);
  498. break;
  499. case 19:
  500. cStepMByte = 1;
  501. break;
  502. }
  503. }
  504. //停止
  505. if(X002 || (LS_bRunning && (X012 || X013 || X014 || X015 || X016 || X017 ||
  506. X020 || X023 || X024 || X025 || X026 )) || !X021)
  507. {
  508. if(dwTickCount >= cDelayTime3)
  509. {
  510. LS_bRunning = 0;
  511. cStepMByte = 0;
  512. Y00 = 0;
  513. Y01 = 0;
  514. Y02 = 0;
  515. Y03 = 0;
  516. Y04 = 0;
  517. Y05 = 0;
  518. Y07 = 0;
  519. Y10 = 0;
  520. Y11 = 0;
  521. Y13 = 0;
  522. Y14 = 0;
  523. cStepMByte = 0;
  524. cStepMByte1 = 0;
  525. cStepMByte2 = 0;
  526. cStepMByte3 = 0;
  527. cStepMByte4 = 0;
  528. cStepMByte5 = 0;
  529. cStepMByte6 = 0;
  530. LS_bRunning = 0;
  531. AxisEgmStop(X_AXIS);
  532. LS_Y02_EN = 0;
  533. LS_Y03_EN = 0;
  534. cDelayTime2 = dwTickCount + 150;
  535. if(!X_DRV)LS_SETCSB_EN();
  536. }
  537. }
  538. else
  539. cDelayTime3 = dwTickCount + 50;
  540. //暂停功能
  541. if(X010)
  542. {
  543. CLRY001();
  544. CLRY002();
  545. CLRY003();
  546. }
  547. else if(X10_DW)
  548. {
  549. if(LS_Y02_EN)
  550. SETY002();
  551. if(LS_Y03_EN)
  552. SETY003();
  553. }
  554. }
  555. #endif