YGJiaoYaDinCun.c 25 KB

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