XDMXC_NiLong_StepJi.c 43 KB

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