GLQueDuanJi.c 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533
  1. #include "global.h"
  2. #if CHANG_SHENG_GEI_LI_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_ExtiActionX31(void);
  12. void QueDuan_BingLian(void);
  13. void QueDuan_ShenJiangAction(void);
  14. static unsigned long cZipCnt = 0,cTableCnt = 0,cTuiFangKuaiCnt = 0;
  15. static long save_limit_pos,cRealPos,cRealPosY;
  16. unsigned char cCheckLianFlg = 0;
  17. unsigned char cCheckLianFlgEN = 0;
  18. unsigned char cGoLimitEn = 0;
  19. unsigned char cLengthErrorFlg = 0;
  20. void QueDuan_ExtiActionX31(void)
  21. {
  22. cCheckLianFlg = 1;
  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. CalFreqTab_X_Free(20);
  34. length_buff = QD_PARAM_CYCLE_LENGTH;
  35. pulse_buff = QD_PARAM_CYCLE_PULSE;
  36. XGearRatio = pulse_buff/length_buff;
  37. axis_y->speed_unit = 300;
  38. length_buff = QD_PARAM_YL_CYCLE_LENGTH;
  39. pulse_buff = QD_PARAM_YL_CYCLE_PULSE;
  40. YGearRatio = pulse_buff/length_buff;
  41. QD_SZ_OUT = 1;
  42. MACHINE_BOOT_WIFI = 1;
  43. }
  44. void QueDuan_Action(void)
  45. {
  46. QueDuan_AlarmProtect();
  47. QueDuan_Motor();
  48. QueDuan_XiaQue();
  49. QueDuan_ManualAction();
  50. QueDuan_YuanDianAction();
  51. QueDuan_TuiLianAction();
  52. QueDuan_BingLian();
  53. QueDuan_ShenJiangAction();
  54. QueDuan_AutoAction();
  55. QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  56. }
  57. long testFlg = 0;
  58. //手动动作
  59. void QueDuan_ManualAction(void)
  60. {
  61. static unsigned short button_cnt;
  62. if(bRunning == 0)
  63. {
  64. if(QD_bSetGZMode)
  65. {
  66. QD_bSetGZMode = 0;
  67. if(QD_PARAM_DC_MODE == 0)QD_GZ_VAVLE = 0;
  68. }
  69. if(dwTickCount >= QD_BUTTONDelay)
  70. {
  71. if(QD_bClearTotal) //计数清零
  72. {
  73. QD_BUTTONDelay = dwTickCount+1000;
  74. button_cnt++;
  75. if(button_cnt >= 3)
  76. {
  77. ClrcToTal(QD_TOTAL_ADDR);
  78. QD_bClearTotal = 0;
  79. }
  80. }
  81. if(QD_bClearNowTotal)
  82. {
  83. QD_BUTTONDelay = dwTickCount+1000;
  84. button_cnt++;
  85. if(button_cnt >= 3)
  86. {
  87. QD_bClearNowTotal = 0;
  88. QD_PARAM_NOW_CNT = 0;
  89. }
  90. }
  91. if(!QD_bClearNowTotal && !QD_bClearTotal)button_cnt = 0;
  92. }
  93. if(QD_bXiaQie)
  94. {
  95. QD_bXiaQie = 0;
  96. if(QD_XiaQieStep == 0)QD_XiaQieStep = 1;
  97. }
  98. if(QD_bQianDianDW)
  99. {
  100. QD_bQianDianDW = 0;
  101. if(QD_MotorStep == 0)
  102. {
  103. QD_MotorStep = 61;
  104. cZipCnt = 0;
  105. }
  106. }
  107. if(QD_bYD)
  108. {
  109. QD_bYD = 0;
  110. QD_YD_VAVLE = ~QD_YD_VAVLE;
  111. }
  112. if(QD_bGZ)
  113. {
  114. QD_bGZ = 0;
  115. QD_GZ_VAVLE = ~QD_GZ_VAVLE;
  116. }
  117. if(QD_bJD)
  118. {
  119. QD_bJD = 0;
  120. QD_JD_VAVEL = ~QD_JD_VAVEL;
  121. }
  122. if(QD_bR_UP)
  123. {
  124. QD_bR_UP = 0;
  125. QD_R_UP_VAVLE = ~QD_R_UP_VAVLE;
  126. }
  127. if(QD_bR_JD)
  128. {
  129. QD_bR_JD = 0;
  130. QD_R_JD = ~QD_R_JD;
  131. }
  132. if(QD_bXM)
  133. {
  134. QD_bXM = 0;
  135. QD_XM_VAVLE = ~QD_XM_VAVLE;
  136. }
  137. if(QD_bSM)
  138. {
  139. QD_bSM = 0;
  140. QD_SM_VAVLE = ~QD_SM_VAVLE;
  141. }
  142. if(QD_bTFK)
  143. {
  144. QD_bTFK = 0;
  145. QD_TFK_VAVEL = ~QD_TFK_VAVEL;
  146. }
  147. if(QD_bTB)
  148. {
  149. QD_bTB = 0;
  150. QD_TABLE_VAVLE = ~QD_TABLE_VAVLE;
  151. }
  152. if(QD_bYBD)
  153. {
  154. QD_bYBD = 0;
  155. QD_YBD_VAVLE = ~QD_YBD_VAVLE;
  156. }
  157. if(QD_bTL)
  158. {
  159. QD_bTL = 0;
  160. QD_TL_VAVLE = ~QD_TL_VAVLE;
  161. }
  162. if(QD_bTestCS)
  163. {
  164. QD_bTestCS = 0;
  165. QD_CS_OUT = 1;
  166. QD_CSDelay = dwTickCount + QD_PARAM_CS_TIME;
  167. }
  168. if(QD_bBL)
  169. {
  170. QD_bBL = 0;
  171. QD_BL_VAVLE = ~QD_BL_VAVLE;
  172. }
  173. if((QD_XiaQieStep == 0))
  174. {
  175. if(dwTickCount >= QD_CSDelay)QD_CS_OUT = 0;
  176. }
  177. if(QD_bYuanDianDW)
  178. {
  179. QD_bYuanDianDW = 0;
  180. if(QD_YuanDianStep == 0)QD_YuanDianStep = 1;
  181. }
  182. //电机控制
  183. if(QD_bYLBACK_MOTOR)
  184. {
  185. QD_YL_DIR = QD_YL_DIR_P;
  186. if(!Y_DRV)AxisContinueMoveAcc(Y_AXIS,5, QD_YL_DIR_P,5,10,10);
  187. }
  188. if(QD_bYLGO_MOTOR)
  189. {
  190. QD_YL_DIR = QD_YL_DIR_N;
  191. if(!Y_DRV)AxisContinueMoveAcc(Y_AXIS,5, QD_YL_DIR_N,5,10,10);
  192. }
  193. if(!QD_bYLBACK_MOTOR && !QD_bYLGO_MOTOR && (QD_MotorStep == 0))
  194. {
  195. if(Y_DRV)AxisDecStop(Y_AXIS);
  196. }
  197. if(QD_bYL)
  198. {
  199. QD_YL_VAVLE = ~QD_YL_VAVLE;
  200. }
  201. if(QD_bBackMotor && !QD_BACK_LIMIT_IN)
  202. {
  203. QD_SZ_OUT = 0;
  204. QD_JZ_DIR = QD_YDIR_P;
  205. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, QD_DIR_P, 5,5,10,10);
  206. }
  207. if(!QD_bGoMotor && !QD_bBackMotor && (QD_MotorStep == 0))
  208. {
  209. if(X_DRV)AxisDecStop(X_AXIS);
  210. }
  211. if(QD_QIAN_LIMIT_IN && (QD_MotorStep == 0) && !QD_bBackMotor &&(QD_AutoStep == 0))
  212. {
  213. if(X_DRV)AxisEgmStop(X_AXIS);
  214. }
  215. if(QD_bGoMotor && !QD_QIAN_LIMIT_IN)
  216. {
  217. QD_SZ_OUT = 0;
  218. QD_JZ_DIR = QD_YDIR_N;
  219. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, QD_DIR_N, 5,5,10,10);
  220. }
  221. if(QD_bCQ)
  222. {
  223. QD_bCQ = 0;
  224. QD_CQ_VAVLE = 1;
  225. QD_CQDelay = dwTickCount + QD_PARAM_CQ_TIME;
  226. }
  227. }
  228. if(QD_CQ_VAVLE && (dwTickCount >= QD_CQDelay) && (QD_MACHINE_TYPE == QD_NO_GL_TUIFANGKUAI))QD_CQ_VAVLE = 0;
  229. }
  230. void QueDuan_ShenJiangAction(void)
  231. {
  232. switch(QD_ShenJiangStep)
  233. {
  234. case 0:break;
  235. case 1:
  236. QD_R_UP_VAVLE = 1;
  237. QD_R_JD = 0;
  238. QD_ShenJiangDelay = dwTickCount + QD_PARAM_SJ_TIME;
  239. QD_ShenJiangStep = 2;
  240. break;
  241. case 2:
  242. if(dwTickCount >= QD_ShenJiangDelay)
  243. {
  244. QD_R_JD = 1;
  245. QD_ShenJiangDelay = dwTickCount + QD_PARAM_SJ_JZ_TIME;
  246. QD_ShenJiangStep = 3;
  247. }
  248. break;
  249. case 3:
  250. if(dwTickCount >= QD_ShenJiangDelay)
  251. {
  252. QD_JD_VAVEL = 0;
  253. QD_R_UP_VAVLE = 0;
  254. QD_ShenJiangStep = 4;
  255. QD_ShenJiangDelay = dwTickCount + QD_PARAM_DELAY_GO;
  256. }
  257. break;
  258. case 4:
  259. if(dwTickCount >= QD_ShenJiangDelay)
  260. {
  261. QD_JZ_DIR = QD_YDIR_N;
  262. if(QD_YL_ORIGIN_IN && (QD_MACHINE_TYPE == QD_NO_GL_TUIFANGKUAI))
  263. if(!X_DRV)MoveAction_Const_Stop_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);//
  264. else
  265. AxisMovePos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LENGTH);
  266. QD_ShenJiangStep = 5;
  267. }
  268. break;
  269. case 5:
  270. if(!X_DRV)
  271. {
  272. QD_R_JD = 0;
  273. QD_ShenJiangStep = 0;
  274. }
  275. break;
  276. case 6:
  277. {
  278. QD_R_JD = 0;
  279. QD_ShenJiangStep = 0;
  280. }
  281. break;
  282. }
  283. }
  284. void QueDuan_YuanDianAction(void)
  285. {
  286. switch(QD_YuanDianStep)
  287. {
  288. case 0:break;
  289. case 1:
  290. if(QD_MotorStep == 0)QD_MotorStep = 61;
  291. QD_YuanDianStep = 2;
  292. break;
  293. case 2:
  294. if(QD_MotorStep == 0)
  295. {
  296. QD_MotorStep = 30;
  297. QD_YuanDianStep = 3;
  298. QD_JD_VAVEL = 1;
  299. }
  300. break;
  301. case 3:
  302. if(QD_MotorStep == 0)
  303. {
  304. QD_MotorStep = 0;
  305. QD_YuanDianStep = 0;
  306. }
  307. break;
  308. }
  309. }
  310. void QueDuan_AlarmProtect(void)
  311. {
  312. cRealPos = GetPos(X_AXIS);
  313. cRealPosY = GetPos(Y_AXIS);
  314. if(QD_PARAM_BACK_ALARM_MODE)
  315. { //感应后限模式
  316. if(!bRunning)
  317. {
  318. if(QD_BACK_LIMIT_IN_UP)
  319. {
  320. if((QD_MotorStep == 0) && X_DRV && QD_bBackMotor) //到后限不能再后退但可以点前进
  321. {
  322. QD_bBackMotor = 0;
  323. AxisDecStop(X_AXIS);
  324. QD_JD_VAVEL = 0;
  325. QD_SetAlarmCode(QD_BACK_ALARM);
  326. }
  327. }
  328. }
  329. else
  330. {
  331. if(QD_BACK_LIMIT_IN_UP)
  332. {
  333. AxisDecStop(X_AXIS);
  334. QD_JD_VAVEL = 0;
  335. QD_SetAlarmCode(QD_BACK_ALARM);
  336. }
  337. }
  338. }
  339. else
  340. {
  341. if(QD_QIAN_LIMIT_IN_UP) //数控后限模式
  342. {
  343. save_limit_pos = cRealPos;
  344. SetData32bits(200,save_limit_pos);
  345. }
  346. if(QD_PARAM_MAX_BACK_LENGTH < (cRealPos - save_limit_pos))
  347. {
  348. if(!bRunning)
  349. {
  350. if((QD_MotorStep == 0) && X_DRV && QD_bBackMotor) //到后限不能再后退但可以点前进
  351. {
  352. QD_bBackMotor = 0;
  353. AxisDecStop(X_AXIS);
  354. QD_JD_VAVEL = 0;
  355. QD_SetAlarmCode(QD_BACK_ALARM);
  356. }
  357. }
  358. else
  359. {
  360. AxisDecStop(X_AXIS);
  361. QD_JD_VAVEL = 0;
  362. QD_SetAlarmCode(QD_BACK_ALARM);
  363. }
  364. }
  365. }
  366. // if(!QD_KADAI_IN)QD_KaDaiDelay = dwTickCount + 3000;
  367. /* if(bRunning)
  368. {
  369. if(dwTickCount >= QD_KaDaiDelay)QD_SetAlarmCode(QD_KA_DAI_ALARM);
  370. }*/
  371. }
  372. void QueDuan_AutoAction(void)
  373. {
  374. if(bRunning)
  375. {
  376. if(dwTickCount >= QD_TBDelay)QD_TABLE_VAVLE = 0;
  377. switch(QD_AutoStep)
  378. {
  379. case 1:
  380. if(dwTickCount >= QD_AutoDelay)
  381. {
  382. QD_AutoStep = 2;
  383. if(QD_MotorStep == 0)
  384. {
  385. QD_MotorStep = 61; //前点定位
  386. }
  387. }
  388. break;
  389. case 2:
  390. if(QD_MotorStep == 0)
  391. {
  392. QD_MotorStep = 30;
  393. QD_AutoStep = 3;
  394. }
  395. break;
  396. case 3:
  397. if(QD_MotorStep == 0)
  398. {
  399. {
  400. if(QD_XiaQieStep == 0)QD_XiaQieStep = 1;
  401. QD_AutoStep = 4;
  402. }
  403. }
  404. break;
  405. case 4:
  406. if(QD_MACHINE_TYPE == QD_NO_GL_TUIFANGKUAI)
  407. {
  408. if(QD_PARAM_LONG_MODE)
  409. {
  410. if((QD_XiaQieStep == 0) && !QD_SHANG_MU_LIMIT_IN)
  411. {
  412. if(QD_MotorStep == 0)
  413. {
  414. QD_MotorStep = 50;
  415. QD_AutoStep = 5;
  416. }
  417. }
  418. }
  419. else
  420. {
  421. if(((QD_XiaQieStep == 0) || (QD_XiaQieStep == 5)) && !QD_SHANG_MU_LIMIT_IN)
  422. {
  423. if(QD_MotorStep == 0)
  424. {
  425. QD_MotorStep = 40; //切完后退
  426. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  427. }
  428. QD_AutoStep = 5;
  429. }
  430. }
  431. }
  432. else
  433. {
  434. if(QD_PARAM_LONG_MODE)
  435. {
  436. if((QD_XiaQieStep == 0) && !QD_SHANG_MU_LIMIT_IN)
  437. {
  438. if(QD_MotorStep == 0)
  439. {
  440. QD_MotorStep = 50;
  441. QD_AutoStep = 5;
  442. }
  443. }
  444. }
  445. else
  446. {
  447. if(((QD_XiaQieStep == 0) || (QD_XiaQieStep == 7)) && !QD_SHANG_MU_LIMIT_IN)
  448. {
  449. if(QD_MotorStep == 0)
  450. {
  451. QD_MotorStep = 40; //切完后退
  452. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  453. }
  454. QD_AutoStep = 5;
  455. }
  456. }
  457. }
  458. break;
  459. case 5:
  460. if(QD_MotorStep == 0)
  461. {
  462. cZipCnt++;
  463. cTableCnt++;
  464. AddToTal(QD_TOTAL_ADDR);
  465. CalProSP(QD_PROSPEED_ADDR);
  466. QD_PARAM_NOW_CNT++;
  467. if(cTableCnt >= QD_PARAM_TABLE_NUM)
  468. {
  469. cTableCnt = 0;
  470. QD_TABLE_VAVLE = 1;
  471. QD_TBDelay = dwTickCount + QD_PARAM_TB_TIME;
  472. }
  473. QD_AutoStep = 1;
  474. if(QD_PARAM_ZHA_SHU == 0)
  475. {
  476. if(QD_PARAM_LONG_MODE)
  477. QD_AutoDelay = dwTickCount + QD_PARAM_DELAY_LONG_GO;
  478. else
  479. QD_AutoDelay = dwTickCount + QD_PARAM_CYCLE_DELAY;
  480. }
  481. else
  482. {
  483. if(QD_PARAM_NOW_CNT >= QD_PARAM_ZHA_SHU)
  484. {
  485. QD_PARAM_NOW_CNT = 0;
  486. QD_AutoDelay = dwTickCount + QD_PARAM_ZS_STOP_TIME + QD_PARAM_CYCLE_DELAY;
  487. }
  488. }
  489. }
  490. break;
  491. }
  492. }
  493. }
  494. void QueDuan_StepCheckStart(void)
  495. {
  496. if(bRunning)
  497. QD_PARAM_RUN_STATE = 1;
  498. else
  499. QD_PARAM_RUN_STATE = 0;
  500. // 启动
  501. if((QD_START_IN_UP) || bStart || QD_bSingle)
  502. {
  503. bStart = 0;
  504. if(!bRunning && (QD_AutoStep == 0))
  505. {
  506. if((QD_XIA_MU_LIMIT_IN && (QD_PARAM_CS_MODE == 1)))QD_SetAlarmCode(QD_XM_DAOWEI);
  507. else if(GetAlarmCode(QD_ALARM_ADDR) != 0);
  508. else if(QD_BL_VAVLE)QD_SetAlarmCode(QD_BL_ALARM);
  509. else if(QD_SM_VAVLE)QD_SetAlarmCode(QD_SM_ALARM);
  510. else if(!QD_YL_ORIGIN_IN)QD_SetAlarmCode(QD_YL_LIMIT_ALARM);
  511. else if(QD_STOP_IN)QD_SetAlarmCode(QD_STOP_IN_ALARM);
  512. else if(QD_SHANG_MU_LIMIT_IN)QD_SetAlarmCode(QD_SM_DAOWEI);
  513. else if(!QD_SHANG_MU_ORIGIN_IN)QD_SetAlarmCode(QD_SM_YUANWEI);
  514. else
  515. {
  516. bRunning = 1;
  517. QD_AutoStep = 1;
  518. if(QD_bSingle) SingOneFlg= 1;
  519. else SingOneFlg= 0;
  520. cZipCnt = 0;
  521. cTuiFangKuaiCnt = 0;
  522. cLengthErrorFlg = 0;
  523. if(GetAlarmCode(QD_ALARM_ADDR) != QD_NO_ALARM)SetAlarmCode(QD_ALARM_ADDR,QD_NO_ALARM);
  524. }
  525. }
  526. QD_bSingle = 0;
  527. }
  528. //停止
  529. if(QD_STOP_IN_UP || bStop)
  530. {
  531. bStop = 0;
  532. if(bRunning)
  533. {
  534. bRunning = 0;
  535. QD_XiaQieStep = 0;
  536. QD_AutoStep = 0;
  537. QD_MotorStep = 0;
  538. QD_TuiLianStep = 0;
  539. QD_TuiFangKuaiStep = 0;
  540. QD_YuanDianStep = 0;
  541. QD_AutoDelay = dwTickCount;
  542. QD_MotorDelay = dwTickCount;
  543. QD_XiaQieDelay = dwTickCount;
  544. QD_KaDaiDelay = dwTickCount;
  545. QD_CSDelay = dwTickCount;
  546. QD_TBDelay = dwTickCount;
  547. QD_TFKDelay = dwTickCount;
  548. QD_TLDelay = dwTickCount;
  549. QD_CheckDelay = dwTickCount;
  550. SingOneFlg = 0;
  551. QD_JD_VAVEL = 0;
  552. QD_SM_VAVLE = 0;
  553. QD_XM_VAVLE = 0;
  554. QD_TFK_VAVEL= 0;
  555. QD_TL_VAVLE = 0;
  556. QD_YBD_VAVLE = 0;
  557. QD_CS_OUT = 0;
  558. QD_XiaQieStep = 0;
  559. QD_MotorStep = 0;
  560. QD_TuiLianStep = 0;
  561. QD_TuiFangKuaiStep = 0;
  562. QD_ShenJiangStep = 0;
  563. //QD_SZ_OUT = 1;
  564. QD_GZ_VAVLE = 0;
  565. QD_TABLE_VAVLE = 0;
  566. AxisDecStop(X_AXIS);
  567. QD_YuanDianStep = 0;
  568. QD_BinLianStep = 0;
  569. QD_BL_VAVLE = 0;
  570. cLengthErrorFlg = 0;
  571. QD_R_JD = 0;
  572. QD_R_UP_VAVLE = 0;
  573. QD_YL_VAVLE = 0;
  574. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  575. }
  576. else
  577. {
  578. bRunning = 0;
  579. QD_XiaQieStep = 0;
  580. QD_AutoStep = 0;
  581. QD_MotorStep = 0;
  582. QD_TuiLianStep = 0;
  583. QD_TuiFangKuaiStep = 0;
  584. QD_YuanDianStep = 0;
  585. QD_AutoDelay = dwTickCount;
  586. QD_MotorDelay = dwTickCount;
  587. QD_XiaQieDelay = dwTickCount;
  588. QD_KaDaiDelay = dwTickCount;
  589. QD_CSDelay = dwTickCount;
  590. QD_TBDelay = dwTickCount;
  591. QD_TFKDelay = dwTickCount;
  592. QD_TLDelay = dwTickCount;
  593. QD_CheckDelay = dwTickCount;
  594. SingOneFlg = 0;
  595. QD_JD_VAVEL = 0;
  596. QD_SM_VAVLE = 0;
  597. QD_XM_VAVLE = 0;
  598. QD_YD_VAVLE = 0;
  599. QD_TFK_VAVEL= 0;
  600. QD_TL_VAVLE = 0;
  601. QD_YBD_VAVLE = 0;
  602. QD_CS_OUT = 0;
  603. QD_XiaQieStep = 0;
  604. QD_MotorStep = 0;
  605. QD_TuiLianStep = 0;
  606. QD_TuiFangKuaiStep = 0;
  607. QD_SZ_OUT = 1;
  608. QD_GZ_VAVLE = 0;
  609. QD_TABLE_VAVLE = 0;
  610. AxisDecStop(X_AXIS);
  611. QD_YuanDianStep = 0;
  612. QD_BinLianStep = 0;
  613. QD_ShenJiangStep = 0;
  614. QD_BL_VAVLE = 0;
  615. cLengthErrorFlg = 0;
  616. QD_R_JD = 0;
  617. QD_R_UP_VAVLE = 0;
  618. QD_YL_VAVLE = 0;
  619. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  620. }
  621. }
  622. if(bAlarmStop)
  623. {
  624. bAlarmStop = 0;
  625. QD_XiaQieStep = 0;
  626. QD_AutoStep = 0;
  627. QD_MotorStep = 0;
  628. QD_TuiLianStep = 0;
  629. QD_TuiFangKuaiStep = 0;
  630. QD_YuanDianStep = 0;
  631. QD_XiaQieStep = 0;
  632. QD_MotorStep = 0;
  633. QD_TuiLianStep = 0;
  634. QD_TuiFangKuaiStep = 0;
  635. QD_ShenJiangStep = 0;
  636. QD_AutoDelay = dwTickCount;
  637. QD_MotorDelay = dwTickCount;
  638. QD_XiaQieDelay = dwTickCount;
  639. QD_KaDaiDelay = dwTickCount;
  640. QD_CSDelay = dwTickCount;
  641. QD_TBDelay = dwTickCount;
  642. QD_TFKDelay = dwTickCount;
  643. QD_TLDelay = dwTickCount;
  644. QD_CheckDelay = dwTickCount;
  645. SingOneFlg = 0;
  646. bRunning = 0;
  647. AxisDecStop(X_AXIS);
  648. QD_TABLE_VAVLE = 0;
  649. }
  650. }
  651. void QueDuan_Motor_CS(void)
  652. {
  653. static long save_buff,gou_zhen_buff,go_buff,jz_buff,go_length_buff,guo_lian_buff,xhg_buff,fz_buff,length_buff;
  654. user_datas[121]= QD_MotorStep;
  655. user_datas[122] = QD_AutoStep;
  656. user_datas[123]= go_length_buff;
  657. user_datas[124] = QD_BinLianStep;
  658. user_datas[126] = cRealPosY;
  659. user_datas[127] = cRealPos;
  660. switch(QD_MotorStep)
  661. {
  662. case 30:
  663. QD_MotorStep = 31;
  664. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  665. break;
  666. case 31:
  667. if(dwTickCount >= QD_MotorDelay)
  668. {
  669. gou_zhen_buff = cRealPos;
  670. save_buff = cRealPos;
  671. QD_JZ_DIR = QD_YDIR_P;
  672. if(QD_PARAM_DEC_MODE == 1) // 记忆长度模式
  673. {
  674. if(cZipCnt < 2)
  675. {
  676. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_FIRST_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  677. }
  678. else
  679. {
  680. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-length_buff);
  681. MoveChangSpeedPos(X_AXIS, QD_PARAM_BACK_LOW_SPEED,(PosToPulse(X_AXIS,QD_PARAM_Back_LOW_SPEED_LENGTH) + MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,5)));
  682. }
  683. }
  684. else if(QD_PARAM_DEC_MODE == 2) // 纯感应模式
  685. {
  686. if(QD_PARAM_LONG_MODE)
  687. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-(QD_PARAM_YL_TRANS_LENGTH));
  688. else
  689. MoveAction_Const_AccDec(X_AXIS, QD_DIR_P, QD_PARAM_BACK_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  690. }
  691. else //长度输入
  692. {
  693. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-(QD_PARAM_ZIPPER_LENGTH - QD_PARAM_OFFSET_LENGTH));
  694. MoveChangSpeedPos(X_AXIS, QD_PARAM_BACK_LOW_SPEED,(PosToPulse(X_AXIS,QD_PARAM_Back_LOW_SPEED_LENGTH) + MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,5)));
  695. }
  696. if(QD_PARAM_LONG_MODE)
  697. QD_MotorStep = 128;
  698. else
  699. QD_MotorStep = 32;
  700. }
  701. break;
  702. case 32:
  703. if(QD_PARAM_DEC_MODE == 1) // 记忆长度模式
  704. {
  705. if(cZipCnt < 2)
  706. {
  707. if(QD_GUO_LIAN_IN_UP)
  708. {
  709. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  710. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  711. fz_buff = cRealPos;
  712. QD_MotorStep = 33;
  713. }
  714. }
  715. else
  716. {
  717. if((cRealPos - gou_zhen_buff) >= (length_buff - QD_PARAM_DELAY_XM_LENGTH))QD_XM_VAVLE = 1;
  718. if(QD_PARAM_GOUZHEN_LENGTH != 0)
  719. {
  720. if((cRealPos - gou_zhen_buff) >= (length_buff - QD_PARAM_GOUZHEN_LENGTH))QD_GZ_VAVLE = 1;
  721. }
  722. if(!X_DRV)
  723. {
  724. QD_GZ_VAVLE = 1;
  725. QD_XM_VAVLE = 1;
  726. QD_MotorStep = 0;
  727. }
  728. }
  729. }
  730. else if(QD_PARAM_DEC_MODE == 2) // 纯感应模式
  731. {
  732. if(QD_PARAM_SPEED_MODE)
  733. {
  734. if(QD_GUO_LIAN_IN_UP)
  735. {
  736. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  737. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  738. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  739. fz_buff = cRealPos;
  740. QD_MotorStep = 33;
  741. }
  742. else if((cRealPos - save_buff) >= (length_buff - PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_ACC_SPEED))))
  743. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  744. }
  745. else
  746. {
  747. if(QD_GUO_LIAN_IN_UP)
  748. {
  749. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  750. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  751. fz_buff = cRealPos;
  752. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  753. QD_MotorStep = 33;
  754. }
  755. }
  756. }
  757. else
  758. {
  759. if((cRealPos - gou_zhen_buff) >= ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_OFFSET_LENGTH) - QD_PARAM_DELAY_XM_LENGTH))QD_XM_VAVLE = 1;
  760. if(QD_PARAM_GOUZHEN_LENGTH != 0)
  761. {
  762. if((cRealPos - gou_zhen_buff) >= (QD_PARAM_ZIPPER_LENGTH - QD_PARAM_GOUZHEN_LENGTH))QD_GZ_VAVLE = 1;
  763. }
  764. if(!X_DRV)
  765. {
  766. QD_GZ_VAVLE = 1;
  767. QD_XM_VAVLE = 1;
  768. QD_MotorStep = 0;
  769. }
  770. }
  771. break;
  772. case 33:
  773. if(QD_PARAM_DEC_MODE==1)
  774. {
  775. if(cZipCnt < 2)
  776. {
  777. if(QD_GUO_LIAN_IN_UP)fz_buff = cRealPos;
  778. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  779. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  780. if((cRealPos - fz_buff) >= QD_PARAM_DELAY_CHECK)
  781. {
  782. if(QD_GUO_LIAN_IN_DW)
  783. {
  784. guo_lian_buff = cRealPos;
  785. QD_MotorStep = 34;
  786. }
  787. }
  788. }
  789. else
  790. {
  791. }
  792. }
  793. else if(QD_PARAM_DEC_MODE == 2) // 纯感应模式
  794. {
  795. if(QD_GUO_LIAN_IN_UP)fz_buff = cRealPos;
  796. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  797. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  798. if((fz_buff - cRealPos) >= QD_PARAM_DELAY_CHECK)
  799. {
  800. if(QD_GUO_LIAN_IN_DW)
  801. {
  802. guo_lian_buff = cRealPos;
  803. QD_MotorStep = 34;
  804. }
  805. }
  806. }
  807. else
  808. {
  809. }
  810. break;
  811. case 34:
  812. if(QD_PARAM_DEC_MODE==1)
  813. {
  814. if(cZipCnt < 2)
  815. {
  816. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  817. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  818. if((cRealPos - guo_lian_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  819. {
  820. AxisEgmStop(X_AXIS);
  821. QD_MotorStep = 35;
  822. }
  823. }
  824. else
  825. {
  826. if((cRealPos - guo_lian_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  827. {
  828. AxisEgmStop(X_AXIS);
  829. QD_MotorStep = 35;
  830. }
  831. }
  832. }
  833. else if(QD_PARAM_DEC_MODE == 2) // 纯感应模式
  834. {
  835. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  836. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  837. if((guo_lian_buff - cRealPos) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  838. {
  839. AxisEgmStop(X_AXIS);
  840. QD_MotorStep = 35;
  841. }
  842. }
  843. else
  844. {
  845. }
  846. break;
  847. case 35:
  848. if(!X_DRV)
  849. {
  850. if(QD_PARAM_DEC_MODE == 2) // 纯感应模式
  851. {
  852. if(!X_DRV)
  853. {
  854. if(cZipCnt == 0);
  855. else if(cZipCnt == 1)
  856. {
  857. length_buff = save_buff - cRealPos;
  858. SetData32bits(1,length_buff - QD_PARAM_OFFSET_LENGTH - QD_PARAM_TC_LENGTH);
  859. }
  860. else
  861. {
  862. if((save_buff - cRealPos) >(length_buff + QD_PARAM_MAX_ERROR_LENGTH))
  863. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  864. else if((save_buff - cRealPos)<(length_buff - QD_PARAM_MAX_ERROR_LENGTH))
  865. QD_SetAlarmCode(QD_LENGTH_SHORT_ALARM);
  866. else;
  867. }
  868. QD_MotorStep = 0;
  869. }
  870. }
  871. else
  872. {
  873. if(cZipCnt == 1)
  874. {
  875. length_buff = cRealPos - save_buff;
  876. SetData32bits(1,length_buff + QD_PARAM_OFFSET_LENGTH);
  877. }
  878. if(cZipCnt == 0)
  879. {
  880. go_length_buff = cRealPos - save_buff;
  881. }
  882. }
  883. QD_XM_VAVLE = 1;
  884. QD_GZ_VAVLE = 1;
  885. QD_MotorStep = 0;
  886. }
  887. break;
  888. case 40:
  889. if(dwTickCount >= QD_MotorDelay)
  890. {
  891. jz_buff = cRealPos;
  892. if(QD_PARAM_SJZ_LENGTH == 0)
  893. {
  894. QD_JD_VAVEL = 0;
  895. }
  896. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_SJ_TIME;
  897. QD_MotorStep = 41;
  898. }
  899. break;
  900. case 41: if((dwTickCount >= QD_MotorDelay) || (QD_JD_VAVEL == 1))
  901. {
  902. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  903. QD_MotorStep = 42;
  904. }
  905. break;
  906. case 42:
  907. // 切断完成后拉电机动作
  908. if(dwTickCount >= QD_MotorDelay)
  909. {
  910. if(((QD_PARAM_SJZ_LENGTH) <= (jz_buff-cRealPos)))
  911. {
  912. QD_JD_VAVEL = 0;
  913. QD_MotorStep = 43;
  914. }
  915. else if(!X_DRV)
  916. {
  917. QD_JD_VAVEL = 0;
  918. QD_MotorStep = 43;
  919. }
  920. }
  921. break;
  922. case 43: // 切断完成后拉电机动作
  923. if(!X_DRV)
  924. {
  925. QD_MotorStep = 0;
  926. QD_MotorDelay = dwTickCount;
  927. }
  928. break;
  929. case 50:
  930. if(!Y_DRV)
  931. {
  932. QD_MotorStep = 51;
  933. QD_YL_DIR = QD_YL_DIR_P;
  934. if(!Y_DRV)AxisContinueMoveAcc(Y_AXIS, QD_PARAM_BACK_SPEED,QD_YL_DIR_P,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  935. QD_MotorDelay = dwTickCount + QD_PARAM_YL_SL_TIME;
  936. QD_YLBackDelay = dwTickCount + QD_PARAM_DELAY_YL_BACK;
  937. }
  938. break;
  939. case 51: if(dwTickCount >= QD_MotorDelay)
  940. {
  941. AxisEgmStop(Y_AXIS);
  942. QD_MotorStep = 52;
  943. }
  944. if(dwTickCount >= QD_YLBackDelay) QD_YL_VAVLE = 0;
  945. break;
  946. case 52: if(!Y_DRV)
  947. {
  948. QD_YL_VAVLE = 0;
  949. QD_MotorStep = 0;
  950. }
  951. break;
  952. case 61: // 前点定位数控模式
  953. if(QD_SZ_OUT)
  954. {
  955. QD_SZ_OUT = 0;
  956. QD_MotorDelay = dwTickCount + 50;
  957. }
  958. if(!QD_TL_VAVLE)
  959. {
  960. if(!QD_SHANG_MU_LIMIT_IN && (QD_TuiLianStep == 0))
  961. {
  962. QD_TuiLianStep = 1;
  963. }
  964. }
  965. QD_MotorStep = 62;
  966. break;
  967. case 62:
  968. if((QD_ShenJiangStep == 0) && QD_YL_ORIGIN_IN)
  969. {
  970. QD_MotorStep = 63;
  971. }
  972. case 63:
  973. if(dwTickCount >= QD_MotorDelay)
  974. {
  975. if(QD_QIAN_LIMIT_IN || QD_QIAN_DEC_IN)
  976. {
  977. QD_JZ_DIR = QD_YDIR_P;
  978. AxisMovePos(X_AXIS,20,-2000);
  979. QD_MotorDelay = dwTickCount + 1000;
  980. }
  981. QD_MotorStep = 64;
  982. QD_JD_VAVEL = 0;
  983. }
  984. break;
  985. case 64:
  986. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay) && !QD_SHANG_MU_LIMIT_IN && !QD_JD_IN)
  987. {
  988. go_buff = cRealPos;
  989. QD_JZ_DIR = QD_YDIR_N;
  990. if((cZipCnt > 0) || (QD_PARAM_DEC_MODE == 2))
  991. {
  992. MoveAction_Const_Stop_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);//
  993. }
  994. else
  995. {
  996. MoveAction_Const_Stop_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  997. }
  998. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  999. QD_MotorStep =65;
  1000. }
  1001. break;
  1002. case 65:
  1003. if(cZipCnt > 0)
  1004. {
  1005. if(QD_PARAM_DEC_MODE == 1) // 长度输入模式
  1006. {
  1007. if(((go_buff - cRealPos) > ((QD_PARAM_ZIPPER_LENGTH + QD_PARAM_OFFSET_LENGTH - QD_PARAM_TC_LENGTH - QD_PARAM_FZ_LENGTH) - (QD_PARAM_Go_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_ACC_SPEED))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || QD_QIAN_DEC_IN_UP)
  1008. {
  1009. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1010. QD_MotorStep =66;
  1011. }
  1012. }
  1013. else if(QD_PARAM_DEC_MODE == 2) //纯感应方式
  1014. {
  1015. if(QD_PARAM_LONG_MODE)
  1016. {
  1017. if(QD_QIAN_DEC_IN_UP)
  1018. {
  1019. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1020. QD_MotorStep =66;
  1021. }
  1022. }
  1023. else
  1024. {
  1025. if((QD_QIAN_DEC_IN_UP && !QD_PARAM_SPEED_MODE)
  1026. || ((QD_QIAN_DEC_IN_UP || ((go_buff - cRealPos) > (go_length_buff - (QD_PARAM_Go_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_ACC_SPEED))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) ) && QD_PARAM_SPEED_MODE))
  1027. {
  1028. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1029. QD_MotorStep =66;
  1030. }
  1031. }
  1032. }
  1033. else
  1034. {
  1035. if(((go_buff - cRealPos) > ((go_length_buff - QD_PARAM_TC_LENGTH - QD_PARAM_FZ_LENGTH) - (QD_PARAM_Go_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_ACC_SPEED))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || QD_QIAN_DEC_IN_UP)
  1036. {
  1037. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1038. QD_MotorStep =66;
  1039. }
  1040. }
  1041. }
  1042. else
  1043. {
  1044. if(QD_PARAM_DEC_MODE == 2) //纯感应方式
  1045. {
  1046. if(QD_QIAN_DEC_IN_UP)
  1047. {
  1048. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1049. QD_MotorStep =66;
  1050. }
  1051. }
  1052. else
  1053. QD_MotorStep =66;
  1054. }
  1055. break;
  1056. case 66:
  1057. if(QD_QIAN_LIMIT_IN_UP)
  1058. {
  1059. AxisEgmStop(X_AXIS);
  1060. QD_MotorDelay = dwTickCount + QD_PARAM_JD_DELAY;
  1061. QD_MotorStep = 67;
  1062. }
  1063. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1064. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1065. break;
  1066. case 67:
  1067. if(!X_DRV && (dwTickCount >= QD_MotorDelay))
  1068. {
  1069. QD_JD_VAVEL = 1;
  1070. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1071. QD_MotorStep = 68;
  1072. }
  1073. break;
  1074. case 68:
  1075. if(1)
  1076. {
  1077. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1078. QD_MotorStep = 69;
  1079. }
  1080. else if(dwTickCount >= QD_MotorDelay)
  1081. {
  1082. QD_SetAlarmCode(QD_JD_IN_ALARM);
  1083. }
  1084. break;
  1085. case 69:
  1086. if(dwTickCount >= QD_MotorDelay)
  1087. {
  1088. QD_TFK_VAVEL = 0;
  1089. QD_TL_VAVLE = 0;
  1090. QD_MotorStep = 0;
  1091. }
  1092. break;
  1093. case 128:
  1094. if(!X_DRV)
  1095. {
  1096. if(QD_QIAN_DEC_IN || QD_QIAN_LIMIT_IN)
  1097. {
  1098. QD_SetAlarmCode(QD_DEC_ALARM);
  1099. }
  1100. else
  1101. {
  1102. QD_MotorStep = 129;
  1103. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1104. QD_YL_VAVLE = 1;
  1105. if(!QD_PARAM_SJ_ENABLE)
  1106. {
  1107. QD_ShenJiangStep = 0;
  1108. QD_R_UP_VAVLE = 0;
  1109. QD_R_JD = 0;
  1110. }
  1111. else
  1112. {
  1113. if(QD_ShenJiangStep == 0)QD_ShenJiangStep = 1;
  1114. }
  1115. QD_YL_DIR = QD_YL_DIR_P;
  1116. }
  1117. }
  1118. else
  1119. {
  1120. if(QD_GUO_LIAN_IN_UP)
  1121. {
  1122. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1123. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1124. fz_buff = cRealPosY;
  1125. QD_MotorStep = 150;
  1126. }
  1127. else
  1128. {
  1129. if(QD_GOUZHEN_IN)
  1130. {
  1131. QD_SetAlarmCode(QD_GZ_ALARM);
  1132. }
  1133. }
  1134. }
  1135. break;
  1136. case 150:
  1137. if(dwTickCount >= QD_GZDelay)
  1138. {
  1139. QD_GZ_VAVLE = 1;
  1140. QD_MotorStep = 151;
  1141. }
  1142. break;
  1143. case 151:
  1144. if(QD_GUO_LIAN_IN_UP)fz_buff = cRealPos;
  1145. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  1146. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  1147. if((cRealPosY - fz_buff) >= QD_PARAM_DELAY_CHECK)
  1148. {
  1149. if(QD_GUO_LIAN_IN_DW)
  1150. {
  1151. guo_lian_buff = cRealPos;
  1152. QD_MotorStep = 152;
  1153. }
  1154. }
  1155. break;
  1156. case 152:
  1157. {
  1158. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  1159. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  1160. if((cRealPosY - guo_lian_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  1161. {
  1162. AxisEgmStop(Y_AXIS);
  1163. QD_MotorStep = 153;
  1164. }
  1165. }
  1166. break;
  1167. case 153:
  1168. {
  1169. if(!Y_DRV)
  1170. {
  1171. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1172. }
  1173. }
  1174. break;
  1175. case 129:
  1176. if(!QD_YL_ORIGIN_IN)
  1177. {
  1178. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_YL;
  1179. QD_MotorStep = 131;
  1180. }
  1181. else if(dwTickCount >= QD_MotorDelay)
  1182. QD_SetAlarmCode(QD_YL_LIMIT_ALARM);
  1183. break;
  1184. case 131:
  1185. if(dwTickCount >= QD_MotorDelay)
  1186. {
  1187. gou_zhen_buff = cRealPos;
  1188. save_buff = cRealPosY;
  1189. if(!Y_DRV)AxisContinueMoveAcc(Y_AXIS, QD_PARAM_YL_HIGH_SPEED,QD_YL_DIR_P,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  1190. QD_MotorStep = 132;
  1191. }
  1192. break;
  1193. case 132:
  1194. if(QD_GUO_LIAN_IN_UP)
  1195. {
  1196. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  1197. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1198. AxisChangeSpeed(Y_AXIS,QD_PARAM_YL_LOW_SPEED);
  1199. fz_buff = cRealPosY;
  1200. QD_MotorStep = 133;
  1201. }
  1202. break;
  1203. case 133:
  1204. if(QD_GUO_LIAN_IN_UP)fz_buff = cRealPosY;
  1205. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  1206. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  1207. if((fz_buff-cRealPosY) >= QD_PARAM_DELAY_CHECK)
  1208. {
  1209. if(QD_GUO_LIAN_IN_DW)
  1210. {
  1211. guo_lian_buff = cRealPos;
  1212. QD_MotorStep = 134;
  1213. }
  1214. }
  1215. break;
  1216. case 134:
  1217. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  1218. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  1219. if((guo_lian_buff-cRealPosY) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  1220. {
  1221. AxisEgmStop(Y_AXIS);
  1222. QD_XM_VAVLE = 1;
  1223. QD_MotorStep = 135;
  1224. }
  1225. break;
  1226. case 135:
  1227. if(!Y_DRV)
  1228. {
  1229. QD_YL_DIR = QD_YL_DIR_N;
  1230. AxisMovePos(Y_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1231. QD_MotorStep = 136;
  1232. }
  1233. break;
  1234. case 136:
  1235. if(cZipCnt == 0);
  1236. else if(cZipCnt == 1)
  1237. {
  1238. length_buff = save_buff - cRealPosY;
  1239. }
  1240. else
  1241. {
  1242. }
  1243. QD_MotorStep = 0;
  1244. break;
  1245. }
  1246. }
  1247. void QueDuan_BingLian(void)
  1248. {
  1249. static long bl_pos_buff;
  1250. user_datas[125]= bl_pos_buff - cRealPos;
  1251. switch(QD_BinLianStep)
  1252. {
  1253. case 0:break;
  1254. case 1:
  1255. bl_pos_buff = cRealPos;
  1256. QD_BinLianStep = 2;
  1257. break;
  1258. case 2:
  1259. if((bl_pos_buff - cRealPos) >= QD_PARAM_DELAY_HL_LENGTH)
  1260. {
  1261. QD_BL_VAVLE = 1;
  1262. QD_BinLianStep = 3;
  1263. }
  1264. break;
  1265. case 3:
  1266. if(QD_GUO_LIAN_IN_DW)
  1267. {
  1268. QD_BLDelay = dwTickCount + QD_PARAM_DELAY_BL_BACK;
  1269. QD_BinLianStep = 4;
  1270. }
  1271. break;
  1272. case 4:
  1273. if(dwTickCount >= QD_BLDelay)
  1274. {
  1275. QD_BL_VAVLE = 0;
  1276. QD_BinLianStep = 0;
  1277. }
  1278. break;
  1279. default:;
  1280. }
  1281. }
  1282. //不带过链感应长度输入电机长度
  1283. void QueDuan_Motor_NoGL(void)
  1284. {
  1285. static long save_buff,gou_zhen_buff,go_buff,jz_buff,go_length_buff,guo_lian_buff,fz_buff,length_buff;
  1286. static long save_pos_y;
  1287. user_datas[121]= QD_MotorStep;
  1288. user_datas[122] = QD_AutoStep;
  1289. user_datas[123]= go_length_buff;
  1290. user_datas[124] = QD_BinLianStep;
  1291. user_datas[126] = cRealPosY;
  1292. user_datas[127] = cRealPos;
  1293. switch(QD_MotorStep)
  1294. {
  1295. case 30:
  1296. QD_MotorStep = 31;
  1297. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  1298. break;
  1299. case 31:
  1300. if(dwTickCount >= QD_MotorDelay)
  1301. {
  1302. gou_zhen_buff = cRealPos;
  1303. save_buff = cRealPos;
  1304. QD_JZ_DIR = QD_YDIR_P;
  1305. if(QD_PARAM_DC_MODE) // 带钩针模式
  1306. {
  1307. if(QD_PARAM_DEC_MODE == 1) // 长度输入模式
  1308. MoveAction_Const_Back(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,PosToPulse(X_AXIS,((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH + QD_PARAM_OFFSET_LENGTH) - (QD_PARAM_Back_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,30))))));
  1309. else if(QD_PARAM_DEC_MODE == 2) // 纯感应模式
  1310. {
  1311. if(QD_PARAM_LONG_MODE)
  1312. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-(QD_PARAM_YL_TRANS_LENGTH));
  1313. else
  1314. MoveAction_Const_AccDec(X_AXIS, QD_DIR_P, QD_PARAM_BACK_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  1315. }
  1316. else //感应方式
  1317. {
  1318. if(cZipCnt < 2)
  1319. {
  1320. MoveAction_Const_AccDec(X_AXIS, QD_DIR_P, QD_PARAM_FIRST_SPEED,QD_PARAM_MIN_SPEED,10,30);
  1321. }
  1322. else
  1323. {
  1324. MoveAction_Const_Back(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,PosToPulse(X_AXIS,(length_buff - (QD_PARAM_Back_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,30))))));
  1325. }
  1326. }
  1327. }
  1328. else // 不带钩针
  1329. {
  1330. if(QD_PARAM_DEC_MODE==1) // 长度输入模式
  1331. {
  1332. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-(QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH + QD_PARAM_OFFSET_LENGTH));
  1333. MoveChangSpeedPos(X_AXIS, QD_PARAM_BACK_LOW_SPEED,(PosToPulse(X_AXIS,QD_PARAM_Back_LOW_SPEED_LENGTH) + MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,5)));
  1334. }
  1335. else if(QD_PARAM_DEC_MODE==2) // 纯感应模式
  1336. {
  1337. MoveAction_Const_AccDec(X_AXIS, QD_DIR_P, QD_PARAM_BACK_SPEED,1,10,30);
  1338. }
  1339. else // 感应方式
  1340. {
  1341. if(cZipCnt < 2)
  1342. {
  1343. MoveAction_Const_AccDec(X_AXIS, QD_DIR_P, QD_PARAM_FIRST_SPEED,1,10,30);
  1344. }
  1345. else
  1346. {
  1347. MoveAction_Const_Back(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,PosToPulse(X_AXIS,(length_buff - (QD_PARAM_Back_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,30))))));
  1348. }
  1349. }
  1350. }
  1351. if(QD_PARAM_LONG_MODE)
  1352. QD_MotorStep = 128;
  1353. else
  1354. QD_MotorStep = 32;
  1355. }
  1356. break;
  1357. case 32:
  1358. if(QD_PARAM_DC_MODE) // 带钩针模式
  1359. {
  1360. if(QD_PARAM_DEC_MODE == 1) // 长度输入模式
  1361. {
  1362. if(((cRealPos - gou_zhen_buff) > ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH + QD_PARAM_OFFSET_LENGTH) - QD_PARAM_GOUZHEN_LENGTH)))QD_GZ_VAVLE = 1;
  1363. if((cRealPos - gou_zhen_buff) >= ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH + QD_PARAM_OFFSET_LENGTH) - (QD_PARAM_DELAY_XM_LENGTH)))QD_XM_VAVLE = 1;
  1364. if(!X_DRV)
  1365. {
  1366. QD_YD_VAVLE = 1;
  1367. QD_XM_VAVLE = 1;
  1368. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1369. QD_MotorStep = 33;
  1370. }
  1371. else if(((cRealPos - save_buff) >= (QD_PARAM_ERROR_LENGTH + QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH + QD_PARAM_OFFSET_LENGTH)) && QD_GZ_VAVLE)
  1372. {
  1373. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1374. }
  1375. }
  1376. else if(QD_PARAM_DEC_MODE == 2)
  1377. {
  1378. if(QD_PARAM_SPEED_MODE)
  1379. {
  1380. if(QD_GUO_LIAN_IN_UP)
  1381. {
  1382. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  1383. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1384. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1385. QD_MotorStep = 33;
  1386. }
  1387. else if((cRealPos - save_buff) >= (length_buff - PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_ACC_SPEED))))
  1388. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1389. }
  1390. else
  1391. {
  1392. if(QD_GUO_LIAN_IN_UP)
  1393. {
  1394. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  1395. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1396. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1397. QD_MotorStep = 33;
  1398. }
  1399. }
  1400. }
  1401. else
  1402. {
  1403. if(cZipCnt < 2)
  1404. {
  1405. if(QD_GUO_LIAN_IN_UP)
  1406. {
  1407. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  1408. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1409. QD_MotorStep = 33;
  1410. }
  1411. }
  1412. else
  1413. {
  1414. if(((cRealPos - gou_zhen_buff) > ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH) - QD_PARAM_GOUZHEN_LENGTH)))QD_GZ_VAVLE = 1;
  1415. if((cRealPos - gou_zhen_buff) >= ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH) - (QD_PARAM_DELAY_XM_LENGTH)))QD_XM_VAVLE = 1;
  1416. if(!X_DRV)
  1417. {
  1418. QD_YD_VAVLE = 1;
  1419. QD_XM_VAVLE = 1;
  1420. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1421. QD_MotorStep = 33;
  1422. }
  1423. else if(((cRealPos - save_buff) >= (QD_PARAM_ERROR_LENGTH + QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH + QD_PARAM_OFFSET_LENGTH)) && QD_GZ_VAVLE)
  1424. {
  1425. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1426. }
  1427. }
  1428. }
  1429. }
  1430. else
  1431. {
  1432. if(QD_PARAM_DEC_MODE==1) // 长度输入模式
  1433. {
  1434. if((cRealPos - gou_zhen_buff) >= ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH + QD_PARAM_OFFSET_LENGTH) - (QD_PARAM_DELAY_XM_LENGTH)))QD_XM_VAVLE = 1;
  1435. if(!X_DRV)
  1436. {
  1437. QD_YD_VAVLE = 1;
  1438. QD_XM_VAVLE = 1;
  1439. QD_MotorStep = 0;
  1440. }
  1441. }
  1442. else if(QD_PARAM_DEC_MODE==2) // 纯感应模式
  1443. {
  1444. if(QD_GUO_LIAN_IN_UP)
  1445. {
  1446. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  1447. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1448. fz_buff = cRealPos;
  1449. QD_MotorStep = 33;
  1450. }
  1451. }
  1452. else //感应方式
  1453. {
  1454. if(QD_GUO_LIAN_IN_UP)
  1455. {
  1456. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  1457. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1458. fz_buff = cRealPos;
  1459. QD_MotorStep = 33;
  1460. }
  1461. }
  1462. }
  1463. break;
  1464. case 33:
  1465. if(QD_PARAM_DC_MODE) // 带钩针模式
  1466. {
  1467. if(QD_PARAM_DEC_MODE==1) // 长度输入模式
  1468. {
  1469. if(!X_DRV)
  1470. {
  1471. QD_MotorStep = 0;
  1472. }
  1473. }
  1474. else if(QD_PARAM_DEC_MODE==2) // 纯感应模式
  1475. {
  1476. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  1477. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  1478. if(QD_GOUZHEN_IN)
  1479. {
  1480. AxisEgmStop(X_AXIS);
  1481. QD_XM_VAVLE = 1;
  1482. QD_YD_VAVLE = 1;
  1483. QD_MotorStep = 34;
  1484. }
  1485. }
  1486. else
  1487. {
  1488. if(cZipCnt < 2)
  1489. {
  1490. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  1491. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  1492. if(QD_GOUZHEN_IN)
  1493. {
  1494. AxisEgmStop(X_AXIS);
  1495. QD_XM_VAVLE = 1;
  1496. QD_MotorStep = 34;
  1497. }
  1498. }
  1499. else
  1500. {
  1501. if(!X_DRV)
  1502. {
  1503. QD_MotorStep = 0;
  1504. }
  1505. }
  1506. }
  1507. }
  1508. else
  1509. {
  1510. if(QD_PARAM_DEC_MODE==1) // 长度输入模式
  1511. {
  1512. }
  1513. else if(QD_PARAM_DEC_MODE==2) //纯感应模式
  1514. {
  1515. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  1516. if((cRealPos - fz_buff) >= QD_PARAM_DELAY_CHECK)
  1517. {
  1518. if(QD_GUO_LIAN_IN_DW)
  1519. {
  1520. guo_lian_buff = cRealPos;
  1521. QD_MotorStep = 34;
  1522. }
  1523. }
  1524. }
  1525. else //感应方式
  1526. {
  1527. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  1528. if((cRealPos - fz_buff) >= QD_PARAM_DELAY_CHECK)
  1529. {
  1530. if(QD_GUO_LIAN_IN_DW)
  1531. {
  1532. guo_lian_buff = cRealPos;
  1533. QD_MotorStep = 34;
  1534. }
  1535. }
  1536. }
  1537. }
  1538. break;
  1539. case 34:
  1540. if(QD_PARAM_DC_MODE) // 带钩针模式
  1541. {
  1542. if(QD_PARAM_DEC_MODE==1) // 长度输入模式
  1543. {
  1544. }
  1545. else if(QD_PARAM_DEC_MODE==2) // 纯感应模式
  1546. {
  1547. // if(!X_DRV)
  1548. {
  1549. {
  1550. QD_YD_VAVLE = 1;
  1551. QD_JZ_DIR = QD_YDIR_N;
  1552. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1553. QD_MotorStep = 35;
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if(!X_DRV)
  1560. {
  1561. QD_YD_VAVLE = 1;
  1562. if(cZipCnt == 1)
  1563. {
  1564. length_buff = cRealPos - save_buff;
  1565. SetData32bits(1,length_buff - QD_PARAM_OFFSET_LENGTH + QD_PARAM_TC_LENGTH);
  1566. }
  1567. else if(cZipCnt == 0)
  1568. {
  1569. go_length_buff = cRealPos - save_buff;
  1570. }
  1571. else
  1572. {
  1573. if((cRealPos - save_buff) >(length_buff + QD_PARAM_MAX_ERROR_LENGTH))
  1574. {
  1575. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1576. cLengthErrorFlg = 1;
  1577. }
  1578. else if((cRealPos - save_buff)<(length_buff - QD_PARAM_MAX_ERROR_LENGTH))
  1579. {
  1580. QD_SetAlarmCode(QD_LENGTH_SHORT_ALARM);
  1581. cLengthErrorFlg = 1;
  1582. }
  1583. else;
  1584. }
  1585. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1586. QD_MotorStep = 35;
  1587. }
  1588. }
  1589. }
  1590. else
  1591. {
  1592. if(QD_PARAM_DEC_MODE==1) // 长度输入模式
  1593. {
  1594. }
  1595. else if(QD_PARAM_DEC_MODE==2) // 纯感应模式
  1596. {
  1597. if((cRealPos - guo_lian_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  1598. {
  1599. AxisEgmStop(X_AXIS);
  1600. QD_MotorStep = 35;
  1601. }
  1602. }
  1603. else //感应方式
  1604. {
  1605. if((cRealPos - guo_lian_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  1606. {
  1607. AxisEgmStop(X_AXIS);
  1608. QD_MotorStep = 35;
  1609. }
  1610. }
  1611. }
  1612. break;
  1613. case 35:
  1614. if(QD_PARAM_DC_MODE) // 带钩针模式
  1615. {
  1616. if(QD_PARAM_DEC_MODE == 1) // 长度输入模式
  1617. {
  1618. }
  1619. else if(QD_PARAM_DEC_MODE == 2) // 纯感应模式
  1620. {
  1621. if(!X_DRV)
  1622. {
  1623. if(cZipCnt == 0);
  1624. else if(cZipCnt == 1)
  1625. {
  1626. length_buff = cRealPos - save_buff;
  1627. SetData32bits(1,length_buff - QD_PARAM_OFFSET_LENGTH - QD_PARAM_TC_LENGTH);
  1628. }
  1629. else
  1630. {
  1631. if((cRealPos - save_buff) >(length_buff + QD_PARAM_MAX_ERROR_LENGTH))
  1632. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1633. else if((cRealPos - save_buff)<(length_buff - QD_PARAM_MAX_ERROR_LENGTH))
  1634. QD_SetAlarmCode(QD_LENGTH_SHORT_ALARM);
  1635. else;
  1636. }
  1637. QD_MotorStep = 0;
  1638. }
  1639. }
  1640. else
  1641. {
  1642. if(!X_DRV)
  1643. {
  1644. QD_MotorStep = 0;
  1645. }
  1646. }
  1647. }
  1648. else
  1649. {
  1650. if(QD_PARAM_DEC_MODE==1) // 长度输入模式
  1651. {
  1652. }
  1653. else if(QD_PARAM_DEC_MODE==2) // 纯感应模式
  1654. {
  1655. if(!X_DRV)
  1656. {
  1657. if(cZipCnt == 0);
  1658. else if(cZipCnt == 1)
  1659. {
  1660. length_buff = cRealPos - save_buff;
  1661. SetData32bits(1,length_buff - QD_PARAM_OFFSET_LENGTH - QD_PARAM_TC_LENGTH);
  1662. }
  1663. else
  1664. {
  1665. if((cRealPos - save_buff) >(length_buff + QD_PARAM_MAX_ERROR_LENGTH))
  1666. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1667. else if((cRealPos - save_buff)<(length_buff - QD_PARAM_MAX_ERROR_LENGTH))
  1668. QD_SetAlarmCode(QD_LENGTH_SHORT_ALARM);
  1669. else;
  1670. }
  1671. QD_MotorStep = 0;
  1672. }
  1673. }
  1674. else
  1675. {
  1676. if(!X_DRV)
  1677. {
  1678. if(cZipCnt == 1)
  1679. {
  1680. length_buff = cRealPos - save_buff;
  1681. SetData32bits(1,length_buff - QD_PARAM_OFFSET_LENGTH - QD_PARAM_TC_LENGTH);
  1682. }
  1683. else if(cZipCnt == 0)
  1684. {
  1685. go_length_buff = cRealPos - save_buff;
  1686. }
  1687. else
  1688. {
  1689. if((cRealPos - save_buff) >(length_buff + QD_PARAM_MAX_ERROR_LENGTH))
  1690. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1691. else if((cRealPos - save_buff)<(length_buff - QD_PARAM_MAX_ERROR_LENGTH))
  1692. QD_SetAlarmCode(QD_LENGTH_SHORT_ALARM);
  1693. else;
  1694. }
  1695. QD_MotorStep = 0;
  1696. }
  1697. }
  1698. }
  1699. break;
  1700. case 40:
  1701. if(dwTickCount >= QD_MotorDelay)
  1702. {
  1703. jz_buff = cRealPos;
  1704. QD_JZ_DIR = QD_YDIR_P;
  1705. if(QD_PARAM_SJZ_LENGTH == 0)
  1706. {
  1707. QD_JD_VAVEL = 0;
  1708. }
  1709. QD_MotorDelay = dwTickCount;
  1710. QD_MotorStep = 41;
  1711. }
  1712. break;
  1713. case 41: if((dwTickCount >= QD_MotorDelay) || (QD_JD_VAVEL == 1))
  1714. {
  1715. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  1716. QD_MotorStep = 42;
  1717. }
  1718. break;
  1719. case 42:
  1720. // 切断完成后拉电机动作
  1721. if(dwTickCount >= QD_MotorDelay)
  1722. {
  1723. if(QD_PARAM_GZ_BACK_DELAY_LENGTH<= (jz_buff - cRealPos))QD_GZ_VAVLE = 0;
  1724. if(((QD_PARAM_SJZ_LENGTH) <= (jz_buff - cRealPos)))
  1725. {
  1726. QD_JD_VAVEL = 0;
  1727. QD_GZ_VAVLE = 0;
  1728. QD_MotorStep = 43;
  1729. }
  1730. else if(!X_DRV)
  1731. {
  1732. QD_JD_VAVEL = 0;
  1733. QD_MotorStep = 43;
  1734. }
  1735. }
  1736. break;
  1737. case 43: // 切断完成后拉电机动作
  1738. if(!X_DRV)
  1739. {
  1740. QD_MotorStep = 0;
  1741. QD_MotorDelay = dwTickCount;
  1742. }
  1743. break;
  1744. case 50:
  1745. if(!Y_DRV)
  1746. {
  1747. QD_MotorStep = 51;
  1748. QD_YL_DIR = QD_YL_DIR_P;
  1749. // AxisMovePos(Y_AXIS,QD_PARAM_BACK_SPEED,QD_PARAM_YL_SL_LENGTH);
  1750. if(QD_PARAM_YL_SL_TIME != 0)
  1751. {
  1752. if(!Y_DRV)AxisContinueMoveAcc(Y_AXIS, QD_PARAM_BACK_SPEED,QD_YL_DIR_P,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  1753. QD_MotorDelay = dwTickCount + QD_PARAM_YL_SL_TIME;
  1754. }
  1755. else
  1756. QD_MotorDelay = dwTickCount;
  1757. QD_YLBackDelay = dwTickCount + QD_PARAM_DELAY_YL_BACK;
  1758. }
  1759. break;
  1760. case 51: if(dwTickCount >= QD_MotorDelay)
  1761. {
  1762. AxisEgmStop(Y_AXIS);
  1763. QD_MotorStep = 52;
  1764. }
  1765. if(dwTickCount >= QD_YLBackDelay) QD_YL_VAVLE = 0;
  1766. break;
  1767. case 52: if(dwTickCount >= QD_YLBackDelay)
  1768. {
  1769. QD_YL_VAVLE = 0;
  1770. QD_MotorStep = 0;
  1771. }
  1772. break;
  1773. case 61: // 前点定位数控模式
  1774. if(QD_SZ_OUT)
  1775. {
  1776. QD_SZ_OUT = 0;
  1777. QD_MotorDelay = dwTickCount + 50;
  1778. }
  1779. if(!QD_TL_VAVLE)
  1780. {
  1781. if(!QD_SHANG_MU_LIMIT_IN && (QD_TuiLianStep == 0))
  1782. {
  1783. QD_TuiLianStep = 1;
  1784. }
  1785. }
  1786. QD_CQ_VAVLE = 1;
  1787. QD_CQDelay = dwTickCount + QD_PARAM_CQ_TIME;
  1788. QD_MotorStep = 62;
  1789. break;
  1790. case 62:
  1791. if((QD_ShenJiangStep == 0) && QD_YL_ORIGIN_IN)
  1792. {
  1793. QD_MotorStep = 63;
  1794. }
  1795. case 63:
  1796. if(dwTickCount >= QD_MotorDelay)
  1797. {
  1798. if(QD_QIAN_LIMIT_IN || QD_QIAN_DEC_IN)
  1799. {
  1800. QD_JZ_DIR = QD_YDIR_P;
  1801. AxisMovePos(X_AXIS,20,-2000);
  1802. QD_MotorDelay = dwTickCount + 1000;
  1803. }
  1804. QD_MotorStep = 64;
  1805. QD_JD_VAVEL = 0;
  1806. }
  1807. break;
  1808. case 64:
  1809. if(!QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay) && !QD_SHANG_MU_LIMIT_IN && !QD_JD_IN)
  1810. {
  1811. go_buff = cRealPos;
  1812. QD_JZ_DIR = QD_YDIR_N;
  1813. if((cZipCnt > 0) || (QD_PARAM_DEC_MODE == 2))
  1814. {
  1815. if(!X_DRV)MoveAction_Const_Stop_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);//
  1816. }
  1817. else
  1818. {
  1819. if(!X_DRV)MoveAction_Const_Stop_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  1820. }
  1821. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1822. QD_MotorStep =65;
  1823. }
  1824. break;
  1825. case 65:
  1826. if(cZipCnt > 0)
  1827. {
  1828. if(QD_PARAM_DEC_MODE == 1) // 长度输入模式
  1829. {
  1830. if(((go_buff - cRealPos) > ((QD_PARAM_ZIPPER_LENGTH + QD_PARAM_OFFSET_LENGTH - QD_PARAM_TC_LENGTH - QD_PARAM_FZ_LENGTH) - (QD_PARAM_Go_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_ACC_SPEED))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || QD_QIAN_DEC_IN_UP)
  1831. {
  1832. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1833. QD_MotorStep =66;
  1834. }
  1835. }
  1836. else if(QD_PARAM_DEC_MODE == 2) //纯感应方式
  1837. {
  1838. if(QD_PARAM_LONG_MODE)
  1839. {
  1840. if(QD_QIAN_DEC_IN_UP)
  1841. {
  1842. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1843. QD_MotorStep =66;
  1844. }
  1845. }
  1846. else
  1847. {
  1848. if((QD_QIAN_DEC_IN_UP && !QD_PARAM_SPEED_MODE)
  1849. || ((QD_QIAN_DEC_IN_UP || ((go_buff - cRealPos) > (go_length_buff - (QD_PARAM_Go_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_ACC_SPEED))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) ) && QD_PARAM_SPEED_MODE))
  1850. {
  1851. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1852. QD_MotorStep =66;
  1853. }
  1854. }
  1855. }
  1856. else
  1857. {
  1858. if(((go_buff - cRealPos) > ((go_length_buff - QD_PARAM_TC_LENGTH - QD_PARAM_FZ_LENGTH) - (QD_PARAM_Go_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_ACC_SPEED))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || QD_QIAN_DEC_IN_UP)
  1859. {
  1860. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1861. QD_MotorStep =66;
  1862. }
  1863. }
  1864. }
  1865. else
  1866. {
  1867. if(QD_PARAM_DEC_MODE == 2) //纯感应方式
  1868. {
  1869. if(QD_QIAN_DEC_IN_UP)
  1870. {
  1871. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1872. QD_MotorStep =66;
  1873. }
  1874. }
  1875. else
  1876. QD_MotorStep =66;
  1877. }
  1878. break;
  1879. case 66:
  1880. if(QD_QIAN_LIMIT_IN_UP)
  1881. {
  1882. AxisEgmStop(X_AXIS);
  1883. QD_MotorDelay = dwTickCount + QD_PARAM_JD_DELAY;
  1884. QD_MotorStep = 67;
  1885. }
  1886. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1887. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1888. break;
  1889. case 67:
  1890. if(!X_DRV && (dwTickCount >= QD_MotorDelay))
  1891. {
  1892. QD_JD_VAVEL = 1;
  1893. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1894. QD_MotorStep = 68;
  1895. }
  1896. break;
  1897. case 68:
  1898. if(1)
  1899. {
  1900. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1901. QD_MotorStep = 69;
  1902. }
  1903. else if(dwTickCount >= QD_MotorDelay)
  1904. {
  1905. QD_SetAlarmCode(QD_JD_IN_ALARM);
  1906. }
  1907. break;
  1908. case 69:
  1909. if(dwTickCount >= QD_MotorDelay)
  1910. {
  1911. QD_YD_VAVLE = 0;
  1912. QD_TL_VAVLE = 0;
  1913. QD_MotorStep = 0;
  1914. }
  1915. break;
  1916. case 128:
  1917. if(!X_DRV)
  1918. {
  1919. if(QD_QIAN_DEC_IN || QD_QIAN_LIMIT_IN)
  1920. {
  1921. QD_SetAlarmCode(QD_DEC_ALARM);
  1922. }
  1923. else
  1924. {
  1925. QD_MotorStep = 129;
  1926. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1927. QD_YL_VAVLE = 1;
  1928. if(!QD_PARAM_SJ_ENABLE)
  1929. {
  1930. QD_ShenJiangStep = 0;
  1931. QD_R_UP_VAVLE = 0;
  1932. QD_R_JD = 0;
  1933. }
  1934. else
  1935. {
  1936. if(QD_ShenJiangStep == 0)QD_ShenJiangStep = 1;
  1937. }
  1938. QD_YL_DIR = QD_YL_DIR_P;
  1939. }
  1940. }
  1941. else
  1942. {
  1943. if(QD_GUO_LIAN_IN_UP)
  1944. {
  1945. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1946. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1947. QD_MotorStep = 150;
  1948. }
  1949. else
  1950. {
  1951. if(QD_GOUZHEN_IN)
  1952. {
  1953. QD_SetAlarmCode(QD_GZ_ALARM);
  1954. }
  1955. }
  1956. }
  1957. break;
  1958. case 150:
  1959. if(dwTickCount >= QD_GZDelay)
  1960. {
  1961. QD_GZ_VAVLE = 1;
  1962. QD_MotorStep = 151;
  1963. }
  1964. break;
  1965. case 151:
  1966. {
  1967. QD_MotorDelay = dwTickCount + 3000;
  1968. QD_MotorStep = 152;
  1969. }
  1970. break;
  1971. case 152:
  1972. {
  1973. if(QD_GOUZHEN_IN)
  1974. {
  1975. AxisEgmStop(X_AXIS);
  1976. QD_YD_VAVLE = 1;
  1977. QD_MotorStep = 153;
  1978. }
  1979. else if(dwTickCount >= QD_MotorDelay)
  1980. QD_SetAlarmCode(QD_GZ_ALARM);
  1981. }
  1982. break;
  1983. case 153:
  1984. {
  1985. if(!X_DRV)
  1986. {
  1987. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1988. }
  1989. }
  1990. break;
  1991. case 129:
  1992. if(!QD_YL_ORIGIN_IN)
  1993. {
  1994. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_YL;
  1995. QD_MotorStep = 131;
  1996. }
  1997. else if(dwTickCount >= QD_MotorDelay)
  1998. QD_SetAlarmCode(QD_YL_LIMIT_ALARM);
  1999. break;
  2000. case 131:
  2001. if(dwTickCount >= QD_MotorDelay)
  2002. {
  2003. gou_zhen_buff = cRealPos;
  2004. save_buff = cRealPosY;
  2005. if(!Y_DRV)AxisContinueMoveAcc(Y_AXIS, QD_PARAM_YL_HIGH_SPEED,QD_YL_DIR_P,QD_PARAM_START_SPEED,QD_PARAM_ACC_SPEED,QD_PARAM_ACC_SPEED);
  2006. QD_MotorStep = 132;
  2007. }
  2008. break;
  2009. case 132:
  2010. if(QD_GUO_LIAN_IN_UP)
  2011. {
  2012. QD_XMDelay = dwTickCount + QD_PARAM_DELAY_XM;
  2013. QD_GZDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  2014. AxisChangeSpeed(Y_AXIS,QD_PARAM_YL_LOW_SPEED);
  2015. QD_MotorStep = 133;
  2016. }
  2017. break;
  2018. case 133:
  2019. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  2020. if(dwTickCount >= QD_GZDelay)QD_GZ_VAVLE = 1;
  2021. if(QD_GOUZHEN_IN)
  2022. {
  2023. AxisEgmStop(Y_AXIS);
  2024. QD_XM_VAVLE = 1;
  2025. QD_YD_VAVLE = 1;
  2026. QD_MotorStep = 134;
  2027. }
  2028. break;
  2029. case 134:
  2030. if(!Y_DRV)
  2031. {
  2032. {
  2033. QD_YD_VAVLE = 1;
  2034. QD_YL_DIR = QD_YL_DIR_N;
  2035. AxisMovePos(Y_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  2036. QD_MotorStep = 135;
  2037. }
  2038. }
  2039. break;
  2040. case 135:
  2041. if(cZipCnt == 0);
  2042. else if(cZipCnt == 1)
  2043. {
  2044. length_buff = save_buff - cRealPosY;
  2045. }
  2046. else
  2047. {
  2048. }
  2049. QD_MotorStep = 0;
  2050. break;
  2051. }
  2052. }
  2053. //电机动作
  2054. void QueDuan_Motor(void) //
  2055. {
  2056. switch(QD_MACHINE_TYPE)
  2057. {
  2058. case QD_NO_CS_TUIFANGKUAI: QueDuan_Motor_CS();break;
  2059. case QD_NO_GL_TUIFANGKUAI:QueDuan_Motor_NoGL();break;
  2060. default:;
  2061. }
  2062. }
  2063. //超声方式下切
  2064. void QueDuan_XiaQue_CS(void)
  2065. {
  2066. switch(QD_XiaQieStep)
  2067. {
  2068. case 0:
  2069. break;
  2070. case 1:
  2071. QD_XiaQieStep = 2;
  2072. QD_GZ_VAVLE = 1;
  2073. QD_XiaQieDelay = dwTickCount + 1000;
  2074. break;
  2075. case 2:
  2076. if(((QD_XIA_MU_LIMIT_IN || !bRunning)&& (QD_PARAM_CS_MODE == 1)) || (QD_PARAM_CS_MODE == 0))
  2077. {
  2078. QD_XiaQieStep = 3;
  2079. QD_XiaQieDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  2080. }
  2081. else if(dwTickCount >= QD_XiaQieDelay)
  2082. {
  2083. QD_SetAlarmCode(QD_XM_DAOWEI);
  2084. }
  2085. break;
  2086. case 3:
  2087. if(dwTickCount >= QD_XiaQieDelay)
  2088. {
  2089. QD_TFK_VAVEL = 1;
  2090. QD_XiaQieDelay = dwTickCount + 1000;
  2091. QD_XiaQieStep = 4;
  2092. }
  2093. break;
  2094. case 4:
  2095. if(QD_GOUZHEN_IN)
  2096. {
  2097. cTuiFangKuaiCnt = 0;
  2098. QD_XM_VAVLE = 1;
  2099. if(bRunning)QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  2100. else
  2101. QD_XiaQieDelay = dwTickCount;
  2102. QD_XiaQieStep = 5;
  2103. }
  2104. else if((dwTickCount >= QD_XiaQieDelay))
  2105. {
  2106. if((cTuiFangKuaiCnt == 0) && bRunning)
  2107. {
  2108. QD_TFK_VAVEL = 0;
  2109. cTuiFangKuaiCnt++;
  2110. QD_XiaQieDelay = dwTickCount + 1000;
  2111. QD_XiaQieStep = 20;
  2112. }
  2113. else
  2114. QD_SetAlarmCode(QD_GZ_ALARM);
  2115. }
  2116. break;
  2117. case 5:
  2118. if(dwTickCount >= QD_XiaQieDelay)
  2119. {
  2120. QD_SM_VAVLE = 1;
  2121. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  2122. QD_XiaQieStep = 6;
  2123. }
  2124. break;
  2125. case 6:
  2126. if(QD_SHANG_MU_LIMIT_IN && (QD_XIA_MU_LIMIT_IN || (QD_PARAM_CS_MODE == 0)))
  2127. {
  2128. if(QD_PARAM_CS_MODE)
  2129. {
  2130. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  2131. QD_XiaQieStep = 100;
  2132. }
  2133. else
  2134. {
  2135. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY; //
  2136. QD_XiaQieStep = 7;
  2137. }
  2138. }
  2139. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  2140. break;
  2141. case 20:
  2142. if((dwTickCount >= QD_XiaQieDelay))
  2143. {
  2144. QD_XiaQieStep = 2;
  2145. }
  2146. break;
  2147. case 7:
  2148. if(dwTickCount >= QD_XiaQieDelay)
  2149. {
  2150. QD_SM_VAVLE = 0;
  2151. QD_XM_VAVLE = 0;
  2152. // QD_TFK_VAVEL = 0;
  2153. QD_BL_VAVLE = 0;
  2154. QD_YL_VAVLE = 0;
  2155. QD_GZ_VAVLE = 0;
  2156. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  2157. QD_XiaQieStep = 8;
  2158. }//
  2159. break;
  2160. case 8:
  2161. if(!QD_XIA_MU_LIMIT_IN && !QD_SHANG_MU_LIMIT_IN)
  2162. {
  2163. QD_XiaQieStep = 0;
  2164. if(QD_TuiLianStep == 0) QD_TuiLianStep = 1;
  2165. if(cLengthErrorFlg == 1)
  2166. {
  2167. cLengthErrorFlg = 0;
  2168. if(QD_MotorStep==0)QD_MotorStep = 40;
  2169. }
  2170. AddToTal(QD_QIE_DUAN_TOTAL_ADDR);
  2171. }
  2172. else if(dwTickCount >= QD_XiaQieDelay)
  2173. {
  2174. QD_SetAlarmCode(QD_SM_YUANWEI);
  2175. }
  2176. break;
  2177. case 100:
  2178. if(dwTickCount >= QD_XiaQieDelay)
  2179. {
  2180. if(QD_PARAM_CS_ENABLE)QD_CS_OUT = 1;
  2181. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  2182. QD_XiaQieStep = 101;
  2183. }
  2184. break;
  2185. case 101:
  2186. if(dwTickCount >= QD_XiaQieDelay)
  2187. {
  2188. QD_CS_OUT = 0;
  2189. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_COLD_TIME; //
  2190. QD_XiaQieStep = 7;
  2191. }
  2192. break;
  2193. }
  2194. }
  2195. void QueDuan_TuiLianNormal(void)
  2196. {
  2197. switch(QD_TuiLianStep)
  2198. {
  2199. case 0:
  2200. break;
  2201. case 1:
  2202. QD_TuiLianStep = 2;
  2203. QD_TFK_VAVEL = 1;
  2204. break;
  2205. case 2:
  2206. QD_TLDelay = dwTickCount+QD_PARAM_TL_DELAY;
  2207. QD_TuiLianStep = 3;
  2208. break;
  2209. case 3:
  2210. if(dwTickCount >= QD_TLDelay)
  2211. {
  2212. QD_TL_VAVLE = 1;
  2213. QD_TLDelay = dwTickCount;
  2214. QD_TuiLianStep = 4;
  2215. }
  2216. break;
  2217. case 4:
  2218. if(dwTickCount >= QD_TLDelay)
  2219. {
  2220. QD_TuiLianStep = 0;
  2221. }
  2222. break;
  2223. }
  2224. }
  2225. void QueDuan_TuiLianNoGL(void)
  2226. {
  2227. switch(QD_TuiLianStep)
  2228. {
  2229. case 0:
  2230. break;
  2231. case 1:
  2232. QD_TuiLianStep = 2;
  2233. break;
  2234. case 2:
  2235. if(!QD_YD_VAVLE)QD_TLDelay = dwTickCount + QD_PARAM_TL_DELAY;
  2236. else
  2237. QD_TLDelay = dwTickCount;
  2238. QD_YD_VAVLE = 1;
  2239. QD_TuiLianStep = 3;
  2240. break;
  2241. case 3:
  2242. if(dwTickCount >= QD_TLDelay)
  2243. {
  2244. QD_TL_VAVLE = 1;
  2245. QD_TLDelay = dwTickCount;
  2246. QD_TuiLianStep = 4;
  2247. }
  2248. break;
  2249. case 4:
  2250. if(dwTickCount >= QD_TLDelay)
  2251. {
  2252. QD_TuiLianStep = 0;
  2253. }
  2254. break;
  2255. }
  2256. }
  2257. void QueDuan_TuiLianAction(void)
  2258. {
  2259. switch(QD_MACHINE_TYPE)
  2260. {
  2261. case QD_NO_CS_TUIFANGKUAI:QueDuan_TuiLianNormal();break;
  2262. case QD_NO_GL_TUIFANGKUAI:QueDuan_TuiLianNoGL();break;
  2263. default:;
  2264. }
  2265. }
  2266. void QueDuan_XiaQue_NO_GL(void)
  2267. {
  2268. switch(QD_XiaQieStep)
  2269. {
  2270. case 0:
  2271. break;
  2272. case 1:
  2273. QD_YD_VAVLE = 1;
  2274. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  2275. QD_XiaQieStep = 2;
  2276. break;
  2277. case 2:
  2278. if(!QD_TL_VAVLE)
  2279. {
  2280. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  2281. QD_XiaQieStep = 3;
  2282. }
  2283. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_TL_ALARM);
  2284. break;
  2285. case 3:
  2286. if(dwTickCount >= QD_XiaQieDelay)
  2287. {
  2288. // if((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0))
  2289. {
  2290. QD_SM_VAVLE = 1;
  2291. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  2292. QD_XiaQieStep = 4;
  2293. }
  2294. }
  2295. break;
  2296. case 4:
  2297. if(QD_SHANG_MU_LIMIT_IN)
  2298. {
  2299. if(QD_PARAM_CS_MODE)
  2300. {
  2301. QD_XiaQieStep = 20;
  2302. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  2303. }
  2304. else
  2305. {
  2306. QD_XiaQieStep = 5;
  2307. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAYBACK_SM; //
  2308. }
  2309. }
  2310. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  2311. break;
  2312. case 5:
  2313. if(dwTickCount >= QD_XiaQieDelay)
  2314. {
  2315. QD_XM_VAVLE = 0;
  2316. if(!QD_PARAM_GZ_BACK_DELAY_LENGTH)QD_GZ_VAVLE = 0;
  2317. QD_SM_VAVLE = 0;
  2318. QD_YL_VAVLE = 0;
  2319. QD_BL_VAVLE = 0;
  2320. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  2321. QD_XiaQieStep = 6;
  2322. }
  2323. break;
  2324. case 6:
  2325. if(!QD_SHANG_MU_LIMIT_IN)
  2326. {
  2327. if(bRunning)
  2328. {
  2329. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  2330. }
  2331. if(!bRunning)QD_JD_VAVEL = 0;
  2332. QD_XiaQieStep = 0;
  2333. if(cLengthErrorFlg)
  2334. {
  2335. cLengthErrorFlg = 0;
  2336. if(QD_MotorStep==0)QD_MotorStep = 40;
  2337. }
  2338. AddToTal(QD_QIE_DUAN_TOTAL_ADDR);
  2339. }
  2340. else if(dwTickCount >= QD_XiaQieDelay)
  2341. {
  2342. QD_SetAlarmCode(QD_SM_DAOWEI);
  2343. }
  2344. break;
  2345. case 20:
  2346. if(dwTickCount >= QD_XiaQieDelay)
  2347. {
  2348. if(QD_PARAM_CS_ENABLE)QD_CS_OUT = 1;
  2349. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  2350. QD_XiaQieStep = 21;
  2351. }
  2352. break;
  2353. case 21:
  2354. if(dwTickCount >= QD_XiaQieDelay)
  2355. {
  2356. QD_CS_OUT = 0;
  2357. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_COLD_TIME; //
  2358. QD_XiaQieStep = 5;
  2359. }
  2360. break;
  2361. }
  2362. }
  2363. //切断动作
  2364. void QueDuan_XiaQue(void)
  2365. {
  2366. switch(QD_MACHINE_TYPE)
  2367. {
  2368. case QD_NO_CS_TUIFANGKUAI:QueDuan_XiaQue_CS();break;
  2369. case QD_NO_GL_TUIFANGKUAI:QueDuan_XiaQue_NO_GL();break;
  2370. default:;
  2371. }
  2372. }
  2373. #endif