JHChuanTouJi.c 23 KB

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