FJJiaoYaDinCun.c 24 KB

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