JTChuanTouJi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. #include "global.h"
  2. #if JUN_TENG_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 ChuanTou_ZhenDongAction(void);
  12. static unsigned char cSongLiaoOk = 0;
  13. static unsigned char cZhuangLiaoOk = 0;
  14. static unsigned char cZLCnt = 0;
  15. void CT_SetAlarmCode(unsigned alarm_code)
  16. {
  17. SetAlarmCode(CT_ALARM_ADDR,alarm_code);
  18. bAlarmStop = 1;
  19. }
  20. void ChuanTou_InitAction(void)
  21. {
  22. float length_buff,pulse_buff;
  23. length_buff = CT_PARAM_CYCLE_LENGTH;
  24. pulse_buff = CT_PARAM_CYCLE_PULSE;
  25. XGearRatio = pulse_buff/length_buff;
  26. YGearRatio = 1;
  27. if(CT_PARAM_CR_MODE)
  28. {
  29. if(!CT_CR_ORIGIN_IN)
  30. {
  31. if(CT_MotorStep == 0)CT_MotorStep = 100;
  32. }
  33. }
  34. }
  35. void ChuanTou_Action(void)
  36. {
  37. ChuanTou_AlarmProtect();
  38. ChuanTou_StepCheckStart(); // 调用脚踏开关检测程序
  39. ChuanTou_Motor();
  40. ChuanTou_ManualAction();
  41. ChuanTou_AutoAction();
  42. ChuanTou_CLT_Step();
  43. ChuanTou_ZhenDongAction();
  44. ChuanTou_SongLiaoAction();
  45. }
  46. //手动动作
  47. void ChuanTou_ManualAction(void)
  48. {
  49. if(bRunning == 0)
  50. {
  51. if(bClearTotal) //切断计数清零
  52. {
  53. bClearTotal = 0;
  54. ClrcToTal(CT_TOTAL_ADDR);
  55. }
  56. if(CT_bFD)
  57. {
  58. CT_bFD = 0;
  59. CT_FD_VAVLE = ~CT_FD_VAVLE;
  60. }
  61. if(CT_bXM)
  62. {
  63. CT_bXM = 0;
  64. CT_XM_VAVLE = ~CT_XM_VAVLE;
  65. }
  66. if(CT_bQYD)
  67. {
  68. CT_bQYD = 0;
  69. CT_QYD_VAVLE = ~CT_QYD_VAVLE;
  70. }
  71. if(CT_bHYD)
  72. {
  73. CT_bHYD = 0;
  74. CT_HYD_VAVLE = ~CT_HYD_VAVLE;
  75. }
  76. if(CT_bSL)
  77. {
  78. CT_bSL = 0;
  79. if(CT_SL_Step == 0)
  80. {
  81. cSongLiaoOk = 0;
  82. CT_SL_Step = 1;
  83. }
  84. }
  85. if(CT_bHL)
  86. {
  87. CT_bHL = 0;
  88. CT_HL_VAVLE = ~CT_HL_VAVLE;
  89. }
  90. if(CT_bCR)
  91. {
  92. CT_bCR = 0;
  93. CT_CR_VAVLE = ~CT_CR_VAVLE;
  94. }
  95. if(CT_bHSL)
  96. {
  97. CT_bHSL = 0;
  98. CT_HSL_VAVLE = ~CT_HSL_VAVLE;
  99. }
  100. if(CT_bZL)
  101. {
  102. CT_bZL = 0;
  103. if(CT_ZL_Step == 0)
  104. {
  105. cSongLiaoOk = 1;
  106. cZhuangLiaoOk = 0;
  107. CT_ZL_Step = 1;
  108. }
  109. }
  110. if(CT_bCLT)
  111. {
  112. CT_bCLT = 0;
  113. if(CT_CLT_Step == 0)CT_CLT_Step = 1;
  114. }
  115. if(CT_bCT_XM)
  116. {
  117. CT_bCT_XM = 0;
  118. }
  119. if(CT_bDW)
  120. {
  121. CT_bDW = 0;
  122. if(CT_MotorStep == 0)CT_MotorStep = 1;
  123. }
  124. if(CT_bAuto_ZL)
  125. {
  126. CT_bAuto_ZL = 0;
  127. }
  128. if(CT_bHM)
  129. {
  130. CT_bHM = 0;
  131. }
  132. if(CT_bMotor)
  133. {
  134. if(!X_DRV)AxisContinueMove(X_AXIS,20,CT_DIR_N);
  135. }
  136. if((QD_MotorStep == 0) && !CT_bMotor && (CT_AutoStep == 0))
  137. {
  138. if(X_DRV)AxisEgmStop(X_AXIS);
  139. }
  140. if(CT_bZDP)
  141. {
  142. CT_bZDP = 0;
  143. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_TIME;
  144. CT_ZDP_OUT = 1;
  145. }
  146. }
  147. }
  148. void ChuanTou_AlarmProtect(void)
  149. {
  150. }
  151. //振动盘控制
  152. void ChuanTou_ZhenDongAction(void)
  153. {
  154. if(bRunning)
  155. {
  156. if(CT_PARAM_ZDP_MODE)
  157. {
  158. if(CT_ZDP_IN_UP && (CT_ZDP_OUT == 0))
  159. {
  160. CT_ZDP_OUT = 1;
  161. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_TIME;
  162. }
  163. if((dwTickCount >= CT_ZDP_Delay) && CT_ZDP_OUT)
  164. {
  165. CT_ZDP_OUT = 0;
  166. }
  167. }
  168. else
  169. {
  170. if(CT_ZDP_IN_DW)CT_ZDP_OUT = 0;
  171. if(CT_ZDP_IN_UP)CT_ZDP_OUT = 1;
  172. }
  173. }
  174. else
  175. {
  176. if(CT_ZDP_IN_UP && (CT_ZDP_OUT == 0))
  177. {
  178. CT_ZDP_OUT = 1;
  179. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_TIME;
  180. }
  181. if((dwTickCount >= CT_ZDP_Delay) && CT_ZDP_OUT)
  182. {
  183. CT_ZDP_OUT = 0;
  184. }
  185. }
  186. }
  187. //送料
  188. void ChuanTou_SongLiaoAction(void)
  189. {
  190. switch(CT_SL_Step)
  191. {
  192. case 1:
  193. {
  194. if(cSongLiaoOk)
  195. {
  196. CT_SL_Step = 0;
  197. }
  198. else
  199. {
  200. CT_SL_Step = 2;
  201. CT_SL_Delay = dwTickCount + 1000;
  202. }
  203. }break;
  204. case 2:
  205. {
  206. if(CT_SL_ORIGIN_IN && CT_CR_ORIGIN_IN && CT_XM_ORIGIN_IN)
  207. {
  208. CT_SL_VAVEL = 1;
  209. CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  210. CT_SL_Step = 3;
  211. }
  212. else if(dwTickCount >= CT_SL_Delay)
  213. {
  214. if(!CT_SL_ORIGIN_IN)CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
  215. else if(!CT_CR_ORIGIN_IN)CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  216. else if(!CT_XM_ORIGIN_IN)CT_SetAlarmCode(CT_XM_ORIGIN_ALARM);
  217. }
  218. }
  219. break;
  220. case 3:
  221. {
  222. if(CT_SL_LIMIT_IN)
  223. {
  224. CT_SL_Step = 3;
  225. CT_SL_Delay = dwTickCount + CT_PARAM_SL_DELAY_BACK;
  226. }
  227. else if(dwTickCount >= CT_SL_Delay)
  228. {
  229. CT_SetAlarmCode(CT_SL_LIMIT_ALARM);
  230. }
  231. }break;
  232. case 4:
  233. {
  234. if(dwTickCount >= CT_SL_Delay)
  235. {
  236. CT_SL_VAVEL = 0;
  237. CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  238. CT_SL_Step = 5;
  239. }
  240. }break;
  241. case 5:
  242. {
  243. if(!CT_SL_LIMIT_IN)
  244. {
  245. cSongLiaoOk = 1;
  246. CT_SL_Step = 0;
  247. }
  248. else if(dwTickCount >= CT_SL_Delay)
  249. {
  250. CT_SetAlarmCode(CT_SL_LIMIT_ALARM);
  251. }
  252. }
  253. break;
  254. }
  255. }
  256. //横送料
  257. void ChuanTou_HengSongLiao_Action(void)
  258. {
  259. /* switch(CT_HSL_Step)
  260. {
  261. case 1:
  262. {
  263. if(CT_SONG_LIAO_ORIGIN_IN && CT_HSL_ORIGIN_IN && CT_XIA_MU_IN && cSongLiaoOk)
  264. {
  265. CT_HSL_Step = 2;
  266. }
  267. else if(!bRunning)
  268. {
  269. CT_HSL_Step = 0;
  270. }
  271. }
  272. break;
  273. case 2:
  274. {
  275. CT_HSL_VAVLE = 1;
  276. cSongLiaoOk = 0;
  277. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  278. CT_HSL_Step = 3;
  279. }
  280. break;
  281. case 3:
  282. {
  283. if(CT_HSL_LIMIT_IN)
  284. {
  285. CT_ZL_XM_VAVLE = 1;
  286. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  287. CT_HSL_Step = 4;
  288. }
  289. else if(dwTickCount >= CT_HSL_Delay)
  290. {
  291. CT_SetAlarmCode(CT_HSL_LIMIT_ALARM);
  292. }
  293. }
  294. break;
  295. case 4:
  296. {
  297. if(CT_ZHUANG_LIAO_IN)
  298. {
  299. CT_HSL_Delay = dwTickCount + CT_PARAM_LOCK_TIME;
  300. CT_HSL_Step = 5;
  301. }
  302. else if(dwTickCount >= CT_HSL_Delay)
  303. {
  304. CT_SetAlarmCode(CT_ZL_LIMIT_ALARM);
  305. }
  306. }
  307. break;
  308. case 5:
  309. if(dwTickCount >= CT_HSL_Delay)
  310. {
  311. CT_GJ_VAVLE = 1;
  312. CT_HSL_Delay = dwTickCount + CT_PARAM_GJ_TIME;
  313. CT_HSL_Step = 6;
  314. }
  315. break;
  316. case 6:
  317. CT_HSL_VAVLE = 0;
  318. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  319. CT_HSL_Step = 7;
  320. break;
  321. case 7:
  322. if(CT_HSL_ORIGIN_IN)
  323. {
  324. CT_ZL_XM_VAVLE = 0;
  325. CT_HSL_Step = 8;
  326. }
  327. else if(dwTickCount >= CT_HSL_Delay)
  328. {
  329. CT_SetAlarmCode(CT_HSL_ORIGIN_ALARM);
  330. }
  331. break;
  332. case 8:
  333. CT_HSL_Step = 0;
  334. CT_SL_Step = 1;
  335. break;
  336. }
  337. */
  338. }
  339. void ChuanTou_ZhuangLiaoStep(void)
  340. {
  341. switch(CT_ZL_Step)
  342. {
  343. case 1:
  344. {
  345. if(cZhuangLiaoOk)CT_ZL_Step = 0;
  346. else
  347. {
  348. CT_CR_VAVLE = 0;
  349. CT_ZL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  350. CT_ZL_Step = 2;
  351. }
  352. }break;
  353. case 2:
  354. {
  355. if(CT_CR_ORIGIN_IN)
  356. {
  357. if(CT_SL_Step == 0) CT_SL_Step = 1;
  358. CT_ZL_Step = 3;
  359. }
  360. else if(dwTickCount >= CT_ZL_Delay)
  361. {
  362. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  363. }
  364. }
  365. break;
  366. case 3:
  367. {
  368. if(CT_SL_Step == 0)
  369. {
  370. CT_ZL_Step = 4;
  371. CT_ZL_Delay = dwTickCount + 1000;
  372. }
  373. }break;
  374. case 4:
  375. {
  376. if(CT_XM_ORIGIN_IN)
  377. {
  378. CT_XM_VAVLE = 1;
  379. cZLCnt++;
  380. CT_ZL_Delay = dwTickCount + 1000;
  381. CT_ZL_Step = 5;
  382. }
  383. else if(dwTickCount >= CT_ZL_Delay)
  384. CT_SetAlarmCode(CT_XM_ORIGIN_ALARM);
  385. }break;
  386. case 5:
  387. {
  388. if(CT_DZ_IN)
  389. {
  390. cZhuangLiaoOk = 1;
  391. cZLCnt = 0;
  392. CT_ZL_Step = 0;
  393. }
  394. else if(dwTickCount >= CT_ZL_Delay)
  395. {
  396. if(cZLCnt >= 2)
  397. {
  398. cSongLiaoOk = 0;
  399. cZhuangLiaoOk = 0;
  400. CT_SetAlarmCode(CT_DZ_ALARM);
  401. }
  402. else
  403. {
  404. cSongLiaoOk = 0;
  405. CT_XM_VAVLE = 0;
  406. CT_ZL_Step = 1;
  407. }
  408. }
  409. }
  410. break;
  411. default:;
  412. }
  413. }
  414. void ChuanTou_CLT_Step(void)
  415. {
  416. static long xm_buff;
  417. static long dwRealPosY;
  418. dwRealPosY = GetPos(Y_AXIS);
  419. switch(CT_CLT_Step)
  420. {
  421. case 1:
  422. CT_CLT_Delay = dwTickCount + 1000;
  423. CT_QYD_VAVLE = 1;
  424. CT_HYD_VAVLE = 1;
  425. CT_CLT_Step = 2;
  426. break;
  427. case 2:
  428. if(CT_CR_ORIGIN_IN)
  429. {
  430. CT_CLT_Delay = dwTickCount + CT_PARAM_FD_DELAY;
  431. CT_CLT_Step = 3;
  432. }
  433. else if(dwTickCount >= CT_CLT_Delay)
  434. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  435. break;
  436. case 3:
  437. if(dwTickCount >= CT_CLT_Delay)
  438. {
  439. CT_FD_VAVLE = 1;
  440. if(CT_PARAM_HL_ENABLE)CT_HL_VAVLE = 1;
  441. CT_CLT_Delay = dwTickCount + VAVLE_ALARM_TIME;
  442. CT_CLT_Step = 4;
  443. }
  444. break;
  445. case 4:
  446. if(CT_FD_IN)
  447. {
  448. CT_CLT_Delay = dwTickCount + CT_PARAM_XM_DELAY;
  449. CT_CLT_Step = 5;
  450. }
  451. else if(dwTickCount >= CT_CLT_Delay)
  452. CT_SetAlarmCode(CT_FD_IN_ALARM);
  453. break;
  454. case 5:
  455. if(dwTickCount >= CT_CLT_Delay)
  456. {
  457. if(CT_ZL_Step == 0)
  458. {
  459. CT_ZL_Step = 1;
  460. CT_CLT_Step = 6;
  461. }
  462. }
  463. break;
  464. case 6:
  465. if(CT_ZL_Step == 0)
  466. {
  467. if(CT_PARAM_CR_MODE == 0)
  468. {
  469. CT_CR_VAVLE = 1;
  470. CT_XM_BACK_Delay = dwTickCount + CT_PARAM_XM_BACK_DELAY;
  471. CT_CLT_Delay = dwTickCount + MOTOR_ALARM_TIME;
  472. CT_CLT_Step = 7;
  473. }
  474. else
  475. {
  476. xm_buff = dwRealPosY;
  477. CT_CRDR_OUT = CT_Y_DIR_P;
  478. if(!Y_DRV)AxisContinueMove(Y_AXIS,CT_PARAM_CR_SPEED,QD_DIR_P);
  479. CT_CLT_Delay = dwTickCount + MOTOR_ALARM_TIME;
  480. CT_CLT_Step = 20;
  481. }
  482. }
  483. break;
  484. case 7:
  485. if(dwTickCount >= CT_XM_BACK_Delay)CT_XM_VAVLE = 0;
  486. if(CT_CR_LIMIT_IN)
  487. {
  488. CT_XM_VAVLE = 0;
  489. CT_QYD_VAVLE = 0;
  490. CT_HYD_VAVLE = 0;
  491. CT_FD_VAVLE = 0;
  492. if(CT_PARAM_HL_ENABLE)CT_HL_VAVLE = 0;
  493. CT_CLT_Step = 8;
  494. CT_CLT_Delay = dwTickCount + VAVLE_ALARM_TIME;
  495. }
  496. else if(dwTickCount >= CT_CLT_Delay)
  497. CT_SetAlarmCode(CT_CR_LIMIT_ALARM);
  498. break;
  499. case 8:
  500. if(!CT_FD_IN)
  501. {
  502. CT_CLT_Step = 9;
  503. CT_CLT_Delay = dwTickCount + CT_PARAM_CR_BACK_DELAY;
  504. }
  505. else if(dwTickCount >= CT_CLT_Delay)
  506. CT_SetAlarmCode(CT_FD_IN_ALARM);
  507. break;
  508. case 9:
  509. if(dwTickCount >= CT_CLT_Delay)
  510. {
  511. if(CT_PARAM_CR_MODE == 0)
  512. {
  513. CT_CR_VAVLE = 0;
  514. CT_CLT_Delay = dwTickCount + VAVLE_ALARM_TIME;
  515. CT_CLT_Step = 10;
  516. }
  517. else
  518. {
  519. CT_CRDR_OUT = CT_Y_DIR_N;
  520. if(!Y_DRV)AxisContinueMove(Y_AXIS,CT_PARAM_CR_SPEED,QD_DIR_N);
  521. CT_CLT_Delay = dwTickCount + VAVLE_ALARM_TIME;
  522. CT_CLT_Step = 30;
  523. }
  524. }
  525. break;
  526. case 10:
  527. if(CT_CR_ORIGIN_IN)
  528. {
  529. CT_CLT_Step = 0;
  530. cSongLiaoOk = 0; // 穿完回到位就可以送料
  531. }
  532. else if(dwTickCount >= CT_CLT_Delay)
  533. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  534. break;
  535. case 20:
  536. if((dwRealPosY - xm_buff) >= CT_PARAM_XM_BACK_DELAY)CT_XM_VAVLE = 0;
  537. if(CT_CR_LIMIT_IN)
  538. {
  539. AxisDecStop(Y_AXIS);
  540. CT_CLT_Step = 21;
  541. }
  542. else if(dwTickCount >= CT_CLT_Delay)
  543. CT_SetAlarmCode(CT_CR_LIMIT_ALARM);
  544. break;
  545. case 21:
  546. if(!Y_DRV)
  547. {
  548. CT_CLT_Step = 7;
  549. }
  550. break;
  551. case 30:
  552. if(CT_CR_ORIGIN_IN)
  553. {
  554. AxisDecStop(Y_AXIS);
  555. CT_CLT_Step = 31;
  556. }
  557. else if(dwTickCount >= CT_CLT_Delay)
  558. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  559. break;
  560. case 31:
  561. if(!Y_DRV)
  562. {
  563. CT_CLT_Step = 0;
  564. cSongLiaoOk = 0; // 穿完回到位就可以送料
  565. }
  566. break;
  567. }
  568. }
  569. void ChuanTou_AutoAction(void)
  570. {
  571. if(bRunning)
  572. {
  573. switch(CT_AutoStep)
  574. {
  575. case 1:
  576. if(dwTickCount >= CT_AutoDelay)
  577. {
  578. CT_AutoStep = 2;
  579. if(CT_MotorStep == 0)
  580. {
  581. CT_MotorStep = 1;
  582. }
  583. }
  584. break;
  585. case 2:
  586. if(CT_MotorStep == 0)
  587. {
  588. CT_AutoStep = 3;
  589. }
  590. break;
  591. case 3:
  592. if((CT_MotorStep == 0) && (CT_CLT_Step == 0))
  593. {
  594. CT_CLT_Step = 1;
  595. CT_AutoStep = 4;
  596. }
  597. break;
  598. case 4:
  599. if((CT_CLT_Step == 0) || (CT_CLT_Step >= 10))
  600. {
  601. CT_AutoStep = 5;
  602. }
  603. break;
  604. case 5:
  605. dwZipCnt++;
  606. AddToTal(CT_TOTAL_ADDR);
  607. CalProSP(CT_PROSPEED_ADDR);
  608. if(SingOneFlg)
  609. {
  610. bRunning = 0;
  611. CT_AutoStep = 0;
  612. SingOneFlg = 0;
  613. }
  614. else
  615. {
  616. CT_AutoStep = 1;
  617. CT_AutoDelay = dwTickCount + CT_PARAM_CYCLE_DELAY;
  618. }
  619. break;
  620. }
  621. }
  622. }
  623. void ChuanTou_StepCheckStart(void)
  624. {
  625. // 启动
  626. if((CT_START_IN_UP) || bStart || CT_bSingle)
  627. {
  628. bStart = 0;
  629. if(!bRunning && (CT_AutoStep == 0))
  630. {
  631. if(CT_FD_IN)CT_SetAlarmCode(CT_FD_IN_ALARM);
  632. else if(CT_DZ_IN)CT_SetAlarmCode(CT_DZ_ALARM);
  633. else if(!CT_XM_ORIGIN_IN)CT_SetAlarmCode(CT_XM_ORIGIN_ALARM);
  634. else if(!CT_CR_ORIGIN_IN)CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  635. else if(!CT_SL_ORIGIN_IN)CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
  636. else if(CT_QYD_VAVLE | CT_HYD_VAVLE | CT_HL_VAVLE)CT_SetAlarmCode(CT_OUT_ALARM);
  637. {
  638. bRunning = 1;
  639. if(cZhuangLiaoOk)
  640. CT_AutoStep = 2;
  641. else
  642. CT_AutoStep = 1;
  643. if(CT_bSingle) SingOneFlg= 1;
  644. dwZipCnt = 0;
  645. }
  646. }
  647. CT_bSingle = 0;
  648. }
  649. //停止
  650. if(CT_STOP_IN_UP || bStop)
  651. {
  652. bStop = 0;
  653. if(bRunning)
  654. {
  655. bRunning = 0;
  656. CT_AutoStep = 0;
  657. CT_MotorStep = 0;
  658. CT_AutoDelay = dwTickCount;
  659. CT_MotorDelay = dwTickCount;
  660. AxisDecStop(X_AXIS);
  661. SingOneFlg = 0;
  662. }
  663. else
  664. {
  665. bRunning = 0;
  666. CT_AutoStep = 0;
  667. CT_MotorStep = 0;
  668. CT_HeMuStep = 0;
  669. CT_SL_Step = 0;
  670. CT_HSL_Step = 0;
  671. CT_ZL_Step = 0;
  672. CT_CLT_Step = 0;
  673. CT_ZD_Step = 0;
  674. CT_AutoDelay = dwTickCount;
  675. CT_MotorDelay = dwTickCount;
  676. CT_HeMuDelay = dwTickCount;
  677. CT_SL_Delay = dwTickCount;
  678. CT_HSL_Delay = dwTickCount;
  679. CT_ZL_Delay = dwTickCount;
  680. CT_XM_BACK_Delay = dwTickCount;
  681. CT_CLT_Delay = dwTickCount;
  682. CT_ZDP_Delay = dwTickCount;
  683. SingOneFlg = 0;
  684. AxisDecStop(X_AXIS);
  685. if(CT_PARAM_CR_MODE)//按停止电机复位
  686. {
  687. if(!CT_CR_ORIGIN_IN)
  688. {
  689. if(CT_MotorStep == 0)CT_MotorStep = 100;
  690. }
  691. }
  692. CT_SZ_OUT = CT_MOTOR_Y_DISEN;
  693. SetEn(X_AXIS,CT_MOTOR_DISEN);
  694. CT_FD_VAVLE = 0;
  695. CT_XM_VAVLE = 0;
  696. CT_SL_VAVEL = 0;
  697. CT_QYD_VAVLE = 0;
  698. CT_HL_VAVLE = 0;
  699. CT_HYD_VAVLE = 0;
  700. CT_CR_VAVLE = 0;
  701. CT_ZDP_OUT = 0;
  702. CT_HSL_VAVLE = 0;
  703. cSongLiaoOk = 0;
  704. cZhuangLiaoOk = 0;
  705. cZLCnt = 0;
  706. if(GetAlarmCode(CT_ALARM_ADDR) != 0)SetAlarmCode(CT_ALARM_ADDR,0);
  707. }
  708. }
  709. if(bAlarmStop)
  710. {
  711. bAlarmStop = 0;
  712. bRunning = 0;
  713. CT_AutoStep = 0;
  714. CT_MotorStep = 0;
  715. CT_AutoDelay = dwTickCount;
  716. CT_MotorDelay = dwTickCount;
  717. SingOneFlg = 0;
  718. AxisDecStop(X_AXIS);
  719. AxisDecStop(Y_AXIS);
  720. }
  721. }
  722. //电机动作
  723. void ChuanTou_Motor(void) //
  724. {
  725. static long back_buff,save_buff;
  726. dwRealPos = GetPos(X_AXIS);
  727. switch(CT_MotorStep)
  728. {
  729. case 0:
  730. break;
  731. case 1:
  732. if(GetEn(X_AXIS) == CT_MOTOR_DISEN)
  733. {
  734. SetEn(X_AXIS,CT_MOTOR_DISEN);
  735. CT_SZ_OUT = CT_MOTOR_Y_EN;
  736. CT_MotorDelay = dwTickCount + 50;
  737. }
  738. CT_MotorStep = 2;
  739. break;
  740. case 2:
  741. if(dwTickCount >= CT_MotorDelay)
  742. {
  743. save_buff = dwRealPos;
  744. if(!X_DRV)AxisContinueMove(X_AXIS,CT_PARAM_HSPEED,QD_DIR_N);
  745. CT_MotorStep = 3;
  746. }
  747. break;
  748. case 3:
  749. if(CT_GUO_LIAN_IN_UP)
  750. {
  751. MoveChangSpeed(X_AXIS,CT_PARAM_LSPEED);
  752. CT_MotorStep = 4;
  753. }
  754. else if((dwRealPos - save_buff) >= CT_PARAM_MAX_LENGTH)
  755. CT_SetAlarmCode(CT_NO_ZIPPER_ALARM);
  756. break;
  757. case 4:
  758. if(CT_GUO_LIAN_IN_DW)
  759. {
  760. back_buff = dwRealPos;
  761. CT_MotorStep = 5;
  762. }
  763. else if((dwRealPos - save_buff) >= CT_PARAM_MAX_LENGTH)
  764. CT_SetAlarmCode(CT_NO_ZIPPER_ALARM);
  765. break;
  766. case 5:
  767. if((dwRealPos - back_buff) >= CT_PARAM_STOP_LENGTH)
  768. {
  769. AxisEgmStop(X_AXIS);
  770. CT_MotorStep = 6;
  771. }
  772. break;
  773. case 6:
  774. if(!X_DRV)
  775. {
  776. CT_MotorStep = 0;
  777. }
  778. break;
  779. case 100: //穿入电机慢慢复位动作
  780. CT_CRDR_OUT = CT_Y_DIR_N;
  781. if(!Y_DRV)AxisContinueMove(Y_AXIS,10,QD_DIR_N);
  782. CT_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  783. CT_MotorStep = 101;
  784. break;
  785. case 101:
  786. if(CT_CR_ORIGIN_IN)
  787. {
  788. AxisDecStop(Y_AXIS);
  789. CT_MotorStep = 102;
  790. }
  791. else if(dwTickCount >= CT_MotorDelay)
  792. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  793. break;
  794. case 102:
  795. if(!Y_DRV)
  796. {
  797. CT_MotorStep = 0;
  798. }
  799. break;
  800. }
  801. }
  802. #endif