WYSJiaoYaDinCun.c 26 KB

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