FXWJiaoYaDinCun.c 22 KB

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