XDJiaoYaDinCun.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. #include "global.h"
  2. #if XI_DONG_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. SetAlarmCode(JYDC_ALARM_ADDR,0);
  44. }
  45. //手动动作
  46. void JYDC_ManualAction(void)
  47. {
  48. //警告跳出
  49. if(bClearTotal)
  50. {
  51. bClearTotal = 0;
  52. ClrcToTal(JYDC_TOTAL_ADDR);
  53. }
  54. if(!JYDC_bRunning)
  55. {
  56. if(JYDC_bAddTooth)
  57. {
  58. JYDC_bAddTooth = 0;
  59. if(JYDC_PARAM_REVICHISHU < 65535)JYDC_PARAM_REVICHISHU++;
  60. }
  61. if(JYDC_bDecTooth)
  62. {
  63. JYDC_bDecTooth = 0;
  64. if(JYDC_PARAM_REVICHISHU != 0)JYDC_PARAM_REVICHISHU--;
  65. }
  66. if(JYDC_bManXiaChong || JYDC_ManXiaChong_UP)
  67. {
  68. JYDC_bManXiaChong = 0;
  69. if(JYDC_XiaChongStep == 0)//if(!JYDC_bRunning && !STOP_IN && !X_DRV && (JYDC_XiaChongStep == 0))
  70. {
  71. JYDC_XiaChongStep = 1;
  72. }
  73. }
  74. if(JYDC_bManSuoChi)
  75. {
  76. JYDC_bManSuoChi = 0;
  77. JYDC_SuoChi_VAVLE = ~JYDC_SuoChi_VAVLE;
  78. }
  79. if(JYDC_bManChuiQi)
  80. {
  81. JYDC_bManChuiQi = 0;
  82. if(JYDC_cChuiQiStep == 0)JYDC_cChuiQiStep = 1;
  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. //吹气
  270. if(JYDC_XiaChong_IN_DW)
  271. {
  272. if(JYDC_cChuiQiStep == 0)JYDC_cChuiQiStep = 1;
  273. }
  274. switch(JYDC_cChuiQiStep)
  275. {
  276. case 1:
  277. JYDC_cChuiQiStep = 2;
  278. JYDC_ChuiQiDelay = dwTickCount+JYDC_PARAM_DELAY_CHUIQI_TIME;
  279. break;
  280. case 2:
  281. if(dwTickCount >= JYDC_ChuiQiDelay)
  282. {
  283. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME;
  284. JYDC_ChuiQi_VAVLE = 1;//
  285. JYDC_cChuiQiStep = 3;
  286. }
  287. break;
  288. case 3:
  289. if(dwTickCount >= JYDC_ChuiQiDelay)
  290. {
  291. JYDC_ChuiQi_VAVLE = 0;//
  292. JYDC_cChuiQiStep = 0;
  293. }
  294. break;
  295. }
  296. if(JYDC_XiChiChuiQi_VAVLE)
  297. {
  298. if(JYDC_XiChiChuiQiDelay < dwTickCount)JYDC_XiChiChuiQi_VAVLE = 0;
  299. }
  300. }
  301. //下冲动作
  302. void JYDC_XiaChong(void)
  303. {
  304. if(JYDC_XiaChongStep == 1)
  305. {
  306. JYDC_ShaChe_VAVLE = 0;
  307. JYDC_SuoChi_VAVLE = 1; //手动下冲不锁齿
  308. JYDC_XiaChongDelay = dwTickCount + XIACONG_DELAY_TIME*10;
  309. JYDC_XiaChongStep = 2;
  310. }
  311. else if((JYDC_XiaChongStep == 2) && (dwTickCount >= JYDC_XiaChongDelay))
  312. {
  313. JYDC_XiaChong_MOTOR = 1;
  314. JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_XC_ALARM_TIME * 10;
  315. JYDC_XiaChongStep = 3;
  316. }
  317. else if(JYDC_XiaChongStep == 3)
  318. {
  319. if(JYDC_XiaChong_IN_UP)
  320. {
  321. JYDC_XiaChong_MOTOR = 0;
  322. JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_SHACHE_DELAY_TIME * 10;
  323. JYDC_XiaChongStep = 4;
  324. }
  325. else if(dwTickCount >= JYDC_XiaChongDelay)
  326. {
  327. JYDC_SetAlarmCode(JYDC_XIACHONG_ARRIVE_ALARM);
  328. JYDC_XiaChong_MOTOR = 0;
  329. JYDC_ShaChe_VAVLE = 0;
  330. }
  331. }
  332. else if((JYDC_XiaChongStep == 4) && (dwTickCount >= JYDC_XiaChongDelay))
  333. {
  334. JYDC_ShaChe_VAVLE = 1;
  335. JYDC_XiaChongStep = 5;
  336. JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_SHACHE_TIME;
  337. }
  338. else if((JYDC_XiaChongStep == 5) && (dwTickCount >= JYDC_XiaChongDelay))
  339. {
  340. JYDC_ShaChe_VAVLE = 0;
  341. JYDC_XiaChongStep = 6;
  342. }
  343. else if(JYDC_XiaChongStep == 6)
  344. {
  345. if(!JYDC_bRunning)
  346. {
  347. CUR_LEN_JY = 0;
  348. cFirstFlg = 1;
  349. RemainKongWeiToothNum = 0;
  350. }
  351. JYDC_XiaChongStep = 0;
  352. }
  353. }
  354. //启动停止故障停止动作
  355. void JYDC_StartStopAction(void)
  356. {
  357. if((START_IN_UP || JYDC_bStart) && !JYDC_bRunning && (JYDC_AutoStep ==0))
  358. {
  359. if(GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL)JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  360. else
  361. {
  362. JYDC_AutoStep = 1;
  363. JYDC_bRunning = 1;
  364. JYDC_SuoChi_VAVLE = 0;
  365. JYDC_AutoDelay = 0;
  366. cAccSpeed = 6;
  367. }
  368. JYDC_bStart = 0;
  369. }
  370. if(JYDC_KaDai_IN && (GetAlarmCode(100) == 0))
  371. {
  372. JYDC_SetAlarmCode(JYDC_KADAI_ALARM);
  373. }
  374. JYDC_STOP_IN_FLAG_OLD = JYDC_STOP_IN_FLAG;
  375. if(STOP_IN)
  376. {
  377. if(JYDC_STOP_FILTER < 50)
  378. {
  379. JYDC_STOP_FILTER++;
  380. }
  381. else
  382. JYDC_STOP_IN_FLAG = 1;
  383. }
  384. else if(JYDC_STOP_FILTER > 25)
  385. {
  386. JYDC_STOP_FILTER--;
  387. }
  388. else
  389. JYDC_STOP_IN_FLAG = 0;
  390. if((JYDC_STOP_IN_FLAG && !JYDC_STOP_IN_FLAG_OLD)|| JYDC_bStop)
  391. {
  392. JYDC_bStop = 0;
  393. if(JYDC_bRunning && (SingOneFlg == 0))
  394. {
  395. if(JYDC_cChuiQiStep == 0)JYDC_cChuiQiStep = 1;
  396. JYDC_AutoDelay = dwTickCount;
  397. JYDC_bRunning = 0;
  398. JYDC_AutoStep = 0;
  399. JYDC_XiChi_MOTOR = 0;
  400. AxisEgmStop(X_AXIS);
  401. JYDC_SuoChi_VAVLE = 1;
  402. SingOneFlg = 0;
  403. }
  404. else
  405. {
  406. if(JYDC_cChuiQiStep == 0)JYDC_cChuiQiStep = 1;
  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. }
  416. }
  417. if(JYDC_bAlarmStop)
  418. {
  419. JYDC_bAlarmStop = 0;
  420. JYDC_XiaChongStep = 0;
  421. JYDC_XiaChong_MOTOR = 0;
  422. JYDC_ShaChe_VAVLE = 1;
  423. AxisEgmStop(X_AXIS);
  424. JYDC_AutoStep = 0;
  425. if(JYDC_bRunning)JYDC_SuoChi_VAVLE = 1;
  426. JYDC_bRunning = 0;
  427. JYDC_XiaChongDelay = dwTickCount;
  428. JYDC_AutoDelay = dwTickCount;
  429. SingOneFlg = 0;
  430. }
  431. }
  432. unsigned long ToothTransPulse(unsigned long tooth)
  433. {
  434. return(JY_JIZHUN_LEN * tooth * 2000 / 250 / JY_JIZHUN_CISHU);
  435. }
  436. unsigned char CheckSpeedError(unsigned char cspeed)
  437. {
  438. unsigned char buff;
  439. buff = cspeed/cAccSpeed;
  440. if(buff < 5)return 5;
  441. else
  442. return buff;
  443. }
  444. unsigned char CheckMaxLowSpeed(unsigned char cspeed)
  445. {
  446. if(cspeed > JYDC_PARAM_SET_SPEED)
  447. return JYDC_PARAM_SET_SPEED;
  448. else
  449. return cspeed;
  450. }
  451. //自动运行动作
  452. void JYDC_AutoRunStep(void)
  453. {
  454. DISPLAY_DATA0 = JYDC_AutoStep;
  455. DISPLAY_DATA1 = ToothNumBuff;
  456. DISPLAY_DATA2 = JYDC_XiaChongStep;
  457. DISPLAY_DATA3 = GetTotal(JYDC_TOTAL_ADDR);
  458. if(JYDC_bRunning)
  459. {
  460. unsigned short buff;
  461. if(JYDC_AutoStep == 1)
  462. {
  463. if(JYDC_XICHI_MOTOR_MODE)JYDC_XiChi_MOTOR = 1;
  464. else JYDC_XiChi_MOTOR = 0;
  465. if(JYDC_SEBIAO_MODE)
  466. {
  467. JYDC_AutoStep = 20;
  468. JYDC_SuoChi_VAVLE = 0;
  469. dwZipCnt = 0;
  470. }
  471. else
  472. {
  473. if(CUR_LEN_JY >= JYDC_PARAM_REVICHISHU)
  474. {
  475. CUR_LEN_JY = 0;
  476. JYDC_XiaChongStep = 1;
  477. JYDC_AutoStep = 2;
  478. }
  479. else
  480. JYDC_AutoStep = 2;
  481. }
  482. }
  483. else if((JYDC_AutoStep == 2) && (JYDC_XiaChongStep == 0))
  484. {
  485. cFirstFlg = 1;
  486. if(RemainKongWeiToothNum == 0)
  487. {
  488. RemainKongWeiToothNum = SET_KOUWEI_JY;
  489. }
  490. else
  491. {
  492. }
  493. JYDC_AutoStep = 3;
  494. }
  495. else if(JYDC_AutoStep == 3)
  496. {
  497. if(RemainKongWeiToothNum >= SET_DAOKOU_JY)
  498. {
  499. if(cFirstFlg)
  500. {
  501. if(JYDC_PARAM_REVICHISHU <= SET_KOUWEI_JY)
  502. {
  503. ToothNumBuff = JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY;
  504. RemainKongWeiToothNum = 0;
  505. }
  506. else
  507. {
  508. // ToothNumBuff = JYDC_PARAM_REVICHISHU + (RemainKongWeiToothNum-SET_DAOKOU_JY) + SET_DAOKOU_JY;
  509. ToothNumBuff = JYDC_PARAM_REVICHISHU+SET_DAOKOU_JY;
  510. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  511. }
  512. }
  513. else
  514. {
  515. ToothNumBuff = ToothNumBuff + SET_DAOKOU_JY;
  516. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  517. }
  518. }
  519. else
  520. {
  521. if(cFirstFlg)
  522. {
  523. ToothNumBuff = JYDC_PARAM_REVICHISHU - RemainKongWeiToothNum + SET_DAOKOU_JY;
  524. }
  525. else
  526. {
  527. ToothNumBuff = ToothNumBuff + RemainKongWeiToothNum;
  528. }
  529. RemainKongWeiToothNum = 0;
  530. }
  531. JYDC_SuoChi_VAVLE = 0;
  532. // JYDC_AutoDelay = dwTickCount + 50;
  533. JYDC_AutoStep = 4;
  534. }
  535. else if((JYDC_AutoStep == 4) && (dwTickCount >= JYDC_AutoDelay))
  536. {
  537. if((ToothNumBuff) > (JYDC_PARAM_LOW_LENGTH + CUR_LEN_JY))
  538. {
  539. AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  540. AxisChangeSpeed(X_AXIS,CheckSpeedError(JYDC_PARAM_SET_SPEED));
  541. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  542. JYDC_XiChiChuiQi_VAVLE = 1;
  543. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  544. JYDC_AutoStep = 5;
  545. }
  546. else
  547. {
  548. AxisContinueMove(X_AXIS,CheckMaxLowSpeed(JYDC_PARAM_LOW_SPEED),0);
  549. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  550. JYDC_XiChiChuiQi_VAVLE = 1;
  551. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  552. JYDC_AutoStep = 6;
  553. }
  554. /* DISPLAY_DATA6 = ToothTransPulse(ToothNumBuff);
  555. DISPLAY_DATA7 = ToothTransPulse(JYDC_PARAM_LOW_LENGTH);
  556. AxisMoveTwoPos(X_AXIS,JYDC_PARAM_SET_SPEED,ToothTransPulse(ToothNumBuff - JYDC_PARAM_LOW_LENGTH),JYDC_PARAM_LOW_SPEED,ToothTransPulse(JYDC_PARAM_LOW_LENGTH+5),0);
  557. JYDC_AutoStep = 6;
  558. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME;*/
  559. }
  560. else if(JYDC_AutoStep == 5)
  561. {
  562. if(cFirstFlg)
  563. {
  564. if((ToothNumBuff) <= (JYDC_PARAM_LOW_LENGTH + CUR_LEN_JY))
  565. {
  566. AxisChangeSpeed(X_AXIS,CheckMaxLowSpeed(JYDC_PARAM_LOW_SPEED));
  567. cFirstFlg = 0;
  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. else
  580. {
  581. if((ToothNumBuff) <= (JYDC_PARAM_LOW_LENGTH + CUR_LEN_JY))
  582. {
  583. AxisChangeSpeed(X_AXIS,CheckMaxLowSpeed(JYDC_PARAM_LOW_SPEED));
  584. JYDC_AutoStep = 6;
  585. }
  586. else if(dwTickCount >= JYDC_AutoDelay)
  587. {
  588. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  589. }
  590. else
  591. {
  592. if(X_DRV)AxisChangeSpeed(X_AXIS,CheckSpeedError(JYDC_PARAM_SET_SPEED));
  593. }
  594. }
  595. }
  596. else if(JYDC_AutoStep == 6)
  597. {
  598. if(!X_DRV)
  599. {
  600. JYDC_XiaChongStep = 1;
  601. JYDC_AutoStep = 7;
  602. }
  603. else if(dwTickCount >= JYDC_AutoDelay)
  604. {
  605. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  606. }
  607. }
  608. else if(JYDC_AutoStep == 7)
  609. {
  610. if(JYDC_XiaChongStep == 0)
  611. {
  612. if(RemainKongWeiToothNum == 0)
  613. {
  614. JYDC_AutoStep = 8;
  615. JYDC_AutoDelay = dwTickCount;
  616. }
  617. else
  618. {
  619. JYDC_AutoStep = 3;
  620. JYDC_AutoDelay = dwTickCount;
  621. }
  622. }
  623. }
  624. else if((JYDC_AutoStep == 8) && (JYDCRunFlg == 1))
  625. {
  626. AddToTal(JYDC_TOTAL_ADDR);
  627. CUR_LEN_JY = 0;
  628. if((GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL) || JYDC_bStop || SingOneFlg)
  629. {
  630. if(JYDC_bStop || SingOneFlg)
  631. {
  632. JYDC_bStop = 0;
  633. JYDC_AutoStep = 0;
  634. JYDC_bRunning = 0;
  635. SingOneFlg = 0;
  636. JYDC_SuoChi_VAVLE = 1;
  637. JYDC_XiChi_MOTOR = 0;
  638. }
  639. else
  640. {
  641. JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  642. }
  643. }
  644. else
  645. {
  646. JYDC_AutoStep = 1;
  647. JYDC_AutoDelay = JYDC_PARAM_CYCLE_DELAY * 10 + dwTickCount;
  648. CalProSP(JYDC_PROSPEED_ADDR);
  649. }
  650. }
  651. else if((JYDC_AutoStep == 20) && (dwTickCount >= JYDC_AutoDelay)) //色标动作
  652. {
  653. cSeBiaoEn = 1;
  654. if(dwZipCnt == 0)
  655. AxisContinueMove(X_AXIS,CheckMaxLowSpeed(JYDC_PARAM_LOW_SPEED),0);
  656. else
  657. AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  658. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  659. JYDC_XiChiChuiQi_VAVLE = 1;
  660. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  661. JYDC_AutoStep = 21;
  662. }
  663. else if(JYDC_AutoStep == 21)
  664. {
  665. if(!X_DRV)
  666. {
  667. JYDC_AutoStep = 22;
  668. JYDC_AutoDelay = dwTickCount;
  669. }
  670. else if(dwTickCount >= JYDC_AutoDelay)
  671. {
  672. JYDC_SetAlarmCode(JYDC_SEBIAO_ALARM);
  673. }
  674. }
  675. else if(JYDC_AutoStep == 22)
  676. {
  677. if(RemainKongWeiToothNum >= SET_DAOKOU_JY)
  678. {
  679. if(cFirstFlg)
  680. {
  681. if(JYDC_PARAM_REVICHISHU <= SET_KOUWEI_JY)
  682. {
  683. ToothNumBuff = JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY;
  684. RemainKongWeiToothNum = 0;
  685. }
  686. else
  687. {
  688. ToothNumBuff = JYDC_PARAM_REVICHISHU + (RemainKongWeiToothNum-SET_DAOKOU_JY) + SET_DAOKOU_JY;
  689. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  690. }
  691. }
  692. else
  693. {
  694. ToothNumBuff = ToothNumBuff + SET_DAOKOU_JY;
  695. RemainKongWeiToothNum -= SET_DAOKOU_JY;
  696. }
  697. }
  698. else
  699. {
  700. if(cFirstFlg)
  701. {
  702. ToothNumBuff = JYDC_PARAM_REVICHISHU - RemainKongWeiToothNum + SET_DAOKOU_JY;
  703. }
  704. else
  705. {
  706. ToothNumBuff = ToothNumBuff + RemainKongWeiToothNum;
  707. }
  708. RemainKongWeiToothNum = 0;
  709. }
  710. JYDC_AutoStep = 23;
  711. }
  712. else if((JYDC_AutoStep == 23) && (dwTickCount >= JYDC_AutoDelay))
  713. {
  714. if((ToothNumBuff - CUR_LEN_JY) > JYDC_PARAM_LOW_LENGTH)
  715. {
  716. if(!X_DRV)AxisContinueMove(X_AXIS,JYDC_PARAM_SET_SPEED,0);
  717. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  718. JYDC_XiChiChuiQi_VAVLE = 1;
  719. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  720. JYDC_AutoStep = 24;
  721. }
  722. else
  723. {
  724. if(!X_DRV)AxisContinueMove(X_AXIS,CheckMaxLowSpeed(JYDC_PARAM_LOW_SPEED),0);
  725. JYDC_AutoDelay = dwTickCount + NO_TOOTHCOUT_TIME * 10;
  726. JYDC_XiChiChuiQi_VAVLE = 1;
  727. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  728. JYDC_AutoStep = 25;
  729. }
  730. }
  731. else if(JYDC_AutoStep == 24)
  732. {
  733. if(cFirstFlg)
  734. {
  735. if((ToothNumBuff - CUR_LEN_JY) <= (JYDC_PARAM_LOW_LENGTH))
  736. {
  737. AxisChangeSpeed(X_AXIS,CheckMaxLowSpeed(JYDC_PARAM_LOW_SPEED));
  738. cFirstFlg = 0;
  739. JYDC_AutoStep = 25;
  740. }
  741. else if(dwTickCount >= JYDC_AutoDelay)
  742. {
  743. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  744. }
  745. }
  746. else
  747. {
  748. if((ToothNumBuff - CUR_LEN_JY) <= JYDC_PARAM_LOW_LENGTH)
  749. {
  750. AxisChangeSpeed(X_AXIS,CheckMaxLowSpeed(JYDC_PARAM_LOW_SPEED));
  751. JYDC_AutoStep = 25;
  752. }
  753. else if(dwTickCount >= JYDC_AutoDelay)
  754. {
  755. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  756. }
  757. }
  758. }
  759. else if(JYDC_AutoStep == 25)
  760. {
  761. if(!X_DRV)
  762. {
  763. JYDC_XiaChongStep = 1;
  764. JYDC_AutoStep = 26;
  765. }
  766. else if(dwTickCount >= JYDC_AutoDelay)
  767. {
  768. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  769. }
  770. }
  771. else if(JYDC_AutoStep == 26)
  772. {
  773. if(JYDC_XiaChongStep == 0)
  774. {
  775. if(RemainKongWeiToothNum == 0)
  776. {
  777. JYDC_AutoStep = 27;
  778. JYDC_AutoDelay = dwTickCount;
  779. }
  780. else
  781. {
  782. JYDC_AutoStep = 22;
  783. JYDC_AutoDelay = dwTickCount;
  784. }
  785. }
  786. }
  787. else if((JYDC_AutoStep == 27) && (JYDCRunFlg == 1))
  788. {
  789. AddToTal(JYDC_TOTAL_ADDR);
  790. dwZipCnt++;
  791. CUR_LEN_JY = 0;
  792. cSeBiaoStep = 0;
  793. if((GetTotal(JYDC_TOTAL_ADDR) >= SET_TOTAL) || JYDC_bStop || SingOneFlg)
  794. {
  795. if(JYDC_bStop || SingOneFlg)
  796. {
  797. JYDC_bStop = 0;
  798. JYDC_AutoStep = 0;
  799. JYDC_bRunning = 0;
  800. SingOneFlg = 0;
  801. JYDC_SuoChi_VAVLE = 1;
  802. JYDC_XiChi_MOTOR = 0;
  803. }
  804. else
  805. {
  806. JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  807. }
  808. }
  809. else
  810. {
  811. JYDC_AutoStep = 1;
  812. JYDC_AutoDelay = JYDC_PARAM_CYCLE_DELAY * 10 + dwTickCount;
  813. CalProSP(JYDC_PROSPEED_ADDR);
  814. }
  815. }
  816. }
  817. }
  818. #endif