HYJiaoYaDinCun.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. #include "global.h"
  2. #if HONG_YE_MACHINE
  3. long RealPosBuff = 0; //记录齿数
  4. unsigned long ToothNumBuff = 0;
  5. unsigned long RemainKongWeiToothNum = 0; // 空位剩余齿数
  6. unsigned char cFirstFlg = 0,cSeBiaoStep = 0;
  7. unsigned short SecondToothNum = 0;
  8. unsigned char cCntEn = 0;
  9. unsigned long dwSeBiaoDelayCnt = 0;
  10. void StopProc(void);
  11. void StartProc(void);
  12. unsigned long CalEncodePulse(void);
  13. void JYDC_DelayAction(void);
  14. void JYDC_InitAction(void);
  15. void JYDC_ExtiActionX30(void);
  16. void JYDC_Action(void);
  17. void ModeSelect(void);
  18. void JYDC_ChuiQi(void);
  19. void JYDC_XiaChong(void);
  20. void JYDC_SetAlarmCode(unsigned alarm_code);
  21. void JYDC_StartStopAction(void);
  22. void JYDC_AutoRunStep(void);
  23. unsigned long GetToothNum(unsigned long zipper_length);
  24. void JYDC_SetAlarmCode(unsigned alarm_code)
  25. {
  26. SetAlarmCode(JYDC_ALARM_ADDR,alarm_code);
  27. JYDC_bAlarmStop = 1;
  28. }
  29. void JYDC_DelayAction(void)
  30. {
  31. }
  32. void JYDC_InitAction(void)
  33. {
  34. if(MODE_SELECT > 3)MODE_SELECT = 0;
  35. ModeSelect();
  36. CUR_LEN_JY = 0;
  37. }
  38. unsigned char test_buff[14]={1,2,3,4,5,6,7,8,9,10,11,12,13,14};
  39. //手动动作
  40. void JYDC_ManualAction(void)
  41. {
  42. //警告跳出
  43. if(bClearTotal)
  44. {
  45. bClearTotal = 0;
  46. ClrcToTal(JYDC_TOTAL_ADDR);
  47. }
  48. if(!JYDC_bRunning)
  49. {
  50. if(JYDC_bAddTooth)
  51. {
  52. JYDC_bAddTooth = 0;
  53. if(JYDC_PARAM_REVICHISHU < 65535)JYDC_PARAM_REVICHISHU++;
  54. }
  55. if(JYDC_bDecTooth)
  56. {
  57. JYDC_bDecTooth = 0;
  58. if(JYDC_PARAM_REVICHISHU != 0)JYDC_PARAM_REVICHISHU--;
  59. }
  60. if(JYDC_bManXiaChong || JYDC_ManXiaChong_UP)
  61. {
  62. JYDC_bManXiaChong = 0;
  63. if(JYDC_XiaChongStep == 0)//if(!JYDC_bRunning && !STOP_IN && !X_DRV && (JYDC_XiaChongStep == 0))
  64. {
  65. JYDC_XiaChongStep = 1;
  66. }
  67. }
  68. if(JYDC_bManSuoChi)
  69. {
  70. JYDC_bManSuoChi = 0;
  71. JYDC_SuoChi_VAVLE = ~JYDC_SuoChi_VAVLE;
  72. }
  73. if(JYDC_bManChuiQi)
  74. {
  75. JYDC_bManChuiQi = 0;
  76. JYDC_ChuiQi_VAVLE = 1;
  77. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  78. }
  79. if(JYDC_bChangeLength)
  80. {
  81. JYDC_bChangeLength = 0;
  82. ModeSelect();
  83. SetData32bits(31,CalInch(SET_ZIPPER_LENGTH));
  84. JYDC_PARAM_REVICHISHU = GetToothNum(SET_ZIPPER_LENGTH);
  85. }
  86. if(JYDC_bSetInch)
  87. {
  88. JYDC_bSetInch = 0;
  89. SetData32bits(6,CalLengthCM(SET_ZIPPER_LENGTH_INCH));
  90. JYDC_bChangeLength = 1;
  91. }
  92. }
  93. }
  94. //高速输入X30/X16定时器中断
  95. void JYDC_ExtiActionX30(void)
  96. {
  97. CUR_LEN_JY++;
  98. if(JYDC_SEBIAO_MODE)
  99. {
  100. if(cSeBiaoStep == 1)
  101. {
  102. dwSeBiaoDelayCnt--;
  103. if(dwSeBiaoDelayCnt == 0)
  104. {
  105. CUR_LEN_JY = 0;
  106. cFirstFlg = 1;
  107. RemainKongWeiToothNum = SET_KOUWEI_JY;
  108. cSeBiaoStep = 2;
  109. }
  110. }
  111. else if(cSeBiaoStep == 2)
  112. {
  113. if((CUR_LEN_JY >= ToothNumBuff) && JYDC_bRunning)
  114. {
  115. AxisEgmStop(X_AXIS);
  116. if(JYDC_bTest)
  117. {
  118. JYDC_bRunning = 0;
  119. JYDC_AutoStep = 0;
  120. JYDC_SuoChi_VAVLE = 1;
  121. cSeBiaoStep = 0;
  122. }
  123. }
  124. }
  125. }
  126. else
  127. {
  128. if((CUR_LEN_JY >= ToothNumBuff) && JYDC_bRunning)
  129. {
  130. AxisEgmStop(X_AXIS);
  131. if(JYDC_bTest)
  132. {
  133. JYDC_bRunning = 0;
  134. JYDC_AutoStep = 0;
  135. JYDC_SuoChi_VAVLE = 1;
  136. }
  137. }
  138. }
  139. }
  140. //高速输入X31/X17外部色标信号中断
  141. void JYDC_ExtiActionX31(void)
  142. {
  143. if(cSeBiaoEn)
  144. { cSeBiaoEn = 0;
  145. dwSeBiaoDelayCnt = JYDC_SEBIAO_DELAY;
  146. if(dwSeBiaoDelayCnt == 0)
  147. {
  148. CUR_LEN_JY = 0;
  149. cFirstFlg = 1;
  150. RemainKongWeiToothNum = SET_KOUWEI_JY;
  151. cSeBiaoStep = 2;
  152. }
  153. else
  154. {
  155. cSeBiaoStep = 1;
  156. }
  157. }
  158. }
  159. //胶牙定寸动作
  160. void JYDC_Action(void)
  161. {
  162. // DISPLAY_DATA0 = cNoPulseStopTime;
  163. // DISPLAY_DATA1 = GetCurSpeed(X_AXIS);
  164. // DISPLAY_DATA2 = GetSetSpeed(X_AXIS);
  165. // DISPLAY_DATA3 = GetState(X_AXIS);
  166. JYDC_ManualAction();
  167. JYDC_ChuiQi();
  168. JYDC_XiaChong();
  169. JYDC_StartStopAction();
  170. JYDC_AutoRunStep();
  171. }
  172. void ModeSelect(void)
  173. {
  174. switch(MODE_SELECT) //模具选择
  175. {
  176. case 0: //3#模具
  177. JY_JIZHUN_CISHU = JY_JIZHUN_CISHU1;//基准长度对应齿数
  178. JY_JIZHUN_LEN = JY_JIZHUN_LEN1;//基准长度
  179. SET_DAOKOU_JY = SET_DAOKOU_JY1; //机械模具刀口
  180. break;
  181. case 1: //5#模具
  182. JY_JIZHUN_CISHU = JY_JIZHUN_CISHU2;//基准长度对应齿数
  183. JY_JIZHUN_LEN = JY_JIZHUN_LEN2;//基准长度
  184. SET_DAOKOU_JY = SET_DAOKOU_JY2; //机械模具刀口
  185. break;
  186. case 2: //8#模具
  187. JY_JIZHUN_CISHU = JY_JIZHUN_CISHU3;//基准长度对应齿数
  188. JY_JIZHUN_LEN = JY_JIZHUN_LEN3;//基准长度
  189. SET_DAOKOU_JY = SET_DAOKOU_JY3; //机械模具刀口
  190. break;
  191. default: //特殊模具
  192. JY_JIZHUN_CISHU = JY_JIZHUN_CISHU4;//基准长度对应齿数
  193. JY_JIZHUN_LEN = JY_JIZHUN_LEN4;//基准长度
  194. SET_DAOKOU_JY = SET_DAOKOU_JY4; //机械模具刀口
  195. break;
  196. }
  197. if((JY_JIZHUN_CISHU == 0) || (JY_JIZHUN_LEN == 0))
  198. {
  199. JY_JIZHUN_CISHU = 49;
  200. JY_JIZHUN_LEN = 1250;
  201. SET_DAOKOU_JY = 10;
  202. }
  203. }
  204. //输入拉链长度返回所输入拉链长度所对应的齿数
  205. unsigned long GetToothNum(unsigned long zipper_length)
  206. {
  207. float length_buff1,tooth_buff,length_buff2;
  208. length_buff1 = zipper_length;
  209. tooth_buff = JY_JIZHUN_CISHU;
  210. length_buff2 = JY_JIZHUN_LEN;
  211. return (unsigned long)round(length_buff1 * tooth_buff / length_buff2);
  212. }
  213. //吹气动作
  214. void JYDC_ChuiQi(void)
  215. {
  216. if(JYDC_XiaChong_DW)
  217. {
  218. JYDC_ChuiQi_VAVLE = 1;
  219. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  220. }
  221. if(JYDC_ChuiQi_VAVLE)
  222. {
  223. if(JYDC_ChuiQiDelay < dwTickCount)JYDC_ChuiQi_VAVLE = 0;
  224. }
  225. if(JYDC_XiChiChuiQi_VAVLE)
  226. {
  227. if(JYDC_XiChiChuiQiDelay < dwTickCount)JYDC_XiChiChuiQi_VAVLE = 0;
  228. }
  229. }
  230. //下冲动作
  231. void JYDC_XiaChong(void)
  232. {
  233. if(JYDC_XiaChongStep == 1)
  234. {
  235. JYDC_ShaChe_VAVLE = 0;
  236. JYDC_SuoChi_VAVLE = 1; //手动下冲不锁齿
  237. JYDC_XiaChongDelay = dwTickCount + XIACONG_DELAY_TIME*10;
  238. JYDC_XiaChongStep = 2;
  239. }
  240. else if((JYDC_XiaChongStep == 2) && (dwTickCount >= JYDC_XiaChongDelay))
  241. {
  242. JYDC_XiaChong_MOTOR = 1;
  243. JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_XC_ALARM_TIME * 10;
  244. JYDC_XiaChongStep = 3;
  245. }
  246. else if(JYDC_XiaChongStep == 3)
  247. {
  248. if(JYDC_XiaChong_IN_UP)
  249. {
  250. JYDC_XiaChong_MOTOR = 0;
  251. JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_SHACHE_DELAY_TIME * 10;
  252. JYDC_XiaChongStep = 4;
  253. }
  254. else if(dwTickCount >= JYDC_XiaChongDelay)
  255. {
  256. JYDC_SetAlarmCode(JYDC_XIACHONG_ARRIVE_ALARM);
  257. JYDC_XiaChong_MOTOR = 0;
  258. JYDC_ShaChe_VAVLE = 0;
  259. }
  260. }
  261. else if((JYDC_XiaChongStep == 4) && (dwTickCount >= JYDC_XiaChongDelay))
  262. {
  263. JYDC_ShaChe_VAVLE = 1;
  264. JYDC_XiaChongStep = 5;
  265. JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_SHACHE_TIME;
  266. }
  267. else if((JYDC_XiaChongStep == 5) && (dwTickCount >= JYDC_XiaChongDelay))
  268. {
  269. JYDC_ShaChe_VAVLE = 0;
  270. JYDC_XiaChongStep = 6;
  271. }
  272. else if(JYDC_XiaChongStep == 6)
  273. {
  274. JYDC_XiaChongStep = 0;
  275. }
  276. }
  277. //启动停止故障停止动作
  278. void JYDC_StartStopAction(void)
  279. {
  280. if((START_IN_UP || JYDC_bStart) && !JYDC_bRunning && (JYDC_AutoStep ==0))
  281. {
  282. if(GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL)JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  283. else
  284. {
  285. JYDC_AutoStep = 1;
  286. JYDC_bRunning = 1;
  287. JYDC_AutoDelay = 0;
  288. }
  289. JYDC_bStart = 0;
  290. }
  291. if(JYDC_KaDai_IN && (GetAlarmCode(100) == 0))
  292. {
  293. JYDC_SetAlarmCode(JYDC_KADAI_ALARM);
  294. }
  295. if(STOP_IN_UP || JYDC_bStop)
  296. {
  297. JYDC_bStop = 0;
  298. if(JYDC_bRunning && (SingOneFlg == 0))
  299. {
  300. SingOneFlg = 1;
  301. /* JYDC_ChuiQi_VAVLE = 1;
  302. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  303. JYDC_SuoChi_VAVLE = 1;
  304. JYDC_bRunning = 0;
  305. JYDC_AutoStep = 0;
  306. AxisEgmStop(X_AXIS);*/
  307. }
  308. else
  309. {
  310. CUR_LEN_JY = 0;
  311. JYDC_ChuiQi_VAVLE = 1;
  312. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  313. JYDC_SuoChi_VAVLE = 0;
  314. JYDC_bRunning = 0;
  315. JYDC_AutoStep = 0;
  316. JYDC_XiChi_MOTOR = 0;
  317. AxisEgmStop(X_AXIS);
  318. SingOneFlg = 0;
  319. }
  320. }
  321. if(JYDC_bAlarmStop)
  322. {
  323. JYDC_bAlarmStop = 0;
  324. JYDC_XiaChongStep = 0;
  325. JYDC_XiaChong_MOTOR = 0;
  326. JYDC_ShaChe_VAVLE = 1;
  327. AxisEgmStop(X_AXIS);
  328. JYDC_AutoStep = 0;
  329. if(JYDC_bRunning)JYDC_SuoChi_VAVLE = 1;
  330. JYDC_bRunning = 0;
  331. SingOneFlg = 0;
  332. }
  333. }
  334. unsigned long ToothTransPulse(unsigned long tooth)
  335. {
  336. return(JY_JIZHUN_LEN * tooth * 2000 / 250 / JY_JIZHUN_CISHU);
  337. }
  338. //自动运行动作
  339. void JYDC_AutoRunStep(void)
  340. {
  341. // DISPLAY_DATA0 = JYDC_AutoStep;
  342. // DISPLAY_DATA1 = ToothNumBuff;
  343. // DISPLAY_DATA2 = SET_TOTAL;
  344. // DISPLAY_DATA3 = GetTotal(JYDC_TOTAL_ADDR);
  345. if(JYDC_bRunning)
  346. {
  347. if(JYDC_AutoStep == 1)
  348. {
  349. JYDC_XiChi_MOTOR = 1;
  350. if(JYDC_SEBIAO_MODE)
  351. {
  352. JYDC_AutoStep = 20;
  353. JYDC_SuoChi_VAVLE = 0;
  354. dwZipCnt = 0;
  355. }
  356. else
  357. JYDC_AutoStep = 2;
  358. }
  359. else if((JYDC_AutoStep == 2))
  360. {
  361. cFirstFlg = 1;
  362. if(RemainKongWeiToothNum == 0)
  363. {
  364. RemainKongWeiToothNum = SET_KOUWEI_JY;
  365. }
  366. else
  367. {
  368. }
  369. JYDC_AutoStep = 3;
  370. }
  371. else if(JYDC_AutoStep == 3)
  372. {
  373. if(RemainKongWeiToothNum >= SET_DAOKOU_JY)
  374. {
  375. if(cFirstFlg)
  376. {
  377. if(JYDC_PARAM_REVICHISHU <= SET_KOUWEI_JY)
  378. {
  379. ToothNumBuff = JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY;
  380. RemainKongWeiToothNum = 0;
  381. }
  382. else
  383. {
  384. ToothNumBuff = JYDC_PARAM_REVICHISHU + (RemainKongWeiToothNum-SET_DAOKOU_JY) + SET_DAOKOU_JY;
  385. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  386. }
  387. }
  388. else
  389. {
  390. ToothNumBuff = ToothNumBuff + SET_DAOKOU_JY;
  391. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  392. }
  393. }
  394. else
  395. {
  396. if(cFirstFlg)
  397. {
  398. ToothNumBuff = JYDC_PARAM_REVICHISHU - RemainKongWeiToothNum + SET_DAOKOU_JY;
  399. }
  400. else
  401. {
  402. ToothNumBuff = ToothNumBuff + RemainKongWeiToothNum;
  403. }
  404. RemainKongWeiToothNum = 0;
  405. }
  406. JYDC_SuoChi_VAVLE = 0;
  407. // JYDC_AutoDelay = dwTickCount + 50;
  408. JYDC_AutoStep = 4;
  409. }
  410. else if((JYDC_AutoStep == 4) && (dwTickCount >= JYDC_AutoDelay))
  411. {
  412. if((ToothNumBuff - CUR_LEN_JY) > JYDC_PARAM_LOW_LENGTH)
  413. {
  414. AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  415. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  416. JYDC_XiChiChuiQi_VAVLE = 1;
  417. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  418. JYDC_AutoStep = 5;
  419. }
  420. else
  421. {
  422. AxisContinueMove(X_AXIS,JYDC_PARAM_LOW_SPEED,0);
  423. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  424. JYDC_XiChiChuiQi_VAVLE = 1;
  425. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  426. JYDC_AutoStep = 6;
  427. }
  428. /* DISPLAY_DATA6 = ToothTransPulse(ToothNumBuff);
  429. DISPLAY_DATA7 = ToothTransPulse(JYDC_PARAM_LOW_LENGTH);
  430. AxisMoveTwoPos(X_AXIS,JYDC_PARAM_SET_SPEED,ToothTransPulse(ToothNumBuff - JYDC_PARAM_LOW_LENGTH),JYDC_PARAM_LOW_SPEED,ToothTransPulse(JYDC_PARAM_LOW_LENGTH+5),0);
  431. JYDC_AutoStep = 6;
  432. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME;*/
  433. }
  434. else if(JYDC_AutoStep == 5)
  435. {
  436. if(cFirstFlg)
  437. {
  438. if((ToothNumBuff - CUR_LEN_JY) <= (JYDC_PARAM_LOW_LENGTH))
  439. {
  440. AxisChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED);
  441. cFirstFlg = 0;
  442. JYDC_AutoStep = 6;
  443. }
  444. else if(dwTickCount >= JYDC_AutoDelay)
  445. {
  446. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  447. }
  448. }
  449. else
  450. {
  451. if((ToothNumBuff - CUR_LEN_JY) <= JYDC_PARAM_LOW_LENGTH)
  452. {
  453. AxisChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED);
  454. JYDC_AutoStep = 6;
  455. }
  456. else if(dwTickCount >= JYDC_AutoDelay)
  457. {
  458. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  459. }
  460. }
  461. }
  462. else if(JYDC_AutoStep == 6)
  463. {
  464. if(!X_DRV)
  465. {
  466. JYDC_XiaChongStep = 1;
  467. JYDC_AutoStep = 7;
  468. }
  469. else if(dwTickCount >= JYDC_AutoDelay)
  470. {
  471. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  472. }
  473. }
  474. else if(JYDC_AutoStep == 7)
  475. {
  476. if(JYDC_XiaChongStep == 0)
  477. {
  478. if(RemainKongWeiToothNum == 0)
  479. {
  480. JYDC_AutoStep = 8;
  481. JYDC_AutoDelay = dwTickCount;
  482. }
  483. else
  484. {
  485. JYDC_AutoStep = 3;
  486. JYDC_AutoDelay = dwTickCount;
  487. }
  488. }
  489. }
  490. else if((JYDC_AutoStep == 8) && (JYDCRunFlg == 1))
  491. {
  492. AddToTal(JYDC_TOTAL_ADDR);
  493. CUR_LEN_JY = 0;
  494. if((GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL) || JYDC_bStop || SingOneFlg)
  495. {
  496. if(JYDC_bStop || SingOneFlg)
  497. {
  498. JYDC_bStop = 0;
  499. JYDC_AutoStep = 0;
  500. JYDC_bRunning = 0;
  501. SingOneFlg = 0;
  502. JYDC_SuoChi_VAVLE = 0;
  503. JYDC_XiChi_MOTOR = 0;
  504. }
  505. else
  506. {
  507. JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  508. }
  509. }
  510. else
  511. {
  512. JYDC_AutoStep = 1;
  513. JYDC_AutoDelay = JYDC_PARAM_CYCLE_DELAY * 10 + dwTickCount;
  514. CalProSP(JYDC_PROSPEED_ADDR);
  515. }
  516. }
  517. else if((JYDC_AutoStep == 20) && (dwTickCount >= JYDC_AutoDelay)) //色标动作
  518. {
  519. cSeBiaoEn = 1;
  520. if(dwZipCnt == 0)
  521. AxisContinueMove(X_AXIS,JYDC_PARAM_LOW_SPEED,0);
  522. else
  523. AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  524. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  525. JYDC_XiChiChuiQi_VAVLE = 1;
  526. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  527. JYDC_AutoStep = 21;
  528. }
  529. else if(JYDC_AutoStep == 21)
  530. {
  531. if(!X_DRV)
  532. {
  533. JYDC_AutoStep = 22;
  534. JYDC_AutoDelay = dwTickCount;
  535. }
  536. else if(dwTickCount >= JYDC_AutoDelay)
  537. {
  538. JYDC_SetAlarmCode(JYDC_SEBIAO_ALARM);
  539. }
  540. }
  541. else if(JYDC_AutoStep == 22)
  542. {
  543. if(RemainKongWeiToothNum >= SET_DAOKOU_JY)
  544. {
  545. if(cFirstFlg)
  546. {
  547. if(JYDC_PARAM_REVICHISHU <= SET_KOUWEI_JY)
  548. {
  549. ToothNumBuff = JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY;
  550. RemainKongWeiToothNum = 0;
  551. }
  552. else
  553. {
  554. ToothNumBuff = JYDC_PARAM_REVICHISHU + (RemainKongWeiToothNum-SET_DAOKOU_JY) + SET_DAOKOU_JY;
  555. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  556. }
  557. }
  558. else
  559. {
  560. ToothNumBuff = ToothNumBuff + SET_DAOKOU_JY;
  561. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  562. }
  563. }
  564. else
  565. {
  566. if(cFirstFlg)
  567. {
  568. ToothNumBuff = JYDC_PARAM_REVICHISHU - RemainKongWeiToothNum + SET_DAOKOU_JY;
  569. }
  570. else
  571. {
  572. ToothNumBuff = ToothNumBuff + RemainKongWeiToothNum;
  573. }
  574. RemainKongWeiToothNum = 0;
  575. }
  576. JYDC_AutoStep = 23;
  577. }
  578. else if((JYDC_AutoStep == 23) && (dwTickCount >= JYDC_AutoDelay))
  579. {
  580. if((ToothNumBuff - CUR_LEN_JY) > JYDC_PARAM_LOW_LENGTH)
  581. {
  582. if(!X_DRV)AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  583. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  584. JYDC_XiChiChuiQi_VAVLE = 1;
  585. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  586. JYDC_AutoStep = 24;
  587. }
  588. else
  589. {
  590. if(!X_DRV)AxisContinueMove(X_AXIS,JYDC_PARAM_LOW_SPEED,0);
  591. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  592. JYDC_XiChiChuiQi_VAVLE = 1;
  593. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  594. JYDC_AutoStep = 25;
  595. }
  596. }
  597. else if(JYDC_AutoStep == 24)
  598. {
  599. if(cFirstFlg)
  600. {
  601. if((ToothNumBuff - CUR_LEN_JY) <= (JYDC_PARAM_LOW_LENGTH))
  602. {
  603. AxisChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED);
  604. cFirstFlg = 0;
  605. JYDC_AutoStep = 25;
  606. }
  607. else if(dwTickCount >= JYDC_AutoDelay)
  608. {
  609. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  610. }
  611. }
  612. else
  613. {
  614. if((ToothNumBuff - CUR_LEN_JY) <= JYDC_PARAM_LOW_LENGTH)
  615. {
  616. AxisChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED);
  617. JYDC_AutoStep = 25;
  618. }
  619. else if(dwTickCount >= JYDC_AutoDelay)
  620. {
  621. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  622. }
  623. }
  624. }
  625. else if(JYDC_AutoStep == 25)
  626. {
  627. if(!X_DRV)
  628. {
  629. JYDC_XiaChongStep = 1;
  630. JYDC_AutoStep = 26;
  631. }
  632. else if(dwTickCount >= JYDC_AutoDelay)
  633. {
  634. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  635. }
  636. }
  637. else if(JYDC_AutoStep == 26)
  638. {
  639. if(JYDC_XiaChongStep == 0)
  640. {
  641. if(RemainKongWeiToothNum == 0)
  642. {
  643. JYDC_AutoStep = 27;
  644. JYDC_AutoDelay = dwTickCount;
  645. }
  646. else
  647. {
  648. JYDC_AutoStep = 22;
  649. JYDC_AutoDelay = dwTickCount;
  650. }
  651. }
  652. }
  653. else if((JYDC_AutoStep == 27) && (JYDCRunFlg == 1))
  654. {
  655. AddToTal(JYDC_TOTAL_ADDR);
  656. dwZipCnt++;
  657. CUR_LEN_JY = 0;
  658. cSeBiaoStep = 0;
  659. if((GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL) || JYDC_bStop || SingOneFlg)
  660. {
  661. if(JYDC_bStop || SingOneFlg)
  662. {
  663. JYDC_bStop = 0;
  664. JYDC_AutoStep = 0;
  665. JYDC_bRunning = 0;
  666. SingOneFlg = 0;
  667. JYDC_SuoChi_VAVLE = 0;
  668. JYDC_XiChi_MOTOR = 0;
  669. }
  670. else
  671. {
  672. JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  673. }
  674. }
  675. else
  676. {
  677. JYDC_AutoStep = 1;
  678. JYDC_AutoDelay = JYDC_PARAM_CYCLE_DELAY * 10 + dwTickCount;
  679. CalProSP(JYDC_PROSPEED_ADDR);
  680. }
  681. }
  682. }
  683. }
  684. #endif