XDQueduanChuantou.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549
  1. #include "global.h"
  2. #if XI_DONG_MACHINE
  3. unsigned long cSlowPusle;
  4. unsigned char bStartOnceTime,bOnceProcess;
  5. unsigned short cWorkCnt;
  6. unsigned char TryCnt = 0;
  7. unsigned short cTbCnt = 0;
  8. unsigned char ZhuangLiaoOkFlg = 0;
  9. unsigned char SongLaTouOkFlg = 0;
  10. unsigned char FirstStartFlg = 0;
  11. unsigned char cBackFlg = 0;
  12. static long save_limit_pos;
  13. void QDCT_ManualAction(void);
  14. void QDCT_JiaLianAction(void);
  15. void QDCT_AutoStepAction(void);
  16. void QDCT_TableAction(void);
  17. void QDCT_Motor(void);
  18. void QDCT_CheckStart(void);
  19. void QDCT_SL_Step(void);
  20. void QDCT_XiaQieAction(void);
  21. void QDCT_AlarmProtect(void);
  22. void QDCT_ZLT_Step(void);
  23. void QDCT_TuiLian(void);
  24. void QDCT_SongLian(void);
  25. void QDCT_ExtiActionX31(void)
  26. {
  27. if(cSeBiaoEn && !cSeBiaoOk)
  28. {
  29. cSeBiaoEn = 0;
  30. cSeBiaoOk = 1;
  31. SetRemainLength(X_AXIS,QDCT_SEBIAO_LENGTH,10);
  32. }
  33. }
  34. //故障报警
  35. void QDCT_SetAlarmCode(unsigned alarm_code)
  36. {
  37. SetAlarmCode(QDCT_ALARM_ADDR,alarm_code);
  38. QDCT_bAlarmStop = 1;
  39. }
  40. unsigned char QDCT_GetYL_Mode(void)
  41. {
  42. if(QDCT_PARAM_SET_ZIPPER_LENGTH > QDCT_PARAM_YL_TRANS_LENGTH)return 1;
  43. else return 0;
  44. }
  45. //初始化动作
  46. void QDCT_InitAction(void)
  47. {
  48. float buff_pulse,buff_dist;
  49. buff_pulse = QDCT_PARAM_CYCLE_PULSE;
  50. buff_dist = QDCT_PARAM_CYCLE_LENGTH;
  51. XGearRatio = buff_pulse/buff_dist;
  52. buff_pulse = QDCT_PARAM_YL_CYCLE_PULSE;
  53. buff_dist = QDCT_PARAM_YL_CYCLE_LENGTH;
  54. YGearRatio = buff_pulse/buff_dist;
  55. QDCT_SZ_OUT = QDCT_MOTOR_DISEN;
  56. }
  57. void QDCT_Action(void)
  58. {
  59. QDCT_AlarmProtect();
  60. QDCT_CheckStart();
  61. QDCT_TuiLian();
  62. QDCT_ZLT_Step();
  63. QDCT_TableAction();
  64. QDCT_SL_Step();
  65. QDCT_SongLian();
  66. QDCT_JiaLianAction();
  67. QDCT_XiaQieAction();
  68. QDCT_Motor();
  69. QDCT_ManualAction();
  70. QDCT_AutoStepAction();
  71. }
  72. void QDCT_AlarmProtect(void)
  73. {
  74. dwRealPos = GetPos(X_AXIS);
  75. if(QDCT_PARAM_BACK_ALARM_MODE)
  76. { //感应后限模式
  77. if(!bRunning)
  78. {
  79. if(QDCT_BACK_LIMIT_IN_UP)
  80. {
  81. if(X_DRV && (QDCT_bMotorBack) || (QDCT_MotorStep != 0)) //到后限不能再后退但可以点前进
  82. {
  83. QDCT_bMotorBack = 0;
  84. AxisEgmStop(X_AXIS);
  85. QDCT_JD_OUT = 0;
  86. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  87. }
  88. }
  89. }
  90. else
  91. {
  92. if(QDCT_BACK_LIMIT_IN_UP)
  93. {
  94. AxisEgmStop(X_AXIS);
  95. QDCT_JD_OUT = 0;
  96. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  97. }
  98. }
  99. }
  100. else
  101. {
  102. if(QDCT_GO_LIMIT_IN_UP) //数控后限模式
  103. {
  104. save_limit_pos = dwRealPos;
  105. SetData32bits(200,save_limit_pos);
  106. }
  107. if(QDCT_PARAM_MAX_BACK_LENGTH < (dwRealPos - save_limit_pos))
  108. {
  109. if(!bRunning)
  110. {
  111. if((QDCT_MotorStep == 0) && X_DRV && QDCT_bMotorBack) //到后限不能再后退但可以点前进
  112. {
  113. QDCT_bMotorBack = 0;
  114. AxisDecStop(X_AXIS);
  115. QDCT_JD_OUT = 0;
  116. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  117. }
  118. }
  119. else
  120. {
  121. AxisDecStop(X_AXIS);
  122. QDCT_JD_OUT = 0;
  123. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  124. }
  125. }
  126. }
  127. if(bRunning)
  128. {
  129. if(!QDCT_NO_ZIPPER_CHECK_IN)QDCT_SetAlarmCode(QDCT_NO_ZIPPER_ALARM);
  130. }
  131. }
  132. void QDCT_JiaLianAction(void)
  133. {
  134. if(QDCT_JZ_IN_UP && QDCT_GO_LIMIT_IN)
  135. {
  136. QDCT_YD_OUT = 0;
  137. QDCT_TL_OUT = 0;
  138. }
  139. if(QDCT_JiaLianStep == 1)
  140. {
  141. QDCT_JD_Delay = dwTickCount + QDCT_PARAM_JD_DELAY;
  142. QDCT_JiaLianStep = 2;
  143. }
  144. else if((QDCT_JiaLianStep == 2) && (dwTickCount >= QDCT_JD_Delay))
  145. {
  146. QDCT_JD_OUT = 1;
  147. QDCT_JD_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  148. QDCT_JiaLianStep = 3;
  149. }
  150. else if(QDCT_JiaLianStep == 3)
  151. {
  152. if(QDCT_JZ_IN)
  153. {
  154. QDCT_JD_Delay = dwTickCount + QDCT_PARAM_KL_DELAY;
  155. QDCT_TL_OUT = 0;
  156. QDCT_YD_OUT = 0;
  157. QDCT_JiaLianStep = 4;
  158. }
  159. else if(dwTickCount >= QDCT_JD_Delay)
  160. {
  161. QDCT_SetAlarmCode(QDCT_JD_ALARM);
  162. }
  163. }
  164. else if(QDCT_JiaLianStep == 4)
  165. {
  166. if(QDCT_PARAM_KL_TIME)
  167. {
  168. QDCT_JiaLianStep = 5;
  169. }
  170. else
  171. {
  172. QDCT_JiaLianStep = 7;
  173. }
  174. }
  175. else if((QDCT_JiaLianStep == 5) && (dwTickCount >= QDCT_JD_Delay))
  176. {
  177. QDCT_KL_OUT = 1;
  178. QDCT_JiaLianStep = 6;
  179. QDCT_JD_Delay = dwTickCount + QDCT_PARAM_KL_TIME;
  180. }
  181. else if((QDCT_JiaLianStep == 6) && (dwTickCount >= QDCT_JD_Delay))
  182. {
  183. QDCT_KL_OUT = 0;
  184. QDCT_JiaLianStep = 7;
  185. }
  186. else if((QDCT_JiaLianStep == 7))
  187. {
  188. QDCT_JiaLianStep = 0;
  189. }
  190. }
  191. //自动动作
  192. void QDCT_AutoStepAction(void)
  193. {
  194. if(bRunning)
  195. {
  196. if(QDCT_AutoStep == 1)
  197. {
  198. QDCT_AutoStep = 2;
  199. QDCT_ZhenDongStep = 1;
  200. if(QDCT_ZhuangLiaoStep == 0)QDCT_ZhuangLiaoStep = 1;
  201. }
  202. else if((QDCT_AutoStep == 2) && (dwTickCount >= QDCT_AutoDelay))
  203. {
  204. QDCT_AutoStep = 3;
  205. }
  206. else if(QDCT_AutoStep == 3)
  207. {
  208. if(QDCT_MotorStep == 0)
  209. {
  210. QDCT_MotorStep = 61;
  211. ZhuangLiaoOkFlg = 0;
  212. QDCT_AutoStep = 4;
  213. }
  214. }
  215. else if(QDCT_AutoStep == 4)
  216. {
  217. QDCT_AutoStep = 5;
  218. }
  219. else if(QDCT_AutoStep == 5)
  220. {
  221. if(QDCT_ZhuangLiaoStep == 0)QDCT_ZhuangLiaoStep = 1;
  222. QDCT_AutoStep = 6;
  223. }
  224. else if(QDCT_AutoStep == 6)
  225. {
  226. if(QDCT_ZhuangLiaoStep == 0)
  227. {
  228. QDCT_AutoStep = 7;
  229. }
  230. }
  231. else if(QDCT_AutoStep == 7)
  232. {
  233. QDCT_AutoStep = 8;
  234. }
  235. else if(QDCT_AutoStep == 8)
  236. {
  237. QDCT_AutoStep = 9;
  238. }
  239. else if(QDCT_AutoStep == 9)
  240. {
  241. if(QDCT_MotorStep == 0)
  242. {
  243. QDCT_AutoStep = 10;
  244. }
  245. }
  246. else if(QDCT_AutoStep == 10)
  247. {
  248. QDCT_AutoStep = 11;
  249. }
  250. else if(QDCT_AutoStep == 11)
  251. {
  252. if((QDCT_MotorStep == 0) && (QDCT_ZhuangLiaoStep == 0)) //
  253. {
  254. if(QDCT_SEBIAO_MODE)
  255. QDCT_MotorStep = 1;
  256. else
  257. QDCT_MotorStep = 30;
  258. QDCT_AutoStep = 12;
  259. }
  260. }
  261. else if(QDCT_AutoStep == 12)
  262. {
  263. if(QDCT_MotorStep == 0)
  264. {
  265. ZhuangLiaoOkFlg = 0;
  266. if(QDCT_ZhuangLiaoStep == 0)QDCT_ZhuangLiaoStep = 1;
  267. QDCT_AutoStep = 13;
  268. }
  269. }
  270. else if(QDCT_AutoStep == 13)
  271. {
  272. QDCT_AutoStep = 14;
  273. }
  274. else if(QDCT_AutoStep == 14)
  275. {
  276. if(bStartOnceTime)
  277. {
  278. bStartOnceTime = 0;
  279. cBackFlg = 1;
  280. QDCT_AutoStep = 0;
  281. bRunning = 0;
  282. }
  283. else
  284. {
  285. if(QDCT_XiaQieStep == 0)
  286. {
  287. QDCT_XiaQieStep = 1;
  288. QDCT_AutoStep = 15;
  289. }
  290. }
  291. }
  292. else if(QDCT_AutoStep == 15)
  293. {
  294. if(((QDCT_XiaQieStep == 0) || (QDCT_XiaQieStep == 6)) && !QDCT_SQ_LIMIT_IN)
  295. {
  296. if(QDCT_MotorStep == 0)
  297. {
  298. QDCT_MotorStep = 40;
  299. QDCT_AutoStep = 16;
  300. if((QDCT_SongLianStep == 0) && QDCT_GetYL_Mode())QDCT_SongLianStep = 1;
  301. }
  302. }
  303. }
  304. else if((QDCT_AutoStep == 16) && (QDCT_MotorStep == 0) && (QDCT_SongLianStep == 0))
  305. {
  306. CalProSP(QDCT_SPEED_ADDR); //计算生产速度
  307. AddToTal(QDCT_TOTAL_ADDR); //生产总量加1并保存
  308. AddToTal(QDCT_NOWTOTAL_ADDR); //生产总量加1并保存
  309. cWorkCnt++;
  310. dwZipCnt++;
  311. cTbCnt++;
  312. if(cTbCnt >= QDCT_PARAM_TABLE_NUM)
  313. {
  314. QDCT_TB_OUT = 1;
  315. cTbCnt = 0;
  316. QDCT_TableDelay = dwTickCount + QDCT_PARAM_TABLE_TIME;
  317. }
  318. if(QDCT_ZHA_STOP_TIME == 0)
  319. {
  320. if(GetTotal(QDCT_NOWTOTAL_ADDR) >= GetTotal(QDCT_SETTOTAL_ADDR))
  321. {
  322. bStartOnceTime = 0;
  323. QDCT_SetAlarmCode(QDCT_TOTAL_ALARM);
  324. }
  325. else
  326. {
  327. QDCT_AutoStep = 17;
  328. }
  329. }
  330. else
  331. {
  332. if(GetTotal(QDCT_NOWTOTAL_ADDR) >= GetTotal(QDCT_SETTOTAL_ADDR))
  333. {
  334. ClrcToTal(QDCT_NOWTOTAL_ADDR);
  335. QDCT_AutoDelay = dwTickCount + QDCT_ZHA_STOP_TIME;
  336. QDCT_AutoStep = 17;
  337. }
  338. else
  339. {
  340. QDCT_AutoDelay = dwTickCount;
  341. QDCT_AutoStep = 17;
  342. }
  343. }
  344. }
  345. else if((QDCT_AutoStep == 17) && (dwTickCount >= QDCT_AutoDelay))
  346. {
  347. {
  348. QDCT_AutoDelay = dwTickCount + QDCT_PARAM_CYCLE_DELAY;
  349. QDCT_AutoStep = 2;
  350. }
  351. }
  352. }
  353. }
  354. void QDCT_SongLian(void)
  355. {
  356. switch(QDCT_SongLianStep)
  357. {
  358. case 0:
  359. break;
  360. case 1:
  361. AxisMovePos(Y_AXIS,QDCT_PARAM_YL_CUT_SPEED,QDCT_PARAM_YL_CUT_LENGTH);
  362. QDCT_SongLianStep = 2;
  363. break;
  364. case 2:
  365. if(!Y_DRV)QDCT_SongLianStep = 3;
  366. break;
  367. case 3:
  368. QDCT_SongLianStep = 4;
  369. break;
  370. case 4:
  371. QDCT_SongLianStep = 0;
  372. break;
  373. default:;
  374. }
  375. }
  376. void QDCT_TuiLian(void)
  377. {
  378. switch(QDCT_TuiLianStep)
  379. {
  380. case 0:
  381. break;
  382. case 1:
  383. QDCT_TuiLianStep = 2;
  384. break;
  385. case 2:
  386. if(QDCT_SQ_LIMIT_IN)
  387. QDCT_SetAlarmCode(QDCT_SQ_LIMIT_ALARM);
  388. else
  389. {
  390. if(!QDCT_YD_OUT)QDCT_TLDelay = dwTickCount + QDCT_PARAM_TL_DELAY;
  391. else
  392. QDCT_TLDelay = dwTickCount;
  393. QDCT_YD_OUT = 1;
  394. QDCT_TuiLianStep = 3;
  395. }
  396. break;
  397. case 3:
  398. if(dwTickCount >= QDCT_TLDelay)
  399. {
  400. QDCT_TL_OUT = 1;
  401. QDCT_TLDelay = dwTickCount;
  402. QDCT_TuiLianStep = 4;
  403. }
  404. break;
  405. case 4:
  406. if(dwTickCount >= QDCT_TLDelay)
  407. {
  408. QDCT_TuiLianStep = 0;
  409. }
  410. break;
  411. }
  412. }
  413. //台面电机动作
  414. void QDCT_TableAction(void)
  415. {
  416. if(QDCT_TB_OUT && (dwTickCount >= QDCT_TableDelay))QDCT_TB_OUT = 0;
  417. }
  418. void QDCT_CheckStart(void)
  419. {
  420. if(bRunning)
  421. QDCT_PARAM_RUN_STATE = 1;
  422. else
  423. QDCT_PARAM_RUN_STATE = 0;
  424. //启动 自动启动 单一自动
  425. if(START_IN_UP || bStart || QDCT_bOnceStart)
  426. {
  427. if(QDCT_bOnceStart)
  428. {
  429. QDCT_bOnceStart = 0;
  430. bStartOnceTime = 1;
  431. dwZipCnt = 0;
  432. }
  433. bStart = 0;
  434. if(!QDCT_NO_ZIPPER_CHECK_IN)QDCT_SetAlarmCode(QDCT_NO_ZIPPER_ALARM);
  435. else if(QDCT_LTCZ_IN)QDCT_SetAlarmCode(QDCT_LTCZ_ALARM);
  436. else if(!QDCT_HSL_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_HSL_ORIGIN_ALARM);
  437. else if(QDCT_HSL_LIMIT_IN)QDCT_SetAlarmCode(QDCT_HSL_LIMIT_ALARM);
  438. else if(!QDCT_XM_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  439. else if(QDCT_SQ_LIMIT_IN)QDCT_SetAlarmCode(QDCT_SQ_LIMIT_ALARM);
  440. else if(QDCT_GO_LIMIT_IN && QDCT_JZ_IN && QDCT_HSL_ORIGIN_IN && !QDCT_SL_LIMIT_IN)
  441. {
  442. if(!bRunning && (QDCT_AutoStep == 0) && (GetAlarmCode(QDCT_ALARM_ADDR) == 0))
  443. {
  444. bRunning = 1;
  445. QDCT_AutoStep = 4;
  446. cWorkCnt = 0;
  447. TryCnt = 0;
  448. SongLaTouOkFlg = 1;
  449. dwZipCnt = 0;
  450. FirstStartFlg = 0;
  451. cBackFlg = 0;
  452. if(QDCT_GetYL_Mode())
  453. {
  454. QDCT_YL_WORK_OUT = 1;
  455. }
  456. else QDCT_YL_WORK_OUT = 0;
  457. }
  458. }
  459. else
  460. {
  461. if(!bRunning && (QDCT_AutoStep == 0) && (GetAlarmCode(QDCT_ALARM_ADDR) == 0))
  462. {
  463. bRunning = 1;
  464. QDCT_AutoStep = 1;
  465. cWorkCnt = 0;
  466. TryCnt = 0;
  467. SongLaTouOkFlg = 1;
  468. dwZipCnt = 0;
  469. FirstStartFlg = 1;
  470. cBackFlg = 0;
  471. if(QDCT_GetYL_Mode())
  472. {
  473. QDCT_YL_WORK_OUT = 1;
  474. }
  475. else QDCT_YL_WORK_OUT = 0;
  476. }
  477. }
  478. }
  479. if(bStop)
  480. {
  481. bStop = 0;
  482. if(bRunning)bStartOnceTime = 1;
  483. }
  484. //停止
  485. if(STOP_IN_UP)
  486. {
  487. {
  488. AxisDecStop(X_AXIS);
  489. AxisDecStop(Y_AXIS);
  490. bRunning = 0;
  491. QDCT_bOnceStart = 0;
  492. bStop = 0;
  493. bStartOnceTime = 0;
  494. QDCT_AutoStep = 0;
  495. QDCT_ZhuangLiaoStep = 0;
  496. QDCT_MotorStep = 0;
  497. QDCT_JiaLianStep = 0;
  498. QDCT_XiaQieStep = 0;
  499. QDCT_ZhenDongStep = 0;
  500. QDCT_SongLiaoStep = 0;
  501. QDCT_TuiLianStep =0;
  502. QDCT_SongLianStep = 0;
  503. QDCT_CS_OUT = 0;
  504. QDCT_SQ_OUT = 0;
  505. QDCT_XM_OUT = 0;
  506. QDCT_JD_OUT = 0;
  507. QDCT_SL_OUT = 0;
  508. QDCT_JLT_OUT= 0;
  509. QDCT_HSL_OUT = 0;
  510. QDCT_KL_OUT = 0;
  511. QDCT_TL_OUT = 0;
  512. QDCT_YD_OUT = 0;
  513. QDCT_YL_WORK_OUT = 0;
  514. QDCT_YL_OUT = 0;
  515. cBackFlg = 0;
  516. QDCT_SZ_OUT = QDCT_MOTOR_DISEN;
  517. if(GetAlarmCode(QDCT_ALARM_ADDR) != 0)QDCT_SetAlarmCode(QDCT_NO_ALARM);
  518. if(!X_DRV && (QDCT_GO_DEC_IN) && !bRunning && (QDCT_MotorStep == 0))
  519. {
  520. QDCT_MotorStep = 20;
  521. }
  522. }
  523. }
  524. if(QDCT_bAlarmStop)
  525. {
  526. bRunning = 0;
  527. QDCT_bOnceStart = 0;
  528. QDCT_bAlarmStop = 0;
  529. bStartOnceTime = 0;
  530. AxisDecStop(X_AXIS);
  531. QDCT_AutoStep = 0;
  532. QDCT_ZhuangLiaoStep = 0;
  533. QDCT_MotorStep = 0;
  534. QDCT_JiaLianStep = 0;
  535. QDCT_XiaQieStep = 0;
  536. QDCT_ZhenDongStep = 0;
  537. QDCT_SongLiaoStep = 0;
  538. QDCT_SongLianStep = 0;
  539. QDCT_CS_OUT = 0;
  540. QDCT_SQ_OUT = 0;
  541. }
  542. }
  543. //电机控制动作
  544. void QDCT_Motor(void) //
  545. {
  546. static long save_buff,length_buff,gou_zhen_buff,back_dec_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  547. long len_buf;
  548. short *revise_buff;
  549. switch(QDCT_MotorStep)
  550. {
  551. case 1:
  552. QDCT_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  553. QDCT_MotorStep = 2;
  554. break;
  555. case 2:
  556. if(dwTickCount >= QDCT_MotorDelay)
  557. {
  558. back_dec_buff = dwRealPos;
  559. if(dwZipCnt == 0)
  560. {
  561. cSeBiaoOk = 0;
  562. cSeBiaoEn = 1;
  563. AxisContinueMove(X_AXIS,20,QDCT_DIR_P);
  564. }
  565. else
  566. {
  567. AxisContinueMove(X_AXIS,QDCT_PARAM_JJBACK_SPEED,QDCT_DIR_P);
  568. }
  569. QDCT_MotorStep = 3;
  570. }
  571. break;
  572. case 3:
  573. if(dwZipCnt != 0)
  574. {
  575. if(QDCT_PARAM_SET_ZIPPER_LENGTH >= (QDCT_SEBIAO_LENGTH + QDCT_REMAIN_CHECK_LENGTH))
  576. {
  577. cSeBiaoOk = 0;
  578. cSeBiaoEn = 1;
  579. }
  580. else
  581. {
  582. if((dwRealPos - back_dec_buff) >= (QDCT_PARAM_SET_ZIPPER_LENGTH - QDCT_SEBIAO_LENGTH - QDCT_REMAIN_CHECK_LENGTH))
  583. {
  584. cSeBiaoOk = 0;
  585. cSeBiaoEn = 1;
  586. }
  587. }
  588. }
  589. if((dwRealPos - back_dec_buff) > (QDCT_PARAM_SET_ZIPPER_LENGTH - (QDCT_BACK_LOWSPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QDCT_PARAM_JJBACK_SPEED,20,30)))))
  590. {
  591. if(X_DRV)MoveChangSpeed(X_AXIS,20);
  592. }
  593. if(cSeBiaoOk)
  594. {
  595. cSeBiaoOk = 0;
  596. cSeBiaoEn = 0;
  597. QDCT_MotorStep = 4;
  598. }
  599. break;
  600. case 4:
  601. if(!X_DRV)
  602. {
  603. QDCT_MotorStep = 0;
  604. }
  605. break;
  606. case 20:
  607. {
  608. if(QDCT_SZ_OUT == QDCT_MOTOR_DISEN)
  609. {
  610. QDCT_SZ_OUT = QDCT_MOTOR_EN;
  611. QDCT_MotorDelay = dwTickCount + 50;
  612. }
  613. QDCT_MotorStep = 21;
  614. }
  615. break;
  616. case 21:
  617. if(dwTickCount >= QDCT_MotorDelay)
  618. {
  619. QDCT_DIR_OUT = QDCT_Y_DIR_N;
  620. AxisMovePos(X_AXIS,20,-QDCT_PARAM_ON_BACK_LENGTH);
  621. QDCT_MotorStep = 22;
  622. }
  623. break;
  624. case 22:
  625. if(!X_DRV)
  626. {
  627. QDCT_MotorStep = 0;
  628. }
  629. break;
  630. case 30:
  631. if(QDCT_SZ_OUT == QDCT_MOTOR_DISEN)
  632. {
  633. QDCT_SZ_OUT = QDCT_MOTOR_EN;
  634. QDCT_MotorDelay = dwTickCount + 50;
  635. }
  636. QDCT_MotorDelay = dwTickCount + QDCT_PARAM_DELAY_BACK;
  637. QDCT_MotorStep = 31;
  638. break;
  639. case 31:
  640. if(dwTickCount >= QDCT_MotorDelay)
  641. {
  642. gou_zhen_buff = dwRealPos;
  643. save_buff = dwRealPos;
  644. QDCT_MotorDelay = dwTickCount + QDCT_PARAM_XM_START_TIME;
  645. QDCT_DIR_OUT = QDCT_Y_DIR_N;
  646. if(QDCT_GetYL_Mode())
  647. {
  648. len_buf = QDCT_PARAM_YL_TRANS_LENGTH - QDCT_YL_MOTOR_SAFE_LENGTH;
  649. MoveAction_Pulse2_AccDec(X_AXIS,PosToPulse(X_AXIS,len_buf),PosToPulse(X_AXIS,QDCT_PARAM_PUTIN_SPEED_LENGTH),PosToPulse(X_AXIS,0),QDCT_PARAM_JJBACK_SPEED,QDCT_PARAM_PUTIN_SPEED,1, 5,10);
  650. QDCT_MotorStep = 132;
  651. }
  652. else
  653. {
  654. MoveAction_Pulse2_AccDec(X_AXIS,PosToPulse(X_AXIS,QDCT_PARAM_SET_ZIPPER_LENGTH),PosToPulse(X_AXIS,QDCT_PARAM_PUTIN_SPEED_LENGTH),PosToPulse(X_AXIS,0),QDCT_PARAM_JJBACK_SPEED,QDCT_PARAM_PUTIN_SPEED,1, 5,10);
  655. QDCT_MotorStep = 32;
  656. }
  657. }
  658. break;
  659. case 32:
  660. if(dwTickCount >= QDCT_MotorDelay)
  661. {
  662. back_buff = dwRealPos;
  663. QDCT_MotorStep = 33;
  664. }
  665. break;
  666. case 33:
  667. if((dwRealPos - back_buff) >= (QDCT_PARAM_PUTIN_LENGTH))
  668. {
  669. QDCT_JLT_OUT = 1;
  670. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  671. QDCT_MotorStep = 34;
  672. }
  673. else if(!X_DRV)
  674. {
  675. QDCT_JLT_OUT = 1;
  676. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  677. QDCT_MotorStep = 34;
  678. }
  679. break;
  680. case 34:
  681. if(!QDCT_JLT_IN)
  682. {
  683. QDCT_XM_OUT = 0;
  684. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  685. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  686. QDCT_MotorStep = 35;
  687. }
  688. else if(!X_DRV && !QDCT_JLT_IN)
  689. {
  690. QDCT_XM_OUT = 0;
  691. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  692. QDCT_MotorStep = 35;
  693. }
  694. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_JLT_ALARM);
  695. break;
  696. case 35:
  697. if(!X_DRV && QDCT_XM_ORIGIN_IN)
  698. {
  699. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  700. QDCT_MotorStep = 36;
  701. }
  702. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  703. break;
  704. case 36:
  705. if(!X_DRV)
  706. {
  707. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  708. QDCT_DIR_OUT = QDCT_Y_DIR_P;
  709. AxisMovePosAccDec(X_AXIS,QDCT_PARAM_JJGO_SPEED,QDCT_PARAM_FZ_LENGTH,1,10,10);
  710. QDCT_MotorStep = 37;
  711. }
  712. break;
  713. case 37:
  714. if(!X_DRV)
  715. {
  716. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  717. QDCT_MotorStep = 0;
  718. }
  719. break;
  720. case 132:
  721. if(dwTickCount >= QDCT_MotorDelay)
  722. {
  723. back_buff = dwRealPos;
  724. QDCT_MotorStep = 133;
  725. }
  726. break;
  727. case 133:
  728. if((dwRealPos - back_buff) >= (QDCT_PARAM_PUTIN_LENGTH))
  729. {
  730. QDCT_JLT_OUT = 1;
  731. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  732. QDCT_MotorStep = 134;
  733. }
  734. else if(!X_DRV)
  735. {
  736. QDCT_MotorStep = 136;
  737. }
  738. break;
  739. case 134:
  740. if(!QDCT_JLT_IN)
  741. {
  742. QDCT_XM_OUT = 0;
  743. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  744. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  745. QDCT_MotorStep = 135;
  746. }
  747. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_JLT_ALARM);
  748. break;
  749. case 135:
  750. if(!X_DRV && QDCT_XM_ORIGIN_IN)
  751. {
  752. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  753. QDCT_MotorStep = 136;
  754. }
  755. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  756. break;
  757. case 136:
  758. {
  759. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  760. QDCT_YL_OUT = 1;
  761. QDCT_MotorStep = 137;
  762. }
  763. break;
  764. case 137:
  765. if(!QDCT_YL_ORIGIN_IN)
  766. {
  767. QDCT_MotorDelay = dwTickCount + QDCT_PARAM_YL_DELAY_START;
  768. QDCT_MotorStep = 138;
  769. }
  770. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_YL_ORIGIN_ALARM);
  771. break;
  772. case 138:
  773. if(dwTickCount >= QDCT_MotorDelay)
  774. {
  775. SetPos(Y_AXIS, 0);
  776. revise_buff = &QDCT_PARAM_YL_OFFSET_LENGTH;
  777. AxisMovePos(Y_AXIS,QDCT_PARAM_YL_SPEED,QDCT_PARAM_SET_ZIPPER_LENGTH - QDCT_PARAM_YL_TRANS_LENGTH + (*revise_buff) + QDCT_YL_MOTOR_SAFE_LENGTH);
  778. if(!QDCT_XM_OUT)QDCT_MotorStep = 139;
  779. else QDCT_MotorStep = 150;
  780. }
  781. break;
  782. case 139:
  783. if(!Y_DRV)
  784. {
  785. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  786. AxisMovePos(Y_AXIS,QDCT_PARAM_YL_SPEED,-QDCT_PARAM_YL_FZ_LENGTH);
  787. QDCT_MotorStep = 140;
  788. }
  789. break;
  790. case 140:
  791. if(!Y_DRV)
  792. {
  793. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  794. QDCT_MotorStep = 0;
  795. }
  796. break;
  797. case 150:
  798. if(((dwRealPos+GetPos(Y_AXIS) - back_buff) >= (QDCT_PARAM_PUTIN_LENGTH)) || !Y_DRV)
  799. {
  800. QDCT_JLT_OUT = 1;
  801. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  802. QDCT_MotorStep = 151;
  803. }
  804. break;
  805. case 151:
  806. if(!QDCT_JLT_IN)
  807. {
  808. QDCT_XM_OUT = 0;
  809. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  810. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  811. QDCT_MotorStep = 152;
  812. }
  813. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_JLT_ALARM);
  814. break;
  815. case 152:
  816. if(!Y_DRV && QDCT_XM_ORIGIN_IN)
  817. {
  818. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  819. QDCT_MotorStep = 139;
  820. }
  821. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  822. break;
  823. case 40:
  824. {
  825. jz_buff = dwRealPos;
  826. if((QDCT_PARAM_SJZ_LENGTH == 0) || QDCT_GetYL_Mode())
  827. {
  828. QDCT_JD_OUT = 0;
  829. }
  830. QDCT_MotorDelay = dwTickCount + QDCT_PARAN_SJ_TIME;
  831. QDCT_MotorStep = 41;
  832. }
  833. break;
  834. case 41:
  835. if(QDCT_JD_OUT && (dwTickCount >= QDCT_MotorDelay))
  836. {
  837. QDCT_DIR_OUT = QDCT_Y_DIR_N;
  838. if(QDCT_GetYL_Mode())
  839. AxisMovePosAccDec(X_AXIS,QDCT_PARAM_CUTBACK_SPEED,-QDCT_PARAM_CUT_BACK_LENGTH,1,10,10);
  840. else
  841. AxisMovePosAccDec(X_AXIS,QDCT_PARAM_CUTBACK_SPEED,-(QDCT_PARAM_SJZ_LENGTH + QDCT_PARAM_CUT_BACK_LENGTH),1,10,10);
  842. QDCT_MotorStep = 42;
  843. }
  844. break;
  845. case 42: // 切断完成后拉电机动作
  846. if(((QDCT_PARAM_SJZ_LENGTH) <= (dwRealPos - jz_buff)))
  847. {
  848. QDCT_JD_OUT = 0;
  849. QDCT_MotorStep = 43;
  850. }
  851. else if(!X_DRV)
  852. {
  853. QDCT_JD_OUT = 0;
  854. QDCT_MotorStep = 43;
  855. }
  856. break;
  857. case 43: // 切断完成后拉电机动作
  858. if(!X_DRV)
  859. {
  860. QDCT_MotorStep = 0;
  861. QDCT_MotorDelay = dwTickCount;
  862. }
  863. break;
  864. case 61: // 前点定位数控模式
  865. if(QDCT_JD_OUT || (QDCT_SZ_OUT == QDCT_MOTOR_DISEN))
  866. {
  867. QDCT_JD_OUT = 0;
  868. QDCT_SZ_OUT = QDCT_MOTOR_EN;
  869. QDCT_MotorDelay = dwTickCount + 50;
  870. }
  871. if((QDCT_TuiLianStep == 0) && !QDCT_TL_OUT)QDCT_TuiLianStep = 1;
  872. QDCT_MotorStep = 62;
  873. break;
  874. case 62:
  875. if(dwTickCount >= QDCT_MotorDelay)
  876. {
  877. if(QDCT_GO_LIMIT_IN || QDCT_GO_DEC_IN)
  878. {
  879. QDCT_DIR_OUT = QDCT_Y_DIR_N;
  880. AxisMovePos(X_AXIS,20,-QDCT_PARAM_ON_BACK_LENGTH);
  881. QDCT_MotorDelay = dwTickCount + 1000;
  882. }
  883. QDCT_MotorStep = 63;
  884. QDCT_JD_OUT = 0;
  885. }
  886. break;
  887. case 63:
  888. if(!X_DRV && !QDCT_GO_LIMIT_IN && (dwTickCount >= QDCT_MotorDelay))
  889. {
  890. go_buff = dwRealPos;
  891. QDCT_DIR_OUT = QDCT_Y_DIR_P;
  892. if(dwZipCnt > 0)
  893. {
  894. MoveAction_Const_Stop_AccDec(X_AXIS,QDCT_DIR_P,QDCT_PARAM_JJGO_SPEED,1,5,10);
  895. }
  896. else
  897. {
  898. MoveAction_Const_Stop_AccDec(X_AXIS,QDCT_DIR_P,QDCT_PARAM_FIRSTSPEED,1,5,10);
  899. }
  900. QDCT_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  901. QDCT_MotorStep = 64;
  902. }
  903. break;
  904. case 64:
  905. if(dwZipCnt > 0)
  906. {
  907. if(((go_buff - dwRealPos) > ((QDCT_PARAM_SET_ZIPPER_LENGTH - QDCT_PARAM_OFFSET_LENGTH) - (QDCT_PARAM_GO_LOWSPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QDCT_PARAM_JJGO_SPEED,QDCT_PARAM_GO_LOWSPEED,5))) + QDCT_PARAM_SJZ_LENGTH + QDCT_PARAM_CUT_BACK_LENGTH)) || QDCT_GO_DEC_IN_UP)
  908. {
  909. MoveChangSpeed(X_AXIS,QDCT_PARAM_GO_LOWSPEED);
  910. QDCT_MotorStep = 66;
  911. QDCT_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  912. }
  913. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_NO_ZIPPER_ALARM);
  914. }
  915. else
  916. {
  917. QDCT_MotorStep = 66;
  918. }
  919. break;
  920. case 65:
  921. if(QDCT_GO_LIMIT_IN_UP)
  922. {
  923. AxisEgmStop(X_AXIS);
  924. QDCT_MotorStep = 66;
  925. }
  926. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_NO_ZIPPER_ALARM);
  927. break;
  928. case 66:
  929. if(!X_DRV)
  930. {
  931. QDCT_MotorDelay = dwTickCount;
  932. QDCT_MotorStep = 67;
  933. }
  934. break;
  935. case 67:
  936. if(dwTickCount >= QDCT_MotorDelay)
  937. {
  938. if(QDCT_JiaLianStep == 0)
  939. {
  940. QDCT_JiaLianStep = 1;
  941. QDCT_MotorStep = 68;
  942. }
  943. }
  944. break;
  945. case 68:
  946. if(QDCT_JiaLianStep == 0)
  947. {
  948. QDCT_MotorStep = 0;
  949. }
  950. break;
  951. case 100://测试用
  952. if((dwTickCount >= QDCT_MotorDelay) && !X_DRV)
  953. {
  954. AxisMovePos(X_AXIS,QDCT_PARAM_JJBACK_SPEED,-(QDCT_PARAM_SET_ZIPPER_LENGTH));
  955. QDCT_MotorStep = 101;
  956. QDCT_MotorDelay = dwTickCount + 1000;
  957. }
  958. break;
  959. case 101:
  960. if((dwTickCount >= QDCT_MotorDelay) && !X_DRV)
  961. {
  962. QDCT_MotorStep = 102;
  963. }
  964. break;
  965. case 102:
  966. AxisMovePos(X_AXIS,QDCT_PARAM_JJBACK_SPEED,(QDCT_PARAM_SET_ZIPPER_LENGTH));
  967. QDCT_MotorStep = 100;
  968. QDCT_MotorDelay = dwTickCount + 1000;
  969. break;
  970. }
  971. }
  972. //切断动作
  973. void QDCT_XiaQieAction(void)
  974. {
  975. user_datas[121] = QDCT_AutoStep;
  976. user_datas[122] = QDCT_ZhuangLiaoStep;
  977. user_datas[123] = QDCT_TuiLianStep;
  978. user_datas[124] = QDCT_MotorStep;
  979. user_datas[125] = QDCT_JiaLianStep;
  980. user_datas[126] = GetPos(Y_AXIS);
  981. // user_datas[127] =
  982. if(QDCT_XiaQieStep == 1)
  983. {
  984. if(QDCT_GO_LIMIT_IN)
  985. {
  986. QDCT_SetAlarmCode(QDCT_GO_LIMIT_ALARM);
  987. }
  988. else if(!QDCT_TL_ORIGIN_IN)
  989. QDCT_SetAlarmCode(QDCT_TL_ORIGIN_ALARM);
  990. else
  991. {
  992. QDCT_XiaQieStep = 2;
  993. }
  994. }
  995. else if(QDCT_XiaQieStep == 2)
  996. {
  997. QDCT_XiaQieDelay = dwTickCount + QDCT_PARAM_CUT_DELAY;
  998. QDCT_XiaQieStep = 3;
  999. }
  1000. else if((QDCT_XiaQieStep == 3) && (dwTickCount >= QDCT_XiaQieDelay))
  1001. {
  1002. QDCT_SQ_OUT = 1;
  1003. QDCT_XiaQieDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1004. QDCT_XiaQieStep = 4;
  1005. }
  1006. else if(QDCT_XiaQieStep == 4)
  1007. {
  1008. if(QDCT_SQ_LIMIT_IN)
  1009. {
  1010. QDCT_XiaQieStep = 5;
  1011. QDCT_XiaQieDelay = dwTickCount + QDCT_PARAM_DELAY_CS;
  1012. }
  1013. else if(dwTickCount >= QDCT_XiaQieDelay)
  1014. {
  1015. QDCT_SetAlarmCode(QDCT_SQ_LIMIT_ALARM);
  1016. }
  1017. }
  1018. else if((QDCT_XiaQieStep == 5) && (dwTickCount >= QDCT_XiaQieDelay))
  1019. {
  1020. QDCT_XiaQieStep = 6;
  1021. if(QDCT_PARAM_CS_ENABLE)QDCT_CS_OUT = 1;
  1022. QDCT_XiaQieDelay = dwTickCount + QDCT_PARAM_CS_TIME;
  1023. }
  1024. else if((QDCT_XiaQieStep == 6) && (dwTickCount >= QDCT_XiaQieDelay))
  1025. {
  1026. QDCT_CS_OUT = 0;
  1027. QDCT_XiaQieStep = 7;
  1028. QDCT_XiaQieDelay = dwTickCount + QDCT_PARAM_COLD_TIME;
  1029. }
  1030. else if((QDCT_XiaQieStep == 7) && (dwTickCount >= QDCT_XiaQieDelay))
  1031. {
  1032. QDCT_SQ_OUT = 0;
  1033. QDCT_XiaQieDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1034. QDCT_XiaQieStep = 8;
  1035. }
  1036. else if(QDCT_XiaQieStep == 8)
  1037. {
  1038. if(!QDCT_SQ_LIMIT_IN)
  1039. {
  1040. QDCT_XiaQieStep = 0;
  1041. if(cBackFlg)
  1042. {
  1043. cBackFlg = 0;
  1044. if(QDCT_MotorStep==0)QDCT_MotorStep = 40;
  1045. }
  1046. QDCT_YD_OUT = 1;
  1047. }
  1048. else if(dwTickCount >= QDCT_XiaQieDelay)
  1049. {
  1050. QDCT_SetAlarmCode(QDCT_SQ_LIMIT_ALARM);
  1051. }
  1052. }
  1053. }
  1054. //装拉头动作
  1055. void QDCT_ZLT_Step(void)
  1056. {
  1057. if(QDCT_ZhuangLiaoStep == 1)
  1058. {
  1059. if(ZhuangLiaoOkFlg)
  1060. {
  1061. QDCT_ZhuangLiaoStep = 0;
  1062. }
  1063. else
  1064. {
  1065. if(FirstStartFlg && QDCT_JLT_IN)
  1066. {
  1067. QDCT_ZhuangLiaoStep = 7;
  1068. }
  1069. else
  1070. {
  1071. FirstStartFlg = 0;
  1072. if(QDCT_SongLiaoStep == 0)
  1073. {
  1074. QDCT_SongLiaoStep = 1;
  1075. QDCT_ZhuangLiaoStep = 2;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. else if(QDCT_ZhuangLiaoStep == 2)
  1081. {
  1082. if(QDCT_SongLiaoStep == 0)
  1083. {
  1084. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1085. if(QDCT_JLT_IN)QDCT_JLT_OUT = 1;
  1086. QDCT_ZhuangLiaoStep = 3;
  1087. }
  1088. }
  1089. else if(QDCT_ZhuangLiaoStep == 3)
  1090. {
  1091. if(QDCT_HSL_ORIGIN_IN && QDCT_XM_ORIGIN_IN && !QDCT_JLT_IN && (QDCT_XiaQieStep == 0))
  1092. {
  1093. QDCT_HSL_OUT = 1;
  1094. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1095. QDCT_ZhuangLiaoStep = 4;
  1096. }
  1097. else if(dwTickCount >= QDCT_ZhuangLiaoDelay)
  1098. {
  1099. if(!QDCT_HSL_ORIGIN_IN)
  1100. QDCT_SetAlarmCode(QDCT_HSL_ORIGIN_ALARM);
  1101. else
  1102. QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  1103. }
  1104. }
  1105. else if(QDCT_ZhuangLiaoStep == 4)
  1106. {
  1107. if(QDCT_HSL_LIMIT_IN)
  1108. {
  1109. QDCT_JLT_OUT = 0;
  1110. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1111. QDCT_ZhuangLiaoStep = 5;
  1112. }
  1113. else if(dwTickCount >= QDCT_ZhuangLiaoDelay)
  1114. {
  1115. QDCT_SetAlarmCode(QDCT_HSL_LIMIT_ALARM);
  1116. }
  1117. }
  1118. else if(QDCT_ZhuangLiaoStep == 5)
  1119. {
  1120. if(QDCT_JLT_IN)
  1121. {
  1122. QDCT_ZhuangLiaoStep = 6;
  1123. }
  1124. else if(dwTickCount >= QDCT_ZhuangLiaoDelay)
  1125. {
  1126. QDCT_SetAlarmCode(QDCT_JLT_ALARM);
  1127. }
  1128. }
  1129. else if(QDCT_ZhuangLiaoStep == 6)
  1130. {
  1131. QDCT_HSL_OUT = 0;
  1132. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1133. if(!bRunning)
  1134. {
  1135. QDCT_ZhuangLiaoStep = 0;
  1136. SongLaTouOkFlg = 0;
  1137. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  1138. }
  1139. else
  1140. QDCT_ZhuangLiaoStep = 7;
  1141. }
  1142. else if(QDCT_ZhuangLiaoStep == 7)
  1143. {
  1144. if(!QDCT_HSL_LIMIT_IN && QDCT_GO_LIMIT_IN)
  1145. {
  1146. QDCT_XM_OUT = 1;
  1147. if(FirstStartFlg)
  1148. {
  1149. FirstStartFlg = 0;
  1150. }
  1151. else
  1152. SongLaTouOkFlg = 0;
  1153. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  1154. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1155. QDCT_ZhuangLiaoStep = 8;
  1156. }
  1157. else if(dwTickCount >= QDCT_ZhuangLiaoDelay)
  1158. {
  1159. if(QDCT_HSL_LIMIT_IN)QDCT_SetAlarmCode(QDCT_HSL_LIMIT_ALARM);
  1160. }
  1161. }
  1162. else if(QDCT_ZhuangLiaoStep == 8)
  1163. {
  1164. if(!QDCT_XM_ORIGIN_IN)
  1165. {
  1166. QDCT_ZhuangLiaoStep = 9;
  1167. QDCT_ZhuangLiaoDelay = dwTickCount + 1000;
  1168. }
  1169. else if(dwTickCount >= QDCT_ZhuangLiaoDelay)
  1170. {
  1171. QDCT_SetAlarmCode(QDCT_XM_LIMIT_ALARM);
  1172. }
  1173. }
  1174. else if(QDCT_ZhuangLiaoStep == 9)
  1175. {
  1176. if(QDCT_LTCZ_IN)
  1177. {
  1178. QDCT_ZhuangLiaoStep = 0;
  1179. ZhuangLiaoOkFlg = 1;
  1180. TryCnt = 0;
  1181. }
  1182. else if(dwTickCount >= QDCT_ZhuangLiaoDelay)
  1183. {
  1184. if(bRunning)
  1185. {
  1186. TryCnt++;
  1187. if(TryCnt > 4)
  1188. {
  1189. QDCT_SetAlarmCode(QDCT_LTCZ_ALARM);
  1190. QDCT_JLT_OUT = 1;
  1191. QDCT_XM_OUT = 0;
  1192. }
  1193. else
  1194. {
  1195. QDCT_ZhuangLiaoStep = 10;
  1196. }
  1197. }
  1198. else
  1199. {
  1200. QDCT_ZhuangLiaoStep = 0;
  1201. QDCT_ZhuangLiaoDelay = dwTickCount;
  1202. }
  1203. }
  1204. }
  1205. else if(QDCT_ZhuangLiaoStep == 10) //装拉头失败重复装几次拉头
  1206. {
  1207. QDCT_XM_OUT = 0;
  1208. QDCT_JLT_OUT = 0;
  1209. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1210. QDCT_ZhuangLiaoStep = 11;
  1211. }
  1212. else if(QDCT_ZhuangLiaoStep == 11)
  1213. {
  1214. if(QDCT_XM_ORIGIN_IN)
  1215. {
  1216. QDCT_ZhuangLiaoStep = 12;
  1217. }
  1218. else if(dwTickCount >= QDCT_ZhuangLiaoDelay)
  1219. {
  1220. QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  1221. }
  1222. }
  1223. else if(QDCT_ZhuangLiaoStep == 12)
  1224. {
  1225. QDCT_ZhuangLiaoStep = 1;
  1226. }
  1227. }
  1228. void QDCT_SL_Step(void)
  1229. {
  1230. if(QDCT_SongLiaoStep == 1)
  1231. {
  1232. if(SongLaTouOkFlg)
  1233. {
  1234. QDCT_SongLiaoStep = 0;
  1235. }
  1236. else
  1237. {
  1238. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1239. QDCT_SongLiaoStep = 2;
  1240. }
  1241. }
  1242. else if(QDCT_SongLiaoStep == 2)
  1243. {
  1244. if(QDCT_HSL_ORIGIN_IN && !QDCT_HSL_LIMIT_IN)
  1245. {
  1246. QDCT_SL_OUT = 1;
  1247. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1248. QDCT_SongLiaoStep = 3;
  1249. }
  1250. else if(dwTickCount >= QDCT_SL_Delay)
  1251. QDCT_SetAlarmCode(QDCT_HSL_ORIGIN_ALARM);
  1252. }
  1253. else if(QDCT_SongLiaoStep == 3)
  1254. {
  1255. if(QDCT_SL_LIMIT_IN)
  1256. {
  1257. QDCT_SL_Delay = dwTickCount + QDCT_PARAM_SL_BACKDELAY;
  1258. QDCT_SongLiaoStep = 4;
  1259. }
  1260. else if(dwTickCount >= QDCT_SL_Delay)
  1261. QDCT_SetAlarmCode(QDCT_SL_ALARM);
  1262. }
  1263. else if((QDCT_SongLiaoStep == 4) && (dwTickCount >= QDCT_SL_Delay))
  1264. {
  1265. QDCT_SL_OUT = 0;
  1266. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1267. QDCT_SongLiaoStep = 5;
  1268. }
  1269. else if(QDCT_SongLiaoStep == 5)
  1270. {
  1271. if(!QDCT_SL_LIMIT_IN)
  1272. {
  1273. QDCT_SongLiaoStep = 0;
  1274. QDCT_SL_Delay = dwTickCount;
  1275. SongLaTouOkFlg = 1;
  1276. }
  1277. else if(dwTickCount >= QDCT_SL_Delay)
  1278. QDCT_SetAlarmCode(QDCT_SL_ALARM);
  1279. }
  1280. }
  1281. //手动动作
  1282. void QDCT_ManualAction(void)
  1283. {
  1284. if(bRunning == 0)
  1285. {
  1286. if(bClearTotal) //切断计数清零
  1287. {
  1288. bClearTotal = 0;
  1289. ClrcToTal(QDCT_TOTAL_ADDR);
  1290. }
  1291. if(QDCT_bClerNowTotal)
  1292. {
  1293. QDCT_bClerNowTotal = 0;
  1294. cTbCnt = 0;
  1295. ClrcToTal(QDCT_NOWTOTAL_ADDR);
  1296. }
  1297. if(QDCT_bQieDuan)
  1298. {
  1299. QDCT_bQieDuan = 0;
  1300. if(QDCT_XiaQieStep == 0)QDCT_XiaQieStep = 1;
  1301. }
  1302. if(QDCT_bQianDianDW)
  1303. {
  1304. QDCT_bQianDianDW = 0;
  1305. if((QDCT_MotorStep == 0) && !QDCT_SQ_LIMIT_IN)
  1306. {
  1307. QDCT_MotorStep = 61;
  1308. dwZipCnt = 0;
  1309. }
  1310. else if(QDCT_SQ_LIMIT_IN)
  1311. QDCT_SetAlarmCode(QDCT_SQ_LIMIT_ALARM);
  1312. }
  1313. if(QDCT_bManXM)
  1314. {
  1315. QDCT_bManXM = 0;
  1316. QDCT_XM_OUT = ~QDCT_XM_OUT;
  1317. if(QDCT_HSL_OUT == 1)QDCT_XM_OUT = 0;
  1318. }
  1319. if(QDCT_bManSQ)
  1320. {
  1321. QDCT_bManSQ = 0;
  1322. QDCT_SQ_OUT = ~QDCT_SQ_OUT;
  1323. if(QDCT_GO_LIMIT_IN) QDCT_SQ_OUT = 0;
  1324. }
  1325. if(QDCT_bManJD)
  1326. {
  1327. QDCT_bManJD = 0;
  1328. QDCT_JD_OUT = ~QDCT_JD_OUT;
  1329. }
  1330. if(QDCT_bManSL)
  1331. {
  1332. QDCT_bManSL = 0;
  1333. QDCT_SL_OUT = ~QDCT_SL_OUT;
  1334. if(!QDCT_HSL_ORIGIN_IN)QDCT_SL_OUT = 0;
  1335. }
  1336. if(QDCT_bManHSL)
  1337. {
  1338. QDCT_bManHSL = 0;
  1339. QDCT_HSL_OUT = ~QDCT_HSL_OUT;
  1340. if(QDCT_JLT_IN)QDCT_JLT_OUT = 1;
  1341. if(QDCT_XM_OUT || QDCT_SL_LIMIT_IN)QDCT_HSL_OUT = 0;
  1342. }
  1343. if(QDCT_bManZD)
  1344. {
  1345. QDCT_bManZD = 0;
  1346. QDCT_ZDP_OUT = ~QDCT_ZDP_OUT;
  1347. }
  1348. if(QDCT_bManKL)
  1349. {
  1350. QDCT_bManKL = 0;
  1351. QDCT_KL_OUT = ~QDCT_KL_OUT;
  1352. }
  1353. if(QDCT_bManJLT)
  1354. {
  1355. QDCT_bManJLT = 0;
  1356. QDCT_JLT_OUT = ~QDCT_JLT_OUT;
  1357. }
  1358. if(QDCT_bManYD)
  1359. {
  1360. QDCT_bManYD = 0;
  1361. QDCT_YD_OUT = ~QDCT_YD_OUT;
  1362. }
  1363. if(QDCT_bManTL)
  1364. {
  1365. QDCT_bManTL = 0;
  1366. if(QDCT_TL_OUT)
  1367. {
  1368. QDCT_TL_OUT = 0;
  1369. QDCT_YD_OUT = 0;
  1370. }
  1371. else
  1372. {
  1373. if(QDCT_TuiLianStep==0)QDCT_TuiLianStep=1;
  1374. }
  1375. }
  1376. if(QDCT_bZhuangLiao)
  1377. {
  1378. QDCT_bZhuangLiao = 0;
  1379. if(QDCT_ZhuangLiaoStep == 0)
  1380. {
  1381. TryCnt = 0;
  1382. SongLaTouOkFlg = 1;
  1383. QDCT_ZhuangLiaoStep = 1;
  1384. FirstStartFlg = 0;
  1385. }
  1386. }
  1387. if(QDCT_bSongLT)
  1388. {
  1389. QDCT_bSongLT = 0;
  1390. if(QDCT_SongLiaoStep == 0)
  1391. {
  1392. QDCT_SongLiaoStep = 1;
  1393. SongLaTouOkFlg = 0;
  1394. }
  1395. }
  1396. if(QDCT_bChuanLT)
  1397. {
  1398. QDCT_bChuanLT = 0;
  1399. if(!QDCT_BACK_LIMIT_IN)
  1400. {
  1401. if(QDCT_MotorStep == 0)QDCT_MotorStep = 30;
  1402. }
  1403. }
  1404. if(QDCT_bManSZ)
  1405. {
  1406. QDCT_bManSZ = 0;
  1407. QDCT_SZ_OUT = ~QDCT_SZ_OUT;
  1408. }
  1409. //电机控制
  1410. if(QDCT_bMotorGo && !QDCT_GO_LIMIT_IN && !QDCT_SQ_LIMIT_IN)
  1411. {
  1412. QDCT_JD_OUT = 0;
  1413. QDCT_SZ_OUT = QDCT_MOTOR_EN;
  1414. QDCT_DIR_OUT = QDCT_Y_DIR_P;
  1415. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, QDCT_DIR_P, 5,5,10,10);
  1416. }
  1417. else if(QDCT_bMotorGo && QDCT_SQ_LIMIT_IN)
  1418. QDCT_SetAlarmCode(QDCT_SQ_LIMIT_ALARM);
  1419. if(QDCT_bMotorBack && !QDCT_BACK_LIMIT_IN)
  1420. {
  1421. QDCT_JD_OUT = 0;
  1422. QDCT_SZ_OUT = QDCT_MOTOR_EN;
  1423. QDCT_DIR_OUT = QDCT_Y_DIR_N;
  1424. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, QDCT_DIR_N, 5,5,10,10);
  1425. }
  1426. if(!QDCT_bMotorGo && !QDCT_bMotorBack && (QDCT_MotorStep == 0))
  1427. {
  1428. if(X_DRV)AxisDecStop(X_AXIS);
  1429. }
  1430. if(QDCT_GO_LIMIT_IN && (QDCT_MotorStep == 0) && !QDCT_bMotorBack &&(QDCT_AutoStep == 0))
  1431. {
  1432. if(X_DRV)AxisEgmStop(X_AXIS);
  1433. }
  1434. if(QDCT_bManMotorSL)
  1435. {
  1436. if(!Y_DRV)AxisContinueMove(Y_AXIS,10,0);
  1437. }
  1438. else
  1439. {
  1440. if(Y_DRV && (QDCT_SongLianStep == 0) && (QDCT_MotorStep == 0))AxisEgmStop(Y_AXIS);
  1441. }
  1442. }
  1443. if(QDCT_PARAM_ZD_ENABLE)QDCT_ZDP_OUT = 1;
  1444. else QDCT_ZDP_OUT = 0;
  1445. }
  1446. #endif