YGMXC_NiLong_StepJi.c 46 KB

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