TYMXC_NiLong_StepJi.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. #include "global.h"
  2. #if TONG_YONG_MACHINE
  3. void MXC_NiLongCheckStart(void);
  4. void MXC_NiLongMotor(void);
  5. void MXC_NiLongXiaChong(void);
  6. void MXC_NiLongFenZhen(void);
  7. void MXC_NiLongChuiQi(void);
  8. void MXC_ManualAction(void);
  9. void MXC_AutoAction(void);
  10. unsigned char MXC_CheckPos(void);
  11. unsigned char cLFengTimer,cRFengTimer;
  12. unsigned long cShaCheTime,cLaLianLine,cGouZhenTime;
  13. unsigned char cChuiQiStep = 0,cGouZhenResetOK;
  14. unsigned short cBudaiCheckDelay = 0;
  15. unsigned char bHandWork,bPulseTatol_EN,bFirst,cInt1_OK,cStopFlag,cOneTimes;
  16. long cSetEncode,cTotal,cDinWeiTime,cAddSetPulseNum,cEncodePulse,cWorkPulseNum;
  17. unsigned long cZipperLength[2];
  18. unsigned char cCheckLengthOk=0,cDaoJu_Flag=0;
  19. unsigned char STOP_IN_FLAG,STOP_IN_FLAG_OLD,STOP_FILTER;
  20. unsigned char MXC_SingOneFlag = 0;
  21. unsigned char MXC_KD_Flag = 0,KD_GO_ON_FLAG = 0,cAlarmStopFlg = 0;
  22. long MXC_KD_pos = 0,save_pos_buff = 0;
  23. long MXC_dwEncPos = 0;
  24. unsigned long MXC_SaveLength = 0;
  25. //故障报警
  26. void MXC_SetAlarmCode(unsigned alarm_code)
  27. {
  28. SetAlarmCode(MXC_ALARM_ADDR,alarm_code);
  29. MXC_bAlarmStop = 1;
  30. cAlarmStopFlg = 1;
  31. }
  32. //高速输入X20外部色标信号中断
  33. void MXC_ExtiActionX20(void)
  34. {
  35. if(cSeBiaoEn && !cSeBiaoOk)
  36. {
  37. cSeBiaoOk = 1;
  38. cSeBiaoEn = 0;
  39. if(X_DRV)SetRemainLength(X_AXIS, MXC_PARAM_SEBIAO_DW_LENGTH,MXC_PARAM_SB_OFFSET_SPEED);
  40. }
  41. }
  42. //高速输入X31/X17外部信号中断
  43. void MXC_ExtiActionX31(void)
  44. {
  45. }
  46. void MXC_InitAction(void)
  47. {
  48. float length_buff,pulse_buff;
  49. CalFreqTab_X_Free(25);
  50. length_buff = MXC_PARAM_DAILUN_LENGTH;
  51. pulse_buff = MXC_PARAM_CYCLE_PULSE;
  52. XGearRatio = pulse_buff/length_buff;
  53. length_buff = MXC_BM_LENGTH;
  54. pulse_buff = 1000;
  55. BMGearRatio = pulse_buff/length_buff;
  56. MXC_SZ_OUT = MXC_SERVER_DISEN;
  57. STOP_IN_FLAG = STOP_IN;
  58. STOP_IN_FLAG_OLD = STOP_IN_FLAG;
  59. MXC_SaveLength = 0;
  60. }
  61. void MXC_NiLongXiuCiJiAction(void)
  62. {
  63. MXC_NiLongCheckStart(); //启动
  64. MXC_NiLongFenZhen(); //左右分针
  65. MXC_NiLongXiaChong(); //下冲
  66. MXC_NiLongChuiQi();
  67. MXC_NiLongMotor(); //拖带控制
  68. MXC_ManualAction();
  69. MXC_AutoAction();
  70. }
  71. void MXC_ManualAction(void)
  72. {
  73. long i;
  74. short *len_buff;
  75. //清总产量
  76. if(MXC_bClear) //清总产量
  77. {
  78. MXC_bClear = 0;
  79. ClrcToTal(MXC_TOTAL_ADDR);
  80. MXC_bSaveWorkData = 1;
  81. }
  82. //当长度改变时,生产总量自动清零
  83. if(MXC_bChangeLength)
  84. {
  85. MXC_bChangeLength = 0;
  86. MXC_SaveLength = 0;
  87. MXC_bClear = 1;
  88. }
  89. //加10
  90. if(MXC_bAddLength)
  91. {
  92. MXC_bAddLength = 0;
  93. i = MXC_SET_REVISE_ZIPPER_LENGTH;
  94. i += 10;
  95. SetData32bits(MXC_ZIPPER_LENGTH_ADDR,i);
  96. }
  97. //减10
  98. if(MXC_bDecLength)
  99. {
  100. MXC_bDecLength = 0;
  101. i = MXC_SET_REVISE_ZIPPER_LENGTH;
  102. i -= 10;
  103. SetData32bits(MXC_ZIPPER_LENGTH_ADDR,i);
  104. }
  105. //工作方式选择(数控定寸和勾针定寸) 
  106. if(MXC_bSetDCMode)
  107. {
  108. MXC_bSetDCMode = 0;
  109. MXC_SaveLength = 0;
  110. MXC_DC_MODE++;
  111. if(MXC_DC_MODE > MXC_DC_BMQ_MODE)MXC_DC_MODE = MXC_DC_GZ_MODE;
  112. if(MXC_DC_MODE != 0)
  113. {
  114. MXC_GouZhen_VAVLE = 1;
  115. MXC_cGouZhenTime = 300;
  116. MXC_XiaZhi_MOTOR = 0;
  117. }
  118. if(MXC_DC_MODE == MXC_DC_SF_MODE)
  119. {
  120. MV_Set_Command_Pos_CPU(X_AXIS,0);
  121. }
  122. }
  123. if(MXC_bSetLength)
  124. {
  125. MXC_bSetLength = 0;
  126. if(MXC_PARAM_INCH_MODE)
  127. {
  128. SetData32bits(15,CalLengthCM(MXC_SET_ZIPPER_LENGTH_INCH));
  129. len_buff = &MXC_SET_REVISE_ZIPPER_LENGTH_INCH;
  130. MXC_SET_REVISE_ZIPPER_LENGTH = CalLengthCM2(*len_buff);
  131. }
  132. else
  133. {
  134. SetData32bits(18,CalInch(MXC_SET_ZIPPER_LENGTH));
  135. len_buff = &MXC_SET_REVISE_ZIPPER_LENGTH;
  136. MXC_SET_REVISE_ZIPPER_LENGTH_INCH = CalInch2(*len_buff);
  137. }
  138. MXC_SaveLength = 0;
  139. }
  140. if((MXC_bRunning) == 0) ////手动
  141. {
  142. if(MXC_bXiaChong)
  143. {
  144. MXC_bXiaChong = 0;
  145. MXC_SaveLength = 0;
  146. if(MXC_cXiaChongStep == 0)MXC_cXiaChongStep = 1;
  147. }
  148. if(MXC_bLeftFenZhen)
  149. {
  150. MXC_bLeftFenZhen = 0;
  151. if(MXC_cXiaChongStep == 0) MXC_LeftFenZhen_VAVLE = ~MXC_LeftFenZhen_VAVLE;
  152. }
  153. if(MXC_bRightFenZhen)
  154. {
  155. MXC_bRightFenZhen = 0;
  156. if(MXC_cXiaChongStep == 0)MXC_RightFenZhen_VAVLE= ~MXC_RightFenZhen_VAVLE;
  157. }
  158. //点动下冲
  159. if((MXC_bDotXiaChong))
  160. {
  161. MXC_bDotXiaChong = 0;
  162. if(MXC_LeftFenZhen_IN && MXC_RighttFenZhen_IN)
  163. {
  164. if(MXC_cXiaChongStep == 0)MXC_cXiaChongStep = 20;
  165. }
  166. else
  167. {
  168. MXC_SetAlarmCode(MXC_XIA_CHONG_ALARM); //下冲条件不满足
  169. }
  170. }
  171. if(MXC_bGouZhen)
  172. {
  173. MXC_bGouZhen = 0;
  174. MXC_cGouZhenTime = dwTickCount + 300;
  175. MXC_GouZhen_VAVLE = 1;
  176. }
  177. if(MXC_DC_MODE != MXC_DC_GZ_MODE) //伺服定寸
  178. {
  179. MXC_GouZhen_VAVLE = 1;
  180. }
  181. else
  182. {
  183. if(dwTickCount >= MXC_cGouZhenTime) MXC_GouZhen_VAVLE = 0;
  184. }
  185. if(MXC_bChuiQi)
  186. {
  187. MXC_bChuiQi = 0;
  188. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  189. }
  190. if(MXC_bTestMotor)
  191. {
  192. if(!X_DRV && MXC_CheckPos())MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P, 10,1,5,5);
  193. }
  194. else
  195. {
  196. if(X_DRV)AxisDecStop(X_AXIS);
  197. }
  198. }
  199. }
  200. void MXC_AutoAction(void)
  201. {
  202. DISPLAY_DATA0 = MXC_cAutoStep;
  203. DISPLAY_DATA1 = MXC_cMotorStep;
  204. DISPLAY_DATA2 = MXC_SaveLength;
  205. DISPLAY_DATA3 = MXC_cRightFenZhenStep;
  206. DISPLAY_DATA4 = MXC_cXiaChongStep;
  207. DISPLAY_DATA5 = dwRealPos;
  208. DISPLAY_DATA6 = MXC_dwEncPos;
  209. if(MXC_XZ_ENABLE)MXC_XiaZhi_MOTOR = 1;
  210. else MXC_XiaZhi_MOTOR = 0;
  211. if(dwTickCount >= MXC_cXiaZhiDelay)MXC_XiaZhi_VAVLE = 0;
  212. if(MXC_bRunning)
  213. {
  214. switch(MXC_cAutoStep)
  215. {
  216. case 0:
  217. break;
  218. case 1:
  219. if(dwTickCount >= MXC_cAutoDelay)
  220. {
  221. MXC_cAutoStep = 2;
  222. }
  223. break;
  224. case 2:
  225. //左右分针要退到位,过链到位要离开
  226. if(dwTickCount >= MXC_cAutoDelay)
  227. {
  228. MXC_cAutoStep = 3;
  229. switch(MXC_DC_MODE)
  230. {
  231. case MXC_DC_SF_MODE:MXC_cMotorStep = 20; break; //伺服
  232. case MXC_DC_SB_MODE:MXC_cMotorStep = 40; break; //色标
  233. case MXC_DC_BMQ_MODE:MXC_cMotorStep = 60; break; //编码器
  234. default:MXC_cMotorStep = 1; //启动拖带 ;//勾针
  235. }
  236. }
  237. break;
  238. case 3:
  239. //拖带已经完成
  240. if(MXC_cMotorStep == 0)
  241. {
  242. if(SingOneFlg)
  243. {
  244. dwZipCnt = 0;
  245. SingOneFlg = 0;
  246. MXC_cAutoStep = 0;
  247. MXC_bRunning = 0;
  248. }
  249. else
  250. {
  251. MXC_cAutoStep = 4;
  252. }
  253. }
  254. break;
  255. case 4:
  256. MXC_cAutoStep = 5;
  257. break;
  258. case 5:
  259. //左右分针都已完成
  260. if((MXC_cLeftFenZhenStep == 0) && (MXC_cRightFenZhenStep == 0))
  261. {
  262. MXC_cXiaChongStep = 1; //下冲电机启动
  263. MXC_cAutoStep = 6;
  264. }
  265. break;
  266. case 6: //下冲已完成
  267. if((MXC_cXiaChongStep == 0) || (MXC_cXiaChongStep == 5))
  268. {
  269. switch(MXC_DC_MODE)
  270. {
  271. case MXC_DC_SF_MODE:
  272. {
  273. MXC_SaveLength += MXC_PARAM_DAOKOU_LENGTH;
  274. if(MXC_SaveLength >= MXC_PARAM_KONG_WEI_LENGTH)
  275. {
  276. dwZipCnt++;
  277. MV_Set_Command_Pos_CPU(X_AXIS,0);
  278. MXC_SaveLength = 0;
  279. AddToTal(MXC_TOTAL_ADDR); //计数增加和保存
  280. CalProSP(MXC_PROSPEED_ADDR);
  281. MXC_cAutoStep = 7;
  282. }
  283. else
  284. {
  285. if((MXC_PARAM_KONG_WEI_LENGTH - MXC_SaveLength) >= MXC_PARAM_DAOKOU_LENGTH)
  286. {
  287. MXC_cAutoStep = 2;
  288. }
  289. else
  290. {
  291. MXC_SaveLength = MXC_PARAM_KONG_WEI_LENGTH - MXC_PARAM_DAOKOU_LENGTH;
  292. MXC_cAutoStep = 2;
  293. }
  294. }
  295. }break; //伺服
  296. case MXC_DC_BMQ_MODE:
  297. {
  298. MXC_SaveLength += MXC_PARAM_DAOKOU_LENGTH;
  299. if(MXC_SaveLength >= MXC_PARAM_KONG_WEI_LENGTH)
  300. {
  301. dwZipCnt++;
  302. SetEncodePos(0);
  303. MXC_SaveLength = 0;
  304. AddToTal(MXC_TOTAL_ADDR); //计数增加和保存
  305. CalProSP(MXC_PROSPEED_ADDR);
  306. MXC_cAutoStep = 7;
  307. }
  308. else
  309. {
  310. if((MXC_PARAM_KONG_WEI_LENGTH - MXC_SaveLength) >= MXC_PARAM_DAOKOU_LENGTH)
  311. {
  312. MXC_cAutoStep = 2;
  313. }
  314. else
  315. {
  316. MXC_SaveLength = MXC_PARAM_KONG_WEI_LENGTH - MXC_PARAM_DAOKOU_LENGTH;
  317. MXC_cAutoStep = 2;
  318. }
  319. }
  320. }
  321. break; //编码器
  322. default:
  323. {
  324. dwZipCnt++;
  325. AddToTal(MXC_TOTAL_ADDR); //计数增加和保存
  326. CalProSP(MXC_PROSPEED_ADDR);
  327. MXC_cAutoStep = 7;
  328. }
  329. }
  330. }
  331. break;
  332. case 7:
  333. if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN && !MXC_GouZhen_IN)
  334. {
  335. if(GetTotal(MXC_TOTAL_ADDR) >= MXC_SET_TOTAL)MXC_SetAlarmCode(MXC_TOTAL_ALARM);
  336. MXC_cAutoStep = 8;
  337. }
  338. break;
  339. case 8:
  340. MXC_cAutoDelay = dwTickCount + MXC_PARAM_MOTOR_DELAY;
  341. if(MXC_SingOneFlag)
  342. {
  343. dwZipCnt = 0;
  344. MXC_SingOneFlag = 0;
  345. MXC_cAutoStep = 0;
  346. MXC_bRunning = 0;
  347. }
  348. MXC_cAutoStep = 1;
  349. break;
  350. }
  351. }
  352. }
  353. // 检测是否踏了脚踏开关
  354. void MXC_NiLongCheckStart(void)
  355. {
  356. // 停止键 不能在工作,手动,停止过程中
  357. if((MXC_bRunning == 0) && (START_IN_UP || MXC_bStart || MXC_bNext))
  358. {
  359. if(!MXC_LeftFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM); //没拉链
  360. else if(GetTotal(MXC_TOTAL_ADDR) >= MXC_SET_TOTAL)MXC_SetAlarmCode(MXC_TOTAL_ALARM);
  361. else if(!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
  362. else if((MXC_PARAM_SEBIAO_DW_LENGTH > MXC_SET_ZIPPER_LENGTH) && (MXC_DC_MODE==2))MXC_SetAlarmCode(MXC_SEBIAO_ZIPPER_LENGTH_ALARM);
  363. else if(MXC_KaDai_IN)MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
  364. else
  365. {
  366. if(MXC_bNext)
  367. {
  368. SingOneFlg = 1;
  369. MXC_bNext = 0;
  370. }
  371. MXC_bRunning = 1;
  372. MXC_cAutoStep = 1;
  373. cGouZhenTime = 1;
  374. cCheckLengthOk = 0;
  375. cZipperLength[0] = 0;
  376. cZipperLength[1] = 0;
  377. dwZipCnt = 0;
  378. MXC_cAutoDelay = dwTickCount;
  379. MXC_cMotorDelay = dwTickCount;
  380. MXC_cXiaChongDelay = dwTickCount;
  381. }
  382. MXC_bStart = 0;
  383. }
  384. //卡带感应
  385. if(MXC_KaDai_IN && (dwTickCount >= MXC_cKaDaiDelay))
  386. {
  387. MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
  388. MXC_cKaDaiDelay = dwTickCount + 2200;
  389. }
  390. if(MXC_KaDai_IN_UP)
  391. {
  392. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  393. }
  394. //停止
  395. STOP_IN_FLAG_OLD = STOP_IN_FLAG;
  396. if(STOP_IN)
  397. {
  398. if(STOP_FILTER < 50)
  399. {
  400. STOP_FILTER++;
  401. }
  402. else
  403. STOP_IN_FLAG = 1;
  404. }
  405. else if(STOP_FILTER > 25)
  406. {
  407. STOP_FILTER--;
  408. }
  409. else
  410. STOP_IN_FLAG = 0;
  411. if(MXC_bStop)
  412. {
  413. MXC_bStop = 0;
  414. if(MXC_bRunning)MXC_SingOneFlag = 1;
  415. }
  416. if(((STOP_IN_FLAG && !STOP_IN_FLAG_OLD)))
  417. {
  418. MXC_bStop = 0;
  419. if(MXC_bRunning)
  420. {
  421. if(MXC_cXiaChongStep==0)
  422. {
  423. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  424. // if(!MXC_XiaChong_MOTOR)MXC_XC_SongZhou = MXC_SERVER_DISEN;
  425. }
  426. MXC_bRunning = 0;
  427. MXC_cAutoStep = 0;
  428. MXC_cMotorStep = 0;
  429. AxisDecStop(X_AXIS);
  430. MXC_cJiaoDaoStep = 0;
  431. SingOneFlg = 0;
  432. MXC_SingOneFlag = 0;
  433. }
  434. else
  435. {
  436. MXC_bRunning = 0;
  437. cStopFlag = 0;
  438. MXC_cAutoStep = 0;
  439. MXC_cMotorStep = 0;
  440. MXC_cXiaChongStep = 0;
  441. MXC_cLeftFenZhenStep = 0;
  442. MXC_cRightFenZhenStep = 0;
  443. MXC_cJiaoDaoStep = 0;
  444. MXC_cDCPStep = 0;
  445. MXC_XiaZhi_VAVLE = 0;
  446. MXC_LeftFenZhen_VAVLE = 0;
  447. MXC_RightFenZhen_VAVLE = 0;
  448. SingOneFlg = 0;
  449. MXC_SingOneFlag = 0;
  450. /* if(MXC_XiaChongMotorMode)
  451. MXC_XC_SongZhou = MXC_SERVER_DISEN;
  452. else
  453. MXC_XC_ShaChe = MXC_SC_DISEN;*/
  454. MXC_XC_ShaChe = MXC_SC_DISEN;
  455. if((MXC_cChuiQiStep == 0) &&(MXC_cXiaChongStep==0))MXC_cChuiQiStep = 1;
  456. AxisDecStop(X_AXIS);
  457. SetAlarmCode(MXC_ALARM_ADDR,MXC_NO_ALARM);
  458. }
  459. }
  460. /* if(!MXC_bRunning && (MXC_cMotorStep==0) && (MXC_cXiaChongStep == 0))
  461. {
  462. if(!X_DRV)MXC_TuoDaiSongZhou = MXC_SERVER_DISEN;
  463. }*/
  464. if(MXC_bAlarmStop)
  465. {
  466. MXC_bAlarmStop = 0;
  467. MXC_bRunning = 0;
  468. MXC_cAutoStep = 0;
  469. MXC_cMotorStep = 0;
  470. MXC_cLeftFenZhenStep = 0;
  471. MXC_cRightFenZhenStep = 0;
  472. MXC_cDCPStep = 0;
  473. MXC_LeftFenZhen_VAVLE = 0;
  474. MXC_RightFenZhen_VAVLE = 0;
  475. MXC_SingOneFlag = 0;
  476. AxisDecStop(X_AXIS);
  477. if((GetAlarmCode(MXC_ALARM_ADDR) == MXC_XIA_CHONG_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_XC_ALARM) ||
  478. (GetAlarmCode(MXC_ALARM_ADDR) == MXC_LFZ_ORIGIN_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_LFZ_LIMIT_ALARM) ||
  479. (GetAlarmCode(MXC_ALARM_ADDR) == MXC_RFZ_ORIGIN_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_RFZ_LIMIT_ALARM))
  480. {
  481. MXC_cXiaChongStep = 0;
  482. MXC_XiaChong_MOTOR = 0;
  483. }
  484. }
  485. }
  486. void MXC_NiLongChuiQi(void)
  487. {
  488. //吹气
  489. if(MXC_XiaChong_IN_UP)
  490. {
  491. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  492. }
  493. switch(MXC_cChuiQiStep)
  494. {
  495. case 1:
  496. MXC_cChuiQiStep = 2;
  497. if(MXC_bRunning)MXC_cChuiQiDelay = dwTickCount+MXC_PARAM_DELAY_CHUIQI_TIME;
  498. break;
  499. case 2:
  500. if(dwTickCount >= MXC_cChuiQiDelay)
  501. {
  502. MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_CHUIQI_TIME;
  503. MXC_ChuiQi_VAVLE = 1;//
  504. MXC_cDCPStep = 1;
  505. MXC_cChuiQiStep = 3;
  506. }
  507. break;
  508. case 3:
  509. if(dwTickCount >= MXC_cChuiQiDelay)
  510. {
  511. MXC_ChuiQi_VAVLE = 0;//
  512. MXC_cChuiQiStep = 0;
  513. }
  514. break;
  515. }
  516. }
  517. unsigned char ComPareLength(void)
  518. {
  519. if((cZipperLength[0] != 0) && (cZipperLength[1] != 0))
  520. {
  521. if(cZipperLength[0] > cZipperLength[1])
  522. {
  523. if((cZipperLength[0] - cZipperLength[1]) > 200)
  524. {
  525. return 0;
  526. }
  527. else
  528. return 1;
  529. }
  530. else
  531. {
  532. if((cZipperLength[1] - cZipperLength[0]) > 200)
  533. {
  534. return 0;
  535. }
  536. else
  537. return 1;
  538. }
  539. }
  540. else
  541. return 0;
  542. }
  543. unsigned char MXC_CheckPos(void)
  544. {
  545. unsigned long zipper_length;
  546. short *revise_buff;
  547. if(MXC_DC_MODE == MXC_DC_BMQ_MODE)
  548. {
  549. revise_buff = &user_datas[17];
  550. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
  551. if(MXC_dwEncPos >= zipper_length)return 0;
  552. else
  553. return 1;
  554. }
  555. else if(MXC_DC_MODE == MXC_DC_GZ_MODE)
  556. {
  557. if(MXC_GouZhen_IN)
  558. return 0;
  559. else
  560. return 1;
  561. }
  562. else if(MXC_DC_MODE == MXC_DC_GZ_MODE)
  563. {
  564. revise_buff = &user_datas[17];
  565. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
  566. if((0 - dwRealPos) > zipper_length) return 0;
  567. else
  568. return 1;
  569. }
  570. else
  571. return 1;
  572. }
  573. void MXC_NiLongMotor(void)
  574. {
  575. static long save_buff,gou_zhen_buff,zipper_length_buff;
  576. static unsigned long zipper_length;
  577. short *revise_buff;
  578. dwRealPos = GetPos(X_AXIS);
  579. MXC_dwEncPos = GetEncodePos();
  580. if(MXC_bRunning)
  581. {
  582. if(!MXC_Zipper_IN && (MXC_DC_MODE != MXC_DC_BMQ_MODE)) MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM);
  583. }
  584. if(!MXC_bRunning)
  585. {
  586. if(MXC_CheckPos() == 0)AxisEgmStop(X_AXIS);
  587. }
  588. switch(MXC_cMotorStep)
  589. {
  590. case 0:
  591. break;
  592. case 1:
  593. if(MXC_SZ_OUT == MXC_SERVER_DISEN)
  594. {
  595. MXC_SZ_OUT = MXC_SERVER_EN;
  596. MXC_cMotorDelay = dwTickCount + 50; //先锁轴
  597. }
  598. MXC_cMotorStep = 2;
  599. break;
  600. case 2://勾针模式
  601. if(dwTickCount >= MXC_cMotorDelay)
  602. {
  603. save_buff = dwRealPos;
  604. revise_buff = &user_datas[17];
  605. save_pos_buff = dwRealPos;
  606. if(cCheckLengthOk)
  607. {
  608. MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_SET_SPEED,1,5,1);
  609. }
  610. else
  611. {
  612. if(cCheckLengthOk == 0)
  613. {
  614. cZipperLength[0] = cZipperLength[1];
  615. cZipperLength[1] = zipper_length_buff - dwRealPos;
  616. zipper_length_buff = dwRealPos;
  617. if(ComPareLength())
  618. {
  619. cCheckLengthOk = 1;
  620. }
  621. }
  622. if(cCheckLengthOk)zipper_length = cZipperLength[1] + (*revise_buff);
  623. MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_FIRST_SPEED,1,5,1);
  624. }
  625. MXC_cMotorDelay = dwTickCount + MXC_PARAM_MOTOR_ALARM_TIME;
  626. MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
  627. MXC_cMotorStep = 3;
  628. }
  629. break;
  630. case 3:
  631. if(((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0)) || (cCheckLengthOk == 0))MXC_GouZhen_VAVLE = 0;
  632. if(MXC_PARAM_AUTO_CHECK_MODE)
  633. {
  634. if(cCheckLengthOk)
  635. {
  636. if(((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_GZ_LENGTH))&&MXC_PARAM_GZ_RESET_MODE)MXC_GouZhen_VAVLE = 0;
  637. if((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_LOWSPEED_LENGTH))
  638. {
  639. AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  640. MXC_cMotorStep = 4;
  641. }
  642. }
  643. else
  644. {
  645. if(MXC_GouZhen_IN)
  646. {
  647. MXC_GouZhen_VAVLE = 0;
  648. MXC_cMotorStep = 5;
  649. AxisEgmStop(X_AXIS);
  650. }
  651. else
  652. {
  653. if(dwTickCount >= MXC_cGouZhenTime)MXC_GouZhen_VAVLE = 0;
  654. MXC_cMotorStep = 4;
  655. }
  656. }
  657. }
  658. if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  659. break;
  660. case 4:
  661. if(((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0)) || (cCheckLengthOk == 0))MXC_GouZhen_VAVLE = 0;
  662. if(MXC_PARAM_AUTO_CHECK_MODE)
  663. {
  664. if(((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_GZ_LENGTH))&&MXC_PARAM_GZ_RESET_MODE &&cCheckLengthOk)MXC_GouZhen_VAVLE = 0;
  665. }
  666. else
  667. {
  668. if(((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_GZ_LENGTH))&&MXC_PARAM_GZ_RESET_MODE)MXC_GouZhen_VAVLE = 0;
  669. }
  670. if(MXC_GouZhen_IN)
  671. {
  672. MXC_GouZhen_VAVLE = 0;
  673. MXC_cMotorStep = 5;
  674. AxisEgmStop(X_AXIS);
  675. }
  676. if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  677. break;
  678. case 5:
  679. if(((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0)) || (cCheckLengthOk == 0))MXC_GouZhen_VAVLE = 0;
  680. if(!X_DRV)
  681. {
  682. MXC_cMotorStep = 0;
  683. MXC_cMotorDelay = dwTickCount;
  684. }
  685. else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  686. break;
  687. case 20:
  688. if(MXC_SZ_OUT == MXC_SERVER_DISEN)
  689. {
  690. MXC_SZ_OUT = MXC_SERVER_EN;
  691. MXC_cMotorDelay = dwTickCount + 50; //先锁轴
  692. }
  693. MXC_cMotorStep = 21;
  694. break;
  695. case 21:
  696. if(dwTickCount >= MXC_cMotorDelay) //电机定寸模式
  697. {
  698. revise_buff = &user_datas[17];
  699. if(cAlarmStopFlg)
  700. {
  701. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
  702. cAlarmStopFlg = 0;
  703. }
  704. else
  705. {
  706. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH + MXC_SaveLength;
  707. if((0 - dwRealPos) > zipper_length)
  708. zipper_length = 0;//MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
  709. else
  710. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH + MXC_SaveLength - (0 - dwRealPos);
  711. }
  712. AxisMovePosAccDec(X_AXIS,MXC_PARAM_SET_SPEED,zipper_length,1,5,1);
  713. MXC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
  714. MXC_cMotorStep = 22;
  715. MXC_cMotorDelay = dwTickCount + MXC_PARAM_MOTOR_ALARM_TIME;
  716. }
  717. break;
  718. case 22:
  719. if(!X_DRV)
  720. {
  721. MXC_cMotorStep = 0;
  722. MXC_cMotorDelay = dwTickCount;
  723. }
  724. else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  725. break;
  726. case 40:
  727. if(MXC_SZ_OUT == MXC_SERVER_DISEN)
  728. {
  729. MXC_SZ_OUT = MXC_SERVER_EN;
  730. MXC_cMotorDelay = dwTickCount + 50; //先锁轴
  731. }
  732. MXC_cMotorStep = 41;
  733. break;
  734. case 41:
  735. if(dwTickCount >= MXC_cMotorDelay)
  736. {
  737. save_buff = dwRealPos;
  738. revise_buff = &user_datas[17];
  739. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff);
  740. if((dwZipCnt==0)||SingOneFlg)MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_SB_LOW_SPEED,1,5,1);
  741. else MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_SB_HIGH_SPEED,1,5,1);
  742. cSeBiaoOk = 0;
  743. cSeBiaoEn = 0;
  744. MXC_cMotorStep = 42;
  745. MXC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
  746. MXC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  747. }
  748. break;
  749. case 42:
  750. if(dwZipCnt==0)
  751. {
  752. cSeBiaoOk = 0;
  753. cSeBiaoEn = 1;
  754. MXC_cMotorStep = 43;
  755. }
  756. else
  757. {
  758. if((save_buff - dwRealPos + MXC_PARAM_LOWSPEED_LENGTH) >= (zipper_length -MXC_PARAM_SEBIAO_DW_LENGTH)) AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  759. if((save_buff - dwRealPos + MXC_PARAM_SEBIAO_TQ_LENGTH) >= (zipper_length - MXC_PARAM_SEBIAO_DW_LENGTH))
  760. {
  761. cSeBiaoOk = 0;
  762. cSeBiaoEn = 1;
  763. MXC_cMotorStep = 43;
  764. }
  765. else if((save_buff - dwRealPos) > (zipper_length + MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  766. }
  767. break;
  768. case 43:
  769. if(dwZipCnt!=0)
  770. {
  771. if((save_buff - dwRealPos) >= (zipper_length - MXC_PARAM_LOWSPEED_LENGTH)) AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  772. if((save_buff - dwRealPos) > (zipper_length + MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  773. }
  774. if(!X_DRV)
  775. {
  776. if(dwZipCnt!=0)
  777. {
  778. if((save_buff - dwRealPos) < (zipper_length - MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  779. }
  780. MXC_cMotorStep = 0;
  781. MXC_cMotorDelay = dwTickCount;
  782. }
  783. else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  784. break;
  785. case 60:
  786. if(MXC_SZ_OUT == MXC_SERVER_DISEN)
  787. {
  788. MXC_SZ_OUT = MXC_SERVER_EN;
  789. MXC_cMotorDelay = dwTickCount + 50; //先锁轴
  790. }
  791. MXC_cMotorStep = 61;
  792. break;
  793. case 61:
  794. if(dwTickCount >= MXC_cMotorDelay)
  795. {
  796. save_buff = MXC_dwEncPos;
  797. revise_buff = &user_datas[17];
  798. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH + MXC_SaveLength;
  799. MoveAction_Const_AccDec(X_AXIS,MXC_DIR_P,MXC_PARAM_SET_SPEED,1,5,1);
  800. MXC_cMotorDelay = dwTickCount + MXC_PARAM_MOTOR_ALARM_TIME;
  801. MXC_cMotorStep = 62;
  802. }
  803. break;
  804. case 62:
  805. if((MXC_dwEncPos) >= (zipper_length - MXC_PARAM_LOWSPEED_LENGTH))
  806. {
  807. AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  808. MXC_cMotorStep = 63;
  809. }
  810. else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  811. break;
  812. case 63:
  813. if((MXC_dwEncPos) >= zipper_length)
  814. {
  815. MXC_cMotorStep = 64;
  816. AxisEgmStop(X_AXIS);
  817. }
  818. else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  819. break;
  820. case 64:
  821. if(!X_DRV)
  822. {
  823. MXC_cMotorStep = 0;
  824. MXC_cMotorDelay = dwTickCount;
  825. }
  826. else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  827. break;
  828. }
  829. }
  830. //下冲
  831. void MXC_NiLongXiaChong(void)
  832. {
  833. switch(MXC_cXiaChongStep)
  834. {
  835. case 0:
  836. return;
  837. break;
  838. case 1:
  839. {
  840. MXC_cRightFenZhenStep = 1;
  841. MXC_cLeftFenZhenStep = 0;
  842. cRFengTimer = 0;
  843. cLFengTimer = 0;
  844. }
  845. MXC_cXiaChongStep = 2;
  846. break;
  847. case 2:
  848. if((MXC_cRightFenZhenStep==0) && (MXC_cLeftFenZhenStep==0))
  849. {
  850. MXC_XC_ShaChe = MXC_SC_DISEN;
  851. if(MXC_bRunning)MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_DELAY_XC;
  852. MXC_cXiaChongStep = 3;
  853. }
  854. break;
  855. case 3:
  856. if(dwTickCount >= MXC_cXiaChongDelay)
  857. {
  858. MXC_cXiaChongStep = 4;
  859. MXC_XiaChong_MOTOR = 1; //下冲电机
  860. if(!MXC_bRunning)MV_Set_Command_Pos_CPU(X_AXIS,0);
  861. if(!MXC_bRunning)SetEncodePos(0);
  862. MXC_cXiaChongDelay = dwTickCount + (unsigned long)MXC_ERRORTIME; //下冲最长时间
  863. if(MXC_bRunning && MXC_XZ_ENABLE)
  864. {
  865. if(MXC_DC_MODE == MXC_DC_GZ_MODE)
  866. {
  867. MXC_XiaZhi_VAVLE = 1;
  868. MXC_cXiaZhiDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
  869. }
  870. else
  871. {
  872. if(MXC_PARAM_DAOKOU_LENGTH >= MXC_PARAM_KONG_WEI_LENGTH)
  873. {
  874. MXC_XiaZhi_VAVLE = 1;
  875. MXC_cXiaZhiDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
  876. }
  877. }
  878. }
  879. if(MXC_XiaChongMotorMode == 1)
  880. {
  881. AxisMoveTwoPos(Y_AXIS,MXC_XiaChongSpeed,2000,MXC_XiaChongLowSpeed,9999999,0);
  882. }
  883. }
  884. break;
  885. case 4: //碰到右大微动,延时停
  886. if(MXC_XiaChong_IN_UP)
  887. {
  888. MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_XC_DELAY;
  889. MXC_cXiaChongStep = 5;
  890. MXC_LeftFenZhen_VAVLE = 0; //退左分针
  891. MXC_RightFenZhen_VAVLE = 0; //退右分针
  892. MXC_GouZhen_VAVLE = 1;
  893. MXC_cGouZhenTime = dwTickCount + 300;
  894. }
  895. else if(dwTickCount >= MXC_cXiaChongDelay) //自动停机
  896. {
  897. MXC_cXiaChongStep = 0;
  898. // MXC_ShaChe_Output();////刹车
  899. MXC_XiaChong_MOTOR = 0;// //下冲电机
  900. MXC_SetAlarmCode(MXC_XC_ALARM);
  901. MXC_LeftFenZhen_VAVLE = 0; //退左分针
  902. MXC_RightFenZhen_VAVLE = 0; //退右分针
  903. AxisEgmStop(Y_AXIS);
  904. }
  905. break;
  906. case 5:
  907. if(dwTickCount >= MXC_cXiaChongDelay)
  908. {
  909. AxisEgmStop(Y_AXIS);
  910. MXC_XiaChong_MOTOR = 0; //延时刹车
  911. if(MXC_PARAM_SC_MODE)
  912. {
  913. MXC_cXiaChongStep = 0;
  914. }
  915. else
  916. {
  917. MXC_cXiaChongStep = 6;
  918. }
  919. }
  920. break;
  921. case 6:
  922. {
  923. MXC_cXiaChongStep = 7;
  924. MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_SC_DELAY;
  925. }
  926. break;
  927. case 7:
  928. if((dwTickCount >= MXC_cXiaChongDelay))
  929. {
  930. MXC_cXiaChongStep = 8;
  931. MXC_cXiaChongDelay = dwTickCount+ 150;
  932. // MXC_XC_SongZhou = MXC_SERVER_DISEN;
  933. MXC_XC_ShaChe = MXC_SC_EN;
  934. }
  935. break;
  936. case 8:
  937. if((dwTickCount >= MXC_cXiaChongDelay))
  938. {
  939. MXC_cXiaChongStep = 0;
  940. // MXC_XC_SongZhou = MXC_SERVER_DISEN;
  941. MXC_XC_ShaChe = MXC_SC_DISEN;
  942. }
  943. break;
  944. case 20: // 点动普通下冲动作
  945. // MXC_XC_SongZhou = MXC_SERVER_EN;
  946. MXC_XC_ShaChe = MXC_SC_DISEN;
  947. MXC_cXiaChongDelay = dwTickCount + 50;
  948. MXC_cXiaChongStep = 21;
  949. break;
  950. case 21:
  951. if((dwTickCount >= MXC_cXiaChongDelay))
  952. {
  953. MXC_XiaChong_MOTOR = 1;
  954. MXC_cXiaChongDelay = dwTickCount + 50;
  955. MXC_cXiaChongStep = 22;
  956. }
  957. break;
  958. case 22:
  959. if((dwTickCount >= MXC_cXiaChongDelay))
  960. {
  961. MXC_XiaChong_MOTOR = 0;
  962. // MXC_XC_SongZhou = MXC_SERVER_EN;
  963. if(MXC_XiaChongMotorMode)
  964. MXC_cXiaChongStep = 0;
  965. else
  966. {
  967. MXC_XC_ShaChe = MXC_SC_EN;
  968. MXC_cXiaChongDelay = dwTickCount + 150;
  969. MXC_cXiaChongStep = 23;
  970. }
  971. }
  972. break;
  973. case 23:
  974. if((dwTickCount >= MXC_cXiaChongDelay))
  975. {
  976. //MXC_XC_SongZhou = MXC_SERVER_DISEN;
  977. MXC_XC_ShaChe = MXC_SC_DISEN;
  978. MXC_cXiaChongStep = 0;
  979. }
  980. break;
  981. case 40: // 点动电机下冲动作
  982. //MXC_XC_SongZhou = MXC_SERVER_EN;
  983. MXC_cXiaChongDelay = dwTickCount + 50;
  984. MXC_cXiaChongStep = 41;
  985. break;
  986. case 41:
  987. if(!Y_DRV)AxisMovePos(Y_AXIS,20,10);
  988. MXC_cXiaChongStep = 42;
  989. break;
  990. case 42:
  991. if(!Y_DRV)
  992. {
  993. MXC_cXiaChongStep = 0;
  994. }
  995. break;
  996. }
  997. }
  998. //分针
  999. void MXC_NiLongFenZhen(void)
  1000. {
  1001. //右分针
  1002. switch(MXC_cRightFenZhenStep)
  1003. {
  1004. case 0:
  1005. break;
  1006. case 1:
  1007. MXC_cFenZhenRightDelay = MXC_PARAM_R_FZ_DELAY+dwTickCount;
  1008. MXC_cRightFenZhenStep = 2;
  1009. break;
  1010. case 2:
  1011. if(dwTickCount >= MXC_cFenZhenRightDelay)
  1012. {
  1013. MXC_cRightFenZhenStep = 3;
  1014. MXC_RightFenZhen_VAVLE = 1;//右分针电磁阀
  1015. MXC_cFenZhenRightDelay = dwTickCount + MXC_FenZhengErrorTime;
  1016. }
  1017. break;
  1018. case 3: //碰到右大微动,延时停
  1019. if(!MXC_RightFenZhen_Origin_IN) //右分针原点离开
  1020. {
  1021. MXC_cFenZhenRightDelay = dwTickCount + MXC_FenZhengErrorTime;
  1022. MXC_cRightFenZhenStep = 4;
  1023. }//右分针不下去
  1024. else if(dwTickCount >= MXC_cFenZhenRightDelay)
  1025. {
  1026. MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
  1027. }
  1028. break;
  1029. case 4:
  1030. if(MXC_RighttFenZhen_IN) //插针到位
  1031. {
  1032. MXC_cRightFenZhenStep = 0;
  1033. MXC_cLeftFenZhenStep = 1; //左分针延时启动
  1034. }
  1035. else if(dwTickCount >= MXC_cFenZhenRightDelay)
  1036. {
  1037. MXC_RightFenZhen_VAVLE = 0;//右分针
  1038. cRFengTimer++;
  1039. //当右分针分不到位时,左分针也要重新分针
  1040. MXC_LeftFenZhen_VAVLE = 0;
  1041. MXC_cRightFenZhenStep = 0;
  1042. if(cRFengTimer < 4)
  1043. {
  1044. MXC_cRightFenZhenStep = 5;
  1045. MXC_cFenZhenRightDelay = dwTickCount + MXC_FenZhengErrorTime;
  1046. }
  1047. else
  1048. {
  1049. MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
  1050. }
  1051. }
  1052. break;
  1053. case 5:
  1054. if(MXC_RightFenZhen_Origin_IN) //退到位
  1055. {
  1056. MXC_cRightFenZhenStep = 6;
  1057. }
  1058. else if(dwTickCount >= MXC_cFenZhenRightDelay)
  1059. {
  1060. MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
  1061. }
  1062. break;
  1063. case 6:
  1064. {
  1065. MXC_cRightFenZhenStep = 1;
  1066. }
  1067. break;
  1068. }
  1069. //左分针
  1070. switch(MXC_cLeftFenZhenStep)
  1071. {
  1072. case 0:
  1073. break;
  1074. case 1:
  1075. MXC_cFenZhenLeftDelay = MXC_PARAM_L_FZ_DELAY+dwTickCount;
  1076. MXC_cLeftFenZhenStep = 2;
  1077. break;
  1078. case 2:
  1079. if(dwTickCount >= MXC_cFenZhenLeftDelay)
  1080. {
  1081. MXC_cLeftFenZhenStep = 3;
  1082. MXC_LeftFenZhen_VAVLE = 1; //左分针电磁阀
  1083. MXC_cFenZhenLeftDelay = dwTickCount + MXC_FenZhengErrorTime;
  1084. }
  1085. break;
  1086. case 3: //离开左分针原点
  1087. if(!MXC_LeftFenZhen_Origin_IN) //左分针原点离开
  1088. {
  1089. MXC_cFenZhenLeftDelay = dwTickCount + MXC_FenZhengErrorTime;
  1090. MXC_cLeftFenZhenStep = 4;
  1091. }//左分针不下去
  1092. else if(dwTickCount >= MXC_cFenZhenLeftDelay)
  1093. {
  1094. MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
  1095. }
  1096. break;
  1097. case 4:
  1098. if(MXC_LeftFenZhen_IN) //插针到位
  1099. MXC_cLeftFenZhenStep = 0;
  1100. else if(dwTickCount >= MXC_cFenZhenLeftDelay)
  1101. {
  1102. MXC_LeftFenZhen_VAVLE = 0;//左分针
  1103. cLFengTimer++;
  1104. if(cLFengTimer < 6)
  1105. {
  1106. MXC_cLeftFenZhenStep = 5;
  1107. MXC_cFenZhenLeftDelay = dwTickCount + MXC_FenZhengErrorTime;
  1108. if((cLFengTimer%2) == 0)
  1109. {
  1110. MXC_RightFenZhen_VAVLE = 0;
  1111. MXC_cRightFenZhenStep = 0;
  1112. }
  1113. }
  1114. else
  1115. {
  1116. MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
  1117. }
  1118. }
  1119. break;
  1120. case 5:
  1121. if(MXC_LeftFenZhen_Origin_IN) //退到位
  1122. {
  1123. MXC_cLeftFenZhenStep = 6;
  1124. }
  1125. else if(dwTickCount >= MXC_cFenZhenLeftDelay)
  1126. {
  1127. MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
  1128. }
  1129. break;
  1130. case 6:
  1131. if((cLFengTimer%2) == 0) //左边插两次都插不到,就退右边再同时插
  1132. {
  1133. MXC_cRightFenZhenStep = 1;
  1134. cRFengTimer = 0;
  1135. MXC_cLeftFenZhenStep = 0;
  1136. }
  1137. else
  1138. {
  1139. MXC_cLeftFenZhenStep = 1;
  1140. }
  1141. break;
  1142. }
  1143. }
  1144. #endif