XSJiaoYaDinCun.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. #include "global.h"
  2. #if XIN_SHENG_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(!JYDC_XiaChong_IN)JYDC_SetAlarmCode(JYDC_START_XIACHONG_ALARM);
  283. else if(GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL)JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  284. else
  285. {
  286. JYDC_AutoStep = 1;
  287. JYDC_bRunning = 1;
  288. JYDC_AutoDelay = 0;
  289. }
  290. JYDC_bStart = 0;
  291. }
  292. if(JYDC_KaDai_IN && (GetAlarmCode(100) == 0))
  293. {
  294. JYDC_SetAlarmCode(JYDC_KADAI_ALARM);
  295. }
  296. if(STOP_IN_UP || JYDC_bStop)
  297. {
  298. JYDC_bStop = 0;
  299. if(JYDC_bRunning && (SingOneFlg == 0))
  300. {
  301. SingOneFlg = 1;
  302. /* JYDC_ChuiQi_VAVLE = 1;
  303. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  304. JYDC_SuoChi_VAVLE = 1;
  305. JYDC_bRunning = 0;
  306. JYDC_AutoStep = 0;
  307. AxisEgmStop(X_AXIS);*/
  308. }
  309. else
  310. {
  311. CUR_LEN_JY = 0;
  312. JYDC_ChuiQi_VAVLE = 1;
  313. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  314. JYDC_SuoChi_VAVLE = 0;
  315. JYDC_bRunning = 0;
  316. JYDC_AutoStep = 0;
  317. JYDC_XiChi_MOTOR = 0;
  318. AxisEgmStop(X_AXIS);
  319. SingOneFlg = 0;
  320. }
  321. }
  322. if(JYDC_bAlarmStop)
  323. {
  324. JYDC_bAlarmStop = 0;
  325. AxisEgmStop(X_AXIS);
  326. JYDC_AutoStep = 0;
  327. if(JYDC_bRunning)JYDC_SuoChi_VAVLE = 1;
  328. JYDC_bRunning = 0;
  329. SingOneFlg = 0;
  330. }
  331. }
  332. unsigned long ToothTransPulse(unsigned long tooth)
  333. {
  334. return(JY_JIZHUN_LEN * tooth * 2000 / 250 / JY_JIZHUN_CISHU);
  335. }
  336. //自动运行动作
  337. void JYDC_AutoRunStep(void)
  338. {
  339. // DISPLAY_DATA0 = JYDC_AutoStep;
  340. // DISPLAY_DATA1 = ToothNumBuff;
  341. // DISPLAY_DATA2 = SET_TOTAL;
  342. // DISPLAY_DATA3 = GetTotal(JYDC_TOTAL_ADDR);
  343. if(JYDC_bRunning)
  344. {
  345. if(JYDC_AutoStep == 1)
  346. {
  347. JYDC_XiChi_MOTOR = 1;
  348. if(JYDC_SEBIAO_MODE)
  349. {
  350. JYDC_AutoStep = 20;
  351. JYDC_SuoChi_VAVLE = 0;
  352. dwZipCnt = 0;
  353. }
  354. else
  355. JYDC_AutoStep = 2;
  356. }
  357. else if((JYDC_AutoStep == 2))
  358. {
  359. cFirstFlg = 1;
  360. if(RemainKongWeiToothNum == 0)
  361. {
  362. RemainKongWeiToothNum = SET_KOUWEI_JY;
  363. }
  364. else
  365. {
  366. }
  367. JYDC_AutoStep = 3;
  368. }
  369. else if(JYDC_AutoStep == 3)
  370. {
  371. if(RemainKongWeiToothNum >= SET_DAOKOU_JY)
  372. {
  373. if(cFirstFlg)
  374. {
  375. if(JYDC_PARAM_REVICHISHU <= SET_KOUWEI_JY)
  376. {
  377. ToothNumBuff = JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY;
  378. RemainKongWeiToothNum = 0;
  379. }
  380. else
  381. {
  382. ToothNumBuff = JYDC_PARAM_REVICHISHU + (RemainKongWeiToothNum-SET_DAOKOU_JY) + SET_DAOKOU_JY;
  383. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  384. }
  385. }
  386. else
  387. {
  388. ToothNumBuff = ToothNumBuff + SET_DAOKOU_JY;
  389. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  390. }
  391. }
  392. else
  393. {
  394. if(cFirstFlg)
  395. {
  396. ToothNumBuff = JYDC_PARAM_REVICHISHU - RemainKongWeiToothNum + SET_DAOKOU_JY;
  397. }
  398. else
  399. {
  400. ToothNumBuff = ToothNumBuff + RemainKongWeiToothNum;
  401. }
  402. RemainKongWeiToothNum = 0;
  403. }
  404. JYDC_SuoChi_VAVLE = 0;
  405. // JYDC_AutoDelay = dwTickCount + 50;
  406. JYDC_AutoStep = 4;
  407. }
  408. else if((JYDC_AutoStep == 4) && (dwTickCount >= JYDC_AutoDelay))
  409. {
  410. if((ToothNumBuff - CUR_LEN_JY) > JYDC_PARAM_LOW_LENGTH)
  411. {
  412. AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  413. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  414. JYDC_XiChiChuiQi_VAVLE = 1;
  415. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  416. JYDC_AutoStep = 5;
  417. }
  418. else
  419. {
  420. AxisContinueMove(X_AXIS,JYDC_PARAM_LOW_SPEED,0);
  421. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  422. JYDC_XiChiChuiQi_VAVLE = 1;
  423. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  424. JYDC_AutoStep = 6;
  425. }
  426. /* DISPLAY_DATA6 = ToothTransPulse(ToothNumBuff);
  427. DISPLAY_DATA7 = ToothTransPulse(JYDC_PARAM_LOW_LENGTH);
  428. AxisMoveTwoPos(X_AXIS,JYDC_PARAM_SET_SPEED,ToothTransPulse(ToothNumBuff - JYDC_PARAM_LOW_LENGTH),JYDC_PARAM_LOW_SPEED,ToothTransPulse(JYDC_PARAM_LOW_LENGTH+5),0);
  429. JYDC_AutoStep = 6;
  430. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME;*/
  431. }
  432. else if(JYDC_AutoStep == 5)
  433. {
  434. if(cFirstFlg)
  435. {
  436. if((ToothNumBuff - CUR_LEN_JY) <= (JYDC_PARAM_LOW_LENGTH))
  437. {
  438. AxisChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED);
  439. cFirstFlg = 0;
  440. JYDC_AutoStep = 6;
  441. }
  442. else if(dwTickCount >= JYDC_AutoDelay)
  443. {
  444. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  445. }
  446. }
  447. else
  448. {
  449. if((ToothNumBuff - CUR_LEN_JY) <= JYDC_PARAM_LOW_LENGTH)
  450. {
  451. AxisChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED);
  452. JYDC_AutoStep = 6;
  453. }
  454. else if(dwTickCount >= JYDC_AutoDelay)
  455. {
  456. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  457. }
  458. }
  459. }
  460. else if(JYDC_AutoStep == 6)
  461. {
  462. if(!X_DRV)
  463. {
  464. JYDC_XiaChongStep = 1;
  465. JYDC_AutoStep = 7;
  466. }
  467. else if(dwTickCount >= JYDC_AutoDelay)
  468. {
  469. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  470. }
  471. }
  472. else if(JYDC_AutoStep == 7)
  473. {
  474. if(JYDC_XiaChongStep == 0)
  475. {
  476. if(RemainKongWeiToothNum == 0)
  477. {
  478. JYDC_AutoStep = 8;
  479. JYDC_AutoDelay = dwTickCount;
  480. }
  481. else
  482. {
  483. JYDC_AutoStep = 3;
  484. JYDC_AutoDelay = dwTickCount;
  485. }
  486. }
  487. }
  488. else if((JYDC_AutoStep == 8) && (JYDCRunFlg == 1))
  489. {
  490. AddToTal(JYDC_TOTAL_ADDR);
  491. CUR_LEN_JY = 0;
  492. if((GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL) || JYDC_bStop || SingOneFlg)
  493. {
  494. if(JYDC_bStop || SingOneFlg)
  495. {
  496. JYDC_bStop = 0;
  497. JYDC_AutoStep = 0;
  498. JYDC_bRunning = 0;
  499. SingOneFlg = 0;
  500. JYDC_SuoChi_VAVLE = 0;
  501. JYDC_XiChi_MOTOR = 0;
  502. }
  503. else
  504. {
  505. JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  506. }
  507. }
  508. else
  509. {
  510. JYDC_AutoStep = 1;
  511. JYDC_AutoDelay = JYDC_PARAM_CYCLE_DELAY * 10 + dwTickCount;
  512. CalProSP(JYDC_PROSPEED_ADDR);
  513. }
  514. }
  515. else if((JYDC_AutoStep == 20) && (dwTickCount >= JYDC_AutoDelay)) //色标动作
  516. {
  517. cSeBiaoEn = 1;
  518. if(dwZipCnt == 0)
  519. AxisContinueMove(X_AXIS,JYDC_PARAM_LOW_SPEED,0);
  520. else
  521. AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  522. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  523. JYDC_XiChiChuiQi_VAVLE = 1;
  524. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  525. JYDC_AutoStep = 21;
  526. }
  527. else if(JYDC_AutoStep == 21)
  528. {
  529. if(!X_DRV)
  530. {
  531. JYDC_AutoStep = 22;
  532. JYDC_AutoDelay = dwTickCount;
  533. }
  534. else if(dwTickCount >= JYDC_AutoDelay)
  535. {
  536. JYDC_SetAlarmCode(JYDC_SEBIAO_ALARM);
  537. }
  538. }
  539. else if(JYDC_AutoStep == 22)
  540. {
  541. if(RemainKongWeiToothNum >= SET_DAOKOU_JY)
  542. {
  543. if(cFirstFlg)
  544. {
  545. if(JYDC_PARAM_REVICHISHU <= SET_KOUWEI_JY)
  546. {
  547. ToothNumBuff = JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY;
  548. RemainKongWeiToothNum = 0;
  549. }
  550. else
  551. {
  552. ToothNumBuff = JYDC_PARAM_REVICHISHU + (RemainKongWeiToothNum-SET_DAOKOU_JY) + SET_DAOKOU_JY;
  553. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  554. }
  555. }
  556. else
  557. {
  558. ToothNumBuff = ToothNumBuff + SET_DAOKOU_JY;
  559. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  560. }
  561. }
  562. else
  563. {
  564. if(cFirstFlg)
  565. {
  566. ToothNumBuff = JYDC_PARAM_REVICHISHU - RemainKongWeiToothNum + SET_DAOKOU_JY;
  567. }
  568. else
  569. {
  570. ToothNumBuff = ToothNumBuff + RemainKongWeiToothNum;
  571. }
  572. RemainKongWeiToothNum = 0;
  573. }
  574. JYDC_AutoStep = 23;
  575. }
  576. else if((JYDC_AutoStep == 23) && (dwTickCount >= JYDC_AutoDelay))
  577. {
  578. if((ToothNumBuff - CUR_LEN_JY) > JYDC_PARAM_LOW_LENGTH)
  579. {
  580. if(!X_DRV)AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  581. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  582. JYDC_XiChiChuiQi_VAVLE = 1;
  583. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  584. JYDC_AutoStep = 24;
  585. }
  586. else
  587. {
  588. if(!X_DRV)AxisContinueMove(X_AXIS,JYDC_PARAM_LOW_SPEED,0);
  589. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  590. JYDC_XiChiChuiQi_VAVLE = 1;
  591. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  592. JYDC_AutoStep = 25;
  593. }
  594. }
  595. else if(JYDC_AutoStep == 24)
  596. {
  597. if(cFirstFlg)
  598. {
  599. if((ToothNumBuff - CUR_LEN_JY) <= (JYDC_PARAM_LOW_LENGTH))
  600. {
  601. AxisChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED);
  602. cFirstFlg = 0;
  603. JYDC_AutoStep = 25;
  604. }
  605. else if(dwTickCount >= JYDC_AutoDelay)
  606. {
  607. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  608. }
  609. }
  610. else
  611. {
  612. if((ToothNumBuff - CUR_LEN_JY) <= JYDC_PARAM_LOW_LENGTH)
  613. {
  614. AxisChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED);
  615. JYDC_AutoStep = 25;
  616. }
  617. else if(dwTickCount >= JYDC_AutoDelay)
  618. {
  619. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  620. }
  621. }
  622. }
  623. else if(JYDC_AutoStep == 25)
  624. {
  625. if(!X_DRV)
  626. {
  627. JYDC_XiaChongStep = 1;
  628. JYDC_AutoStep = 26;
  629. }
  630. else if(dwTickCount >= JYDC_AutoDelay)
  631. {
  632. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  633. }
  634. }
  635. else if(JYDC_AutoStep == 26)
  636. {
  637. if(JYDC_XiaChongStep == 0)
  638. {
  639. if(RemainKongWeiToothNum == 0)
  640. {
  641. JYDC_AutoStep = 27;
  642. JYDC_AutoDelay = dwTickCount;
  643. }
  644. else
  645. {
  646. JYDC_AutoStep = 22;
  647. JYDC_AutoDelay = dwTickCount;
  648. }
  649. }
  650. }
  651. else if((JYDC_AutoStep == 27) && (JYDCRunFlg == 1))
  652. {
  653. AddToTal(JYDC_TOTAL_ADDR);
  654. dwZipCnt++;
  655. CUR_LEN_JY = 0;
  656. cSeBiaoStep = 0;
  657. if((GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL) || JYDC_bStop || SingOneFlg)
  658. {
  659. if(JYDC_bStop || SingOneFlg)
  660. {
  661. JYDC_bStop = 0;
  662. JYDC_AutoStep = 0;
  663. JYDC_bRunning = 0;
  664. SingOneFlg = 0;
  665. JYDC_SuoChi_VAVLE = 0;
  666. JYDC_XiChi_MOTOR = 0;
  667. }
  668. else
  669. {
  670. JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  671. }
  672. }
  673. else
  674. {
  675. JYDC_AutoStep = 1;
  676. JYDC_AutoDelay = JYDC_PARAM_CYCLE_DELAY * 10 + dwTickCount;
  677. CalProSP(JYDC_PROSPEED_ADDR);
  678. }
  679. }
  680. }
  681. }
  682. #endif