YGQueDuanJi.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987
  1. #include "global.h"
  2. #if YOU_GUAN_MACHINE
  3. void QueDuan_AlarmProtect(void);
  4. void QueDuan_ManualAction(void);
  5. void QueDuan_AutoAction(void);
  6. void QueDuan_StepCheckStart(void);
  7. void QueDuan_XiaQue(void);
  8. void QueDuan_Motor(void);
  9. void QueDuan_YuanDianAction(void);
  10. void QueDuan_TuiLianAction(void);
  11. void QueDuan_TuiFangKuai(void);
  12. void QueDuan_ExtiActionX31(void);
  13. void QueDuan_BingLian(void);
  14. static unsigned long cZipCnt = 0,cTableCnt = 0;
  15. static long save_limit_pos,cRealPos;
  16. unsigned char cCheckLianFlg = 0;
  17. unsigned char cCheckLianFlgEN = 0;
  18. unsigned char cGoLimitEn = 0;
  19. void QueDuan_ExtiActionX31(void)
  20. {
  21. cCheckLianFlg = 1;
  22. // user_datas[123]++;
  23. }
  24. void QD_SetAlarmCode(unsigned alarm_code)
  25. {
  26. SetAlarmCode(QD_ALARM_ADDR,alarm_code);
  27. bAlarmStop = 1;
  28. }
  29. void QueDuan_InitAction(void)
  30. {
  31. float length_buff,pulse_buff;
  32. save_limit_pos = QD_SAVE_POS;
  33. axis_x->speed_unit = 500;
  34. SetAccTime(X_AXIS,10);
  35. SetDecTime(X_AXIS,10);
  36. length_buff = QD_PARAM_CYCLE_LENGTH;
  37. pulse_buff = QD_PARAM_CYCLE_PULSE;
  38. XGearRatio = pulse_buff/length_buff;
  39. axis_y->speed_unit = 300;
  40. SetAccTime(Y_AXIS,3);
  41. SetDecTime(Y_AXIS,3);
  42. length_buff = QD_PARAM_TL_CYCLE_LENGTH;
  43. pulse_buff = QD_PARAM_TL_CYCLE_PULSE;
  44. YGearRatio = pulse_buff/length_buff;
  45. QD_SZ_OUT = 1;
  46. }
  47. void QueDuan_Action(void)
  48. {
  49. QueDuan_AlarmProtect();
  50. QueDuan_TuiFangKuai();
  51. QueDuan_Motor();
  52. QueDuan_XiaQue();
  53. QueDuan_ManualAction();
  54. QueDuan_YuanDianAction();
  55. QueDuan_TuiLianAction();
  56. QueDuan_BingLian();
  57. QueDuan_AutoAction();
  58. QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  59. }
  60. //手动动作
  61. void QueDuan_ManualAction(void)
  62. {
  63. if(bRunning == 0)
  64. {
  65. if(QD_bClearTotal) //切断计数清零
  66. {
  67. QD_bClearTotal = 0;
  68. ClrcToTal(QD_TOTAL_ADDR);
  69. }
  70. if(QD_bClearNowTotal)
  71. {
  72. QD_bClearNowTotal = 0;
  73. QD_PARAM_NOW_CNT = 0;
  74. }
  75. if(QD_bXiaQie)
  76. {
  77. QD_bXiaQie = 0;
  78. if(QD_XiaQieStep == 0)QD_XiaQieStep = 1;
  79. }
  80. if(QD_bQianDianDW)
  81. {
  82. QD_bQianDianDW = 0;
  83. if(QD_MotorStep == 0)
  84. {
  85. QD_MotorStep = 61;
  86. cZipCnt = 0;
  87. }
  88. }
  89. if(QD_bTL)
  90. {
  91. if(QD_PARAM_TL_MODE)
  92. {
  93. if(!Y_DRV)AxisMovePos(Y_AXIS,QD_PARAM_TL_SPEED,QD_PARAM_TL_LENGTH);
  94. }
  95. else
  96. {
  97. QD_bTL = 0;
  98. QD_TL_VAVLE = ~QD_TL_VAVLE;
  99. }
  100. }
  101. if(!Y_DRV)QD_bTL = 0;
  102. if(QD_bYD)
  103. {
  104. QD_bYD = 0;
  105. QD_YD_VAVLE = ~QD_YD_VAVLE;
  106. }
  107. if(QD_bGZ)
  108. {
  109. QD_bGZ = 0;
  110. QD_GZ_VAVLE = ~QD_GZ_VAVLE;
  111. }
  112. if(QD_bJD)
  113. {
  114. QD_bJD = 0;
  115. QD_JD_VAVEL = ~QD_JD_VAVEL;
  116. }
  117. if(QD_bXM)
  118. {
  119. QD_bXM = 0;
  120. QD_XM_VAVLE = ~QD_XM_VAVLE;
  121. }
  122. if(QD_bSM)
  123. {
  124. QD_bSM = 0;
  125. QD_SM_VAVLE = ~QD_SM_VAVLE;
  126. }
  127. if(QD_bTFK)
  128. {
  129. QD_bTFK = 0;
  130. QD_TFK_VAVEL = ~QD_TFK_VAVEL;
  131. }
  132. if(QD_bTB)
  133. {
  134. QD_bTB = 0;
  135. QD_TABLE_VAVLE = ~QD_TABLE_VAVLE;
  136. }
  137. if(QD_bYBD)
  138. {
  139. QD_bYBD = 0;
  140. QD_YBD_VAVLE = ~QD_YBD_VAVLE;
  141. }
  142. if(QD_bTestCS)
  143. {
  144. QD_bTestCS = 0;
  145. QD_CS_OUT = 1;
  146. QD_CSDelay = dwTickCount + QD_PARAM_CS_TIME;
  147. }
  148. if(QD_bBL)
  149. {
  150. QD_bBL = 0;
  151. QD_BL_VAVLE = ~QD_BL_VAVLE;
  152. }
  153. if(QD_XiaQieStep == 0)
  154. {
  155. if(dwTickCount >= QD_CSDelay)QD_CS_OUT = 0;
  156. }
  157. if(QD_bYuanDianDW)
  158. {
  159. QD_bYuanDianDW = 0;
  160. if(QD_YuanDianStep == 0)QD_YuanDianStep = 1;
  161. }
  162. //电机控制
  163. if(QD_bGoMotor && !QD_QIAN_LIMIT_IN)
  164. {
  165. QD_SZ_OUT = 0;
  166. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_N;
  167. if(!X_DRV)AxisContinueMove(X_AXIS,20,QD_DIR_N);
  168. }
  169. if(QD_bBackMotor && !QD_BACK_LIMIT_IN)
  170. {
  171. QD_SZ_OUT = 0;
  172. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  173. if(!X_DRV)AxisContinueMove(X_AXIS,20,QD_DIR_P);
  174. }
  175. if(!QD_bGoMotor && !QD_bBackMotor && (QD_MotorStep == 0))
  176. {
  177. if(X_DRV)AxisDecStop(X_AXIS);
  178. }
  179. if(QD_QIAN_LIMIT_IN && (QD_MotorStep == 0) && !QD_bBackMotor &&(QD_AutoStep == 0))
  180. {
  181. if(X_DRV)AxisEgmStop(X_AXIS);
  182. }
  183. }
  184. }
  185. void QueDuan_YuanDianAction(void)
  186. {
  187. switch(QD_YuanDianStep)
  188. {
  189. case 0:break;
  190. case 1:
  191. if(QD_MotorStep == 0)QD_MotorStep = 1;
  192. QD_YuanDianStep = 2;
  193. break;
  194. case 2:
  195. if(QD_MotorStep == 0)
  196. {
  197. QD_MotorStep = 30;
  198. QD_YuanDianStep = 3;
  199. QD_JD_VAVEL = 1;
  200. }
  201. break;
  202. case 3:
  203. if(QD_MotorStep == 0)
  204. {
  205. QD_MotorStep = 0;
  206. QD_YuanDianStep = 0;
  207. }
  208. break;
  209. }
  210. }
  211. void QueDuan_AlarmProtect(void)
  212. {
  213. cRealPos = GetPos(X_AXIS);
  214. if(QD_PARAM_BACK_ALARM_MODE)
  215. { //感应后限模式
  216. if(!bRunning)
  217. {
  218. if(QD_BACK_LIMIT_IN_UP)
  219. {
  220. if((QD_MotorStep == 0) && X_DRV && QD_bBackMotor) //到后限不能再后退但可以点前进
  221. {
  222. QD_bBackMotor = 0;
  223. AxisDecStop(X_AXIS);
  224. QD_JD_VAVEL = 0;
  225. QD_SetAlarmCode(QD_BACK_ALARM);
  226. }
  227. }
  228. }
  229. else
  230. {
  231. if(QD_BACK_LIMIT_IN_UP)
  232. {
  233. AxisDecStop(X_AXIS);
  234. QD_JD_VAVEL = 0;
  235. QD_SetAlarmCode(QD_BACK_ALARM);
  236. }
  237. }
  238. }
  239. else
  240. {
  241. if(QD_QIAN_LIMIT_IN_UP) //数控后限模式
  242. {
  243. save_limit_pos = cRealPos;
  244. SetData32bits(200,save_limit_pos);
  245. }
  246. if(QD_PARAM_MAX_BACK_LENGTH < (cRealPos - save_limit_pos))
  247. {
  248. if(!bRunning)
  249. {
  250. if((QD_MotorStep == 0) && X_DRV && QD_bBackMotor) //到后限不能再后退但可以点前进
  251. {
  252. QD_bBackMotor = 0;
  253. AxisDecStop(X_AXIS);
  254. QD_JD_VAVEL = 0;
  255. QD_SetAlarmCode(QD_BACK_ALARM);
  256. }
  257. }
  258. else
  259. {
  260. AxisDecStop(X_AXIS);
  261. QD_JD_VAVEL = 0;
  262. QD_SetAlarmCode(QD_BACK_ALARM);
  263. }
  264. }
  265. }
  266. // if(!QD_KADAI_IN)QD_KaDaiDelay = dwTickCount + 3000;
  267. /* if(bRunning)
  268. {
  269. if(dwTickCount >= QD_KaDaiDelay)QD_SetAlarmCode(QD_KA_DAI_ALARM);
  270. }*/
  271. }
  272. void QueDuan_AutoAction(void)
  273. {
  274. if(bRunning)
  275. {
  276. if(dwTickCount >= QD_TBDelay)QD_TABLE_VAVLE = 0;
  277. switch(QD_AutoStep)
  278. {
  279. case 1:
  280. if(dwTickCount >= QD_AutoDelay)
  281. {
  282. QD_AutoStep = 2;
  283. if(QD_MotorStep == 0)
  284. {
  285. QD_MotorStep = 61; //前点定位
  286. // else QD_MotorStep = 1;
  287. }
  288. }
  289. break;
  290. case 2:
  291. if(QD_MotorStep == 0)
  292. {
  293. if(QD_PARAM_DC_MODE == 0)
  294. QD_MotorStep = 20; //后退到位
  295. else
  296. QD_MotorStep = 30;
  297. QD_AutoStep = 3;
  298. }
  299. break;
  300. case 3:
  301. if(QD_MotorStep == 0)
  302. {
  303. if(QD_XiaQieStep == 0)QD_XiaQieStep = 1;
  304. QD_AutoStep = 4;
  305. }
  306. break;
  307. case 4:
  308. if(QD_MACHINE_TYPE == QD_QQ_TUIFANGKUAI)
  309. {
  310. if(((QD_XiaQieStep == 0) || (QD_XiaQieStep >= 4)) && !QD_SHANG_MU_LIMIT_IN)
  311. {
  312. if(QD_MotorStep == 0)
  313. {
  314. QD_MotorStep = 40; //切完后退
  315. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  316. }
  317. QD_AutoStep = 5;
  318. }
  319. }
  320. else
  321. {
  322. if((QD_XiaQieStep == 0) && !QD_SHANG_MU_LIMIT_IN)
  323. {
  324. if(QD_MotorStep == 0)
  325. {
  326. QD_MotorStep = 40; //切完后退
  327. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  328. }
  329. QD_AutoStep = 5;
  330. }
  331. }
  332. break;
  333. case 5:
  334. if(QD_MotorStep == 0)
  335. {
  336. cZipCnt++;
  337. QD_PARAM_NOW_CNT++;
  338. cTableCnt++;
  339. AddToTal(QD_TOTAL_ADDR);
  340. CalProSP(QD_PROSPEED_ADDR);
  341. if(cTableCnt >= QD_PARAM_TABLE_NUM)
  342. {
  343. cTableCnt = 0;
  344. QD_TABLE_VAVLE = 1;
  345. QD_TBDelay = dwTickCount + QD_PARAM_TB_TIME;
  346. }
  347. if((GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) || SingOneFlg)
  348. {
  349. bRunning = 0;
  350. QD_AutoStep = 0;
  351. SingOneFlg = 0;
  352. if(GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) QD_SetAlarmCode(QD_TOTAL_ALARM);
  353. }
  354. else
  355. {
  356. QD_AutoStep = 1;
  357. if(QD_PARAM_NOW_CNT >= QD_PARAM_ZHA_SHU)
  358. {
  359. QD_AutoDelay = dwTickCount + QD_PARAM_ZS_STOP_TIME + 50;
  360. QD_PARAM_NOW_CNT = 0;
  361. }
  362. else
  363. QD_AutoDelay = dwTickCount + QD_PARAM_CYCLE_DELAY;
  364. }
  365. }
  366. break;
  367. }
  368. }
  369. }
  370. void QueDuan_StepCheckStart(void)
  371. {
  372. // 启动
  373. if((START_IN_UP) || bStart || QD_bSingle)
  374. {
  375. bStart = 0;
  376. if(!bRunning && (QD_AutoStep == 0))
  377. {
  378. if(!QD_SHANG_MU_ORIGIN_IN)QD_SetAlarmCode(QD_SM_YUANWEI);
  379. else if(GetAlarmCode(QD_ALARM_ADDR) != 0);
  380. else if(GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) QD_SetAlarmCode(QD_TOTAL_ALARM);
  381. else if(QD_BL_VAVLE)QD_SetAlarmCode(QD_BL_ALARM);
  382. else if(QD_SM_VAVLE)QD_SetAlarmCode(QD_SM_ALARM);
  383. else
  384. {
  385. bRunning = 1;
  386. QD_AutoStep = 1;
  387. if(QD_bSingle) SingOneFlg= 1;
  388. cZipCnt = 0;
  389. if(QD_PARAM_TL_MODE)
  390. {
  391. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  392. }
  393. }
  394. }
  395. QD_bSingle = 0;
  396. }
  397. //停止
  398. if(STOP_IN_UP || bStop)
  399. {
  400. bStop = 0;
  401. /* if(bRunning)
  402. {
  403. if(SingOneFlg)
  404. {
  405. bRunning = 0;
  406. QD_XiaQieStep = 0;
  407. QD_AutoStep = 0;
  408. QD_MotorStep = 0;
  409. QD_TuiLianStep = 0;
  410. QD_TuiFangKuaiStep = 0;
  411. QD_YuanDianStep = 0;
  412. QD_BinLianStep = 0;
  413. SingOneFlg = 0;
  414. QD_JD_VAVEL = 0;
  415. QD_SM_VAVLE = 0;
  416. QD_XM_VAVLE = 0;
  417. QD_YD_VAVLE = 0;
  418. QD_XHG_VAVLE = 0;
  419. // QD_CS_OUT = 0;
  420. QD_TL_VAVLE = 0;
  421. QD_SZ_OUT = 1;
  422. QD_GZ_VAVLE = 0;
  423. QD_YBD_VAVLE = 0;
  424. QD_TFK_VAVEL = 0;
  425. QD_TABLE_VAVLE = 0;
  426. QD_BL_VAVLE = 0;
  427. QD_AutoDelay = dwTickCount;
  428. QD_MotorDelay = dwTickCount;
  429. QD_XiaQieDelay = dwTickCount;
  430. QD_KaDaiDelay = dwTickCount;
  431. QD_CSDelay = dwTickCount;
  432. QD_TBDelay = dwTickCount;
  433. QD_TFKDelay = dwTickCount;
  434. QD_TLDelay = dwTickCount;
  435. QD_CheckDelay = dwTickCount;
  436. AxisDecStop(X_AXIS);
  437. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  438. }
  439. else
  440. {
  441. SingOneFlg = 1;
  442. }
  443. }
  444. else
  445. {
  446. bRunning = 0;
  447. QD_XiaQieStep = 0;
  448. QD_AutoStep = 0;
  449. QD_MotorStep = 0;
  450. QD_TuiLianStep = 0;
  451. QD_TuiFangKuaiStep = 0;
  452. QD_YuanDianStep = 0;
  453. QD_AutoDelay = dwTickCount;
  454. QD_MotorDelay = dwTickCount;
  455. QD_XiaQieDelay = dwTickCount;
  456. QD_KaDaiDelay = dwTickCount;
  457. QD_CSDelay = dwTickCount;
  458. QD_TBDelay = dwTickCount;
  459. QD_TFKDelay = dwTickCount;
  460. QD_TLDelay = dwTickCount;
  461. QD_CheckDelay = dwTickCount;
  462. SingOneFlg = 0;
  463. QD_JD_VAVEL = 0;
  464. QD_SM_VAVLE = 0;
  465. QD_XM_VAVLE = 0;
  466. QD_YD_VAVLE = 0;
  467. QD_TFK_VAVEL= 0;
  468. QD_TL_VAVLE = 0;
  469. QD_YBD_VAVLE = 0;
  470. //QD_CS_OUT = 0;
  471. QD_XiaQieStep = 0;
  472. QD_MotorStep = 0;
  473. QD_TuiLianStep = 0;
  474. QD_TuiFangKuaiStep = 0;
  475. QD_SZ_OUT = 1;
  476. QD_GZ_VAVLE = 0;
  477. QD_TABLE_VAVLE = 0;
  478. QD_XHG_VAVLE = 0;
  479. AxisDecStop(X_AXIS);
  480. QD_YuanDianStep = 0;
  481. QD_BinLianStep = 0;
  482. QD_BL_VAVLE = 0;
  483. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  484. }*/
  485. if(bRunning)
  486. {
  487. bRunning = 0;
  488. QD_XiaQieStep = 0;
  489. QD_AutoStep = 0;
  490. QD_MotorStep = 0;
  491. QD_TuiLianStep = 0;
  492. QD_TuiFangKuaiStep = 0;
  493. QD_YuanDianStep = 0;
  494. QD_AutoDelay = dwTickCount;
  495. QD_MotorDelay = dwTickCount;
  496. QD_XiaQieDelay = dwTickCount;
  497. QD_KaDaiDelay = dwTickCount;
  498. QD_CSDelay = dwTickCount;
  499. QD_TBDelay = dwTickCount;
  500. QD_TFKDelay = dwTickCount;
  501. QD_TLDelay = dwTickCount;
  502. QD_CheckDelay = dwTickCount;
  503. dwTickCount = QD_TBDelay;
  504. SingOneFlg = 0;
  505. QD_JD_VAVEL = 0;
  506. QD_SM_VAVLE = 0;
  507. QD_XM_VAVLE = 0;
  508. QD_YD_VAVLE = 0;
  509. QD_TFK_VAVEL= 0;
  510. QD_TL_VAVLE = 0;
  511. QD_YBD_VAVLE = 0;
  512. QD_CS_OUT = 0;
  513. QD_XiaQieStep = 0;
  514. QD_MotorStep = 0;
  515. QD_TuiLianStep = 0;
  516. QD_TuiFangKuaiStep = 0;
  517. //QD_SZ_OUT = 1;
  518. QD_GZ_VAVLE = 0;
  519. QD_TABLE_VAVLE = 0;
  520. QD_XHG_VAVLE = 0;
  521. AxisDecStop(X_AXIS);
  522. QD_YuanDianStep = 0;
  523. QD_BinLianStep = 0;
  524. QD_BL_VAVLE = 0;
  525. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  526. }
  527. else
  528. {
  529. bRunning = 0;
  530. QD_XiaQieStep = 0;
  531. QD_AutoStep = 0;
  532. QD_MotorStep = 0;
  533. QD_TuiLianStep = 0;
  534. QD_TuiFangKuaiStep = 0;
  535. QD_YuanDianStep = 0;
  536. QD_AutoDelay = dwTickCount;
  537. QD_MotorDelay = dwTickCount;
  538. QD_XiaQieDelay = dwTickCount;
  539. QD_KaDaiDelay = dwTickCount;
  540. QD_CSDelay = dwTickCount;
  541. QD_TBDelay = dwTickCount;
  542. QD_TFKDelay = dwTickCount;
  543. QD_TLDelay = dwTickCount;
  544. QD_CheckDelay = dwTickCount;
  545. dwTickCount = QD_TBDelay;
  546. SingOneFlg = 0;
  547. QD_JD_VAVEL = 0;
  548. QD_SM_VAVLE = 0;
  549. QD_XM_VAVLE = 0;
  550. QD_YD_VAVLE = 0;
  551. QD_TFK_VAVEL= 0;
  552. QD_TL_VAVLE = 0;
  553. QD_YBD_VAVLE = 0;
  554. QD_CS_OUT = 0;
  555. QD_XiaQieStep = 0;
  556. QD_MotorStep = 0;
  557. QD_TuiLianStep = 0;
  558. QD_TuiFangKuaiStep = 0;
  559. QD_SZ_OUT = 1;
  560. QD_GZ_VAVLE = 0;
  561. QD_TABLE_VAVLE = 0;
  562. QD_XHG_VAVLE = 0;
  563. AxisDecStop(X_AXIS);
  564. QD_YuanDianStep = 0;
  565. QD_BinLianStep = 0;
  566. QD_BL_VAVLE = 0;
  567. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  568. }
  569. }
  570. if(bAlarmStop)
  571. {
  572. bAlarmStop = 0;
  573. QD_XiaQieStep = 0;
  574. QD_AutoStep = 0;
  575. QD_MotorStep = 0;
  576. QD_TuiLianStep = 0;
  577. QD_TuiFangKuaiStep = 0;
  578. QD_YuanDianStep = 0;
  579. QD_XiaQieStep = 0;
  580. QD_MotorStep = 0;
  581. QD_TuiLianStep = 0;
  582. QD_TuiFangKuaiStep = 0;
  583. QD_AutoDelay = dwTickCount;
  584. QD_MotorDelay = dwTickCount;
  585. QD_XiaQieDelay = dwTickCount;
  586. QD_KaDaiDelay = dwTickCount;
  587. QD_CSDelay = dwTickCount;
  588. QD_TBDelay = dwTickCount;
  589. QD_TFKDelay = dwTickCount;
  590. QD_TLDelay = dwTickCount;
  591. QD_CheckDelay = dwTickCount;
  592. SingOneFlg = 0;
  593. bRunning = 0;
  594. AxisDecStop(X_AXIS);
  595. dwTickCount = QD_TBDelay;
  596. QD_TABLE_VAVLE = 0;
  597. }
  598. }
  599. void QueDuan_Motor_CS(void)
  600. {
  601. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff;
  602. user_datas[124]= QD_MotorStep;
  603. user_datas[125]= go_length_buff;
  604. user_datas[123] = length_buff;
  605. user_datas[127] = cRealPos;
  606. user_datas[126] = go_buff - cRealPos;
  607. user_datas[121] = QD_BinLianStep;
  608. switch(QD_MotorStep)
  609. {
  610. case 0:
  611. break;
  612. case 1: // 前点定位数控模式
  613. if(QD_SZ_OUT)
  614. {
  615. QD_SZ_OUT = 0;
  616. QD_MotorDelay = dwTickCount + 50;
  617. }
  618. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  619. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE && !QD_PARAM_TL_MODE)QD_TuiLianStep = 1;
  620. QD_MotorStep = 2;
  621. break;
  622. case 2:
  623. if(dwTickCount >= QD_MotorDelay)
  624. {
  625. if(QD_QIAN_LIMIT_IN)
  626. {
  627. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  628. AxisMovePos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_ON_BACK_LENGTH);
  629. QD_MotorDelay = dwTickCount + 1000;
  630. }
  631. QD_MotorStep = 3;
  632. QD_JD_VAVEL = 0;
  633. }
  634. break;
  635. case 3:
  636. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  637. {
  638. if(cZipCnt == 0)
  639. {
  640. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  641. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P); //第一条走低速
  642. }
  643. else
  644. {
  645. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  646. AxisMoveTwoPos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,(length_buff - QD_PARAM_Go_LOW_SPEED_LENGTH + QD_PARAM_BACK_LENGTH +QD_PARAM_SJZ_LENGTH),QD_PARAM_GO_LOW_SPEED,0xFFFFFF,QD_DIR_P);//第二条开始走两段速
  647. }
  648. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  649. QD_MotorStep = 4;
  650. }
  651. break;
  652. case 4:
  653. if(QD_QIAN_LIMIT_IN_UP)
  654. {
  655. AxisEgmStop(X_AXIS);
  656. QD_MotorStep = 5;
  657. }
  658. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  659. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  660. break;
  661. case 5:
  662. if(!X_DRV)
  663. {
  664. QD_MotorDelay = dwTickCount;
  665. QD_MotorStep = 6;
  666. }
  667. break;
  668. case 6:
  669. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0))
  670. {
  671. if(bRunning)
  672. {
  673. QD_JD_VAVEL = 1;
  674. }
  675. QD_MotorStep = 7;
  676. QD_MotorDelay = dwTickCount + 100;
  677. }
  678. break;
  679. case 7:
  680. if(dwTickCount >= QD_MotorDelay)
  681. {
  682. QD_YBD_VAVLE = 0;
  683. QD_TL_VAVLE = 0;
  684. QD_MotorStep = 0;
  685. }
  686. break;
  687. case 20:// 后退使用电机定长
  688. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  689. QD_MotorStep = 21;
  690. break;
  691. case 21:
  692. if(dwTickCount >= QD_MotorDelay)
  693. {
  694. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  695. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-QD_PARAM_ZIPPER_LENGTH);
  696. QD_MotorStep = 22;
  697. }
  698. break;
  699. case 22:
  700. if(!X_DRV)
  701. {
  702. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_FZ;
  703. QD_MotorStep = 23;
  704. }
  705. break;
  706. case 23:
  707. if(dwTickCount >= QD_MotorDelay)
  708. {
  709. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  710. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  711. QD_MotorStep = 24;
  712. }
  713. break;
  714. case 24:
  715. if(!X_DRV)
  716. {
  717. QD_MotorStep = 0;
  718. QD_MotorDelay = dwTickCount;
  719. }
  720. break;
  721. case 30:
  722. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  723. QD_MotorStep = 31;
  724. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  725. break;
  726. case 31: // 后退使用钩针定长
  727. if(dwTickCount >= QD_MotorDelay)
  728. {
  729. save_buff = cRealPos;
  730. back_buff = cRealPos;
  731. if(QD_PARAM_DEC_MODE == 0)
  732. {
  733. AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_P);
  734. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  735. QD_MotorStep = 32;
  736. }
  737. else
  738. {
  739. if(cZipCnt < 2)
  740. {
  741. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P);
  742. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  743. QD_MotorStep = 32;
  744. }
  745. else
  746. {
  747. gouzhen_buff = cRealPos;
  748. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-length_buff);
  749. MoveChangSpeedPos(X_AXIS, QD_PARAM_GO_LOW_SPEED,PosToPulse(X_AXIS,QD_PARAM_Back_LOW_SPEED_LENGTH));
  750. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  751. QD_MotorStep = 33;
  752. }
  753. }
  754. }
  755. break;
  756. case 32:
  757. if(QD_PARAM_BACK_MODE)
  758. {
  759. if(cZipCnt < 2)
  760. {
  761. if(QD_GUO_LIAN_IN_UP)
  762. {
  763. cCheckLianFlg = 0;
  764. checkdelay_buff = cRealPos;
  765. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  766. QD_MotorStep = 33;
  767. dwTickCount = QD_MotorDelay;
  768. }
  769. else if(dwTickCount >= QD_MotorDelay)
  770. {
  771. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  772. }
  773. }
  774. else
  775. {
  776. QD_MotorStep = 36;
  777. }
  778. }
  779. else
  780. {
  781. if(QD_GUO_LIAN_IN_UP)
  782. {
  783. cCheckLianFlg = 0;
  784. checkdelay_buff = cRealPos;
  785. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  786. QD_MotorStep = 33;
  787. }
  788. else if(dwTickCount >= QD_MotorDelay)
  789. {
  790. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  791. }
  792. }
  793. break;
  794. case 33:
  795. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  796. {
  797. if(dwTickCount >= QD_MotorDelay)
  798. {
  799. QD_MotorStep = 34;
  800. }
  801. }
  802. else
  803. {
  804. if((cRealPos - back_buff) > (length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH))
  805. {
  806. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  807. QD_MotorStep = 34;
  808. }
  809. }
  810. break;
  811. case 34:
  812. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  813. {
  814. if((cRealPos - checkdelay_buff) >= QD_PARAM_DELAY_CHECK)
  815. {
  816. cCheckLianFlgEN = 1;
  817. if(cCheckLianFlg)
  818. {
  819. cCheckLianFlg = 0;
  820. gou_zhen_buff = cRealPos;
  821. QD_MotorStep = 35;
  822. }
  823. }
  824. }
  825. else
  826. {
  827. if((cRealPos - gouzhen_buff) >= (length_buff - QD_PARAM_GOUZHEN_LENGTH))
  828. {
  829. QD_MotorStep = 36;
  830. }
  831. }
  832. break;
  833. case 35:
  834. if(cCheckLianFlg)
  835. {
  836. cCheckLianFlg = 0;
  837. gou_zhen_buff = cRealPos;
  838. }
  839. if(QD_GUO_LIAN_IN_DW)
  840. {
  841. gou_zhen_buff = cRealPos;
  842. }
  843. if(QD_GUO_LIAN_IN_UP)
  844. {
  845. gou_zhen_buff = cRealPos;
  846. }
  847. if((cRealPos - gou_zhen_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  848. {
  849. AxisEgmStop(X_AXIS);
  850. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  851. QD_MotorStep = 36;
  852. }
  853. break;
  854. case 36:
  855. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  856. {
  857. cCheckLianFlgEN = 0;
  858. if(QD_PARAM_DEC_MODE == 0)QD_GZ_VAVLE = 1;
  859. QD_YD_VAVLE = 1;
  860. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  861. QD_MotorStep = 37;
  862. }
  863. break;
  864. case 37:
  865. if(dwTickCount >= QD_MotorDelay)
  866. {
  867. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  868. QD_MotorStep = 38;
  869. }
  870. break;
  871. case 38:
  872. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  873. {
  874. if(cZipCnt == 1)
  875. {
  876. length_buff = cRealPos - save_buff - QD_PARAM_OFFSET_LENGTH;
  877. }
  878. if(cZipCnt == 0)
  879. {
  880. go_length_buff = cRealPos - save_buff;
  881. }
  882. QD_MotorStep = 0;
  883. }
  884. else if(dwTickCount >= QD_MotorDelay)
  885. {
  886. QD_SetAlarmCode(QD_GZ_ALARM);
  887. }
  888. break;
  889. case 40:
  890. if(dwTickCount >= QD_MotorDelay)
  891. {
  892. // 切断完成后拉电机动作
  893. if(QD_PARAM_SJZ_LENGTH == 0)
  894. {
  895. QD_MotorDelay = dwTickCount + 50;
  896. QD_JD_VAVEL = 0;
  897. }
  898. else if(QD_PARAM_SJZ_LENGTH <= 100)
  899. {
  900. QD_MotorDelay = dwTickCount + 40;
  901. QD_JD_VAVEL = 0;
  902. }
  903. else if(QD_PARAM_SJZ_LENGTH <= 200)
  904. {
  905. QD_MotorDelay = dwTickCount + 30;
  906. QD_JD_VAVEL = 0;
  907. }
  908. else if(QD_PARAM_SJZ_LENGTH <= 300)
  909. {
  910. QD_MotorDelay = dwTickCount + 20;
  911. QD_JD_VAVEL = 0;
  912. }
  913. else if(QD_PARAM_SJZ_LENGTH <= 400)
  914. {
  915. QD_MotorDelay = dwTickCount + 10;
  916. QD_JD_VAVEL = 0;
  917. }
  918. else if(QD_PARAM_SJZ_LENGTH <= 500)
  919. {
  920. QD_MotorDelay = dwTickCount + 5;
  921. QD_JD_VAVEL = 0;
  922. }
  923. else
  924. {
  925. QD_MotorDelay = dwTickCount;
  926. }
  927. QD_MotorStep = 41;
  928. }
  929. break;
  930. case 41:
  931. if(dwTickCount >= QD_MotorDelay)
  932. {
  933. save_buff = cRealPos;
  934. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  935. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH));
  936. QD_MotorStep = 42;
  937. }
  938. break;
  939. case 42: // 切断完成后拉电机动作
  940. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - save_buff)))
  941. {
  942. QD_JD_VAVEL = 0;
  943. QD_MotorStep = 43;
  944. }
  945. else if(!X_DRV)
  946. {
  947. QD_JD_VAVEL = 0;
  948. QD_MotorStep = 43;
  949. }
  950. break;
  951. case 43: // 切断完成后拉电机动作
  952. if(!X_DRV)
  953. {
  954. QD_MotorStep = 0;
  955. QD_MotorDelay = dwTickCount;
  956. }
  957. break;
  958. case 61: // 前点定位数控模式
  959. if(QD_SZ_OUT)
  960. {
  961. QD_SZ_OUT = 0;
  962. QD_MotorDelay = dwTickCount + 50;
  963. }
  964. if(QD_PARAM_TL_MODE)
  965. {
  966. }
  967. else
  968. {
  969. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE)QD_TuiLianStep = 1;
  970. }
  971. QD_MotorStep = 62;
  972. break;
  973. case 62:
  974. if(dwTickCount >= QD_MotorDelay)
  975. {
  976. if(QD_QIAN_LIMIT_IN)
  977. {
  978. AxisMovePos(X_AXIS,QD_PARAM_FIRST_SPEED,-QD_PARAM_ON_BACK_LENGTH);
  979. QD_MotorDelay = dwTickCount + 1000;
  980. }
  981. QD_MotorStep = 63;
  982. QD_JD_VAVEL = 0;
  983. }
  984. break;
  985. case 63:
  986. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  987. {
  988. go_buff = cRealPos;
  989. if(cZipCnt > 0)
  990. {
  991. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED);//
  992. }
  993. else
  994. {
  995. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED);
  996. }
  997. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  998. QD_MotorStep = 64;
  999. }
  1000. break;
  1001. case 64:
  1002. if(QD_PARAM_GO_MODE)
  1003. {
  1004. if(cZipCnt > 0)
  1005. {
  1006. if((go_buff - cRealPos) > (go_length_buff - QD_PARAM_Go_LOW_SPEED_LENGTH + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH))
  1007. {
  1008. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1009. QD_MotorStep =65;
  1010. }
  1011. }
  1012. else
  1013. {
  1014. QD_MotorStep =65;
  1015. }
  1016. }
  1017. else
  1018. {
  1019. QD_MotorStep =65;
  1020. }
  1021. break;
  1022. case 65:
  1023. if(QD_QIAN_LIMIT_IN_UP)
  1024. {
  1025. if(QD_PARAM_DAO_MODE)
  1026. {
  1027. dandao_buff = cRealPos;
  1028. QD_MotorStep = 70;
  1029. }
  1030. else
  1031. {
  1032. AxisEgmStop(X_AXIS);
  1033. QD_MotorStep = 66;
  1034. }
  1035. }
  1036. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1037. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1038. break;
  1039. case 70:
  1040. if((dandao_buff - cRealPos) >= QD_PARAM_DANDAO_MODE_LENGTH)
  1041. {
  1042. AxisEgmStop(X_AXIS);
  1043. QD_MotorStep = 66;
  1044. }
  1045. break;
  1046. case 66:
  1047. if(!X_DRV)
  1048. {
  1049. QD_MotorDelay = dwTickCount;
  1050. QD_MotorStep = 67;
  1051. }
  1052. break;
  1053. case 67:
  1054. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1055. {
  1056. if(bRunning)
  1057. {
  1058. QD_JD_VAVEL = 1;
  1059. }
  1060. QD_MotorStep = 68;
  1061. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1062. }
  1063. break;
  1064. case 68:
  1065. if(dwTickCount >= QD_MotorDelay)
  1066. {
  1067. QD_YD_VAVLE = 0;
  1068. QD_MotorStep = 0;
  1069. }
  1070. break;
  1071. }
  1072. }
  1073. //推方块动作
  1074. void QueDuan_TuiFangKuai(void)
  1075. {
  1076. }
  1077. void QueDuan_BingLian(void)
  1078. {
  1079. static long bl_pos_buff;
  1080. switch(QD_BinLianStep)
  1081. {
  1082. case 0:break;
  1083. case 1:
  1084. bl_pos_buff = cRealPos;
  1085. QD_BinLianStep = 2;
  1086. break;
  1087. case 2:
  1088. if((cRealPos - bl_pos_buff) >= QD_PARAM_DELAY_HL_LENGTH)
  1089. {
  1090. QD_BL_VAVLE = 1;
  1091. QD_BinLianStep = 3;
  1092. }
  1093. break;
  1094. case 3:
  1095. if(QD_SM_VAVLE)QD_BL_VAVLE = 0;
  1096. break;
  1097. default:;
  1098. }
  1099. }
  1100. void QueDuan_Motor_QD(void)
  1101. {
  1102. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff;
  1103. user_datas[124]= QD_MotorStep;
  1104. user_datas[125]= go_length_buff;
  1105. user_datas[123] = length_buff;
  1106. user_datas[127] = cRealPos;
  1107. user_datas[126] = go_buff - cRealPos;
  1108. user_datas[121] = QD_BinLianStep;
  1109. switch(QD_MotorStep)
  1110. {
  1111. case 0:
  1112. break;
  1113. case 1: // 前点定位数控模式
  1114. if(QD_SZ_OUT)
  1115. {
  1116. QD_SZ_OUT = 0;
  1117. QD_MotorDelay = dwTickCount + 50;
  1118. }
  1119. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1120. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE && !QD_PARAM_TL_MODE)QD_TuiLianStep = 1;
  1121. QD_MotorStep = 2;
  1122. break;
  1123. case 2:
  1124. if(dwTickCount >= QD_MotorDelay)
  1125. {
  1126. if(QD_QIAN_LIMIT_IN)
  1127. {
  1128. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  1129. AxisMovePos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_ON_BACK_LENGTH);
  1130. QD_MotorDelay = dwTickCount + 1000;
  1131. }
  1132. QD_MotorStep = 3;
  1133. QD_JD_VAVEL = 0;
  1134. }
  1135. break;
  1136. case 3:
  1137. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  1138. {
  1139. if(cZipCnt == 0)
  1140. {
  1141. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1142. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P); //第一条走低速
  1143. }
  1144. else
  1145. {
  1146. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1147. AxisMoveTwoPos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,(length_buff - QD_PARAM_Go_LOW_SPEED_LENGTH + QD_PARAM_BACK_LENGTH +QD_PARAM_SJZ_LENGTH),QD_PARAM_GO_LOW_SPEED,0xFFFFFF,QD_DIR_P);//第二条开始走两段速
  1148. }
  1149. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1150. QD_MotorStep = 4;
  1151. }
  1152. break;
  1153. case 4:
  1154. if(QD_QIAN_LIMIT_IN_UP)
  1155. {
  1156. AxisEgmStop(X_AXIS);
  1157. QD_MotorStep = 5;
  1158. }
  1159. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1160. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1161. break;
  1162. case 5:
  1163. if(!X_DRV)
  1164. {
  1165. QD_MotorDelay = dwTickCount;
  1166. QD_MotorStep = 6;
  1167. }
  1168. break;
  1169. case 6:
  1170. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0))
  1171. {
  1172. if(bRunning)
  1173. {
  1174. QD_JD_VAVEL = 1;
  1175. }
  1176. QD_MotorStep = 7;
  1177. QD_MotorDelay = dwTickCount + 100;
  1178. }
  1179. break;
  1180. case 7:
  1181. if(dwTickCount >= QD_MotorDelay)
  1182. {
  1183. QD_YBD_VAVLE = 0;
  1184. QD_TL_VAVLE = 0;
  1185. QD_MotorStep = 0;
  1186. }
  1187. break;
  1188. case 20:// 后退使用电机定长
  1189. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1190. QD_MotorStep = 21;
  1191. break;
  1192. case 21:
  1193. if(dwTickCount >= QD_MotorDelay)
  1194. {
  1195. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1196. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-QD_PARAM_ZIPPER_LENGTH);
  1197. QD_MotorStep = 22;
  1198. }
  1199. break;
  1200. case 22:
  1201. if(!X_DRV)
  1202. {
  1203. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_FZ;
  1204. QD_MotorStep = 23;
  1205. }
  1206. break;
  1207. case 23:
  1208. if(dwTickCount >= QD_MotorDelay)
  1209. {
  1210. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  1211. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1212. QD_MotorStep = 24;
  1213. }
  1214. break;
  1215. case 24:
  1216. if(!X_DRV)
  1217. {
  1218. QD_MotorStep = 0;
  1219. QD_MotorDelay = dwTickCount;
  1220. }
  1221. break;
  1222. case 30:
  1223. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1224. QD_MotorStep = 31;
  1225. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  1226. break;
  1227. case 31: // 后退使用钩针定长
  1228. if(dwTickCount >= QD_MotorDelay)
  1229. {
  1230. save_buff = cRealPos;
  1231. back_buff = cRealPos;
  1232. SetAccTime(X_AXIS,5);
  1233. SetDecTime(X_AXIS,5);
  1234. if(QD_PARAM_DEC_MODE == 0)
  1235. {
  1236. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1237. AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_P);
  1238. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1239. QD_MotorStep = 32;
  1240. }
  1241. else
  1242. {
  1243. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1244. if(cZipCnt < 2)
  1245. {
  1246. QD_XHG_VAVLE = 0;
  1247. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P);
  1248. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1249. QD_MotorStep = 32;
  1250. }
  1251. else
  1252. {
  1253. gouzhen_buff = cRealPos;
  1254. QD_XHG_VAVLE = 1;
  1255. //AxisMoveTwoPos(X_AXIS,QD_PARAM_BACK_SPEED,(length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH),QD_PARAM_GO_LOW_SPEED,QD_PARAM_Back_LOW_SPEED_LENGTH,QD_DIR_N);
  1256. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-length_buff);
  1257. MoveChangSpeedPos(X_AXIS, QD_PARAM_GO_LOW_SPEED,PosToPulse(X_AXIS,QD_PARAM_Back_LOW_SPEED_LENGTH));
  1258. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1259. QD_MotorStep = 33;
  1260. }
  1261. // AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_N);
  1262. }
  1263. }
  1264. break;
  1265. case 32:
  1266. if(QD_PARAM_BACK_MODE)
  1267. {
  1268. if(cZipCnt < 2)
  1269. {
  1270. if(QD_GUO_LIAN_IN_UP)
  1271. {
  1272. cCheckLianFlg = 0;
  1273. checkdelay_buff = cRealPos;
  1274. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1275. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1276. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1277. QD_MotorDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1278. // QD_CheckDelay = dwTickCount + QD_PARAM_DELAY_CHECK;
  1279. QD_MotorStep = 33;
  1280. }
  1281. else if(dwTickCount >= QD_MotorDelay)
  1282. {
  1283. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1284. }
  1285. }
  1286. else
  1287. {
  1288. /* if((cRealPos - back_buff) > (length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH))
  1289. {
  1290. // if(X_DRV)MoveChangSpeedPos(X_AXIS, QD_PARAM_GO_LOW_SPEED,PosToPulse(X_AXIS,QD_PARAM_Back_LOW_SPEED_LENGTH));
  1291. }*/
  1292. QD_MotorStep = 36;
  1293. }
  1294. }
  1295. else
  1296. {
  1297. if(QD_GUO_LIAN_IN_UP)
  1298. {
  1299. cCheckLianFlg = 0;
  1300. checkdelay_buff = cRealPos;
  1301. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1302. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1303. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1304. QD_MotorDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1305. // QD_CheckDelay = dwTickCount + QD_PARAM_DELAY_CHECK;
  1306. QD_MotorStep = 33;
  1307. }
  1308. else if(dwTickCount >= QD_MotorDelay)
  1309. {
  1310. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1311. }
  1312. }
  1313. break;
  1314. case 33:
  1315. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  1316. {
  1317. if(dwTickCount >= QD_MotorDelay)
  1318. {
  1319. QD_GZ_VAVLE = 1;
  1320. QD_MotorStep = 34;
  1321. }
  1322. }
  1323. else
  1324. {
  1325. if((cRealPos - back_buff) > (length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH))
  1326. {
  1327. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1328. QD_MotorStep = 34;
  1329. }
  1330. }
  1331. break;
  1332. case 34:
  1333. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  1334. {
  1335. if((cRealPos - checkdelay_buff) >= QD_PARAM_DELAY_CHECK)
  1336. {
  1337. //user_datas[125]= cRealPos - checkdelay_buff;
  1338. cCheckLianFlgEN = 1;
  1339. if(cCheckLianFlg)//(!QD_GUO_LIAN_IN)
  1340. {
  1341. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1342. cCheckLianFlg = 0;
  1343. gou_zhen_buff = cRealPos;
  1344. QD_MotorStep = 35;
  1345. }
  1346. }
  1347. }
  1348. else
  1349. {
  1350. if((cRealPos - gouzhen_buff) >= (length_buff - QD_PARAM_GOUZHEN_LENGTH))
  1351. {
  1352. QD_GZ_VAVLE = 1;
  1353. QD_MotorStep = 36;
  1354. }
  1355. }
  1356. break;
  1357. case 35:
  1358. if(cCheckLianFlg)
  1359. {
  1360. cCheckLianFlg = 0;
  1361. gou_zhen_buff = cRealPos;
  1362. }
  1363. if(QD_GUO_LIAN_IN_DW)
  1364. {
  1365. gou_zhen_buff = cRealPos;
  1366. }
  1367. if(QD_GUO_LIAN_IN_UP)
  1368. {
  1369. gou_zhen_buff = cRealPos;
  1370. }
  1371. if((cRealPos - gou_zhen_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  1372. {
  1373. AxisEgmStop(X_AXIS);
  1374. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1375. QD_MotorStep = 36;
  1376. }
  1377. break;
  1378. case 36:
  1379. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  1380. {
  1381. cCheckLianFlgEN = 0;
  1382. if(QD_PARAM_DEC_MODE == 0)QD_GZ_VAVLE = 1;
  1383. if(!QD_PARAM_TL_MODE)QD_YBD_VAVLE = 1;
  1384. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  1385. QD_MotorStep = 37;
  1386. }
  1387. break;
  1388. case 37:
  1389. if(dwTickCount >= QD_MotorDelay)
  1390. {
  1391. QD_TFK_VAVEL = 1;
  1392. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1393. QD_MotorStep = 38;
  1394. }
  1395. break;
  1396. case 38:
  1397. if(QD_GOUZHEN_IN && !X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  1398. {
  1399. if(QD_PARAM_TL_MODE)QD_YBD_VAVLE = 1;
  1400. if(cZipCnt == 1)
  1401. {
  1402. length_buff = cRealPos - save_buff - QD_PARAM_OFFSET_LENGTH;
  1403. }
  1404. if(cZipCnt == 0)
  1405. {
  1406. go_length_buff = cRealPos - save_buff;
  1407. }
  1408. QD_MotorStep = 0;
  1409. }
  1410. else if(dwTickCount >= QD_MotorDelay)
  1411. {
  1412. QD_SetAlarmCode(QD_GZ_ALARM);
  1413. }
  1414. break;
  1415. case 40:
  1416. if(dwTickCount >= QD_MotorDelay)
  1417. {
  1418. // 切断完成后拉电机动作
  1419. if(QD_PARAM_SJZ_LENGTH == 0)
  1420. {
  1421. QD_MotorDelay = dwTickCount + 50;
  1422. QD_JD_VAVEL = 0;
  1423. }
  1424. else if(QD_PARAM_SJZ_LENGTH <= 100)
  1425. {
  1426. QD_MotorDelay = dwTickCount + 40;
  1427. QD_JD_VAVEL = 0;
  1428. }
  1429. else if(QD_PARAM_SJZ_LENGTH <= 200)
  1430. {
  1431. QD_MotorDelay = dwTickCount + 30;
  1432. QD_JD_VAVEL = 0;
  1433. }
  1434. else if(QD_PARAM_SJZ_LENGTH <= 300)
  1435. {
  1436. QD_MotorDelay = dwTickCount + 20;
  1437. QD_JD_VAVEL = 0;
  1438. }
  1439. else if(QD_PARAM_SJZ_LENGTH <= 400)
  1440. {
  1441. QD_MotorDelay = dwTickCount + 10;
  1442. QD_JD_VAVEL = 0;
  1443. }
  1444. else if(QD_PARAM_SJZ_LENGTH <= 500)
  1445. {
  1446. QD_MotorDelay = dwTickCount + 5;
  1447. QD_JD_VAVEL = 0;
  1448. }
  1449. else
  1450. {
  1451. QD_MotorDelay = dwTickCount;
  1452. }
  1453. QD_MotorStep = 41;
  1454. }
  1455. break;
  1456. case 41:
  1457. if(dwTickCount >= QD_MotorDelay)
  1458. {
  1459. save_buff = cRealPos;
  1460. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1461. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH));
  1462. QD_MotorStep = 42;
  1463. }
  1464. break;
  1465. case 42: // 切断完成后拉电机动作
  1466. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - save_buff)))
  1467. {
  1468. QD_JD_VAVEL = 0;
  1469. QD_MotorStep = 43;
  1470. }
  1471. else if(!X_DRV)
  1472. {
  1473. QD_JD_VAVEL = 0;
  1474. QD_MotorStep = 43;
  1475. }
  1476. break;
  1477. case 43: // 切断完成后拉电机动作
  1478. if(!X_DRV)
  1479. {
  1480. QD_MotorStep = 0;
  1481. QD_MotorDelay = dwTickCount;
  1482. }
  1483. break;
  1484. case 61: // 前点定位数控模式
  1485. if(QD_SZ_OUT)
  1486. {
  1487. QD_SZ_OUT = 0;
  1488. QD_MotorDelay = dwTickCount + 50;
  1489. }
  1490. if(QD_PARAM_TL_MODE)
  1491. {
  1492. // if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  1493. }
  1494. else
  1495. {
  1496. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE)QD_TuiLianStep = 1;
  1497. }
  1498. // cGoLimitEn = 1;
  1499. SetAccTime(X_AXIS,10);
  1500. SetDecTime(X_AXIS,10);
  1501. QD_MotorStep = 62;
  1502. break;
  1503. case 62:
  1504. if(dwTickCount >= QD_MotorDelay)
  1505. {
  1506. if(QD_QIAN_LIMIT_IN)
  1507. {
  1508. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1509. AxisMovePos(X_AXIS,QD_PARAM_FIRST_SPEED,-QD_PARAM_ON_BACK_LENGTH);
  1510. QD_MotorDelay = dwTickCount + 1000;
  1511. }
  1512. QD_MotorStep = 63;
  1513. QD_JD_VAVEL = 0;
  1514. }
  1515. break;
  1516. case 63:
  1517. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  1518. {
  1519. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_N;
  1520. go_buff = cRealPos;
  1521. if(cZipCnt > 0)
  1522. {
  1523. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED);//
  1524. }
  1525. else
  1526. {
  1527. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED);
  1528. }
  1529. // MoveAction_Const_Stop(X_AXIS, QD_DIR_P,QD_PARAM_GO_HIGH_SPEED);//
  1530. // AxisContinueMove(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_DIR_P); //第一条走低速
  1531. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1532. QD_MotorStep =64;
  1533. }
  1534. break;
  1535. case 64:
  1536. if(QD_PARAM_GO_MODE)
  1537. {
  1538. if(cZipCnt > 0)
  1539. {
  1540. if((go_buff - cRealPos) > (go_length_buff - QD_PARAM_Go_LOW_SPEED_LENGTH + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH))
  1541. {
  1542. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1543. QD_MotorStep =65;
  1544. }
  1545. }
  1546. else
  1547. {
  1548. // if(QD_QIAN_DEC_IN)
  1549. {
  1550. // if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);//AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1551. QD_MotorStep =65;
  1552. }
  1553. }
  1554. }
  1555. else
  1556. {
  1557. // if(QD_QIAN_DEC_IN)
  1558. {
  1559. // if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);//AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1560. QD_MotorStep =65;
  1561. }
  1562. }
  1563. break;
  1564. case 65:
  1565. if(QD_QIAN_LIMIT_IN_UP)
  1566. {
  1567. if(QD_PARAM_DAO_MODE)
  1568. {
  1569. dandao_buff = cRealPos;
  1570. QD_MotorStep = 70;
  1571. }
  1572. else
  1573. {
  1574. AxisEgmStop(X_AXIS);
  1575. QD_MotorStep = 66;
  1576. }
  1577. }
  1578. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1579. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1580. break;
  1581. case 70:
  1582. if((dandao_buff - cRealPos) >= QD_PARAM_DANDAO_MODE_LENGTH)
  1583. {
  1584. AxisEgmStop(X_AXIS);
  1585. QD_MotorStep = 66;
  1586. }
  1587. break;
  1588. case 66:
  1589. if(!X_DRV)
  1590. {
  1591. QD_MotorDelay = dwTickCount;
  1592. QD_MotorStep = 67;
  1593. }
  1594. break;
  1595. case 67:
  1596. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1597. {
  1598. if(bRunning)
  1599. {
  1600. QD_JD_VAVEL = 1;
  1601. }
  1602. QD_MotorStep = 68;
  1603. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1604. }
  1605. break;
  1606. case 68:
  1607. if(dwTickCount >= QD_MotorDelay)
  1608. {
  1609. QD_YBD_VAVLE = 0;
  1610. QD_TL_VAVLE = 0;
  1611. QD_MotorStep = 0;
  1612. }
  1613. break;
  1614. }
  1615. }
  1616. //电机动作
  1617. void QueDuan_Motor(void) //
  1618. {
  1619. switch(QD_MACHINE_TYPE)
  1620. {
  1621. case QD_CS_TUIFANGKUAI: QueDuan_Motor_CS();break;
  1622. case QD_QQ_TUIFANGKUAI: QueDuan_Motor_QD();break;
  1623. default:;
  1624. }
  1625. }
  1626. //超声方式下切
  1627. void QueDuan_XiaQue_CS(void)
  1628. {
  1629. switch(QD_XiaQieStep)
  1630. {
  1631. case 0:
  1632. break;
  1633. case 1:
  1634. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1635. QD_XiaQieStep = 2;
  1636. break;
  1637. case 2:
  1638. if(dwTickCount >= QD_XiaQieDelay)
  1639. {
  1640. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1641. QD_XM_VAVLE = 1;
  1642. QD_XiaQieStep = 3;
  1643. }
  1644. break;
  1645. case 3:
  1646. if(QD_XIA_MU_LIMIT_IN)
  1647. {
  1648. QD_XiaQieDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1649. QD_XiaQieStep = 4;
  1650. }
  1651. else if(dwTickCount >= QD_XiaQieDelay)
  1652. {
  1653. QD_SetAlarmCode(QD_XM_DAOWEI);
  1654. }
  1655. break;
  1656. case 4:
  1657. if(dwTickCount >= QD_XiaQieDelay)
  1658. {
  1659. QD_GZ_VAVLE = 1;
  1660. QD_XiaQieDelay = dwTickCount + QD_PARAM_TFK_DELAY; //
  1661. QD_XiaQieStep = 5;
  1662. }
  1663. break;
  1664. case 5:
  1665. if(dwTickCount >= QD_XiaQieDelay)
  1666. {
  1667. QD_TFK_VAVEL = 1;
  1668. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1669. QD_XiaQieStep = 6;
  1670. }
  1671. break;
  1672. case 6:
  1673. if(QD_GOUZHEN_IN)
  1674. {
  1675. QD_SM_VAVLE = 1;
  1676. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1677. QD_XiaQieStep = 7;
  1678. }
  1679. else if(dwTickCount >= QD_XiaQieDelay)
  1680. {
  1681. QD_SetAlarmCode(QD_GZ_ALARM);
  1682. }
  1683. break;
  1684. case 7:
  1685. if(QD_SHANG_MU_LIMIT_IN && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1686. {
  1687. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  1688. QD_XiaQieStep = 8;
  1689. }
  1690. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  1691. break;
  1692. case 8:
  1693. if(dwTickCount >= QD_XiaQieDelay)
  1694. {
  1695. if(QD_PARAM_CS_ENABLE)QD_CS_OUT = 1;
  1696. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  1697. QD_XiaQieStep = 9;
  1698. }
  1699. break;
  1700. case 9:
  1701. if(dwTickCount >= QD_XiaQieDelay)
  1702. {
  1703. QD_CS_OUT = 0;
  1704. QD_SM_VAVLE = 0;
  1705. QD_XM_VAVLE = 0;
  1706. QD_TFK_VAVEL = 0;
  1707. QD_GZ_VAVLE = 0;
  1708. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1709. QD_XiaQieStep = 10;
  1710. }
  1711. break;
  1712. case 10:
  1713. if(QD_SHANG_MU_ORIGIN_IN && !QD_XIA_MU_LIMIT_IN)
  1714. {
  1715. QD_XiaQieStep = 0;
  1716. }
  1717. else if(dwTickCount >= QD_XiaQieDelay)
  1718. {
  1719. QD_SetAlarmCode(QD_SM_YUANWEI);
  1720. }
  1721. break;
  1722. }
  1723. }
  1724. void QueDuan_TuiLianAction(void)
  1725. {
  1726. switch(QD_TuiLianStep)
  1727. {
  1728. case 0:
  1729. break;
  1730. case 1:
  1731. QD_TuiLianStep = 2;
  1732. break;
  1733. case 2:
  1734. QD_YBD_VAVLE = 1;
  1735. QD_TLDelay = dwTickCount + QD_PARAM_YD_DELAY;
  1736. QD_TuiLianStep = 3;
  1737. break;
  1738. case 3:
  1739. if(dwTickCount >= QD_TLDelay)
  1740. {
  1741. if(QD_PARAM_TL_MODE)
  1742. {
  1743. QD_TuiLianStep = 10;
  1744. }
  1745. else
  1746. {
  1747. QD_TL_VAVLE = 1;
  1748. QD_TLDelay = dwTickCount + QD_PARAM_TL_DELAY;
  1749. QD_TuiLianStep = 4;
  1750. }
  1751. }
  1752. break;
  1753. case 4:
  1754. if(dwTickCount >= QD_TLDelay)
  1755. {
  1756. // QD_TL_VAVLE = 0;
  1757. QD_TuiLianStep = 0;
  1758. }
  1759. break;
  1760. case 10:
  1761. if(bRunning && QD_PARAM_TL_MODE)AxisMovePos(Y_AXIS,QD_PARAM_TL_SPEED,QD_PARAM_TL_LENGTH);
  1762. QD_TuiLianStep = 11;
  1763. break;
  1764. case 11:
  1765. if(!Y_DRV)
  1766. {
  1767. {
  1768. QD_TuiLianStep = 0;
  1769. }
  1770. }
  1771. break;
  1772. }
  1773. }
  1774. //气动推方块方式下切
  1775. void QueDuan_XiaQue_QD(void)
  1776. {
  1777. switch(QD_XiaQieStep)
  1778. {
  1779. case 0:
  1780. break;
  1781. case 1:
  1782. if(!bRunning)
  1783. {
  1784. QD_XiaQieDelay = dwTickCount + 50;
  1785. QD_GZ_VAVLE = 1;
  1786. QD_XiaQieStep = 20;
  1787. }
  1788. else
  1789. {
  1790. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1791. QD_XiaQieStep = 2;
  1792. }
  1793. break;
  1794. case 20:
  1795. if(dwTickCount >= QD_XiaQieDelay)
  1796. {
  1797. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1798. QD_TFK_VAVEL = 1;
  1799. QD_XiaQieStep = 2;
  1800. }
  1801. break;
  1802. case 2:
  1803. if(dwTickCount >= QD_XiaQieDelay)
  1804. {
  1805. QD_SM_VAVLE = 1;
  1806. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1807. QD_XiaQieStep = 3;
  1808. }
  1809. break;
  1810. case 3:
  1811. if(QD_SHANG_MU_LIMIT_IN && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1812. {
  1813. QD_XiaQieStep = 4;
  1814. QD_XiaQieDelay = dwTickCount + 100;
  1815. }
  1816. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  1817. break;
  1818. case 4:
  1819. if(dwTickCount >= QD_XiaQieDelay)
  1820. {
  1821. QD_SM_VAVLE = 0;
  1822. QD_TFK_VAVEL = 0;
  1823. QD_GZ_VAVLE = 0;
  1824. if(!QD_PARAM_TL_MODE)
  1825. {
  1826. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  1827. }
  1828. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1829. QD_XiaQieStep = 5;
  1830. }
  1831. break;
  1832. case 5:
  1833. if(QD_SHANG_MU_ORIGIN_IN && (QD_TuiLianStep == 0))
  1834. {
  1835. if(QD_PARAM_TL_MODE)
  1836. {
  1837. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  1838. }
  1839. QD_XiaQieStep = 0;
  1840. QD_XiaQieDelay = dwTickCount + QD_PARAM_TL_DELAY;
  1841. }
  1842. else if(dwTickCount >= QD_XiaQieDelay)
  1843. {
  1844. QD_SetAlarmCode(QD_SM_YUANWEI);
  1845. }
  1846. break;
  1847. }
  1848. }
  1849. //切断动作
  1850. void QueDuan_XiaQue(void)
  1851. {
  1852. switch(QD_MACHINE_TYPE)
  1853. {
  1854. case QD_CS_TUIFANGKUAI:QueDuan_XiaQue_CS();break;
  1855. case QD_QQ_TUIFANGKUAI:QueDuan_XiaQue_QD();break;
  1856. default:;
  1857. }
  1858. }
  1859. #endif