GLJiaoYaDinCun_ZG.c 26 KB

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