HHChuanTouJi.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. #include "global.h"
  2. #if HAI_HUA_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(CT_PARAM_ZDP_MODE)
  160. {
  161. if(!CT_ZDP_IN && (CT_ZDP_OUT == 0) && (dwTickCount >= CT_ZDP_Delay))
  162. {
  163. CT_ZDP_OUT = 1;
  164. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_TIME;
  165. }
  166. if((dwTickCount >= CT_ZDP_Delay) && (CT_ZDP_OUT == 1) && CT_ZDP_IN)
  167. {
  168. CT_ZDP_OUT = 0;
  169. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_TIME;
  170. }
  171. }
  172. else
  173. {
  174. if(CT_ZDP_IN)CT_ZDP_OUT = 0;
  175. if(!CT_ZDP_IN)CT_ZDP_OUT = 1;
  176. }
  177. }
  178. //送料
  179. void ChuanTou_SongLiaoAction(void)
  180. {
  181. switch(CT_SL_Step)
  182. {
  183. case 1:
  184. {
  185. if(cSongLiaoOk)
  186. {
  187. CT_SL_Step = 0;
  188. }
  189. else
  190. {
  191. CT_SL_Step = 2;
  192. CT_SL_Delay = dwTickCount + 1000;
  193. }
  194. }break;
  195. case 2:
  196. {
  197. if(CT_SL_ORIGIN_IN && CT_CR_ORIGIN_IN && CT_XM_ORIGIN_IN)
  198. {
  199. CT_SL_Delay = dwTickCount + CT_PARAM_SL_DELAY;
  200. CT_SL_Step = 3;
  201. }
  202. else if(dwTickCount >= CT_SL_Delay)
  203. {
  204. if(!CT_SL_ORIGIN_IN)CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
  205. else if(!CT_CR_ORIGIN_IN)CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  206. else if(!CT_XM_ORIGIN_IN)CT_SetAlarmCode(CT_XM_ORIGIN_ALARM);
  207. }
  208. }
  209. break;
  210. case 3:
  211. if(dwTickCount >= CT_SL_Delay)
  212. {
  213. CT_SL_VAVEL = 1;
  214. CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  215. CT_SL_Step = 4;
  216. }
  217. break;
  218. case 4:
  219. {
  220. if(CT_SL_LIMIT_IN)
  221. {
  222. CT_SL_Step = 5;
  223. CT_SL_Delay = dwTickCount + CT_PARAM_SL_DELAY_BACK;
  224. }
  225. else if(dwTickCount >= CT_SL_Delay)
  226. {
  227. CT_SetAlarmCode(CT_SL_LIMIT_ALARM);
  228. }
  229. }break;
  230. case 5:
  231. {
  232. if(dwTickCount >= CT_SL_Delay)
  233. {
  234. CT_SL_VAVEL = 0;
  235. CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  236. CT_SL_Step = 6;
  237. }
  238. }break;
  239. case 6:
  240. {
  241. if(!CT_SL_LIMIT_IN)
  242. {
  243. cSongLiaoOk = 1;
  244. CT_SL_Step = 0;
  245. }
  246. else if(dwTickCount >= CT_SL_Delay)
  247. {
  248. CT_SetAlarmCode(CT_SL_LIMIT_ALARM);
  249. }
  250. }
  251. break;
  252. }
  253. }
  254. //横送料
  255. void ChuanTou_HengSongLiao_Action(void)
  256. {
  257. /* switch(CT_HSL_Step)
  258. {
  259. case 1:
  260. {
  261. if(CT_SONG_LIAO_ORIGIN_IN && CT_HSL_ORIGIN_IN && CT_XIA_MU_IN && cSongLiaoOk)
  262. {
  263. CT_HSL_Step = 2;
  264. }
  265. else if(!bRunning)
  266. {
  267. CT_HSL_Step = 0;
  268. }
  269. }
  270. break;
  271. case 2:
  272. {
  273. CT_HSL_VAVLE = 1;
  274. cSongLiaoOk = 0;
  275. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  276. CT_HSL_Step = 3;
  277. }
  278. break;
  279. case 3:
  280. {
  281. if(CT_HSL_LIMIT_IN)
  282. {
  283. CT_ZL_XM_VAVLE = 1;
  284. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  285. CT_HSL_Step = 4;
  286. }
  287. else if(dwTickCount >= CT_HSL_Delay)
  288. {
  289. CT_SetAlarmCode(CT_HSL_LIMIT_ALARM);
  290. }
  291. }
  292. break;
  293. case 4:
  294. {
  295. if(CT_ZHUANG_LIAO_IN)
  296. {
  297. CT_HSL_Delay = dwTickCount + CT_PARAM_LOCK_TIME;
  298. CT_HSL_Step = 5;
  299. }
  300. else if(dwTickCount >= CT_HSL_Delay)
  301. {
  302. CT_SetAlarmCode(CT_ZL_LIMIT_ALARM);
  303. }
  304. }
  305. break;
  306. case 5:
  307. if(dwTickCount >= CT_HSL_Delay)
  308. {
  309. CT_GJ_VAVLE = 1;
  310. CT_HSL_Delay = dwTickCount + CT_PARAM_GJ_TIME;
  311. CT_HSL_Step = 6;
  312. }
  313. break;
  314. case 6:
  315. CT_HSL_VAVLE = 0;
  316. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  317. CT_HSL_Step = 7;
  318. break;
  319. case 7:
  320. if(CT_HSL_ORIGIN_IN)
  321. {
  322. CT_ZL_XM_VAVLE = 0;
  323. CT_HSL_Step = 8;
  324. }
  325. else if(dwTickCount >= CT_HSL_Delay)
  326. {
  327. CT_SetAlarmCode(CT_HSL_ORIGIN_ALARM);
  328. }
  329. break;
  330. case 8:
  331. CT_HSL_Step = 0;
  332. CT_SL_Step = 1;
  333. break;
  334. }
  335. */
  336. }
  337. void ChuanTou_ZhuangLiaoStep(void)
  338. {
  339. switch(CT_ZL_Step)
  340. {
  341. case 1:
  342. {
  343. if(cZhuangLiaoOk)CT_ZL_Step = 0;
  344. else
  345. {
  346. CT_CR_VAVLE = 0;
  347. CT_ZL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  348. CT_ZL_Step = 2;
  349. }
  350. }break;
  351. case 2:
  352. {
  353. if(CT_CR_ORIGIN_IN)
  354. {
  355. if(CT_SL_Step == 0) CT_SL_Step = 1;
  356. CT_ZL_Step = 3;
  357. }
  358. else if(dwTickCount >= CT_ZL_Delay)
  359. {
  360. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  361. }
  362. }
  363. break;
  364. case 3:
  365. {
  366. if(CT_SL_Step == 0)
  367. {
  368. CT_ZL_Step = 4;
  369. CT_ZL_Delay = dwTickCount + 1000;
  370. }
  371. }break;
  372. case 4:
  373. {
  374. if(CT_XM_ORIGIN_IN)
  375. {
  376. CT_XM_VAVLE = 1;
  377. cZLCnt++;
  378. CT_ZL_Delay = dwTickCount + 1000;
  379. CT_ZL_Step = 5;
  380. }
  381. /* else if(dwTickCount >= CT_ZL_Delay)
  382. CT_SetAlarmCode(CT_XM_ORIGIN_ALARM);*/
  383. }break;
  384. case 5:
  385. {
  386. if(CT_DZ_IN)
  387. {
  388. cZhuangLiaoOk = 1;
  389. cZLCnt = 0;
  390. CT_ZL_Step = 0;
  391. }
  392. else if(dwTickCount >= CT_ZL_Delay)
  393. {
  394. if(cZLCnt >= 2)
  395. {
  396. cSongLiaoOk = 0;
  397. cZhuangLiaoOk = 0;
  398. CT_SetAlarmCode(CT_DZ_ALARM);
  399. }
  400. else
  401. {
  402. cSongLiaoOk = 0;
  403. CT_XM_VAVLE = 0;
  404. CT_ZL_Step = 1;
  405. }
  406. }
  407. }
  408. break;
  409. default:;
  410. }
  411. }
  412. void ChuanTou_CLT_Step(void)
  413. {
  414. static long xm_buff;
  415. static long dwRealPosY;
  416. dwRealPosY = GetPos(Y_AXIS);
  417. switch(CT_CLT_Step)
  418. {
  419. case 1:
  420. CT_CLT_Delay = dwTickCount + 1000;
  421. CT_QYD_VAVLE = 1;
  422. CT_HYD_VAVLE = 1;
  423. CT_CLT_Step = 2;
  424. break;
  425. case 2:
  426. if(CT_CR_ORIGIN_IN)
  427. {
  428. CT_CLT_Delay = dwTickCount + CT_PARAM_FD_DELAY;
  429. CT_CLT_Step = 3;
  430. }
  431. else if(dwTickCount >= CT_CLT_Delay)
  432. {
  433. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  434. }
  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_Delay = dwTickCount + CT_PARAM_CR_DELAY;
  470. CT_FDDelay = dwTickCount + CT_PARAM_FD_BACK_DELAY;
  471. CT_CLT_Delay = dwTickCount + VAVLE_ALARM_TIME;
  472. CT_TM_Delay = dwTickCount + CT_PARAM_MAX_TIME;
  473. CT_CLT_Step = 7;
  474. }
  475. else
  476. {
  477. xm_buff = dwRealPosY;
  478. CT_CRDR_OUT = CT_Y_DIR_P;
  479. if(!Y_DRV)AxisContinueMove(Y_AXIS,CT_PARAM_CR_SPEED,QD_DIR_P);
  480. CT_CLT_Delay = dwTickCount + MOTOR_ALARM_TIME;
  481. CT_CLT_Step = 20;
  482. }
  483. }
  484. break;
  485. case 7:
  486. if(dwTickCount >= CT_CR_Delay)CT_CR_VAVLE = 1;
  487. if(dwTickCount >= CT_FDDelay)CT_FD_VAVLE = 0;
  488. if(dwTickCount >= CT_TM_Delay)CT_FD_VAVLE = 0;
  489. if(CT_FD_IN_DW)
  490. {
  491. if(CT_PARAM_HL_ENABLE)CT_HL_VAVLE = 0;
  492. CT_XM_VAVLE = 0;
  493. CT_QYD_VAVLE = 0;
  494. CT_HYD_VAVLE = 0;
  495. }
  496. if(CT_CR_LIMIT_IN)
  497. {
  498. if(CT_PARAM_HL_ENABLE)CT_HL_VAVLE = 0;
  499. CT_FD_VAVLE = 0;
  500. CT_XM_VAVLE = 0;
  501. CT_QYD_VAVLE = 0;
  502. CT_HYD_VAVLE = 0;
  503. CT_CLT_Step = 8;
  504. CT_CLT_Delay = dwTickCount + VAVLE_ALARM_TIME;
  505. }
  506. else if(dwTickCount >= CT_CLT_Delay)
  507. CT_SetAlarmCode(CT_CR_LIMIT_ALARM);
  508. break;
  509. case 8:
  510. if(!CT_FD_IN)
  511. {
  512. CT_CLT_Step = 9;
  513. CT_CLT_Delay = dwTickCount + CT_PARAM_CR_BACK_DELAY;
  514. }
  515. else if(dwTickCount >= CT_CLT_Delay)
  516. CT_SetAlarmCode(CT_FD_IN_ALARM);
  517. break;
  518. case 9:
  519. if(dwTickCount >= CT_CLT_Delay)
  520. {
  521. if(CT_PARAM_CR_MODE == 0)
  522. {
  523. CT_CR_VAVLE = 0;
  524. CT_CLT_Delay = dwTickCount + VAVLE_ALARM_TIME;
  525. CT_CLT_Step = 13;
  526. }
  527. else
  528. {
  529. CT_CRDR_OUT = CT_Y_DIR_N;
  530. if(!Y_DRV)AxisContinueMove(Y_AXIS,CT_PARAM_CR_SPEED,QD_DIR_N);
  531. CT_CLT_Delay = dwTickCount + VAVLE_ALARM_TIME;
  532. CT_CLT_Step = 30;
  533. }
  534. }
  535. break;
  536. case 13:
  537. if(CT_CR_ORIGIN_IN)
  538. {
  539. CT_CLT_Step = 0;
  540. cSongLiaoOk = 0; // 穿完回到位就可以送料
  541. cZhuangLiaoOk = 0;
  542. if(CT_SL_Step == 0)CT_SL_Step = 1;
  543. }
  544. else if(dwTickCount >= CT_CLT_Delay)
  545. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  546. break;
  547. case 20:
  548. // if((dwRealPosY - xm_buff) >= CT_PARAM_XM_BACK_DELAY)CT_XM_VAVLE = 0;
  549. if(CT_CR_LIMIT_IN)
  550. {
  551. AxisDecStop(Y_AXIS);
  552. CT_CLT_Step = 21;
  553. }
  554. else if(dwTickCount >= CT_CLT_Delay)
  555. CT_SetAlarmCode(CT_CR_LIMIT_ALARM);
  556. break;
  557. case 21:
  558. if(!Y_DRV)
  559. {
  560. CT_CLT_Step = 7;
  561. }
  562. break;
  563. case 30:
  564. if(CT_CR_ORIGIN_IN)
  565. {
  566. AxisDecStop(Y_AXIS);
  567. CT_CLT_Step = 31;
  568. }
  569. else if(dwTickCount >= CT_CLT_Delay)
  570. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  571. break;
  572. case 31:
  573. if(!Y_DRV)
  574. {
  575. CT_CLT_Step = 0;
  576. cSongLiaoOk = 0; // 穿完回到位就可以送料
  577. }
  578. break;
  579. }
  580. }
  581. void ChuanTou_AutoAction(void)
  582. {
  583. if(bRunning)
  584. {
  585. switch(CT_AutoStep)
  586. {
  587. case 1:
  588. if(dwTickCount >= CT_AutoDelay)
  589. {
  590. CT_AutoStep = 2;
  591. if(CT_MotorStep == 0)
  592. {
  593. CT_MotorStep = 1;
  594. }
  595. }
  596. break;
  597. case 2:
  598. if(CT_MotorStep == 0)
  599. {
  600. CT_AutoStep = 3;
  601. }
  602. break;
  603. case 3:
  604. if((CT_MotorStep == 0) && (CT_CLT_Step == 0))
  605. {
  606. CT_CLT_Step = 1;
  607. CT_AutoStep = 4;
  608. }
  609. break;
  610. case 4:
  611. if((CT_CLT_Step == 0) || (CT_CLT_Step >= 10))
  612. {
  613. CT_AutoStep = 5;
  614. }
  615. break;
  616. case 5:
  617. dwZipCnt++;
  618. AddToTal(CT_TOTAL_ADDR);
  619. CalProSP(CT_PROSPEED_ADDR);
  620. if(SingOneFlg)
  621. {
  622. bRunning = 0;
  623. CT_AutoStep = 0;
  624. SingOneFlg = 0;
  625. }
  626. else
  627. {
  628. CT_AutoStep = 1;
  629. CT_AutoDelay = dwTickCount + CT_PARAM_CYCLE_DELAY;
  630. }
  631. break;
  632. }
  633. }
  634. }
  635. void ChuanTou_StepCheckStart(void)
  636. {
  637. // 启动
  638. if((CT_START_IN_UP) || bStart || CT_bSingle)
  639. {
  640. bStart = 0;
  641. if(!bRunning && (CT_AutoStep == 0))
  642. {
  643. if(CT_FD_IN)CT_SetAlarmCode(CT_FD_IN_ALARM);
  644. else if(CT_DZ_IN)CT_SetAlarmCode(CT_DZ_ALARM);
  645. else if(!CT_XM_ORIGIN_IN)CT_SetAlarmCode(CT_XM_ORIGIN_ALARM);
  646. else if(!CT_CR_ORIGIN_IN)CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  647. else if(!CT_SL_ORIGIN_IN)CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
  648. {
  649. bRunning = 1;
  650. CT_AutoStep = 2;
  651. cSongLiaoOk = 1;
  652. cZhuangLiaoOk = 0;
  653. if(CT_bSingle) SingOneFlg= 1;
  654. dwZipCnt = 0;
  655. }
  656. }
  657. CT_bSingle = 0;
  658. }
  659. STOP_IN_FLAG_OLD = STOP_IN_FLAG;
  660. if(CT_STOP_IN)
  661. {
  662. if(STOP_FILTER < 200)
  663. {
  664. STOP_FILTER++;
  665. }
  666. else
  667. STOP_IN_FLAG = 1;
  668. }
  669. else if(STOP_FILTER > 100)
  670. {
  671. STOP_FILTER--;
  672. }
  673. else
  674. STOP_IN_FLAG = 0;
  675. //停止
  676. if((STOP_IN_FLAG && !STOP_IN_FLAG_OLD) || bStop)
  677. {
  678. bStop = 0;
  679. if(bRunning)
  680. {
  681. bRunning = 0;
  682. CT_AutoStep = 0;
  683. CT_MotorStep = 0;
  684. CT_AutoDelay = dwTickCount;
  685. CT_MotorDelay = dwTickCount;
  686. AxisDecStop(X_AXIS);
  687. SingOneFlg = 0;
  688. }
  689. else
  690. {
  691. bRunning = 0;
  692. CT_AutoStep = 0;
  693. CT_MotorStep = 0;
  694. CT_HeMuStep = 0;
  695. CT_SL_Step = 0;
  696. CT_HSL_Step = 0;
  697. CT_ZL_Step = 0;
  698. CT_CLT_Step = 0;
  699. CT_ZD_Step = 0;
  700. CT_AutoDelay = dwTickCount;
  701. CT_MotorDelay = dwTickCount;
  702. CT_SL_Delay = dwTickCount;
  703. CT_HSL_Delay = dwTickCount;
  704. CT_ZL_Delay = dwTickCount;
  705. CT_FDDelay = dwTickCount;
  706. CT_CLT_Delay = dwTickCount;
  707. CT_ZDP_Delay = dwTickCount;
  708. SingOneFlg = 0;
  709. AxisDecStop(X_AXIS);
  710. if(CT_PARAM_CR_MODE)//按停止电机复位
  711. {
  712. if(!CT_CR_ORIGIN_IN)
  713. {
  714. if(CT_MotorStep == 0)CT_MotorStep = 100;
  715. }
  716. }
  717. CT_SZ_OUT = CT_MOTOR_Y_DISEN;
  718. SetEn(X_AXIS,CT_MOTOR_DISEN);
  719. CT_FD_VAVLE = 0;
  720. CT_XM_VAVLE = 0;
  721. CT_SL_VAVEL = 0;
  722. CT_QYD_VAVLE = 0;
  723. CT_HL_VAVLE = 0;
  724. CT_HYD_VAVLE = 0;
  725. CT_CR_VAVLE = 0;
  726. CT_ZDP_OUT = 0;
  727. CT_HSL_VAVLE = 0;
  728. cSongLiaoOk = 0;
  729. cZhuangLiaoOk = 0;
  730. cZLCnt = 0;
  731. if(GetAlarmCode(CT_ALARM_ADDR) != 0)SetAlarmCode(CT_ALARM_ADDR,0);
  732. }
  733. }
  734. if(bAlarmStop)
  735. {
  736. bAlarmStop = 0;
  737. bRunning = 0;
  738. CT_AutoStep = 0;
  739. CT_MotorStep = 0;
  740. CT_AutoDelay = dwTickCount;
  741. CT_MotorDelay = dwTickCount;
  742. SingOneFlg = 0;
  743. AxisDecStop(X_AXIS);
  744. AxisDecStop(Y_AXIS);
  745. }
  746. }
  747. //电机动作
  748. void ChuanTou_Motor(void) //
  749. {
  750. static long back_buff,save_buff;
  751. dwRealPos = GetPos(X_AXIS);
  752. switch(CT_MotorStep)
  753. {
  754. case 0:
  755. break;
  756. case 1:
  757. if(GetDir(X_AXIS) == CT_MOTOR_EN)
  758. {
  759. SetEn(X_AXIS,CT_MOTOR_EN);
  760. CT_MotorDelay = dwTickCount + 50;
  761. }
  762. if(CT_SZ_OUT != CT_MOTOR_Y_EN)
  763. {
  764. CT_SZ_OUT = CT_MOTOR_Y_EN;
  765. CT_MotorDelay = dwTickCount + 50;
  766. }
  767. CT_MotorStep = 2;
  768. break;
  769. case 2:
  770. if(dwTickCount >= CT_MotorDelay)
  771. {
  772. save_buff = dwRealPos;
  773. if(!X_DRV)AxisContinueMove(X_AXIS,CT_PARAM_HSPEED,QD_DIR_P);
  774. CT_MotorStep = 3;
  775. }
  776. break;
  777. case 3:
  778. if(CT_GUO_LIAN_IN_DW)
  779. {
  780. // MoveChangSpeed(X_AXIS,CT_PARAM_LSPEED);
  781. AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED);
  782. CT_MotorStep = 4;
  783. }
  784. else if((dwRealPos - save_buff) >= CT_PARAM_MAX_LENGTH)
  785. CT_SetAlarmCode(CT_NO_ZIPPER_ALARM);
  786. break;
  787. case 4:
  788. if(CT_GUO_LIAN_IN_UP)
  789. {
  790. back_buff = dwRealPos;
  791. CT_MotorStep = 5;
  792. }
  793. else if((dwRealPos - save_buff) >= CT_PARAM_MAX_LENGTH)
  794. CT_SetAlarmCode(CT_NO_ZIPPER_ALARM);
  795. break;
  796. case 5:
  797. if((dwRealPos - back_buff) >= CT_PARAM_STOP_LENGTH)
  798. {
  799. AxisEgmStop(X_AXIS);
  800. CT_MotorStep = 6;
  801. }
  802. break;
  803. case 6:
  804. if(!X_DRV)
  805. {
  806. CT_MotorStep = 0;
  807. CT_QYD_VAVLE = 1;
  808. CT_HYD_VAVLE = 1;
  809. if(CT_PARAM_HL_ENABLE)CT_HL_VAVLE = 1;
  810. }
  811. break;
  812. case 100: //穿入电机慢慢复位动作
  813. CT_CRDR_OUT = CT_Y_DIR_N;
  814. if(!Y_DRV)AxisContinueMove(Y_AXIS,10,QD_DIR_N);
  815. CT_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  816. CT_MotorStep = 101;
  817. break;
  818. case 101:
  819. if(CT_CR_ORIGIN_IN)
  820. {
  821. AxisDecStop(Y_AXIS);
  822. CT_MotorStep = 102;
  823. }
  824. else if(dwTickCount >= CT_MotorDelay)
  825. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  826. break;
  827. case 102:
  828. if(!Y_DRV)
  829. {
  830. CT_MotorStep = 0;
  831. }
  832. break;
  833. }
  834. }
  835. #endif