CCQueduanChuantou.c 53 KB

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