HYQueDuanJi.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  1. #include "global.h"
  2. #if HONG_YE_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_BL_VAVLE = 1;
  861. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  862. QD_MotorStep = 37;
  863. }
  864. break;
  865. case 37:
  866. if(dwTickCount >= QD_MotorDelay)
  867. {
  868. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  869. QD_MotorStep = 38;
  870. }
  871. break;
  872. case 38:
  873. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  874. {
  875. if(cZipCnt == 1)
  876. {
  877. length_buff = cRealPos - save_buff - QD_PARAM_OFFSET_LENGTH;
  878. }
  879. if(cZipCnt == 0)
  880. {
  881. go_length_buff = cRealPos - save_buff;
  882. }
  883. QD_MotorStep = 0;
  884. }
  885. else if(dwTickCount >= QD_MotorDelay)
  886. {
  887. QD_SetAlarmCode(QD_GZ_ALARM);
  888. }
  889. break;
  890. case 40:
  891. if(dwTickCount >= QD_MotorDelay)
  892. {
  893. // 切断完成后拉电机动作
  894. if(QD_PARAM_SJZ_LENGTH == 0)
  895. {
  896. QD_MotorDelay = dwTickCount + 50;
  897. QD_JD_VAVEL = 0;
  898. }
  899. else if(QD_PARAM_SJZ_LENGTH <= 100)
  900. {
  901. QD_MotorDelay = dwTickCount + 40;
  902. QD_JD_VAVEL = 0;
  903. }
  904. else if(QD_PARAM_SJZ_LENGTH <= 200)
  905. {
  906. QD_MotorDelay = dwTickCount + 30;
  907. QD_JD_VAVEL = 0;
  908. }
  909. else if(QD_PARAM_SJZ_LENGTH <= 300)
  910. {
  911. QD_MotorDelay = dwTickCount + 20;
  912. QD_JD_VAVEL = 0;
  913. }
  914. else if(QD_PARAM_SJZ_LENGTH <= 400)
  915. {
  916. QD_MotorDelay = dwTickCount + 10;
  917. QD_JD_VAVEL = 0;
  918. }
  919. else if(QD_PARAM_SJZ_LENGTH <= 500)
  920. {
  921. QD_MotorDelay = dwTickCount + 5;
  922. QD_JD_VAVEL = 0;
  923. }
  924. else
  925. {
  926. QD_MotorDelay = dwTickCount;
  927. }
  928. QD_MotorStep = 41;
  929. }
  930. break;
  931. case 41:
  932. if(dwTickCount >= QD_MotorDelay)
  933. {
  934. save_buff = cRealPos;
  935. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  936. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH));
  937. QD_MotorStep = 42;
  938. }
  939. break;
  940. case 42: // 切断完成后拉电机动作
  941. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - save_buff)))
  942. {
  943. QD_JD_VAVEL = 0;
  944. QD_MotorStep = 43;
  945. }
  946. else if(!X_DRV)
  947. {
  948. QD_JD_VAVEL = 0;
  949. QD_MotorStep = 43;
  950. }
  951. break;
  952. case 43: // 切断完成后拉电机动作
  953. if(!X_DRV)
  954. {
  955. QD_MotorStep = 0;
  956. QD_MotorDelay = dwTickCount;
  957. }
  958. break;
  959. case 61: // 前点定位数控模式
  960. if(QD_SZ_OUT)
  961. {
  962. QD_SZ_OUT = 0;
  963. QD_MotorDelay = dwTickCount + 50;
  964. }
  965. if(QD_PARAM_TL_MODE)
  966. {
  967. }
  968. else
  969. {
  970. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE)QD_TuiLianStep = 1;
  971. }
  972. QD_MotorStep = 62;
  973. break;
  974. case 62:
  975. if(dwTickCount >= QD_MotorDelay)
  976. {
  977. if(QD_QIAN_LIMIT_IN)
  978. {
  979. AxisMovePos(X_AXIS,QD_PARAM_FIRST_SPEED,-QD_PARAM_ON_BACK_LENGTH);
  980. QD_MotorDelay = dwTickCount + 1000;
  981. }
  982. QD_MotorStep = 63;
  983. QD_JD_VAVEL = 0;
  984. }
  985. break;
  986. case 63:
  987. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  988. {
  989. go_buff = cRealPos;
  990. if(cZipCnt > 0)
  991. {
  992. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED);//
  993. }
  994. else
  995. {
  996. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED);
  997. }
  998. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  999. QD_MotorStep = 64;
  1000. }
  1001. break;
  1002. case 64:
  1003. if(QD_PARAM_GO_MODE)
  1004. {
  1005. if(cZipCnt > 0)
  1006. {
  1007. if((go_buff - cRealPos) > (go_length_buff - QD_PARAM_Go_LOW_SPEED_LENGTH + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH))
  1008. {
  1009. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1010. QD_MotorStep =65;
  1011. }
  1012. }
  1013. else
  1014. {
  1015. QD_MotorStep =65;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. QD_MotorStep =65;
  1021. }
  1022. break;
  1023. case 65:
  1024. if(QD_QIAN_LIMIT_IN_UP)
  1025. {
  1026. if(QD_PARAM_DAO_MODE)
  1027. {
  1028. dandao_buff = cRealPos;
  1029. QD_MotorStep = 70;
  1030. }
  1031. else
  1032. {
  1033. AxisEgmStop(X_AXIS);
  1034. QD_MotorStep = 66;
  1035. }
  1036. }
  1037. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1038. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1039. break;
  1040. case 70:
  1041. if((dandao_buff - cRealPos) >= QD_PARAM_DANDAO_MODE_LENGTH)
  1042. {
  1043. AxisEgmStop(X_AXIS);
  1044. QD_MotorStep = 66;
  1045. }
  1046. break;
  1047. case 66:
  1048. if(!X_DRV)
  1049. {
  1050. QD_MotorDelay = dwTickCount;
  1051. QD_MotorStep = 67;
  1052. }
  1053. break;
  1054. case 67:
  1055. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1056. {
  1057. if(bRunning)
  1058. {
  1059. QD_JD_VAVEL = 1;
  1060. }
  1061. QD_MotorStep = 68;
  1062. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1063. }
  1064. break;
  1065. case 68:
  1066. if(dwTickCount >= QD_MotorDelay)
  1067. {
  1068. QD_YD_VAVLE = 0;
  1069. QD_BL_VAVLE = 0;
  1070. QD_MotorStep = 0;
  1071. }
  1072. break;
  1073. }
  1074. }
  1075. //推方块动作
  1076. void QueDuan_TuiFangKuai(void)
  1077. {
  1078. }
  1079. void QueDuan_BingLian(void)
  1080. {
  1081. static long bl_pos_buff;
  1082. switch(QD_BinLianStep)
  1083. {
  1084. case 0:break;
  1085. case 1:
  1086. bl_pos_buff = cRealPos;
  1087. QD_BinLianStep = 2;
  1088. break;
  1089. case 2:
  1090. if((cRealPos - bl_pos_buff) >= QD_PARAM_DELAY_HL_LENGTH)
  1091. {
  1092. QD_BL_VAVLE = 1;
  1093. QD_BinLianStep = 3;
  1094. }
  1095. break;
  1096. case 3:
  1097. if(QD_SM_VAVLE)QD_BL_VAVLE = 0;
  1098. break;
  1099. default:;
  1100. }
  1101. }
  1102. void QueDuan_Motor_QD(void)
  1103. {
  1104. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff;
  1105. user_datas[124]= QD_MotorStep;
  1106. user_datas[125]= go_length_buff;
  1107. user_datas[123] = length_buff;
  1108. user_datas[127] = cRealPos;
  1109. user_datas[126] = go_buff - cRealPos;
  1110. user_datas[121] = QD_BinLianStep;
  1111. switch(QD_MotorStep)
  1112. {
  1113. case 0:
  1114. break;
  1115. case 1: // 前点定位数控模式
  1116. if(QD_SZ_OUT)
  1117. {
  1118. QD_SZ_OUT = 0;
  1119. QD_MotorDelay = dwTickCount + 50;
  1120. }
  1121. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1122. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE && !QD_PARAM_TL_MODE)QD_TuiLianStep = 1;
  1123. QD_MotorStep = 2;
  1124. break;
  1125. case 2:
  1126. if(dwTickCount >= QD_MotorDelay)
  1127. {
  1128. if(QD_QIAN_LIMIT_IN)
  1129. {
  1130. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  1131. AxisMovePos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_ON_BACK_LENGTH);
  1132. QD_MotorDelay = dwTickCount + 1000;
  1133. }
  1134. QD_MotorStep = 3;
  1135. QD_JD_VAVEL = 0;
  1136. }
  1137. break;
  1138. case 3:
  1139. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  1140. {
  1141. if(cZipCnt == 0)
  1142. {
  1143. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1144. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P); //第一条走低速
  1145. }
  1146. else
  1147. {
  1148. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1149. 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);//第二条开始走两段速
  1150. }
  1151. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1152. QD_MotorStep = 4;
  1153. }
  1154. break;
  1155. case 4:
  1156. if(QD_QIAN_LIMIT_IN_UP)
  1157. {
  1158. AxisEgmStop(X_AXIS);
  1159. QD_MotorStep = 5;
  1160. }
  1161. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1162. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1163. break;
  1164. case 5:
  1165. if(!X_DRV)
  1166. {
  1167. QD_MotorDelay = dwTickCount;
  1168. QD_MotorStep = 6;
  1169. }
  1170. break;
  1171. case 6:
  1172. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0))
  1173. {
  1174. if(bRunning)
  1175. {
  1176. QD_JD_VAVEL = 1;
  1177. }
  1178. QD_MotorStep = 7;
  1179. QD_MotorDelay = dwTickCount + 100;
  1180. }
  1181. break;
  1182. case 7:
  1183. if(dwTickCount >= QD_MotorDelay)
  1184. {
  1185. QD_YBD_VAVLE = 0;
  1186. QD_TL_VAVLE = 0;
  1187. QD_MotorStep = 0;
  1188. }
  1189. break;
  1190. case 20:// 后退使用电机定长
  1191. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1192. QD_MotorStep = 21;
  1193. break;
  1194. case 21:
  1195. if(dwTickCount >= QD_MotorDelay)
  1196. {
  1197. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1198. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-QD_PARAM_ZIPPER_LENGTH);
  1199. QD_MotorStep = 22;
  1200. }
  1201. break;
  1202. case 22:
  1203. if(!X_DRV)
  1204. {
  1205. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_FZ;
  1206. QD_MotorStep = 23;
  1207. }
  1208. break;
  1209. case 23:
  1210. if(dwTickCount >= QD_MotorDelay)
  1211. {
  1212. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  1213. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1214. QD_MotorStep = 24;
  1215. }
  1216. break;
  1217. case 24:
  1218. if(!X_DRV)
  1219. {
  1220. QD_MotorStep = 0;
  1221. QD_MotorDelay = dwTickCount;
  1222. }
  1223. break;
  1224. case 30:
  1225. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1226. QD_MotorStep = 31;
  1227. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  1228. break;
  1229. case 31: // 后退使用钩针定长
  1230. if(dwTickCount >= QD_MotorDelay)
  1231. {
  1232. save_buff = cRealPos;
  1233. back_buff = cRealPos;
  1234. SetAccTime(X_AXIS,5);
  1235. SetDecTime(X_AXIS,5);
  1236. if(QD_PARAM_DEC_MODE == 0)
  1237. {
  1238. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1239. AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_P);
  1240. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1241. QD_MotorStep = 32;
  1242. }
  1243. else
  1244. {
  1245. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1246. if(cZipCnt < 2)
  1247. {
  1248. QD_XHG_VAVLE = 0;
  1249. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P);
  1250. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1251. QD_MotorStep = 32;
  1252. }
  1253. else
  1254. {
  1255. gouzhen_buff = cRealPos;
  1256. QD_XHG_VAVLE = 1;
  1257. //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);
  1258. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-length_buff);
  1259. MoveChangSpeedPos(X_AXIS, QD_PARAM_GO_LOW_SPEED,PosToPulse(X_AXIS,QD_PARAM_Back_LOW_SPEED_LENGTH));
  1260. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1261. QD_MotorStep = 33;
  1262. }
  1263. // AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_N);
  1264. }
  1265. }
  1266. break;
  1267. case 32:
  1268. if(QD_PARAM_BACK_MODE)
  1269. {
  1270. if(cZipCnt < 2)
  1271. {
  1272. if(QD_GUO_LIAN_IN_UP)
  1273. {
  1274. cCheckLianFlg = 0;
  1275. checkdelay_buff = cRealPos;
  1276. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1277. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1278. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1279. QD_MotorDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1280. // QD_CheckDelay = dwTickCount + QD_PARAM_DELAY_CHECK;
  1281. QD_MotorStep = 33;
  1282. }
  1283. else if(dwTickCount >= QD_MotorDelay)
  1284. {
  1285. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1286. }
  1287. }
  1288. else
  1289. {
  1290. /* if((cRealPos - back_buff) > (length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH))
  1291. {
  1292. // if(X_DRV)MoveChangSpeedPos(X_AXIS, QD_PARAM_GO_LOW_SPEED,PosToPulse(X_AXIS,QD_PARAM_Back_LOW_SPEED_LENGTH));
  1293. }*/
  1294. QD_MotorStep = 36;
  1295. }
  1296. }
  1297. else
  1298. {
  1299. if(QD_GUO_LIAN_IN_UP)
  1300. {
  1301. cCheckLianFlg = 0;
  1302. checkdelay_buff = cRealPos;
  1303. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1304. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1305. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1306. QD_MotorDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1307. // QD_CheckDelay = dwTickCount + QD_PARAM_DELAY_CHECK;
  1308. QD_MotorStep = 33;
  1309. }
  1310. else if(dwTickCount >= QD_MotorDelay)
  1311. {
  1312. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1313. }
  1314. }
  1315. break;
  1316. case 33:
  1317. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  1318. {
  1319. if(dwTickCount >= QD_MotorDelay)
  1320. {
  1321. QD_GZ_VAVLE = 1;
  1322. QD_MotorStep = 34;
  1323. }
  1324. }
  1325. else
  1326. {
  1327. if((cRealPos - back_buff) > (length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH))
  1328. {
  1329. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1330. QD_MotorStep = 34;
  1331. }
  1332. }
  1333. break;
  1334. case 34:
  1335. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  1336. {
  1337. if((cRealPos - checkdelay_buff) >= QD_PARAM_DELAY_CHECK)
  1338. {
  1339. //user_datas[125]= cRealPos - checkdelay_buff;
  1340. cCheckLianFlgEN = 1;
  1341. if(cCheckLianFlg)//(!QD_GUO_LIAN_IN)
  1342. {
  1343. // AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1344. cCheckLianFlg = 0;
  1345. gou_zhen_buff = cRealPos;
  1346. QD_MotorStep = 35;
  1347. }
  1348. }
  1349. }
  1350. else
  1351. {
  1352. if((cRealPos - gouzhen_buff) >= (length_buff - QD_PARAM_GOUZHEN_LENGTH))
  1353. {
  1354. QD_GZ_VAVLE = 1;
  1355. QD_MotorStep = 36;
  1356. }
  1357. }
  1358. break;
  1359. case 35:
  1360. if(cCheckLianFlg)
  1361. {
  1362. cCheckLianFlg = 0;
  1363. gou_zhen_buff = cRealPos;
  1364. }
  1365. if(QD_GUO_LIAN_IN_DW)
  1366. {
  1367. gou_zhen_buff = cRealPos;
  1368. }
  1369. if(QD_GUO_LIAN_IN_UP)
  1370. {
  1371. gou_zhen_buff = cRealPos;
  1372. }
  1373. if((cRealPos - gou_zhen_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  1374. {
  1375. AxisEgmStop(X_AXIS);
  1376. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1377. QD_MotorStep = 36;
  1378. }
  1379. break;
  1380. case 36:
  1381. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  1382. {
  1383. cCheckLianFlgEN = 0;
  1384. if(QD_PARAM_DEC_MODE == 0)QD_GZ_VAVLE = 1;
  1385. if(!QD_PARAM_TL_MODE)QD_YBD_VAVLE = 1;
  1386. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  1387. QD_MotorStep = 37;
  1388. }
  1389. break;
  1390. case 37:
  1391. if(dwTickCount >= QD_MotorDelay)
  1392. {
  1393. QD_TFK_VAVEL = 1;
  1394. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1395. QD_MotorStep = 38;
  1396. }
  1397. break;
  1398. case 38:
  1399. if(QD_GOUZHEN_IN && !X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  1400. {
  1401. if(QD_PARAM_TL_MODE)QD_YBD_VAVLE = 1;
  1402. if(cZipCnt == 1)
  1403. {
  1404. length_buff = cRealPos - save_buff - QD_PARAM_OFFSET_LENGTH;
  1405. }
  1406. if(cZipCnt == 0)
  1407. {
  1408. go_length_buff = cRealPos - save_buff;
  1409. }
  1410. QD_MotorStep = 0;
  1411. }
  1412. else if(dwTickCount >= QD_MotorDelay)
  1413. {
  1414. QD_SetAlarmCode(QD_GZ_ALARM);
  1415. }
  1416. break;
  1417. case 40:
  1418. if(dwTickCount >= QD_MotorDelay)
  1419. {
  1420. // 切断完成后拉电机动作
  1421. if(QD_PARAM_SJZ_LENGTH == 0)
  1422. {
  1423. QD_MotorDelay = dwTickCount + 50;
  1424. QD_JD_VAVEL = 0;
  1425. }
  1426. else if(QD_PARAM_SJZ_LENGTH <= 100)
  1427. {
  1428. QD_MotorDelay = dwTickCount + 40;
  1429. QD_JD_VAVEL = 0;
  1430. }
  1431. else if(QD_PARAM_SJZ_LENGTH <= 200)
  1432. {
  1433. QD_MotorDelay = dwTickCount + 30;
  1434. QD_JD_VAVEL = 0;
  1435. }
  1436. else if(QD_PARAM_SJZ_LENGTH <= 300)
  1437. {
  1438. QD_MotorDelay = dwTickCount + 20;
  1439. QD_JD_VAVEL = 0;
  1440. }
  1441. else if(QD_PARAM_SJZ_LENGTH <= 400)
  1442. {
  1443. QD_MotorDelay = dwTickCount + 10;
  1444. QD_JD_VAVEL = 0;
  1445. }
  1446. else if(QD_PARAM_SJZ_LENGTH <= 500)
  1447. {
  1448. QD_MotorDelay = dwTickCount + 5;
  1449. QD_JD_VAVEL = 0;
  1450. }
  1451. else
  1452. {
  1453. QD_MotorDelay = dwTickCount;
  1454. }
  1455. QD_MotorStep = 41;
  1456. }
  1457. break;
  1458. case 41:
  1459. if(dwTickCount >= QD_MotorDelay)
  1460. {
  1461. save_buff = cRealPos;
  1462. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1463. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH));
  1464. QD_MotorStep = 42;
  1465. }
  1466. break;
  1467. case 42: // 切断完成后拉电机动作
  1468. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - save_buff)))
  1469. {
  1470. QD_JD_VAVEL = 0;
  1471. QD_MotorStep = 43;
  1472. }
  1473. else if(!X_DRV)
  1474. {
  1475. QD_JD_VAVEL = 0;
  1476. QD_MotorStep = 43;
  1477. }
  1478. break;
  1479. case 43: // 切断完成后拉电机动作
  1480. if(!X_DRV)
  1481. {
  1482. QD_MotorStep = 0;
  1483. QD_MotorDelay = dwTickCount;
  1484. }
  1485. break;
  1486. case 61: // 前点定位数控模式
  1487. if(QD_SZ_OUT)
  1488. {
  1489. QD_SZ_OUT = 0;
  1490. QD_MotorDelay = dwTickCount + 50;
  1491. }
  1492. if(QD_PARAM_TL_MODE)
  1493. {
  1494. // if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  1495. }
  1496. else
  1497. {
  1498. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE)QD_TuiLianStep = 1;
  1499. }
  1500. // cGoLimitEn = 1;
  1501. SetAccTime(X_AXIS,10);
  1502. SetDecTime(X_AXIS,10);
  1503. QD_MotorStep = 62;
  1504. break;
  1505. case 62:
  1506. if(dwTickCount >= QD_MotorDelay)
  1507. {
  1508. if(QD_QIAN_LIMIT_IN)
  1509. {
  1510. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1511. AxisMovePos(X_AXIS,QD_PARAM_FIRST_SPEED,-QD_PARAM_ON_BACK_LENGTH);
  1512. QD_MotorDelay = dwTickCount + 1000;
  1513. }
  1514. QD_MotorStep = 63;
  1515. QD_JD_VAVEL = 0;
  1516. }
  1517. break;
  1518. case 63:
  1519. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  1520. {
  1521. if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_N;
  1522. go_buff = cRealPos;
  1523. if(cZipCnt > 0)
  1524. {
  1525. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED);//
  1526. }
  1527. else
  1528. {
  1529. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED);
  1530. }
  1531. // MoveAction_Const_Stop(X_AXIS, QD_DIR_P,QD_PARAM_GO_HIGH_SPEED);//
  1532. // AxisContinueMove(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_DIR_P); //第一条走低速
  1533. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1534. QD_MotorStep =64;
  1535. }
  1536. break;
  1537. case 64:
  1538. if(QD_PARAM_GO_MODE)
  1539. {
  1540. if(cZipCnt > 0)
  1541. {
  1542. if((go_buff - cRealPos) > (go_length_buff - QD_PARAM_Go_LOW_SPEED_LENGTH + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH))
  1543. {
  1544. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1545. QD_MotorStep =65;
  1546. }
  1547. }
  1548. else
  1549. {
  1550. // if(QD_QIAN_DEC_IN)
  1551. {
  1552. // if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);//AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1553. QD_MotorStep =65;
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. // if(QD_QIAN_DEC_IN)
  1560. {
  1561. // if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);//AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1562. QD_MotorStep =65;
  1563. }
  1564. }
  1565. break;
  1566. case 65:
  1567. if(QD_QIAN_LIMIT_IN_UP)
  1568. {
  1569. if(QD_PARAM_DAO_MODE)
  1570. {
  1571. dandao_buff = cRealPos;
  1572. QD_MotorStep = 70;
  1573. }
  1574. else
  1575. {
  1576. AxisEgmStop(X_AXIS);
  1577. QD_MotorStep = 66;
  1578. }
  1579. }
  1580. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1581. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1582. break;
  1583. case 70:
  1584. if((dandao_buff - cRealPos) >= QD_PARAM_DANDAO_MODE_LENGTH)
  1585. {
  1586. AxisEgmStop(X_AXIS);
  1587. QD_MotorStep = 66;
  1588. }
  1589. break;
  1590. case 66:
  1591. if(!X_DRV)
  1592. {
  1593. QD_MotorDelay = dwTickCount;
  1594. QD_MotorStep = 67;
  1595. }
  1596. break;
  1597. case 67:
  1598. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1599. {
  1600. if(bRunning)
  1601. {
  1602. QD_JD_VAVEL = 1;
  1603. }
  1604. QD_MotorStep = 68;
  1605. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1606. }
  1607. break;
  1608. case 68:
  1609. if(dwTickCount >= QD_MotorDelay)
  1610. {
  1611. QD_YBD_VAVLE = 0;
  1612. QD_TL_VAVLE = 0;
  1613. QD_MotorStep = 0;
  1614. }
  1615. break;
  1616. }
  1617. }
  1618. //电机动作
  1619. void QueDuan_Motor(void) //
  1620. {
  1621. switch(QD_MACHINE_TYPE)
  1622. {
  1623. case QD_CS_TUIFANGKUAI: QueDuan_Motor_CS();break;
  1624. case QD_QQ_TUIFANGKUAI: QueDuan_Motor_QD();break;
  1625. default:;
  1626. }
  1627. }
  1628. //超声方式下切
  1629. void QueDuan_XiaQue_CS(void)
  1630. {
  1631. switch(QD_XiaQieStep)
  1632. {
  1633. case 0:
  1634. break;
  1635. case 1:
  1636. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1637. QD_XiaQieStep = 2;
  1638. break;
  1639. case 2:
  1640. if(dwTickCount >= QD_XiaQieDelay)
  1641. {
  1642. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1643. QD_XM_VAVLE = 1;
  1644. QD_XiaQieStep = 3;
  1645. }
  1646. break;
  1647. case 3:
  1648. if(QD_XIA_MU_LIMIT_IN)
  1649. {
  1650. QD_XiaQieDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1651. QD_XiaQieStep = 4;
  1652. }
  1653. else if(dwTickCount >= QD_XiaQieDelay)
  1654. {
  1655. QD_SetAlarmCode(QD_XM_DAOWEI);
  1656. }
  1657. break;
  1658. case 4:
  1659. if(dwTickCount >= QD_XiaQieDelay)
  1660. {
  1661. QD_GZ_VAVLE = 1;
  1662. QD_XiaQieDelay = dwTickCount + QD_PARAM_TFK_DELAY; //
  1663. QD_XiaQieStep = 5;
  1664. }
  1665. break;
  1666. case 5:
  1667. if(dwTickCount >= QD_XiaQieDelay)
  1668. {
  1669. QD_TFK_VAVEL = 1;
  1670. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1671. QD_XiaQieStep = 6;
  1672. }
  1673. break;
  1674. case 6:
  1675. if(QD_GOUZHEN_IN)
  1676. {
  1677. QD_SM_VAVLE = 1;
  1678. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1679. QD_XiaQieStep = 7;
  1680. }
  1681. else if(dwTickCount >= QD_XiaQieDelay)
  1682. {
  1683. QD_SetAlarmCode(QD_GZ_ALARM);
  1684. }
  1685. break;
  1686. case 7:
  1687. if(QD_SHANG_MU_LIMIT_IN && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1688. {
  1689. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  1690. QD_XiaQieStep = 8;
  1691. }
  1692. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  1693. break;
  1694. case 8:
  1695. if(dwTickCount >= QD_XiaQieDelay)
  1696. {
  1697. if(QD_PARAM_CS_ENABLE)QD_CS_OUT = 1;
  1698. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  1699. QD_XiaQieStep = 9;
  1700. }
  1701. break;
  1702. case 9:
  1703. if(dwTickCount >= QD_XiaQieDelay)
  1704. {
  1705. QD_CS_OUT = 0;
  1706. QD_SM_VAVLE = 0;
  1707. QD_XM_VAVLE = 0;
  1708. QD_TFK_VAVEL = 0;
  1709. QD_GZ_VAVLE = 0;
  1710. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1711. QD_XiaQieStep = 10;
  1712. }
  1713. break;
  1714. case 10:
  1715. if(QD_SHANG_MU_ORIGIN_IN && !QD_XIA_MU_LIMIT_IN)
  1716. {
  1717. QD_XiaQieStep = 0;
  1718. }
  1719. else if(dwTickCount >= QD_XiaQieDelay)
  1720. {
  1721. QD_SetAlarmCode(QD_SM_YUANWEI);
  1722. }
  1723. break;
  1724. }
  1725. }
  1726. void QueDuan_TuiLianAction(void)
  1727. {
  1728. switch(QD_TuiLianStep)
  1729. {
  1730. case 0:
  1731. break;
  1732. case 1:
  1733. QD_TuiLianStep = 2;
  1734. break;
  1735. case 2:
  1736. QD_YBD_VAVLE = 1;
  1737. QD_TLDelay = dwTickCount + QD_PARAM_YD_DELAY;
  1738. QD_TuiLianStep = 3;
  1739. break;
  1740. case 3:
  1741. if(dwTickCount >= QD_TLDelay)
  1742. {
  1743. if(QD_PARAM_TL_MODE)
  1744. {
  1745. QD_TuiLianStep = 10;
  1746. }
  1747. else
  1748. {
  1749. QD_TL_VAVLE = 1;
  1750. QD_TLDelay = dwTickCount + QD_PARAM_TL_DELAY;
  1751. QD_TuiLianStep = 4;
  1752. }
  1753. }
  1754. break;
  1755. case 4:
  1756. if(dwTickCount >= QD_TLDelay)
  1757. {
  1758. // QD_TL_VAVLE = 0;
  1759. QD_TuiLianStep = 0;
  1760. }
  1761. break;
  1762. case 10:
  1763. if(bRunning && QD_PARAM_TL_MODE)AxisMovePos(Y_AXIS,QD_PARAM_TL_SPEED,QD_PARAM_TL_LENGTH);
  1764. QD_TuiLianStep = 11;
  1765. break;
  1766. case 11:
  1767. if(!Y_DRV)
  1768. {
  1769. {
  1770. QD_TuiLianStep = 0;
  1771. }
  1772. }
  1773. break;
  1774. }
  1775. }
  1776. //气动推方块方式下切
  1777. void QueDuan_XiaQue_QD(void)
  1778. {
  1779. switch(QD_XiaQieStep)
  1780. {
  1781. case 0:
  1782. break;
  1783. case 1:
  1784. if(!bRunning)
  1785. {
  1786. QD_XiaQieDelay = dwTickCount + 50;
  1787. QD_GZ_VAVLE = 1;
  1788. QD_XiaQieStep = 20;
  1789. }
  1790. else
  1791. {
  1792. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1793. QD_XiaQieStep = 2;
  1794. }
  1795. break;
  1796. case 20:
  1797. if(dwTickCount >= QD_XiaQieDelay)
  1798. {
  1799. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1800. QD_TFK_VAVEL = 1;
  1801. QD_XiaQieStep = 2;
  1802. }
  1803. break;
  1804. case 2:
  1805. if(dwTickCount >= QD_XiaQieDelay)
  1806. {
  1807. QD_SM_VAVLE = 1;
  1808. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1809. QD_XiaQieStep = 3;
  1810. }
  1811. break;
  1812. case 3:
  1813. if(QD_SHANG_MU_LIMIT_IN && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1814. {
  1815. QD_XiaQieStep = 4;
  1816. QD_XiaQieDelay = dwTickCount + 100;
  1817. }
  1818. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  1819. break;
  1820. case 4:
  1821. if(dwTickCount >= QD_XiaQieDelay)
  1822. {
  1823. QD_SM_VAVLE = 0;
  1824. QD_TFK_VAVEL = 0;
  1825. QD_GZ_VAVLE = 0;
  1826. if(!QD_PARAM_TL_MODE)
  1827. {
  1828. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  1829. }
  1830. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1831. QD_XiaQieStep = 5;
  1832. }
  1833. break;
  1834. case 5:
  1835. if(QD_SHANG_MU_ORIGIN_IN && (QD_TuiLianStep == 0))
  1836. {
  1837. if(QD_PARAM_TL_MODE)
  1838. {
  1839. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  1840. }
  1841. QD_XiaQieStep = 0;
  1842. QD_XiaQieDelay = dwTickCount + QD_PARAM_TL_DELAY;
  1843. }
  1844. else if(dwTickCount >= QD_XiaQieDelay)
  1845. {
  1846. QD_SetAlarmCode(QD_SM_YUANWEI);
  1847. }
  1848. break;
  1849. }
  1850. }
  1851. //切断动作
  1852. void QueDuan_XiaQue(void)
  1853. {
  1854. switch(QD_MACHINE_TYPE)
  1855. {
  1856. case QD_CS_TUIFANGKUAI:QueDuan_XiaQue_CS();break;
  1857. case QD_QQ_TUIFANGKUAI:QueDuan_XiaQue_QD();break;
  1858. default:;
  1859. }
  1860. }
  1861. #endif