GLHeLian -ZG.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. #include "global.h"
  2. #if CHANG_SHENG_GEI_LI_MACHINE
  3. void HL_InitAction(void);
  4. void HL_Action(void);
  5. void HL_SetAlarmCode(unsigned alarm_code);
  6. void HL_StartStopAction(void);
  7. void HL_AutoRunStep(void);
  8. void HL_Motor(void);
  9. void HL_Step(void);
  10. void HL_PWMAction(void);
  11. unsigned char cDWflg=0,cZCXflg=0,cHLflg=0;
  12. unsigned char cBBflg = 0;
  13. short *offset_length_buff;
  14. static unsigned char OldGuoLian,GuoLian;
  15. static unsigned long guolian_flter;
  16. unsigned char work_flg,work_Num;
  17. unsigned short cCheckStep;
  18. void HL_ConectAction(void)
  19. {
  20. static unsigned long start_delay;
  21. if(HL_PARAM_CONNECT_MODE)
  22. {
  23. if(cCheckStep == 1)
  24. {
  25. if(HL_STOP_IN_DW)
  26. {
  27. start_delay = HL_PARAM_DELAY_START + dwTickCount;
  28. cCheckStep = 2;
  29. }
  30. else if(HL_STOP_IN)
  31. work_flg = 0;
  32. }
  33. else if((cCheckStep == 2) && (dwTickCount >= start_delay))
  34. {
  35. work_flg = 1;
  36. cCheckStep = 3;
  37. }
  38. else if(cCheckStep == 3)
  39. {
  40. if(HL_STOP_IN)
  41. {
  42. work_flg = 0;
  43. cCheckStep = 1;
  44. }
  45. }
  46. }
  47. else
  48. work_flg = 1;
  49. }
  50. void HL_SetAlarmCode(unsigned alarm_code)
  51. {
  52. SetAlarmCode(HL_ALARM_ADDR,alarm_code);
  53. HL_bAlarmStop = 1;
  54. }
  55. void HL_InitAction(void)
  56. {
  57. CalFreqTab_X_Free(14);
  58. // length_buff = 54.1*3.14;//JYDC_CYCLE_LENGTH;
  59. // pulse_buff = 2000;//JYDC_CYCLE_PULSE;
  60. // XGearRatio = 2000pulse_buff/length_buff;
  61. XGearRatio = 1;
  62. }
  63. //手动动作
  64. void HL_ManualAction(void)
  65. {
  66. if(!HL_bRunning)
  67. {
  68. //清产量
  69. if(bClearTotal)
  70. {
  71. bClearTotal = 0;
  72. ClrcToTal(HL_TOTAL_ADDR);
  73. HL_bSetWorkData = 1;
  74. }
  75. //定位数据加
  76. if(HL_bAdd)
  77. {
  78. HL_bAdd = 0;
  79. HL_PARAM_DELAY_STOP += 10;
  80. }
  81. //定位数据减
  82. if(HL_bDec)
  83. {
  84. HL_bDec = 0;
  85. if(HL_PARAM_DELAY_STOP >= 10)
  86. HL_PARAM_DELAY_STOP -= 10;
  87. }
  88. //合模
  89. if(HL_bHM)
  90. {
  91. HL_bHM = 0;
  92. if(HL_HM_VAVLE)
  93. {
  94. HL_HM_VAVLE = 0;
  95. HL_YD_VAVLE = 0;
  96. }
  97. else if((!HL_TFK_VAVLE) || (!HL_BB_VAVLE))
  98. HL_HM_VAVLE = 1;
  99. }
  100. //推方块
  101. if(HL_bTFK)
  102. {
  103. HL_bTFK = 0;
  104. HL_TFK_VAVLE = ~HL_TFK_VAVLE;
  105. }
  106. //摆 臂
  107. if(HL_bBB)
  108. {
  109. HL_bBB = 0;
  110. HL_BB_VAVLE = ~HL_BB_VAVLE;
  111. if(HL_BB_VAVLE)cBBflg = 1;
  112. }
  113. if(cBBflg)
  114. {
  115. if(HL_BB_LIMIT_IN)
  116. {
  117. cBBflg = 0;
  118. }
  119. }
  120. //压插销
  121. if(HL_bYCX)
  122. {
  123. HL_bYCX = 0;
  124. HL_YCX_VAVLE = 1;
  125. HL_YCXDelay = dwTickCount + HL_PARAM_YCX_TIME;
  126. }
  127. //上挡块
  128. if(HL_bDK_UP)
  129. {
  130. HL_bDK_UP = 0;
  131. HL_DK_UP_VAVLE = ~HL_DK_UP_VAVLE;
  132. }
  133. //夹 带
  134. if(HL_bJD)
  135. {
  136. HL_bJD = 0;
  137. HL_JD_VAVLE = ~HL_JD_VAVLE;
  138. }
  139. //穿插销
  140. if(HL_bCCX)
  141. {
  142. HL_bCCX = 0;
  143. HL_CCX_VAVLE = ~HL_CCX_VAVLE;
  144. }
  145. //挡块前后
  146. if(HL_bDK_GO)
  147. {
  148. HL_bDK_GO = 0;
  149. HL_DK_GO_VAVLE = ~HL_DK_GO_VAVLE;
  150. }
  151. //压 带
  152. if(HL_bYD)
  153. {
  154. HL_bYD = 0;
  155. HL_YD_VAVLE = ~HL_YD_VAVLE;
  156. }
  157. //松 紧
  158. if(HL_bSJ)
  159. {
  160. HL_bSJ = 0;
  161. HL_SJ_VAVLE = ~HL_SJ_VAVLE;
  162. }
  163. if(HL_bHMYD)
  164. {
  165. HL_bHMYD = 0;
  166. if(HL_HM_VAVLE)
  167. {
  168. HL_HM_VAVLE = 0;
  169. }
  170. else
  171. {
  172. HL_HM_VAVLE = 1;
  173. }
  174. }
  175. //上挡块
  176. if(HL_bDKUP)
  177. {
  178. HL_bDKUP = 0;
  179. if(HL_DK_UP_VAVLE)
  180. {
  181. HL_DK_UP_VAVLE = 0;
  182. HL_DK_GO_VAVLE = 0;
  183. HL_YD_VAVLE = 0;
  184. }
  185. else
  186. {
  187. if(HL_ManDKStep == 0)HL_ManDKStep=1;
  188. }
  189. }
  190. if(HL_ManDKStep == 1)
  191. {
  192. HL_DK_UP_VAVLE = 1; //挡块上下
  193. HL_ManDKStep = 2;
  194. }
  195. else if((HL_ManDKStep == 2) && HL_DK_UP_LIMIT_IN)
  196. {
  197. HL_ManDKDelay = dwTickCount + HL_PARAM_DELAY_DK_UP;
  198. HL_ManDKStep = 3;
  199. }
  200. else if((HL_ManDKStep == 3) && (dwTickCount >= HL_ManDKDelay))
  201. {
  202. HL_DK_GO_VAVLE = 1; //挡块前后
  203. HL_ManDKStep = 0;
  204. }
  205. if(HL_bCD)
  206. {
  207. HL_bCD = 0;
  208. HL_CD_MOTOR = ~HL_CD_MOTOR;
  209. }
  210. if(HL_bYCD)
  211. {
  212. HL_bYCD = 0;
  213. HL_CD_VAVLE = ~HL_CD_VAVLE;
  214. }
  215. if(HL_bMotor)
  216. {
  217. SetEn(X_AXIS,HL_MOTOR_EN);
  218. if(!X_DRV)AxisContinueMove(X_AXIS,10,HL_DIR_P);
  219. }
  220. else
  221. {
  222. if(X_DRV)AxisDecStop(X_AXIS);
  223. }
  224. }
  225. }
  226. //合链动作
  227. void HL_Action(void)
  228. {
  229. HL_ConectAction();
  230. HL_ManualAction();
  231. HL_StartStopAction();
  232. HL_Motor();
  233. HL_Step();
  234. HL_AutoRunStep();
  235. }
  236. //启动停止故障停止动作
  237. void HL_StartStopAction(void)
  238. {
  239. static unsigned long dwstop_cnt = 0;
  240. if((START_IN_UP || HL_bStart || HL_bSingStart || HL_bDW || HL_bZCX || HL_bHL) && !HL_bRunning && (HL_AutoStep ==0))
  241. {
  242. if(GetTotal(HL_TOTAL_ADDR) >= SET_TOTAL)HL_SetAlarmCode(HL_TOTAL_ALARM);
  243. // else if(HL_SM_LIMIT_IN)HL_SetAlarmCode(HL_SM_LIMIT_ALARM);
  244. // else if(HL_XM_LIMIT_IN)HL_SetAlarmCode(HL_XM_LIMIT_ALARM);
  245. // else if(HL_BB_LIMIT_IN)HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
  246. // else if(HL_DK_LIMIT_IN)HL_SetAlarmCode(HL_DK_LIMIT_ALARM);
  247. // else if(!HL_DK_ORIGIN_IN)HL_SetAlarmCode(HL_DK_ORIGIN_ALARM);
  248. // else if(HL_DK_UP_LIMIT_IN)HL_SetAlarmCode(HL_DK_UP_LIMIT_ALARM);
  249. // else if(HL_CCX_LIMIT_IN)HL_SetAlarmCode(HL_CCX_LIMIT_ALARM);
  250. // else if(!HL_CCX_ORIGIN_IN)HL_SetAlarmCode(HL_CCX_ORIGIN_ALARM);
  251. // else if(HL_TFK_LIMIT_IN)HL_SetAlarmCode(HL_TFK_LIMIT_ALARM);
  252. // else if(!HL_TFK_ORIGIN_IN)HL_SetAlarmCode(HL_TFK_ORIGIN_ALARM);
  253. else
  254. {
  255. SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
  256. HL_bRunning = 1;
  257. cCheckStep = 1;
  258. dwZipCnt = 0;
  259. if(HL_PARAM_CONNECT_MODE)
  260. {
  261. work_Num = 0;
  262. HL_OVEROUt_VAVLE = 1;
  263. HL_Y15Delay = dwTickCount + 100;
  264. }
  265. //单次启动
  266. if(HL_bSingStart)
  267. {
  268. HL_bSingStart = 0;
  269. SingOneFlg = 1;
  270. }
  271. //定位
  272. if(HL_bDW)
  273. {
  274. cDWflg = 1;
  275. dwZipCnt = 1;
  276. }
  277. work_Num = 0;
  278. bCheckOK = 1;
  279. if(HL_bZCX)cZCXflg = 1;//装插销
  280. if(HL_bHL)cHLflg = 1; //合链
  281. work_flg = 1;
  282. if(HL_bZCX)HL_AutoStep = 4;
  283. else if(HL_bHL)HL_AutoStep = 1;
  284. else HL_AutoStep = 1;
  285. }
  286. HL_bDW = 0;
  287. HL_bZCX = 0;
  288. HL_bHL = 0;
  289. HL_bSingStart = 0;
  290. HL_bStart = 0;
  291. }
  292. if(!HL_bMotor && !X_DRV && !HL_bRunning && (HL_MotorStep==0))
  293. SetEn(X_AXIS,HL_MOTOR_DISEN);
  294. if(HL_bStop)
  295. {
  296. HL_bStop = 0;
  297. if(HL_bRunning)
  298. SingOneFlg = 1;
  299. else
  300. {
  301. HL_HM_VAVLE = 0;
  302. HL_TFK_VAVLE = 0;
  303. HL_BB_VAVLE = 0;
  304. HL_DK_UP_VAVLE = 0;
  305. HL_JD_VAVLE = 0;
  306. HL_CCX_VAVLE = 0;
  307. HL_DK_GO_VAVLE = 0;
  308. HL_YD_VAVLE = 0;
  309. HL_SJ_VAVLE = 0;
  310. HL_CD_MOTOR = 0;
  311. HL_ALARM_OUT = 0;
  312. HL_bRunning = 0;
  313. HL_AutoStep = 0;
  314. HL_MotorStep = 0;
  315. SingOneFlg = 0;
  316. HL_bMotor = 0;
  317. cDWflg = 0;
  318. cZCXflg = 0;
  319. cHLflg = 0;
  320. HL_ManDKStep = 0;
  321. HL_CD_VAVLE = 0;
  322. AxisEgmStop(X_AXIS);
  323. SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
  324. }
  325. }
  326. DISPLAY_DATA7 = dwstop_cnt;
  327. if(STOP_IN)dwstop_cnt++;
  328. else dwstop_cnt = 0;
  329. if(dwstop_cnt >= 10000)
  330. {
  331. HL_HM_VAVLE = 0;
  332. HL_BB_VAVLE = 0;
  333. }
  334. if(STOP_IN_UP)
  335. {
  336. HL_bStop = 0;
  337. // if(HL_bRunning)
  338. {
  339. HL_TFK_VAVLE = 0;
  340. // HL_BB_VAVLE = 0;
  341. HL_DK_UP_VAVLE = 0;
  342. HL_JD_VAVLE = 0;
  343. HL_CCX_VAVLE = 0;
  344. HL_DK_GO_VAVLE = 0;
  345. HL_YD_VAVLE = 0;
  346. HL_SJ_VAVLE = 0;
  347. HL_CD_MOTOR = 0;
  348. HL_ALARM_OUT = 0;
  349. HL_bRunning = 0;
  350. HL_AutoStep = 0;
  351. HL_MotorStep = 0;
  352. HL_HLStep = 0;
  353. HL_ManDKStep = 0;
  354. SingOneFlg = 0;
  355. HL_bMotor = 0;
  356. cDWflg = 0;
  357. cZCXflg = 0;
  358. cHLflg = 0;
  359. SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
  360. AxisEgmStop(X_AXIS);
  361. }
  362. /* else
  363. {
  364. HL_HM_VAVLE = 0;
  365. HL_TFK_VAVLE = 0;
  366. HL_BB_VAVLE = 0;
  367. HL_DK_UP_VAVLE = 0;
  368. HL_JD_VAVLE = 0;
  369. HL_CCX_VAVLE = 0;
  370. HL_DK_GO_VAVLE = 0;
  371. HL_YD_VAVLE = 0;
  372. HL_SJ_VAVLE = 0;
  373. HL_CD_MOTOR = 0;
  374. HL_bRunning = 0;
  375. HL_AutoStep = 0;
  376. HL_MotorStep = 0;
  377. HL_HLStep = 0;
  378. SingOneFlg = 0;
  379. cDWflg = 0;
  380. cZCXflg = 0;
  381. cHLflg = 0;
  382. HL_bMotor = 0;
  383. SetAlarmCode(HL_ALARM_ADDR,HL_NO_ALARM);
  384. AxisEgmStop(X_AXIS);
  385. }*/
  386. }
  387. if(HL_bAlarmStop)
  388. {
  389. HL_ALARM_OUT = 1;
  390. HL_bAlarmStop = 0;
  391. AxisEgmStop(X_AXIS);
  392. HL_AutoStep = 0;
  393. HL_ManDKStep = 0;
  394. HL_MotorStep = 0;
  395. HL_HLStep = 0;
  396. HL_bRunning = 0;
  397. SingOneFlg = 0;
  398. cDWflg = 0;
  399. cZCXflg = 0;
  400. cHLflg = 0;
  401. }
  402. }
  403. //合链动作
  404. void HL_Step(void)
  405. {
  406. static long hm_save_buff;
  407. switch(HL_HLStep)
  408. {
  409. case 1:
  410. if(HL_GUO_LIAN_IN_UP)//过链上升沿
  411. {
  412. hm_save_buff = dwRealPos;
  413. HL_HLStep = 2;
  414. }
  415. break;
  416. case 2://上升沿后延迟长度开合模
  417. if((dwRealPos + HL_PARAM_DELAY_HM_BACK) <= hm_save_buff)
  418. {
  419. HL_HM_VAVLE = 0;//开模
  420. HL_HLDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  421. HL_HLStep = 3;
  422. }
  423. else if(!X_DRV)HL_SetAlarmCode(HL_HM_BACK_ALARM);
  424. break;
  425. case 3: //上下模到位离开
  426. if(!HL_SM_LIMIT_IN && !HL_XM_LIMIT_IN)
  427. {
  428. HL_HLStep = 4;
  429. //延时关摆臂
  430. HL_HLDelay = dwTickCount + HL_PARAM_DELAY_BB_BACK;
  431. }
  432. else if(dwTickCount >= HL_HLDelay)
  433. {
  434. if(HL_SM_LIMIT_IN)HL_SetAlarmCode(HL_SM_LIMIT_ALARM);
  435. else HL_SetAlarmCode(HL_XM_LIMIT_ALARM);
  436. }
  437. break;
  438. case 4:
  439. if(dwTickCount >= HL_HLDelay) //开模延时关摆臂
  440. {
  441. HL_HLStep = 5;
  442. HL_BB_VAVLE = 0; //
  443. HL_HLDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  444. }
  445. break;
  446. case 5:
  447. if(!HL_BB_LIMIT_IN) //摆臂到位信号灭
  448. {
  449. HL_HLStep = 0;
  450. if(SingOneFlg) //单一自动
  451. {
  452. SingOneFlg = 0;
  453. HL_AutoStep = 0;
  454. HL_bRunning = 0;
  455. HL_MotorStep = 0;
  456. }
  457. HL_HLDelay = dwTickCount;
  458. }
  459. else if(dwTickCount >= HL_HLDelay)
  460. {
  461. HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
  462. }
  463. break;
  464. }
  465. }
  466. void HL_PWMAction(void)
  467. {
  468. }
  469. //电机动作
  470. void HL_Motor(void) //
  471. {
  472. static long save_buff;
  473. DISPLAY_DATA0 = user_datas[100];
  474. DISPLAY_DATA1 = HL_AutoStep;
  475. DISPLAY_DATA2 = HL_MotorStep;
  476. DISPLAY_DATA3 = HL_HLStep;
  477. //实时位置
  478. dwRealPos = GetPos(X_AXIS);
  479. switch(HL_MotorStep)
  480. {
  481. case 0:break;
  482. case 1:
  483. if(GetEn(X_AXIS) == 0) //未锁轴情况下有锁轴时间
  484. {
  485. SetEn(X_AXIS,HL_MOTOR_EN);
  486. HL_MotorDelay = dwTickCount + 300; //100MSq锁轴时间
  487. }
  488. else
  489. HL_MotorDelay = dwTickCount + 0;
  490. HL_MotorStep = 2;
  491. break;
  492. case 2:
  493. if(dwTickCount >= HL_MotorDelay)
  494. {
  495. HL_MotorDelay = dwTickCount + HL_PARAM_MOTOR_ALARM_TIME;
  496. SetPos(X_AXIS, 0);
  497. if(dwZipCnt >= 2) //2条后测出拉链长度
  498. MoveAction_Const_AccDec(X_AXIS,HL_DIR_P,HL_PARAM_HIGH_SPEED,2,6,1);
  499. else
  500. MoveAction_Const_AccDec(X_AXIS,HL_DIR_P,HL_PARAM_HIGH_SPEED,2,6,1);
  501. HL_MotorStep = 3;
  502. *offset_length_buff = 0;
  503. if(HL_HM_VAVLE) //如果合模有输出启动合链
  504. {
  505. if(HL_HLStep == 0)
  506. HL_HLStep = 1;
  507. }
  508. }
  509. break;
  510. case 3://过链感应下降沿
  511. if(HL_GUO_LIAN_IN)
  512. { //变为低速
  513. AxisChangeSpeed(X_AXIS,HL_PARAM_LOW_SPEED);
  514. //空位延时检测
  515. HL_MotorDelay = dwTickCount + HL_PARAM_DELAY_CHECK_TIME;
  516. HL_MotorStep = 6;
  517. save_buff = dwRealPos; //当位置保存
  518. }
  519. else if(dwTickCount >= HL_MotorDelay)//长时间没信号警告
  520. HL_SetAlarmCode(HL_GUOLIAN_ALARM);
  521. else //联机控制
  522. {
  523. if(HL_PARAM_CONNECT_MODE)
  524. {
  525. if(HL_START_IN)
  526. {
  527. if(dwTickCount >= HL_MotorDelay)
  528. {
  529. if(!X_DRV)
  530. {
  531. HL_MotorStep = 2;
  532. HL_MotorDelay = dwTickCount;
  533. }
  534. }
  535. }
  536. else
  537. {
  538. if(HL_STOP_IN)
  539. {
  540. HL_MotorStep = 50;
  541. AxisEgmStop(X_AXIS);
  542. HL_MotorDelay = dwTickCount + HL_PARAM_DELAY_START;
  543. }
  544. }
  545. }
  546. #if 0 //郑广程序
  547. if(work_flg)
  548. {
  549. if(!X_DRV)
  550. {
  551. HL_MotorStep = 2;
  552. HL_MotorDelay = dwTickCount;
  553. }
  554. }
  555. else if(HL_GUO_LIAN_IN)
  556. {
  557. if(X_DRV)AxisEgmStop(X_AXIS);
  558. }
  559. #endif
  560. }
  561. break;
  562. case 4:
  563. if(dwTickCount >= HL_MotorDelay)
  564. {
  565. HL_MotorStep = 5;
  566. HL_MotorDelay = dwTickCount + HL_PARAM_MOTOR_ALARM_TIME;
  567. }
  568. break;
  569. case 5:
  570. //过链上升沿
  571. if(HL_GUO_LIAN_IN_UP)
  572. {
  573. AxisChangeSpeed(X_AXIS,HL_PARAM_LOW_SPEED);
  574. save_buff = dwRealPos; //当位置保存
  575. HL_MotorStep = 6;
  576. }
  577. else if(dwTickCount >= HL_MotorDelay)//规定时间没到链上警告
  578. HL_SetAlarmCode(HL_GUOLIAN_ALARM);
  579. case 6: // 定位长度
  580. if((dwRealPos + HL_PARAM_DELAY_STOP) <= save_buff)
  581. {
  582. AxisEgmStop(X_AXIS);
  583. HL_MotorStep = 7;
  584. }
  585. break;
  586. case 7://定位和合链完成
  587. if(!X_DRV && (HL_HLStep == 0))
  588. {
  589. HL_MotorStep = 0;
  590. HL_MotorDelay = dwTickCount;
  591. }
  592. break;
  593. case 50:
  594. if(HL_START_IN)
  595. {
  596. if(dwTickCount >= HL_MotorDelay)
  597. {
  598. if(!X_DRV)
  599. {
  600. HL_MotorStep = 2;
  601. HL_MotorDelay = dwTickCount;
  602. }
  603. }
  604. }
  605. else
  606. {
  607. if(HL_STOP_IN)
  608. {
  609. AxisEgmStop(X_AXIS);
  610. }
  611. HL_MotorDelay = dwTickCount + HL_PARAM_DELAY_START;
  612. }
  613. break;
  614. /*
  615. case 20:
  616. // if(!X_DRV)
  617. {
  618. HL_MotorStep = 21;
  619. HL_HM_VAVLE = 0;
  620. HL_MotorDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  621. }
  622. break;
  623. case 21:
  624. if(!HL_SM_LIMIT_IN && !HL_XM_LIMIT_IN)
  625. {
  626. HL_MotorStep = 22;
  627. HL_MotorDelay = dwTickCount + HL_PARAM_DELAY_BB_BACK;
  628. }
  629. else if(dwTickCount >= HL_MotorDelay)
  630. {
  631. if(HL_SM_LIMIT_IN)HL_SetAlarmCode(HL_SM_LIMIT_ALARM);
  632. else HL_SetAlarmCode(HL_XM_LIMIT_ALARM);
  633. }
  634. break;
  635. case 22:
  636. if(dwTickCount >= HL_MotorDelay)
  637. {
  638. if(cHLflg)
  639. HL_MotorStep = 0;
  640. else
  641. HL_MotorStep = 23;
  642. HL_BB_VAVLE = 0;
  643. if(SingOneFlg)
  644. {
  645. SingOneFlg = 0;
  646. HL_MotorStep = 0;
  647. HL_AutoStep = 0;
  648. HL_bRunning = 0;
  649. }
  650. HL_MotorDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  651. }
  652. break;
  653. case 23:
  654. if(!HL_BB_LIMIT_IN)
  655. {
  656. HL_MotorStep = 0;
  657. // if(!X_DRV)AxisMovePosAccDec(X_AXIS,HL_PARAM_LOW_SPEED,HL_PARAM_DELAY_STOP2,1,5,5);
  658. }
  659. else if(dwTickCount >= HL_MotorDelay)
  660. {
  661. HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
  662. }
  663. break;
  664. case 24:
  665. if(!X_DRV)
  666. {
  667. HL_MotorStep = 0;
  668. HL_MotorDelay = dwTickCount;
  669. }
  670. break;
  671. */
  672. }
  673. }
  674. //自动运行动作
  675. void HL_AutoRunStep(void)
  676. {
  677. static unsigned long yd_delay_back;
  678. static unsigned char yd_back_flg = 0;
  679. static unsigned long dk_up_delay;
  680. if((dwTickCount >= HL_YCXDelay) && HL_YCX_VAVLE)HL_YCX_VAVLE = 0;
  681. // if((dwTickCount >= HL_Y14Delay) && Y14)Y14 = 0;
  682. if(dwTickCount >= HL_Y15Delay) //工作完成输出信号延时关
  683. HL_OVEROUt_VAVLE = 0;
  684. if(HL_front_IN_DW)
  685. bCheckOK = 1;
  686. if(HL_bRunning)
  687. {
  688. if(yd_back_flg)
  689. {
  690. if(dwTickCount >= yd_delay_back)
  691. {
  692. yd_back_flg = 0;
  693. HL_YD_VAVLE = 0; //压带
  694. }
  695. }
  696. switch(HL_AutoStep)
  697. {
  698. case 1:
  699. HL_AutoStep = 2;
  700. break;
  701. case 2:
  702. if((dwTickCount >= HL_AutoDelay))
  703. {
  704. if(HL_MotorStep == 0)
  705. {////1为联机模式 //联网信号上 前机态拖带电机输出
  706. // if((!HL_PARAM_CONNECT_MODE))// || (!HL_STOP_IN && HL_front_IN && bCheckOK))//屏蔽部分为和前机有信号联动
  707. {
  708. HL_AutoStep = 3;
  709. HL_MotorStep = 1; //电机启动
  710. bCheckOK = 0;
  711. }
  712. // if((HL_front_IN_DW) && (work_Num == 0))
  713. // {
  714. // / work_Num++;
  715. // HL_OVEROUt_VAVLE = 1;
  716. // HL_Y15Delay = dwTickCount + 100;
  717. // }
  718. HL_CD_VAVLE = 0; //扯带电磁阀
  719. HL_SJ_VAVLE = 0; //松紧气缸
  720. }
  721. }
  722. break;
  723. case 3:
  724. if(HL_MotorStep == 0)
  725. {
  726. if(cDWflg | cHLflg)
  727. {
  728. cDWflg = 0;
  729. cHLflg = 0;
  730. HL_AutoStep = 0;
  731. HL_bRunning = 0;
  732. }
  733. else
  734. {
  735. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_TFK; // 延时推方块
  736. HL_AutoStep = 4;
  737. }
  738. }
  739. break;
  740. #if 0
  741. if((HL_front_IN_DW) && (work_Num == 0))
  742. {
  743. work_Num++;
  744. HL_OVEROUt_VAVLE = 1;
  745. HL_Y15Delay = dwTickCount + 100;
  746. }
  747. #endif
  748. case 4:
  749. if(dwTickCount >= HL_AutoDelay)
  750. {
  751. HL_TFK_VAVLE = 1; //推方块输出
  752. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  753. HL_AutoStep = 5;
  754. }
  755. break;
  756. case 5:
  757. if(HL_TFK_LIMIT_IN) //推方块到位
  758. {
  759. HL_AutoStep = 6;
  760. //延时合模
  761. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_HM;
  762. }
  763. else if(dwTickCount >= HL_AutoDelay)
  764. {
  765. HL_SetAlarmCode(HL_TFK_LIMIT_ALARM);
  766. }
  767. break;
  768. case 6:
  769. if(dwTickCount >= HL_AutoDelay)
  770. {
  771. HL_HM_VAVLE = 1; //Y00 //合模
  772. HL_SJ_VAVLE = 1; //Y10 //松紧气缸
  773. HL_YD_VAVLE = 1; // 压带
  774. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  775. HL_AutoStep = 7;
  776. }
  777. break;
  778. case 7:
  779. //上下模合模到位
  780. if(HL_SM_LIMIT_IN && HL_XM_LIMIT_IN)
  781. {
  782. HL_AutoStep = 8;
  783. //延时关推方块
  784. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_TFK_BACK;
  785. }
  786. else if(dwTickCount >= HL_AutoDelay)
  787. {
  788. if(!HL_SM_LIMIT_IN)
  789. HL_SetAlarmCode(HL_SM_LIMIT_ALARM);
  790. else
  791. HL_SetAlarmCode(HL_XM_LIMIT_ALARM);
  792. }
  793. break;
  794. case 8:
  795. if(dwTickCount >= HL_AutoDelay)
  796. {
  797. HL_AutoStep = 9;
  798. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  799. HL_TFK_VAVLE = 0;
  800. }
  801. break;
  802. case 9:
  803. if(HL_TFK_ORIGIN_IN) //推方块回到原点
  804. {
  805. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_DK_UP;
  806. HL_AutoStep = 10;
  807. }
  808. else if(dwTickCount >= HL_AutoDelay)
  809. HL_SetAlarmCode(HL_TFK_ORIGIN_ALARM);
  810. break;
  811. case 10:
  812. if((dwTickCount >= HL_AutoDelay))
  813. {
  814. HL_DK_UP_VAVLE = 1; //Y03 //挡块上下
  815. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  816. HL_AutoStep = 11;
  817. }
  818. break;
  819. case 11:
  820. if(HL_DK_UP_LIMIT_IN) //挡块上到位
  821. {
  822. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_DK_GO; //延时输出挡块前后
  823. HL_AutoStep = 100;
  824. }
  825. else if(dwTickCount >= HL_AutoDelay)
  826. HL_SetAlarmCode(HL_DK_UP_LIMIT_ALARM);
  827. break;
  828. case 100:
  829. if(dwTickCount >= HL_AutoDelay)
  830. {
  831. HL_DK_GO_VAVLE = 1; ////挡块前后输出
  832. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  833. HL_AutoStep = 12;
  834. }
  835. break;
  836. case 12:
  837. if(HL_DK_LIMIT_IN)//挡块前后输出到位
  838. {
  839. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_BB;
  840. HL_YCX_VAVLE = 1; //压插销电磁阀
  841. // Y14 = 1;
  842. HL_YCXDelay = dwTickCount + HL_PARAM_YCX_TIME;
  843. HL_Y14Delay = dwTickCount + HL_PARAM_DELAY_Y14_BACK;
  844. HL_AutoStep = 13;
  845. }
  846. else if(dwTickCount >= HL_AutoDelay)
  847. HL_SetAlarmCode(HL_DK_LIMIT_ALARM);
  848. break;
  849. case 13:
  850. if(dwTickCount >= HL_AutoDelay)
  851. {
  852. if(HL_PARAM_BB_ENABLE == 0)HL_BB_VAVLE = 1; //摆臂输出
  853. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  854. HL_AutoStep = 14;
  855. }
  856. break;
  857. case 14:
  858. if(HL_PARAM_BB_ENABLE == 0)
  859. {
  860. if(HL_BB_LIMIT_IN)//摆臂到位
  861. {
  862. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
  863. HL_AutoStep = 15;
  864. }
  865. else if(dwTickCount >= HL_AutoDelay)
  866. HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
  867. }
  868. else
  869. {
  870. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_BB;
  871. HL_AutoStep = 15;
  872. }
  873. break;
  874. case 15:
  875. if((HL_AutoStep == 15) && (dwTickCount >= HL_AutoDelay))
  876. {
  877. if(HL_PARAM_CCX_MODE)////穿插销模式 1为电机穿 0为夹带气缸穿
  878. {
  879. if(HL_PARAM_BB_ENABLE) //后输出模式
  880. {
  881. HL_BB_VAVLE = 1;
  882. HL_AutoStep = 180;
  883. HL_AutoDelay = dwTickCount+HL_PARAM_DELAY_CCX;
  884. }
  885. else
  886. {
  887. if(!X_DRV)
  888. AxisMovePosAccDec(X_AXIS,HL_PARAM_CCX_SPEED,HL_PARAM_CCX_LENGTH,1,5,5);
  889. HL_AutoDelay = dwTickCount;
  890. HL_AutoStep = 16;
  891. }
  892. }
  893. else
  894. {
  895. if(HL_PARAM_BB_ENABLE)
  896. HL_BB_VAVLE = 1;
  897. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
  898. HL_JD_VAVLE = 1;
  899. HL_AutoStep = 16;
  900. }
  901. }
  902. break;
  903. case 180:
  904. if((dwTickCount >= HL_AutoDelay))
  905. {
  906. if(!X_DRV)
  907. AxisMovePosAccDec(X_AXIS,HL_PARAM_CCX_SPEED,HL_PARAM_CCX_LENGTH,1,5,5);
  908. HL_AutoDelay = dwTickCount;
  909. HL_AutoStep = 16;
  910. }
  911. break;
  912. case 16:
  913. if((dwTickCount >= HL_AutoDelay) && !HL_YCX_VAVLE)
  914. {
  915. if(HL_PARAM_CCX_MODE)
  916. {
  917. if(!X_DRV)
  918. {
  919. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  920. HL_CheckDelay = dwTickCount + HL_PARAM_DELAY_CHECK_CCX;
  921. HL_AutoStep = 17;
  922. if(HL_PARAM_CD_ENABLE)
  923. HL_JD_VAVLE = 1;
  924. // HL_AutoStep = 71;
  925. }
  926. }
  927. else
  928. {
  929. HL_CCX_VAVLE = 1;
  930. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  931. HL_CheckDelay = dwTickCount + HL_PARAM_DELAY_CHECK_CCX;
  932. HL_AutoStep = 17;
  933. if(HL_PARAM_CD_ENABLE)
  934. HL_JD_VAVLE = 1;
  935. }
  936. }
  937. break;
  938. case 17:
  939. if((dwTickCount >= HL_CheckDelay))
  940. {
  941. if(HL_CCX_LIMIT_IN)
  942. {
  943. if(HL_PARAM_CCX_MODE)
  944. {
  945. HL_DK_UP_VAVLE = 0;
  946. // if(HL_PARAM_CD_ENABLE)
  947. // SetEn(X_AXIS,HL_MOTOR_DISEN);
  948. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  949. HL_AutoStep = 18;
  950. }
  951. else
  952. {
  953. HL_DK_UP_VAVLE = 0;
  954. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD_BACK;
  955. HL_AutoStep = 50;
  956. }
  957. }
  958. else if(dwTickCount >= HL_AutoDelay)
  959. HL_SetAlarmCode(HL_CCX_LIMIT_ALARM);
  960. }
  961. break;
  962. case 50:
  963. if(dwTickCount >= HL_AutoDelay)
  964. {
  965. HL_JD_VAVLE = 0;
  966. HL_AutoDelay = dwTickCount + 0;
  967. HL_AutoStep = 51;
  968. }
  969. break;
  970. case 51:
  971. if(dwTickCount >= HL_AutoDelay)
  972. {
  973. if(!X_DRV)AxisMovePosAccDec(X_AXIS,HL_PARAM_CCX_SPEED,HL_PARAM_CCX_LENGTH,1,5,5);
  974. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  975. HL_AutoStep = 18;
  976. }
  977. break;
  978. case 18:
  979. if(HL_DK_UP_LIMIT_IN && !X_DRV && ((HL_BB_LIMIT_IN && (HL_PARAM_BB_ENABLE == 0)) || (HL_PARAM_BB_ENABLE == 1)))
  980. {
  981. HL_CCX_VAVLE = 0;
  982. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_BACK_DK_UP;
  983. HL_AutoStep = 19;
  984. }
  985. else if(dwTickCount >= HL_AutoDelay)
  986. {
  987. if(!HL_DK_UP_LIMIT_IN)HL_SetAlarmCode(HL_DK_UP_LIMIT_ALARM);
  988. else HL_SetAlarmCode(HL_BB_LIMIT_ALARM);
  989. }
  990. break;
  991. case 19:
  992. if(dwTickCount >= HL_AutoDelay)
  993. {
  994. HL_DK_GO_VAVLE = 0;
  995. if(!HL_PARAM_CCX_TIMES)
  996. {
  997. yd_back_flg = 1;
  998. yd_delay_back = dwTickCount + HL_PARAM_DELAY_YD_BACK;
  999. }
  1000. HL_AutoDelay = dwTickCount + HL_VAVLE_ALARM_TIME;
  1001. HL_AutoStep = 20;
  1002. }
  1003. break;
  1004. case 20:
  1005. if(HL_DK_ORIGIN_IN)
  1006. {
  1007. if(HL_PARAM_CCX_MODE)
  1008. {
  1009. HL_AutoDelay = dwTickCount;
  1010. if(HL_PARAM_CD_ENABLE)
  1011. HL_AutoStep = 21;
  1012. else
  1013. HL_AutoStep = 25;
  1014. }
  1015. else
  1016. {
  1017. if(!HL_PARAM_CCX_TIMES)
  1018. {
  1019. HL_AutoDelay = dwTickCount;
  1020. HL_AutoStep = 25;
  1021. }
  1022. else
  1023. {
  1024. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD;
  1025. HL_AutoStep = 21;
  1026. }
  1027. }
  1028. }
  1029. else if(dwTickCount >= HL_AutoDelay)
  1030. HL_SetAlarmCode(HL_DK_ORIGIN_ALARM);
  1031. case 21:
  1032. if(dwTickCount >= HL_AutoDelay)
  1033. {
  1034. HL_JD_VAVLE = 1;
  1035. if(HL_PARAM_CD_ENABLE)
  1036. {
  1037. HL_AutoStep = 150;
  1038. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CD;
  1039. }
  1040. else
  1041. {
  1042. HL_AutoStep = 22;
  1043. if(!HL_PARAM_CCX_MODE)HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
  1044. }
  1045. }
  1046. break;
  1047. case 150:
  1048. if((dwTickCount >= HL_AutoDelay))
  1049. {
  1050. HL_CD_VAVLE = 1;
  1051. if(!HL_PARAM_CCX_MODE)HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
  1052. HL_AutoStep = 22;
  1053. }
  1054. break;
  1055. case 22:
  1056. if((dwTickCount >= HL_AutoDelay))
  1057. {
  1058. HL_CCX_VAVLE = 1;
  1059. HL_AutoStep = 23;
  1060. }
  1061. break;
  1062. case 23:
  1063. if(dwTickCount >= HL_AutoDelay)
  1064. {
  1065. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD_BACK;
  1066. HL_AutoStep = 24;
  1067. }
  1068. break;
  1069. case 24:
  1070. if(dwTickCount >= HL_AutoDelay)
  1071. {
  1072. HL_JD_VAVLE = 0;
  1073. // HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
  1074. HL_AutoStep = 25;
  1075. }
  1076. break;
  1077. case 25:
  1078. if((dwTickCount >= HL_AutoDelay))
  1079. {
  1080. if(HL_PARAM_BB_ENABLE)HL_BB_VAVLE = 0;
  1081. HL_CCX_VAVLE = 0;
  1082. yd_back_flg = 1;
  1083. yd_delay_back = dwTickCount + HL_PARAM_DELAY_YD_BACK;
  1084. if(cZCXflg)
  1085. {
  1086. cZCXflg = 0;
  1087. HL_AutoStep = 0;
  1088. HL_bRunning = 0;
  1089. }
  1090. else
  1091. {
  1092. HL_AutoStep = 26;
  1093. }
  1094. }
  1095. break;
  1096. case 26:
  1097. if(HL_PARAM_CONNECT_MODE)
  1098. {
  1099. work_Num = 0;
  1100. HL_OVEROUt_VAVLE = 1;
  1101. HL_Y15Delay = dwTickCount + 100;
  1102. }
  1103. AddToTal(HL_TOTAL_ADDR);
  1104. dwZipCnt++;
  1105. if(GetTotal(HL_TOTAL_ADDR) >= HL_PARAM_SET_TOTAL)
  1106. {
  1107. HL_SetAlarmCode(HL_TOTAL_ALARM);
  1108. }
  1109. else
  1110. {
  1111. HL_AutoStep = 2;
  1112. HL_AutoDelay = HL_PARAM_CYCLE_DELAY + dwTickCount;
  1113. CalProSP(HL_PROSPEED_ADDR);
  1114. }
  1115. break;
  1116. case 71:
  1117. if(dwTickCount >= HL_AutoDelay)
  1118. {
  1119. HL_JD_VAVLE = 1;
  1120. HL_DK_GO_VAVLE = 0;
  1121. HL_AutoStep = 72;
  1122. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
  1123. dk_up_delay = dwTickCount +HL_PARAM_DELAY_BACK_DK_UP;
  1124. }
  1125. break;
  1126. case 72:
  1127. if(dwTickCount >= HL_AutoDelay)
  1128. {
  1129. if(dwTickCount >= dk_up_delay)HL_DK_UP_VAVLE = 0;
  1130. HL_CCX_VAVLE = 1;
  1131. HL_AutoStep = 73;
  1132. }
  1133. break;
  1134. case 73:
  1135. if(dwTickCount >= HL_AutoDelay)
  1136. {
  1137. if(dwTickCount >= dk_up_delay)HL_DK_UP_VAVLE = 0;
  1138. if(HL_CCX_LIMIT_IN)
  1139. {
  1140. HL_AutoDelay = dwTickCount;
  1141. HL_AutoStep = 74;
  1142. }
  1143. }
  1144. break;
  1145. case 74:
  1146. if(dwTickCount >= HL_AutoDelay)
  1147. {
  1148. if(dwTickCount >= dk_up_delay)HL_DK_UP_VAVLE = 0;
  1149. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_JD_BACK;
  1150. HL_AutoStep = 75;
  1151. }
  1152. break;
  1153. case 75:
  1154. if(dwTickCount >= HL_AutoDelay)
  1155. {
  1156. HL_JD_VAVLE = 0;
  1157. {
  1158. HL_AutoStep = 76;
  1159. HL_AutoDelay = dwTickCount;
  1160. }
  1161. }
  1162. break;
  1163. case 76:
  1164. if(dwTickCount >= HL_AutoDelay)
  1165. {
  1166. HL_AutoDelay = dwTickCount + HL_PARAM_DELAY_CCX;
  1167. HL_AutoStep = 77;
  1168. }
  1169. break;
  1170. case 77:
  1171. if(dwTickCount >= HL_AutoDelay)
  1172. {
  1173. HL_DK_UP_VAVLE = 0;
  1174. HL_CCX_VAVLE = 0;
  1175. yd_back_flg = 1;
  1176. yd_delay_back = dwTickCount + HL_PARAM_DELAY_YD_BACK;
  1177. if(HL_DK_UP_LIMIT_IN && (HL_DK_ORIGIN_IN))
  1178. {
  1179. if(cZCXflg)
  1180. {
  1181. cZCXflg = 0;
  1182. HL_AutoStep = 0;
  1183. HL_bRunning = 0;
  1184. }
  1185. else
  1186. {
  1187. HL_AutoStep = 26;
  1188. }
  1189. }
  1190. }
  1191. break;
  1192. }
  1193. }
  1194. }
  1195. #endif