YGChuanTouJi.c 24 KB

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