YWXMXC_NiLong_StepJi.c 51 KB

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