TYJiaoYaDinCun.c 25 KB

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