JCWYQueduanChuantou.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. #include "global.h"
  2. #if JIA_CHENG_WEI_YE_MACHINE
  3. unsigned short cTaiMiamMotor;
  4. unsigned long cSlowPusle;
  5. unsigned char bDecEn;
  6. unsigned char bStartOnceTime;
  7. unsigned short cWorkCnt;
  8. unsigned char TryCnt = 0;
  9. unsigned short cZhaCnt = 0;
  10. unsigned char ZhuangLiaoOkFlg = 0;
  11. unsigned char SongLaTouOkFlg = 0;
  12. static long save_limit_pos;
  13. static unsigned long cZipCnt = 0;
  14. void QDCT_ManualAction(void);
  15. void QDCT_JiaLianAction(void);
  16. void QDCT_AutoStepAction(void);
  17. void QDCT_ZhenDongAction(void);
  18. void QDCT_TableAction(void);
  19. void QDCT_GL_Step(void);
  20. void QDCT_Motor(void);
  21. void QDCT_CheckStart(void);
  22. void QDCT_SL_Step(void);
  23. void QDCT_XiaQieAction(void);
  24. void QDCT_ExtiActionX31(void)
  25. {
  26. if(cSeBiaoEn && !cSeBiaoOk)
  27. {
  28. cSeBiaoEn = 0;
  29. cSeBiaoOk = 1;
  30. SetRemainLength(X_AXIS,QDCT_SEBIAO_LENGTH,10);
  31. }
  32. }
  33. //故障报警
  34. void QDCT_SetAlarmCode(unsigned alarm_code)
  35. {
  36. SetAlarmCode(QDCT_ALARM_ADDR,alarm_code);
  37. QDCT_bAlarmStop = 1;
  38. }
  39. //初始化动作
  40. void QDCT_InitAction(void)
  41. {
  42. float buff_pulse,buff_dist;
  43. buff_pulse = QDCT_PARAM_CYCLE_PULSE;
  44. buff_dist = QDCT_PARAM_CYCLE_LENGTH;
  45. XGearRatio = buff_pulse/buff_dist;
  46. }
  47. void QDCT_Action(void)
  48. {
  49. QDCT_CheckStart();
  50. QDCT_ZhenDongAction();
  51. QDCT_TableAction();
  52. QDCT_SL_Step();
  53. QDCT_JiaLianAction();
  54. QDCT_XiaQieAction();
  55. QDCT_Motor();
  56. QDCT_ManualAction();
  57. QDCT_AutoStepAction();
  58. }
  59. void QDCT_AlarmProtect(void)
  60. {
  61. dwRealPos = GetPos(X_AXIS);
  62. if(QDCT_PARAM_BACK_ALARM_MODE)
  63. { //感应后限模式
  64. if(!bRunning)
  65. {
  66. if(QDCT_BACK_LIMIT_IN_UP)
  67. {
  68. if((QDCT_MotorStep == 0) && X_DRV && QDCT_bMotorBack) //到后限不能再后退但可以点前进
  69. {
  70. QDCT_bMotorBack = 0;
  71. AxisDecStop(X_AXIS);
  72. QDCT_JD_OUT = 0;
  73. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  74. }
  75. }
  76. }
  77. else
  78. {
  79. if(QDCT_BACK_LIMIT_IN_UP)
  80. {
  81. AxisDecStop(X_AXIS);
  82. QDCT_JD_OUT = 0;
  83. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  84. }
  85. }
  86. }
  87. else
  88. {
  89. if(QDCT_GO_LIMIT_IN_UP) //数控后限模式
  90. {
  91. save_limit_pos = dwRealPos;
  92. SetData32bits(200,save_limit_pos);
  93. }
  94. if(QDCT_PARAM_MAX_BACK_LENGTH < (dwRealPos - save_limit_pos))
  95. {
  96. if(!bRunning)
  97. {
  98. if((QDCT_MotorStep == 0) && X_DRV && QDCT_bMotorBack) //到后限不能再后退但可以点前进
  99. {
  100. QDCT_bMotorBack = 0;
  101. AxisDecStop(X_AXIS);
  102. QDCT_JD_OUT = 0;
  103. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  104. }
  105. }
  106. else
  107. {
  108. AxisDecStop(X_AXIS);
  109. QDCT_JD_OUT = 0;
  110. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  111. }
  112. }
  113. }
  114. }
  115. void QDCT_JiaLianAction(void)
  116. {
  117. if(QDCT_JiaLianStep == 1)
  118. {
  119. // QDCT_JD_Delay = dwTickCount + QDCT_PARAM_JD_DELAY;
  120. QDCT_JiaLianStep = 2;
  121. }
  122. else if((QDCT_JiaLianStep == 2) && (dwTickCount >= QDCT_JD_Delay))
  123. {
  124. QDCT_JD_OUT = 1;
  125. QDCT_JD_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  126. QDCT_JiaLianStep = 3;
  127. }
  128. else if(QDCT_JiaLianStep == 3)
  129. {
  130. if(QDCT_JZ_LEFT_IN && QDCT_JZ_RIGHT_IN)
  131. {
  132. QDCT_JiaLianStep = 4;
  133. }
  134. else if(dwTickCount >= QDCT_JD_Delay)
  135. {
  136. if(!QDCT_JZ_LEFT_IN)QDCT_SetAlarmCode(QDCT_JD_LEFT_ALARM);
  137. else if(!QDCT_JZ_RIGHT_IN)QDCT_SetAlarmCode(QDCT_JD_RIGHT_ALARM);
  138. }
  139. }
  140. else if(QDCT_JiaLianStep == 4)
  141. {
  142. if(QDCT_PARAM_KL_TIME)
  143. {
  144. // QDCT_JD_Delay = dwTickCount + QDCT_PARAM_KL_DELAY;
  145. QDCT_JiaLianStep = 5;
  146. }
  147. else
  148. {
  149. QDCT_JiaLianStep = 7;
  150. }
  151. }
  152. else if((QDCT_JiaLianStep == 5) && (dwTickCount >= QDCT_JD_Delay))
  153. {
  154. QDCT_KL_OUT = 1;
  155. QDCT_JiaLianStep = 6;
  156. QDCT_JD_Delay = dwTickCount + QDCT_PARAM_KL_TIME;
  157. }
  158. else if((QDCT_JiaLianStep == 6) && (dwTickCount >= QDCT_JD_Delay))
  159. {
  160. QDCT_KL_OUT = 0;
  161. QDCT_JiaLianStep = 7;
  162. }
  163. else if((QDCT_JiaLianStep == 7))
  164. {
  165. QDCT_JiaLianStep = 0;
  166. }
  167. }
  168. //自动动作
  169. void QDCT_AutoStepAction(void)
  170. {
  171. if(bRunning)
  172. {
  173. if(QDCT_AutoStep == 1)
  174. {
  175. QDCT_AutoStep = 2;
  176. QDCT_ZhenDongStep = 1;
  177. }
  178. else if((QDCT_AutoStep == 2) && (dwTickCount >= QDCT_AutoDelay))
  179. {
  180. QDCT_AutoStep = 3;
  181. }
  182. else if(QDCT_AutoStep == 3)
  183. {
  184. if(QDCT_MotorStep == 0)
  185. {
  186. QDCT_MotorStep = 1;
  187. ZhuangLiaoOkFlg = 0;
  188. QDCT_AutoStep = 4;
  189. }
  190. }
  191. else if(QDCT_AutoStep == 4)
  192. {
  193. QDCT_AutoStep = 5;
  194. }
  195. else if(QDCT_AutoStep == 5)
  196. {
  197. if(QDCT_ZhuangLiaoStep == 0)
  198. {
  199. QDCT_ZhuangLiaoStep = 1;
  200. QDCT_AutoStep = 6;
  201. }
  202. }
  203. else if(QDCT_AutoStep == 6)
  204. {
  205. if(QDCT_ZhuangLiaoStep == 0)
  206. {
  207. QDCT_AutoStep = 7;
  208. }
  209. }
  210. else if(QDCT_AutoStep == 7)
  211. {
  212. QDCT_AutoStep = 8;
  213. }
  214. else if(QDCT_AutoStep == 8)
  215. {
  216. QDCT_AutoStep = 9;
  217. }
  218. else if(QDCT_AutoStep == 9)
  219. {
  220. if(QDCT_MotorStep == 0)
  221. {
  222. QDCT_AutoStep = 10;
  223. }
  224. }
  225. else if(QDCT_AutoStep == 10)
  226. {
  227. QDCT_AutoStep = 11;
  228. }
  229. else if(QDCT_AutoStep == 11)
  230. {
  231. if(QDCT_MotorStep == 0) //
  232. {
  233. if(QDCT_SEBIAO_MODE)
  234. QDCT_MotorStep = 1;
  235. else
  236. QDCT_MotorStep = 30;
  237. QDCT_AutoStep = 12;
  238. }
  239. }
  240. else if(QDCT_AutoStep == 12)
  241. {
  242. if(QDCT_MotorStep == 0)
  243. {
  244. QDCT_AutoStep = 13;
  245. }
  246. }
  247. else if(QDCT_AutoStep == 13)
  248. {
  249. QDCT_AutoStep = 14;
  250. }
  251. else if(QDCT_AutoStep == 14)
  252. {
  253. if(QDCT_XiaQieStep == 0)
  254. {
  255. QDCT_XiaQieStep = 1;
  256. QDCT_AutoStep = 15;
  257. }
  258. }
  259. else if(QDCT_AutoStep == 15)
  260. {
  261. if(QDCT_XiaQieStep == 0)
  262. {
  263. QDCT_AutoStep = 16;
  264. }
  265. }
  266. else if(QDCT_AutoStep == 16)
  267. {
  268. CalProSP(QDCT_SPEED_ADDR); //计算生产速度
  269. AddToTal(QDCT_TOTAL_ADDR); //生产总量加1并保存
  270. AddToTal(QDCT_NOWTOTAL_ADDR); //生产总量加1并保存
  271. cWorkCnt++;
  272. cZhaCnt++;
  273. cZipCnt++;
  274. if(GetTotal(QDCT_NOWTOTAL_ADDR) >= GetTotal(QDCT_SETTOTAL_ADDR))
  275. {
  276. ClrcToTal(QDCT_NOWTOTAL_ADDR);
  277. bStartOnceTime = 0;
  278. QDCT_SetAlarmCode(QDCT_TOTAL_ALARM);
  279. }
  280. else
  281. {
  282. if(bStartOnceTime)
  283. {
  284. bStartOnceTime = 0;
  285. QDCT_AutoStep = 0;
  286. bRunning = 0;
  287. }
  288. else
  289. QDCT_AutoStep = 17;
  290. }
  291. }
  292. else if(QDCT_AutoStep == 17)
  293. {
  294. if(cZhaCnt >= QDCT_ZHA_NO)
  295. {
  296. cZhaCnt = 0;
  297. QDCT_AutoDelay = dwTickCount + QDCT_ZHA_STOP_TIME;
  298. QDCT_AutoStep = 2;
  299. }
  300. else
  301. {
  302. QDCT_AutoDelay = dwTickCount + QDCT_PARAM_CYCLE_DELAY;
  303. QDCT_AutoStep = 2;
  304. }
  305. /* if(!QDCT_LTCZ_IN)
  306. {
  307. QDCT_AutoStep = 2;
  308. }
  309. else
  310. {
  311. QDCT_SetAlarmCode(QDCT_LTCZ_ALARM);
  312. }*/
  313. }
  314. }
  315. }
  316. //振动盘控制
  317. void QDCT_ZhenDongAction(void)
  318. {
  319. if(QDCT_ZhenDongStep == 1)
  320. {
  321. QDCT_ZhenDongStep = 2;
  322. }
  323. else if(QDCT_ZhenDongStep == 2)
  324. {
  325. if(QDCT_LT_IN)
  326. {
  327. }
  328. else
  329. {
  330. QDCT_ZDP_OUT = 1;
  331. QDCT_ZhenDongStep = 3;
  332. }
  333. }
  334. else if(QDCT_ZhenDongStep == 3)
  335. {
  336. if(QDCT_PARAM_ZD_MODE)
  337. {
  338. QDCT_ZhenDongStep = 0;
  339. }
  340. else
  341. {
  342. QDCT_ZhenDongStep = 4;
  343. QDCT_ZhenDongDelay = dwTickCount + QDCT_PARAM_ZD_WORK_TIME ;
  344. }
  345. }
  346. else if((QDCT_ZhenDongStep == 4) && (dwTickCount >= QDCT_ZhenDongDelay))
  347. {
  348. QDCT_ZDP_OUT = 0;
  349. QDCT_ZhenDongStep = 2;
  350. }
  351. else if(QDCT_ZhenDongStep == 6)
  352. {
  353. QDCT_ZhenDongStep = 0;
  354. }
  355. }
  356. //台面电机动作
  357. void QDCT_TableAction(void)
  358. {
  359. if(QDCT_TB_OUT && (dwTickCount >= QDCT_TableDelay))QDCT_TB_OUT = 0;
  360. }
  361. void QDCT_CheckStart(void)
  362. {
  363. //启动 自动启动 单一自动
  364. if(START_IN_UP || bStart || QDCT_bOnceStart)
  365. {
  366. if(QDCT_bOnceStart)
  367. {
  368. QDCT_bOnceStart = 0;
  369. bStartOnceTime = 1;
  370. }
  371. bStart = 0;
  372. if(!QDCT_NO_ZIPPER_CHECK_IN)QDCT_SetAlarmCode(QDCT_START_NO_ZIPPER_ALARM);
  373. else if(QDCT_JLT_IN)QDCT_SetAlarmCode(QDCT_START_JLT_ALARM);
  374. else if(QDCT_LTCZ_IN)QDCT_SetAlarmCode(QDCT_START_LTCZ_ALARM);
  375. else if(!QDCT_HSL_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_START_GL_ORIGIN_ALARM);
  376. else if(QDCT_HSL_LIMIT_IN)QDCT_SetAlarmCode(QDCT_START_SL_LIMIT_ALARM);
  377. else if(!QDCT_SQ_LIMIT_IN)QDCT_SetAlarmCode(QDCT_START_SQ_ORIGIN_ALARM);
  378. else if(!QDCT_XQ_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_START_XQ_ORIGIN_ALARM);
  379. else if(!QDCT_XM_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_START_SM_ORIGIN_ALARM);
  380. else
  381. {
  382. if(!bRunning && (QDCT_AutoStep == 0) && (GetAlarmCode(QDCT_ALARM_ADDR) == 0))
  383. {
  384. bRunning = 1;
  385. QDCT_AutoStep = 1;
  386. cWorkCnt = 0;
  387. TryCnt = 0;
  388. SongLaTouOkFlg = 1;
  389. cZipCnt = 0;
  390. }
  391. }
  392. }
  393. //停止
  394. if(STOP_IN_UP|| bStop)
  395. {
  396. AxisDecStop(X_AXIS);
  397. bRunning = 0;
  398. QDCT_bOnceStart = 0;
  399. bStop = 0;
  400. bStartOnceTime = 0;
  401. QDCT_SQ_OUT = 0;
  402. QDCT_XQ_OUT = 0;
  403. QDCT_XM_OUT = 0;
  404. QDCT_JD_OUT = 0;
  405. QDCT_SL_OUT = 0;
  406. QDCT_JLT_OUT= 0;
  407. QDCT_HSL_OUT = 0;
  408. QDCT_KL_OUT = 0;
  409. QDCT_ZDP_OUT= 0;
  410. QDCT_SLT_OUT= 0;
  411. if(GetAlarmCode(QDCT_ALARM_ADDR) != 0)QDCT_SetAlarmCode(QDCT_NO_ALARM);
  412. }
  413. if(bAlarmStop)
  414. {
  415. QDCT_bOnceStart = 0;
  416. bAlarmStop = 0;
  417. bStartOnceTime = 0;
  418. QDCT_ZDP_OUT = 0;
  419. AxisDecStop(X_AXIS);
  420. }
  421. }
  422. //电机控制动作
  423. void QDCT_Motor(void) //
  424. {
  425. 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;
  426. user_datas[123] = QD_PARAM_ON_BACK_LENGTH;
  427. user_datas[124] = QD_AutoStep;
  428. user_datas[127] = QDCT_MotorStep;
  429. switch(QDCT_MotorStep)
  430. {
  431. case 1:
  432. QDCT_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  433. QDCT_MotorStep = 2;
  434. break;
  435. case 2:
  436. if(dwTickCount >= QDCT_MotorDelay)
  437. {
  438. back_dec_buff = dwRealPos;
  439. if(cZipCnt == 0)
  440. {
  441. cSeBiaoOk = 0;
  442. cSeBiaoEn = 1;
  443. AxisContinueMove(X_AXIS,QDCT_BACK_LOWSPEED,QDCT_DIR_P);
  444. }
  445. else
  446. {
  447. AxisContinueMove(X_AXIS,QDCT_PARAM_JJBACK_SPEED,QDCT_DIR_P);
  448. }
  449. QDCT_MotorStep = 3;
  450. }
  451. break;
  452. case 3:
  453. if(cZipCnt != 0)
  454. {
  455. if(QDCT_PARAM_SET_ZIPPER_LENGTH >= (QDCT_SEBIAO_LENGTH + QDCT_REMAIN_CHECK_LENGTH))
  456. {
  457. cSeBiaoOk = 0;
  458. cSeBiaoEn = 1;
  459. }
  460. else
  461. {
  462. if((dwRealPos - back_dec_buff) >= (QDCT_PARAM_SET_ZIPPER_LENGTH - QDCT_SEBIAO_LENGTH - QDCT_REMAIN_CHECK_LENGTH))
  463. {
  464. cSeBiaoOk = 0;
  465. cSeBiaoEn = 1;
  466. }
  467. }
  468. }
  469. 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,QDCT_BACK_LOWSPEED,30)))))
  470. {
  471. if(X_DRV)MoveChangSpeed(X_AXIS,QDCT_BACK_LOWSPEED);
  472. }
  473. if(cSeBiaoOk)
  474. {
  475. cSeBiaoOk = 0;
  476. cSeBiaoEn = 0;
  477. QDCT_MotorStep = 4;
  478. }
  479. break;
  480. case 4:
  481. if(!X_DRV)
  482. {
  483. QDCT_MotorStep = 0;
  484. }
  485. break;
  486. case 30:
  487. QDCT_MotorDelay = dwTickCount + QDCT_PARAM_DELAY_BACK;
  488. QDCT_MotorStep = 31;
  489. break;
  490. case 31:
  491. if(dwTickCount >= QDCT_MotorDelay)
  492. {
  493. back_buff = dwRealPos;
  494. gou_zhen_buff = dwRealPos;
  495. save_buff = dwRealPos;
  496. MoveAction_Pulse2(X_AXIS,PosToPulse(X_AXIS,QDCT_PARAM_SET_ZIPPER_LENGTH),PosToPulse(X_AXIS,QDCT_PARAM_PUTIN_SPEED_LENGTH),PosToPulse(X_AXIS,QDCT_BACK_LOWSPEED_LENGTH),QDCT_PARAM_JJBACK_SPEED,QDCT_PARAM_PUTIN_SPEED);
  497. QDCT_MotorStep = 33;
  498. }
  499. break;
  500. case 32:
  501. if((dwRealPos - back_buff) >= (QDCT_PARAM_PUTIN_LENGTH + QDCT_PARAM_PUTIN_START_LENGTH))
  502. {
  503. QDCT_JLT_OUT = 0;
  504. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  505. QDCT_MotorStep = 33;
  506. }
  507. else if(!X_DRV)
  508. {
  509. QDCT_JLT_OUT = 0;
  510. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  511. QDCT_MotorStep = 33;
  512. }
  513. break;
  514. case 33:
  515. if(!QDCT_JLT_IN)
  516. {
  517. QDCT_XM_OUT = 0;
  518. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  519. QDCT_MotorStep = 34;
  520. }
  521. else if(!X_DRV)
  522. {
  523. QDCT_XM_OUT = 0;
  524. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  525. QDCT_MotorStep = 34;
  526. }
  527. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_JLT_ALARM);
  528. break;
  529. case 34:
  530. if(!X_DRV && QDCT_XM_ORIGIN_IN && !QDCT_XM_LIMIT_IN)
  531. {
  532. // AxisMovePos(X_AXIS,QDCT_BACK_LOWSPEED,QDCT_PARAM_JJFZ_LENGTH);
  533. QDCT_MotorStep = 35;
  534. }
  535. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  536. break;
  537. case 35:
  538. if(!X_DRV)
  539. {
  540. QDCT_MotorStep = 36;
  541. }
  542. break;
  543. case 36:
  544. QDCT_MotorStep = 0;
  545. break;
  546. case 40:
  547. if(dwTickCount >= QDCT_MotorDelay)
  548. {
  549. jz_buff = dwRealPos;
  550. if(QDCT_PARAM_SJZ_LENGTH == 0)
  551. {
  552. QDCT_JD_OUT = 0;
  553. }
  554. QDCT_MotorDelay = dwTickCount + QDCT_PARAN_SJ_TIME;
  555. QDCT_MotorStep = 41;
  556. }
  557. break;
  558. case 41:
  559. if(QDCT_JD_OUT && (dwTickCount >= QDCT_MotorDelay))
  560. {
  561. AxisMovePos(X_AXIS,QDCT_PARAM_CUTBACK_SPEED,-(QDCT_PARAM_SJZ_LENGTH + QDCT_PARAM_CUT_BACK_LENGTH));
  562. QDCT_MotorStep = 42;
  563. }
  564. break;
  565. case 42: // 切断完成后拉电机动作
  566. if(((QDCT_PARAM_SJZ_LENGTH) <= (dwRealPos - jz_buff)))
  567. {
  568. QDCT_JD_OUT = 0;
  569. QDCT_MotorStep = 43;
  570. }
  571. else if(!X_DRV)
  572. {
  573. QDCT_JD_OUT = 0;
  574. QDCT_MotorStep = 43;
  575. }
  576. break;
  577. case 43: // 切断完成后拉电机动作
  578. if(!X_DRV)
  579. {
  580. QDCT_MotorStep = 0;
  581. QDCT_MotorDelay = dwTickCount;
  582. }
  583. break;
  584. case 61: // 前点定位数控模式
  585. if(QDCT_JD_OUT)
  586. {
  587. QDCT_JD_OUT = 0;
  588. QDCT_MotorDelay = dwTickCount + 50;
  589. }
  590. if(!QDCT_TL_OUT)
  591. {
  592. //if(QD_TuiLianStep == 0)
  593. {
  594. QDCT_MotorStep = 62;
  595. }
  596. }
  597. else
  598. QDCT_MotorStep = 62;
  599. break;
  600. case 62:
  601. if(dwTickCount >= QDCT_MotorDelay)
  602. {
  603. if(QDCT_GO_LIMIT_IN || QDCT_GO_DEC_IN)
  604. {
  605. AxisMovePos(X_AXIS,QDCT_BACK_LOWSPEED,-QDCT_PARAM_ON_BACK_LENGTH);
  606. QDCT_MotorDelay = dwTickCount + 1000;
  607. }
  608. QDCT_MotorStep = 63;
  609. QDCT_JD_OUT = 0;
  610. }
  611. break;
  612. case 63:
  613. if(!X_DRV && !QDCT_GO_LIMIT_IN && (dwTickCount >= QDCT_MotorDelay) && QDCT_XM_ORIGIN_IN)
  614. {
  615. go_buff = dwRealPos;
  616. if(dwZipCnt > 0)
  617. {
  618. MoveAction_Const_Stop(X_AXIS, QDCT_DIR_N,QDCT_PARAM_JJGO_SPEED);//
  619. }
  620. else
  621. {
  622. MoveAction_Const_Stop(X_AXIS, QDCT_DIR_N,QDCT_PARAM_GO_LOWSPEED);
  623. }
  624. QDCT_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  625. QDCT_MotorStep = 64;
  626. }
  627. break;
  628. case 64:
  629. if(((go_buff - dwRealPos) > ((QDCT_PARAM_SET_ZIPPER_LENGTH - QDCT_PARAM_OFFSET_LENGTH) - (QDCT_PARAM_GO_LOWSPEED + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QDCT_PARAM_JJBACK_SPEED,QDCT_BACK_LOWSPEED,30))) + QDCT_BACK_LOWSPEED_LENGTH + QDCT_PARAM_SJZ_LENGTH + QDCT_PARAM_CUT_BACK_LENGTH)) || QDCT_GO_DEC_IN_UP)
  630. {
  631. MoveChangSpeed(X_AXIS,QDCT_PARAM_GO_LOWSPEED);
  632. QDCT_MotorStep =65;
  633. }
  634. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_NO_ZIPPER_ALARM);
  635. break;
  636. case 65:
  637. if(QDCT_GO_LIMIT_IN_UP)
  638. {
  639. AxisEgmStop(X_AXIS);
  640. QDCT_MotorStep = 66;
  641. }
  642. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_NO_ZIPPER_ALARM);
  643. else if(QDCT_JD_ALARM)QDCT_SetAlarmCode(QDCT_JD_ALARM);
  644. break;
  645. case 66:
  646. if(!X_DRV)
  647. {
  648. QDCT_MotorDelay = dwTickCount;
  649. QDCT_MotorStep = 67;
  650. }
  651. break;
  652. case 67:
  653. if(dwTickCount >= QDCT_MotorDelay)
  654. {
  655. if(bRunning)
  656. {
  657. QDCT_JD_OUT = 1;
  658. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  659. QDCT_MotorStep = 68;
  660. }
  661. else
  662. {
  663. QDCT_MotorStep = 0;
  664. }
  665. }
  666. break;
  667. case 68:
  668. if(QDCT_JZ_LEFT_IN && QDCT_JZ_RIGHT_IN)
  669. {
  670. QDCT_MotorDelay = dwTickCount + QDCT_PARAM_JD_DELAY;
  671. QDCT_MotorStep = 69;
  672. }
  673. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_JD_ALARM);
  674. break;
  675. case 69:
  676. if(dwTickCount >= QDCT_MotorDelay)QDCT_MotorStep = 0;
  677. break;
  678. }
  679. }
  680. //切断动作
  681. void QDCT_XiaQieAction(void)
  682. {
  683. if(QDCT_XiaQieStep == 1)
  684. {
  685. QDCT_XiaQieStep = 2;
  686. QDCT_XiaQieDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  687. QDCT_XQ_OUT = 1;
  688. }
  689. else if(QDCT_XiaQieStep == 2)
  690. {
  691. if(QDCT_XQ_LIMIT_IN)
  692. {
  693. QDCT_XiaQieStep = 3;
  694. }
  695. else if(dwTickCount >= QDCT_XiaQieDelay)
  696. {
  697. QDCT_SetAlarmCode(14);
  698. }
  699. }
  700. else if(QDCT_XiaQieStep == 3)
  701. {
  702. QDCT_SQ_OUT = 1;
  703. QDCT_XiaQieDelay = dwTickCount + QDCT_PARAM_CUTBACK_DELAY;
  704. QDCT_XiaQieStep = 4;
  705. }
  706. else if((QDCT_XiaQieStep == 4) && (dwTickCount >= QDCT_XiaQieDelay))
  707. {
  708. QDCT_SQ_OUT = 0;
  709. QDCT_XQ_OUT = 0;
  710. QDCT_XiaQieDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  711. QDCT_XiaQieStep = 5;
  712. }
  713. else if(QDCT_XiaQieStep == 5)
  714. {
  715. if(!QDCT_SQ_LIMIT_IN && QDCT_XQ_ORIGIN_IN)
  716. {
  717. QDCT_XiaQieStep = 0;
  718. }
  719. else if(dwTickCount >= QDCT_XiaQieDelay)
  720. {
  721. if(!QDCT_SQ_LIMIT_IN) QDCT_SetAlarmCode(QDCT_SQ_ORIGIN_ALARM);
  722. else if(!QDCT_XQ_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_XQ_ORIGIN_ALARM);
  723. }
  724. }
  725. }
  726. //装拉头动作
  727. void QDCT_ZLT_Step(void)
  728. {
  729. if(QDCT_ZhuangLiaoStep == 1)
  730. {
  731. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  732. QDCT_ZhuangLiaoStep = 2;
  733. }
  734. else if(QDCT_ZhuangLiaoStep == 2)
  735. {
  736. if(QDCT_SongLiaoStep == 0)
  737. {
  738. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  739. QDCT_ZhuangLiaoStep = 3;
  740. }
  741. }
  742. else if(QDCT_ZhuangLiaoStep == 3)
  743. {
  744. if(QDCT_HSL_ORIGIN_IN)
  745. {
  746. QDCT_HSL_OUT = 1;
  747. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  748. QDCT_ZhuangLiaoStep = 4;
  749. }
  750. else if(dwTickCount >= QDCT_XiaQieDelay)
  751. {
  752. QDCT_SetAlarmCode(QDCT_HSL_ORIGIN_ALARM);
  753. }
  754. }
  755. else if(QDCT_ZhuangLiaoStep == 4)
  756. {
  757. if(QDCT_HSL_LIMIT_IN)
  758. {
  759. QDCT_JLT_OUT = 1;
  760. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  761. QDCT_ZhuangLiaoStep = 5;
  762. }
  763. else if(dwTickCount >= QDCT_XiaQieDelay)
  764. {
  765. QDCT_SetAlarmCode(QDCT_HSL_LIMIT_ALARM);
  766. }
  767. }
  768. else if(QDCT_ZhuangLiaoStep == 5)
  769. {
  770. if(QDCT_JLT_IN)
  771. {
  772. QDCT_ZhuangLiaoStep = 6;
  773. }
  774. else if(dwTickCount >= QDCT_XiaQieDelay)
  775. {
  776. QDCT_SetAlarmCode(QDCT_JLT_ALARM);
  777. }
  778. }
  779. else if(QDCT_ZhuangLiaoStep == 6)
  780. {
  781. QDCT_HSL_OUT = 0;
  782. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  783. QDCT_ZhuangLiaoStep = 7;
  784. }
  785. else if(QDCT_ZhuangLiaoStep == 7)
  786. {
  787. if(!QDCT_HSL_LIMIT_IN)
  788. {
  789. QDCT_XM_OUT = 1;
  790. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  791. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  792. QDCT_ZhuangLiaoStep = 8;
  793. }
  794. else if(dwTickCount >= QDCT_XiaQieDelay)
  795. {
  796. QDCT_SetAlarmCode(QDCT_HSL_LIMIT_ALARM);
  797. }
  798. }
  799. else if(QDCT_ZhuangLiaoStep == 8)
  800. {
  801. if(QDCT_XM_LIMIT_IN)
  802. {
  803. QDCT_ZhuangLiaoStep = 9;
  804. QDCT_ZhuangLiaoDelay = dwTickCount + 1000;
  805. }
  806. else if(dwTickCount >= QDCT_XiaQieDelay)
  807. {
  808. QDCT_SetAlarmCode(QDCT_XM_LIMIT_ALARM);
  809. }
  810. }
  811. else if(QDCT_ZhuangLiaoStep == 9)
  812. {
  813. if(QDCT_LTCZ_IN)
  814. {
  815. if(QDCT_PARAM_LOCK_TIME)
  816. {
  817. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_PARAM_LOCK_TIME;
  818. QDCT_SLT_OUT = 1;
  819. QDCT_ZhuangLiaoStep = 20;
  820. }
  821. else
  822. {
  823. QDCT_ZhuangLiaoStep = 0;
  824. ZhuangLiaoOkFlg = 1;
  825. }
  826. TryCnt = 0;
  827. }
  828. else if(dwTickCount >= QDCT_XiaQieDelay)
  829. {
  830. TryCnt++;
  831. if(TryCnt > 4)
  832. {
  833. QDCT_SetAlarmCode(QDCT_ZLT_ALARM);
  834. }
  835. else
  836. {
  837. QDCT_ZhuangLiaoStep = 10;
  838. }
  839. }
  840. SongLaTouOkFlg = 0;
  841. }
  842. else if(QDCT_ZhuangLiaoStep == 10) //装拉头失败重复装几次拉头
  843. {
  844. QDCT_XM_OUT = 0;
  845. QDCT_JLT_OUT = 0;
  846. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  847. QDCT_ZhuangLiaoStep = 11;
  848. }
  849. else if(QDCT_ZhuangLiaoStep == 11)
  850. {
  851. if(QDCT_XM_ORIGIN_IN)
  852. {
  853. QDCT_ZhuangLiaoStep = 12;
  854. }
  855. else if(dwTickCount >= QDCT_XiaQieDelay)
  856. {
  857. QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  858. }
  859. }
  860. else if(QDCT_ZhuangLiaoStep == 12)
  861. {
  862. QDCT_ZhuangLiaoStep = 1;
  863. }
  864. else if(QDCT_ZhuangLiaoStep == 20)
  865. {
  866. QDCT_ZhuangLiaoStep = 0;
  867. QDCT_ZhuangLiaoDelay = dwTickCount;
  868. ZhuangLiaoOkFlg = 1;
  869. }
  870. }
  871. void QDCT_SL_Step(void)
  872. {
  873. if(QDCT_SongLiaoStep == 1)
  874. {
  875. if(SongLaTouOkFlg)
  876. {
  877. QDCT_SongLiaoStep = 0;
  878. }
  879. else
  880. {
  881. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  882. QDCT_SongLiaoStep = 2;
  883. }
  884. }
  885. else if(QDCT_SongLiaoStep == 2)
  886. {
  887. if(QDCT_HSL_ORIGIN_IN)
  888. {
  889. QDCT_SL_OUT = 1;
  890. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  891. QDCT_SongLiaoStep = 3;
  892. }
  893. else if(dwTickCount >= QDCT_SL_Delay)
  894. QDCT_SetAlarmCode(QDCT_SL_ALARM);
  895. }
  896. else if(QDCT_SongLiaoStep == 3)
  897. {
  898. if(QDCT_HSL_LIMIT_IN)
  899. {
  900. QDCT_SL_OUT = 0;
  901. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  902. QDCT_SongLiaoStep = 4;
  903. }
  904. else if(dwTickCount >= QDCT_SL_Delay)
  905. QDCT_SetAlarmCode(QDCT_SL_ALARM);
  906. }
  907. else if(QDCT_SongLiaoStep == 4)
  908. {
  909. if(!QDCT_HSL_LIMIT_IN)
  910. {
  911. QDCT_SongLiaoStep = 0;
  912. }
  913. else if(dwTickCount >= QDCT_SL_Delay)
  914. QDCT_SetAlarmCode(QDCT_SL_ALARM);
  915. }
  916. }
  917. //手动动作
  918. void QDCT_ManualAction(void)
  919. {
  920. if(bRunning == 0)
  921. {
  922. if(bClearTotal) //切断计数清零
  923. {
  924. bClearTotal = 0;
  925. ClrcToTal(QDCT_TOTAL_ADDR);
  926. }
  927. if(QDCT_bClerNowTotal)
  928. {
  929. QDCT_bClerNowTotal = 0;
  930. ClrcToTal(QDCT_NOWTOTAL_ADDR);
  931. }
  932. if(QDCT_bManXQ)
  933. {
  934. QDCT_bManXQ = 0;
  935. if(QDCT_XiaQieStep == 0)QDCT_XiaQieStep = 1;
  936. }
  937. if(QDCT_bQianDianDW)
  938. {
  939. QDCT_bQianDianDW = 0;
  940. if(QDCT_MotorStep == 0)
  941. {
  942. QDCT_MotorStep = 61;
  943. dwZipCnt = 0;
  944. }
  945. }
  946. if(QDCT_bManXM)
  947. {
  948. QDCT_bManXM = 0;
  949. QDCT_XM_OUT = ~QDCT_XM_OUT;
  950. }
  951. if(QDCT_bManSQ)
  952. {
  953. QDCT_bManSQ = 0;
  954. QDCT_SQ_OUT = ~QDCT_SQ_OUT;
  955. }
  956. if(QDCT_bManJD)
  957. {
  958. QDCT_bManJD = 0;
  959. QDCT_JD_OUT = ~QDCT_JD_OUT;
  960. }
  961. if(QDCT_bManSL)
  962. {
  963. QDCT_bManSL = 0;
  964. QDCT_SL_OUT = ~QDCT_SL_OUT;
  965. }
  966. if(QDCT_bManHSL)
  967. {
  968. QDCT_bManHSL = 0;
  969. QDCT_HSL_OUT = ~QDCT_HSL_OUT;
  970. }
  971. if(QDCT_bManZD)
  972. {
  973. QDCT_bManZD = 0;
  974. if(QDCT_ZDP_OUT == 0)
  975. {
  976. QDCT_ZDP_OUT = 1;
  977. QDCT_ZhenDongDelay = dwTickCount + QDCT_PARAM_ZD_WORK_TIME;
  978. }
  979. }
  980. if(QDCT_bManKL)
  981. {
  982. QDCT_bManKL = 0;
  983. if(QDCT_KL_OUT == 0)
  984. {
  985. QDCT_KL_OUT = 1;
  986. QDCT_KL_Delay = dwTickCount + QDCT_PARAM_KL_DELAY;
  987. }
  988. }
  989. if(QDCT_bManSLT)
  990. {
  991. QDCT_bManSLT = 0;
  992. QDCT_SLT_OUT = ~QDCT_SLT_OUT;
  993. }
  994. if(QDCT_bManJLT)
  995. {
  996. QDCT_bManJLT = 0;
  997. QDCT_JLT_OUT = ~QDCT_JLT_OUT;
  998. }
  999. if(QDCT_bZhuangLiao)
  1000. {
  1001. QDCT_bZhuangLiao = 0;
  1002. if(QDCT_ZhuangLiaoStep == 0)QDCT_ZhuangLiaoStep = 1;
  1003. }
  1004. if(QDCT_bSongLT)
  1005. {
  1006. QDCT_bSongLT = 0;
  1007. if(QDCT_SongLiaoStep == 0)
  1008. {
  1009. QDCT_SongLiaoStep = 1;
  1010. SongLaTouOkFlg = 0;
  1011. }
  1012. }
  1013. if(QDCT_bChuanLT)
  1014. {
  1015. QDCT_bChuanLT = 0;
  1016. if(QDCT_MotorStep == 0)QDCT_MotorStep = 30;
  1017. }
  1018. //电机控制
  1019. if(QDCT_bMotorGo && !QDCT_GO_LIMIT_IN)
  1020. {
  1021. QDCT_JD_OUT = 0;
  1022. if(!X_DRV)AxisContinueMove(X_AXIS,QDCT_PARAM_JJGO_SPEED,QDCT_DIR_P);
  1023. }
  1024. if(QDCT_bMotorBack && !QDCT_BACK_LIMIT_IN)
  1025. {
  1026. QDCT_JD_OUT = 0;
  1027. if(!X_DRV)AxisContinueMove(X_AXIS,QDCT_PARAM_JJGO_SPEED,QDCT_DIR_N);
  1028. }
  1029. if(!QDCT_bMotorGo && !QDCT_bMotorBack && (QDCT_MotorStep == 0))
  1030. {
  1031. if(X_DRV)AxisDecStop(X_AXIS);
  1032. }
  1033. if(QDCT_GO_LIMIT_IN && (QDCT_MotorStep == 0) && !QDCT_bMotorBack &&(QDCT_AutoStep == 0))
  1034. {
  1035. if(X_DRV)AxisEgmStop(X_AXIS);
  1036. }
  1037. }
  1038. }
  1039. #endif