FJMXC_NiLong_StepJi.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  1. #include "global.h"
  2. #if FU_JIAN_MACHINE
  3. //免修齿
  4. //输入说明
  5. //X000 启动
  6. //X001 停止
  7. //X002 手动下冲
  8. //X003 勾针到位接近开关
  9. //X004 减速信号
  10. //X005 卡带、数量到
  11. //X006 左分针退到位
  12. //X007 左分针到位信号
  13. //STOP_IN0 下冲原位
  14. //STOP_IN1 右分针退到位
  15. //STOP_IN2 右分针到位信号
  16. //
  17. //STOP_IN3 左大微动(吹气信号)
  18. //STOP_IN4 有链检测(数控定寸时的光电开关,不用是请接电源的GND)
  19. //STOP_IN5 色标信号
  20. //STOP_IN6 下止选择(有触摸屏时不用接)
  21. //STOP_IN7 发超声信号
  22. //X020 分带信号
  23. //X021 过链(固定勾针)接近开关
  24. //X022 0普通勾针方式,1勾针固定方式
  25. //输出说明
  26. //输出说明
  27. //Y000 离合器(离合器方式时才接线)
  28. //Y001 刹车
  29. //Y002 吹气电磁阀
  30. //Y003 下止电磁阀
  31. //Y004 左分针电磁阀
  32. //Y005 勾针/储带
  33. //Y006 右分针电磁阀
  34. //Y007 下冲电机/
  35. //Y010 超声输出/
  36. //Y011   计数(不用触摸屏用)
  37. //Y012   拖带电机(步进型不用接)
  38. //Y013 分带电磁阀
  39. //Y014   储带
  40. //Y015 固定勾针
  41. //Y017 拖带步进松轴/伺服电机使能
  42. //步进驱动 板
  43. //PU+ PU+
  44. //PU- PU-
  45. //MF+ 24V
  46. //MF- Y17
  47. /*
  48. D[0] 下止电磁阀输出时间
  49. D[1] 吹气时间
  50. D[2] 超声时间
  51. D[3] 延时刹车
  52. D[4] 刹车时间
  53. D[5] 延时停下冲电机  
  54. D[6] 起动速度
  55. D[7] 加速度
  56. D[8] 最高速度
  57. D[9] 空位最低速度
  58. D[10] 定位时间(慢速长度)
  59. D[11] 动作配置 {D11->0 0普通下止,1超声下止;D11->1 0刹车不释放,1释放,
  60. D[12] 延时上勾针
  61. D[13] 模具长度(刀口长度)
  62. D[14] 拖带轮长度
  63. D[15] 拉链长度低位
  64. D[16] 拉链长度高位
  65. D[17] 修正长度低位
  66. D[18] 修正长度高位
  67. D[19] 勾针伺服选择
  68. D[20] 下止选择{0 选择,1 不下止}
  69. D[21] 勾针定寸时的减速方式(0勾针减速信号,1长度自动减速同用)
  70. D[22] 产量设定低位
  71. D[23] 产量设定高位
  72. D[24] 勾针方式选择 D24 0普通勾针方式,1勾针固定方式
  73. D[25] 固定勾针方式时感应信号(0, 空位时亮,空位时灭)
  74. D[26] 延时发超声
  75. D[27] 下冲电机配置(0,普通电机,1 步进电机)
  76. D[28] 下冲电机的起动速度
  77. D[29] 下冲电机的最高速度
  78. D[30] 拖带电机配置(0 步进 1 伺服)
  79. D[31] 延时吹气
  80. D[32] 勾针定寸方式第一条的最高速度
  81. */
  82. void MXC_NiLongXiuCiJiCheckStart(void);
  83. void CuiQi_Start(void);
  84. void ShaChe_Output(void);
  85. void Output_XiaCi(void);
  86. void Close_XiaCi(void);
  87. void NiLongXiuCiJi_Motor(void);
  88. void NiLongXiuCiJi_XiaC(void);
  89. void Start_FenZ(void);
  90. void NiLongXiuCiJi_FenZhengProc(void);
  91. void ChuiQiProc(void);
  92. void JiaoDao(void);
  93. void MXC_ManualAction(void);
  94. void MXC_AutoAction(void);
  95. unsigned char cLFengTimer,cRFengTimer,cGuZhangStop = 0;
  96. unsigned long cShaCheTime,cLaLianLine,cGouZhenTime;
  97. unsigned char cChuiQiStep = 0,cGouZhenResetOK;
  98. unsigned short cBudaiCheckDelay = 0;
  99. unsigned char bHandWork,bPulseTatol_EN,bFirst,cInt1_OK,cStopFlag,cOneTimes,cKey_Time,cHMI_Test;
  100. long cSetEncode,cTotal,cDinWeiTime,cAddSetPulseNum,cEncodePulse,cWorkPulseNum;
  101. void MXC_InitAction(void)
  102. {
  103. MXC_XC_SongZhou = 1;
  104. XIA_ZHI_ENABLE = 0;
  105. if(MOTOR_MODE == 0)
  106. MXC_TuoDaiSongZhou = 1;
  107. else
  108. MXC_TuoDaiSongZhou = 0;
  109. if(XIA_ZHI_ENABLE)
  110. MXC_XiaZhi_MOTOR = 1;
  111. else
  112. MXC_XiaZhi_MOTOR = 0;
  113. }
  114. void MXC_NiLongXiuCiJiAction(void)
  115. {
  116. MXC_NiLongXiuCiJiCheckStart(); //启动
  117. NiLongXiuCiJi_FenZhengProc(); //左右分针
  118. NiLongXiuCiJi_XiaC(); //下冲
  119. NiLongXiuCiJi_Motor(); //拖带控制
  120. JiaoDao();
  121. MXC_ManualAction();
  122. MXC_AutoAction();
  123. /* if(cHMI_Test == 0)
  124. {
  125. if(user_datas[100] < 32)
  126. {
  127. if(user_datas[75] == 6) //输入
  128. {
  129. user_datas[100] += 48;
  130. }
  131. else if(user_datas[75] == 7) //输出
  132. user_datas[100] += 32;
  133. }
  134. } */
  135. }
  136. void MXC_ManualAction(void)
  137. {
  138. long i;
  139. //清总产量
  140. if(MXC_bClear) //清总产量
  141. {
  142. MXC_bClear = 0;
  143. ClrcToTal(76);
  144. }
  145. //当长度改变时,生产总量自动清零
  146. if(MXC_bChangeLength)
  147. {
  148. MXC_bChangeLength = 0;
  149. i = SET_ZIPPER_LENGTH;
  150. if(cLaLianLine != i)
  151. {
  152. cLaLianLine = i;
  153. SetZipperLength(17,0);
  154. ClrcToTal(76);
  155. }
  156. }
  157. //加10
  158. if(MXC_bAddLength)
  159. {
  160. MXC_bAddLength = 0;
  161. i = SET_REVISE_ZIPPER_LENGTH;
  162. i += 10;
  163. SetZipperLength(17,i);
  164. }
  165. //减10
  166. if(MXC_bDecLength)
  167. {
  168. MXC_bDecLength = 0;
  169. i = SET_REVISE_ZIPPER_LENGTH;
  170. i -= 10;
  171. SetZipperLength(17,i);
  172. }
  173. //工作方式选择(数控定寸和勾针定寸) 
  174. if(MXC_bSetDCMode)
  175. {
  176. MXC_bSetDCMode = 0;
  177. if(!bRunning)
  178. {
  179. DC_MODE++;
  180. if(DC_MODE > 2)DC_MODE = 0;
  181. if(DC_MODE != 0)
  182. {
  183. MXC_GouZhen_VAVLE = 1;
  184. XIA_ZHI_ENABLE = 0;
  185. MXC_XiaZhi_MOTOR = 0;
  186. }
  187. }
  188. }
  189. //勾针方式选择(活动勾针和固定勾针) 
  190. if(MXC_bChangeGouZhenMode)
  191. {
  192. MXC_bChangeGouZhenMode = 0;
  193. if(!bRunning)
  194. {
  195. GOU_ZHEN_MODE++;
  196. if(GOU_ZHEN_MODE > 1)GOU_ZHEN_MODE = 0;
  197. }
  198. }
  199. //下止工作选择) 
  200. if(MXC_bChangeXiaZhiMode)
  201. {
  202. MXC_bChangeXiaZhiMode = 0;
  203. if(!bRunning)
  204. {
  205. XIA_ZHI_ENABLE++;
  206. if(XIA_ZHI_ENABLE > 1)XIA_ZHI_ENABLE = 0;
  207. if(XIA_ZHI_ENABLE)
  208. MXC_XiaZhi_MOTOR = 1;
  209. else
  210. MXC_XiaZhi_MOTOR = 0;
  211. }
  212. }
  213. if(MXC_bJiaoDao)
  214. {
  215. cJiaoDaoStep = 1;
  216. MXC_bJiaoDao = 0;
  217. }
  218. //吹气
  219. if((MXC_ChuiQi_VAVLE == 0))
  220. {
  221. if(MXC_DingChuPian_IN_DW)
  222. {
  223. MXC_bChuiQi = 0;
  224. cChuiQiDelay = dwTickCount + 10*PARAM_DELAY_CHUIQI_TIME;
  225. cChuiQiStep = 1;
  226. }
  227. else if(MXC_bChuiQi == 1)
  228. {
  229. MXC_bChuiQi = 0;
  230. cChuiQiDelay = 0;
  231. cChuiQiStep = 1;
  232. }
  233. }
  234. ChuiQiProc();
  235. if(MXC_ChuiQi_VAVLE && (dwTickCount >= cChuiQiDelay))
  236. {
  237. MXC_ChuiQi_VAVLE = 1;//
  238. MXC_XiChiChuiQi = 1;
  239. cChuiQiDelay = dwTickCount + 10 * PARAM_CHUIQI_TIME;
  240. }
  241. if(MXC_XiChiChuiQi && (dwTickCount >= cChuiQiDelay))
  242. {
  243. MXC_XiChiChuiQi = 0;
  244. }
  245. //刹车方式
  246. if(ShaCheMode)
  247. {
  248. if(MXC_XC_SongZhou && (dwTickCount >= cShaCheTime) && (XiaCongMotorMode == 0)) MXC_XC_SongZhou = 0;
  249. }
  250. if((bRunning) == 0) ////手动
  251. {
  252. if(DC_MODE != 0) //伺服定寸
  253. {
  254. MXC_GuDingGouZhen = 1;
  255. MXC_GouZhen_VAVLE = 1;
  256. }
  257. else if((GouZMode == 0) )//普通勾针(活动)过链
  258. {
  259. if(dwTickCount >= cGouZhenTime)
  260. MXC_GouZhen_VAVLE = 0;
  261. }
  262. else
  263. {
  264. if(XiaMode) //0普通下止,1超声下止
  265. {
  266. if(MXC_GuoLian_IN_UP)
  267. {
  268. MXC_GuDingGouZhen = 0;
  269. }
  270. }
  271. else //刘铁方式(下拉一下就可以复位)
  272. {
  273. if(MXC_GuDingGouZhen && (dwTickCount >= cGouZhenTime))
  274. MXC_GuDingGouZhen = 0;
  275. }
  276. }
  277. //下止动作
  278. if(MXC_XiaZhi_IN_UP || MXC_bXiaZhi)
  279. {
  280. MXC_bXiaZhi = 0;
  281. if(MXC_XiaZhi_VAVLE)
  282. {
  283. MXC_XiaZhi_VAVLE = 0;
  284. MXC_ChaoSheng = 0;
  285. MXC_FenDai_VAVLE = 0; //分带输出
  286. }
  287. else
  288. Output_XiaCi();
  289. }
  290. else if(MXC_XiaZhi_IN_DW)
  291. {
  292. MXC_XiaZhi_VAVLE = 0; //下止电磁阀
  293. MXC_ChaoSheng = 0; //超声输出
  294. MXC_FenDai_VAVLE = 0; //分带输出
  295. }
  296. Close_XiaCi();
  297. if(MXC_bChuDai)
  298. {
  299. MXC_ChuDai_VAVLE = 1;
  300. }
  301. else
  302. {
  303. MXC_ChuDai_VAVLE = 0;
  304. }
  305. if((!STOP_IN) && (MXC_ManXiaChong_UP || (MXC_bXiaChong)) && (bHandWork == 0))//加模到位 2006.7.31
  306. {
  307. MXC_bXiaChong = 0;//cMidleCoil[0] &= ~((1<<3));
  308. cAutoStep = 1;
  309. MXC_XiaChong_MOTOR = 0;
  310. bHandWork = 1;
  311. }
  312. switch(cAutoStep)
  313. {
  314. case 1: //先启动分针
  315. Start_FenZ();
  316. cAutoStep = 2;
  317. break;
  318. case 2://左右分针都已完成
  319. if((cLeftFenZhenStep == 0) && (cRightFenZhenStep == 0))
  320. {
  321. cXiaChongStep = 1; //下冲电机启动
  322. cAutoStep = 3;
  323. }
  324. break;
  325. case 3: //下冲已完成
  326. if(cXiaChongStep == 0)
  327. {
  328. MXC_LeftFenZhen_VAVLE = 0;
  329. MXC_RightFenZhen_VAVLE = 0;
  330. cAutoStep = 4;
  331. cAutoDelay = dwTickCount + 50;
  332. }
  333. break;
  334. case 4:
  335. if(dwTickCount >= cAutoDelay)
  336. {
  337. cAutoStep = 5;
  338. }
  339. break;
  340. case 5:
  341. if((dwTickCount >= cGouZhenTime))
  342. {
  343. bHandWork = 0;
  344. cAutoStep = 0;
  345. if(DC_MODE == 0)
  346. {
  347. MXC_GouZhen_VAVLE = 0;
  348. }
  349. }
  350. break;
  351. }
  352. if(bHandWork == 0) //在未手动下冲的情况下
  353. {
  354. if(MXC_bLeftFenZhen)
  355. {
  356. MXC_LeftFenZhen_VAVLE = 1;
  357. }
  358. else
  359. MXC_LeftFenZhen_VAVLE = 0;
  360. if(MXC_bRightFenZhen)
  361. {
  362. MXC_RightFenZhen_VAVLE = 1;
  363. }
  364. else
  365. MXC_RightFenZhen_VAVLE = 0;
  366. if(MXC_bGouZhen)
  367. {
  368. MXC_bGouZhen = 0;//cMidleCoil[0] &= ~((1<<9));
  369. cGouZhenTime = dwTickCount + (unsigned long)300; //勾针延时退
  370. if((GouZMode == 0))//普通勾针(活动)过链
  371. {
  372. if(MXC_GouZhen_VAVLE)
  373. MXC_GouZhen_VAVLE = 0;
  374. else
  375. {
  376. MXC_GouZhen_VAVLE = 1;
  377. }
  378. }
  379. else //固定勾针
  380. {
  381. if(MXC_GuDingGouZhen)
  382. MXC_GuDingGouZhen = 0;
  383. else
  384. {
  385. MXC_GuDingGouZhen = 1;
  386. }
  387. }
  388. }
  389. //点动下冲
  390. if((MXC_bDotXiaChong))
  391. {
  392. MXC_bDotXiaChong = 0;
  393. if(MXC_LeftFenZhen_IN && MXC_RighttFenZhen_IN)
  394. {
  395. MXC_bDotXiaChongDisplay = 1;
  396. MXC_XiaChong_MOTOR = 1;//下冲电机
  397. bPulseTatol_EN = 1;
  398. if(XiaCongMotorMode == 0)
  399. cAutoDelay = dwTickCount + 50;
  400. else
  401. {
  402. MXC_XC_SongZhou = 0;
  403. cAutoDelay = dwTickCount + 65;
  404. AxisContinueMove(X_AXIS,PARAM_LOW_SPEED,0);
  405. }
  406. }
  407. else
  408. {
  409. SetAlarmCode(100,MXC_XIA_CHONG_ALARM); //下冲条件不满足
  410. // user_datas[75] = 5; //页面跳转
  411. MXC_bSaveWorkData = 1;
  412. }
  413. }
  414. if((!MXC_XiaChong_MOTOR) && (dwTickCount >= cAutoDelay) && (MXC_bDotXiaChongDisplay))
  415. {
  416. MXC_XiaChong_MOTOR = 1; //下冲电机
  417. }
  418. if((MXC_XiaChong_MOTOR) && (dwTickCount >= cAutoDelay) && (MXC_bDotXiaChongDisplay))
  419. {
  420. bPulseTatol_EN = 0;
  421. AxisDecStop(X_AXIS);
  422. MXC_XiaChong_MOTOR = 0; //下冲电机
  423. MXC_bDotXiaChongDisplay = 0;
  424. ShaChe_Output();//
  425. }
  426. }
  427. else
  428. {
  429. MXC_bLeftFenZhen = 0;MXC_bRightFenZhen = 0;MXC_bDotXiaChong = 0;MXC_bDotXiaChongDisplay = 0;MXC_bGouZhen = 0;
  430. }
  431. }
  432. }
  433. void MXC_AutoAction(void)
  434. {
  435. unsigned long i;
  436. if(!bRunning)
  437. {
  438. if(MXC_XiaZhi_IN || (!MXC_Zipper_IN))
  439. MXC_ChuDai_VAVLE = 0;
  440. else
  441. MXC_ChuDai_VAVLE = 1;
  442. if((DC_MODE == 0) && (GouZMode == 0))
  443. {
  444. if(MXC_GouZhen_IN_UP)cGouZhenTime = 1;
  445. }
  446. else
  447. cGouZhenTime = 1;
  448. switch(cAutoStep)
  449. {
  450. case 0:
  451. break;
  452. case 1:
  453. //左右分针要退到位,过链到位要离开
  454. if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN && (dwTickCount >= cAutoDelay))
  455. {
  456. cAutoStep = 2;
  457. cMotorStep = 1; //启动拖带
  458. }
  459. break;
  460. case 2:
  461. //拖带已经完成
  462. if(cMotorStep == 0)
  463. {
  464. bFirst = 1;
  465. //调试功能
  466. if(DC_MODE != 2)cAutoStep = 3;
  467. // 调试功能 下一条 下冲
  468. else if((!MXC_bDingWei) || MXC_bNext || MXC_ManXiaChong_UP || MXC_bXiaChong)
  469. {
  470. if(MXC_bNext)
  471. {
  472. cAutoStep = 1;
  473. MXC_bNext = 0;
  474. cInt1_OK = 0;
  475. }
  476. else
  477. {
  478. cAutoStep = 3;
  479. MXC_bDingWei = 0;
  480. }
  481. }
  482. cAutoDelay = dwTickCount + 5; //延时分针
  483. }
  484. break;
  485. case 3:
  486. if((dwTickCount >= cAutoDelay) && cGouZhenTime)
  487. {
  488. cGouZhenTime = 0;
  489. cAutoStep = 4;
  490. Start_FenZ();
  491. if(XiaCongMotorMode == 1)
  492. {
  493. MXC_XiaChong_MOTOR = 1; //下冲电机
  494. }
  495. }
  496. break;
  497. case 4:
  498. //左右分针都已完成
  499. if((cLeftFenZhenStep == 0) && (cRightFenZhenStep == 0))
  500. {
  501. cXiaChongStep = 1; //下冲电机启动
  502. cAutoStep = 5;
  503. AddToTal(76); //计数增加和保存
  504. CalProSP(78);
  505. }
  506. break;
  507. case 5: //下冲已完成
  508. if(cXiaChongStep == 0)
  509. {
  510. cAutoStep = 6;
  511. cAutoDelay = dwTickCount + (unsigned long)15; //延时检测退到位
  512. }
  513. break;
  514. case 6:
  515. if(dwTickCount >= cAutoDelay)
  516. {
  517. if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN)
  518. {
  519. cAutoDelay = dwTickCount + (unsigned long)15; //延时检测退到位
  520. cAutoStep = 7;
  521. i = SET_TOTAL;
  522. if(cTotal >= i)
  523. {
  524. cStopFlag = 1;
  525. SetAlarmCode(100,MXC_FEN_ZHEN_ALARM);//分针不成功
  526. // user_datas[75] = 5; //页面跳转
  527. MXC_bSaveWorkData = 1;
  528. }
  529. }
  530. }
  531. break;
  532. case 7:
  533. if((dwTickCount >= cAutoDelay) && (MXC_Dec_IN || user_datas[21] || DC_MODE))
  534. {
  535. if(cOneTimes == 0)
  536. {
  537. cAutoStep = 1;
  538. }
  539. else
  540. {
  541. cStopFlag = 1;
  542. }
  543. }
  544. break;
  545. case 8:
  546. if((dwTickCount >= cAutoDelay))
  547. {
  548. if(DC_MODE == 0)
  549. {
  550. cAutoStep = 9;
  551. }
  552. else
  553. {
  554. if(cOneTimes == 0)
  555. {
  556. cAutoStep = 1;
  557. }
  558. else
  559. {
  560. cStopFlag = 1;
  561. }
  562. }
  563. }
  564. break;
  565. case 9:
  566. if((dwTickCount >= cGouZhenTime) && (MXC_Dec_IN == 1))
  567. {
  568. MXC_GouZhen_VAVLE = 0;
  569. if(cOneTimes == 0)
  570. {
  571. cAutoStep = 1;
  572. }
  573. else
  574. {
  575. cStopFlag = 1;
  576. }
  577. }
  578. break;
  579. }
  580. }
  581. }
  582. // 检测是否踏了脚踏开关
  583. void MXC_NiLongXiuCiJiCheckStart(void)
  584. {
  585. // 停止键 不能在工作,手动,停止过程中
  586. if((!STOP_IN) && (bHandWork == 0) && (bRunning == 0) && (cStopFlag==0)
  587. // 启动
  588. && (START_IN_UP || (MXC_bStart)) && (cKey_Time == 0) && (!MXC_GuoLian_IN))
  589. {
  590. if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_KaDai_IN)
  591. {
  592. bRunning = 1;
  593. MXC_bClearAlarm = 1;
  594. cKey_Time = 10;
  595. cAutoStep = 1;
  596. cMotorStep = 0;
  597. cXiaChongStep = 0;
  598. cLeftFenZhenStep = 0;
  599. cRightFenZhenStep = 0;
  600. SetAlarmCode(100,MXC_NO_ALARM);
  601. cAutoDelay = dwTickCount + (unsigned long)200; //先锁轴
  602. cOneTimes = 0;
  603. cGouZhenTime = 1;
  604. MXC_XiaChong_MOTOR = 0; //
  605. if(XiaCongMotorMode == 1)
  606. {
  607. MXC_XC_SongZhou = 0;
  608. }
  609. if(MOTOR_MODE == 0)
  610. MXC_TuoDaiSongZhou = 0;
  611. else
  612. MXC_TuoDaiSongZhou = 1;
  613. if(MXC_bDingWei)cSetEncode = 0;
  614. bFirst = 0;
  615. }
  616. else
  617. {
  618. // user_datas[75] = 5; //页面跳转
  619. if(MXC_KaDai_IN)
  620. SetAlarmCode(100,MXC_KA_DAI_ALARM); //卡带
  621. else
  622. SetAlarmCode(100,MXC_START_ALARM); //起动条件不满足
  623. }
  624. MXC_bStart = 0;
  625. }
  626. //卡带感应
  627. if(MXC_KaDai_IN && (dwTickCount >= cKaDaiDelay))
  628. {
  629. SetAlarmCode(100,MXC_KA_DAI_ALARM); //警告清
  630. // user_datas[75] = 5; //页面跳转
  631. cKaDaiDelay = dwTickCount + 2200;
  632. }
  633. if(MXC_KaDai_IN_UP)
  634. {
  635. MXC_bSaveWorkData = 1;
  636. }
  637. //停止
  638. if((STOP_IN_UP || (MXC_bStop)))
  639. {
  640. // 不是下冲状态
  641. if((cXiaChongStep == 0) && (bRunning == 0))
  642. {
  643. CuiQi_Start();
  644. if(!MXC_XiaChong_MOTOR)MXC_XC_SongZhou = 1;
  645. }
  646. if((cStopFlag == 0) && (cKey_Time == 0))
  647. {
  648. cKey_Time = 4;
  649. if(((DC_MODE == 0) || STOP_IN_UP) && ((XiaCongMotorMode == 0) || (cXiaChongStep == 0)))
  650. {
  651. AxisDecStop(X_AXIS);
  652. }
  653. MXC_GuDingGouZhen = 0;
  654. CuiQi_Start();
  655. if(X_DRV && !MXC_XiaChong_MOTOR && (DC_MODE == 1))
  656. {
  657. cGuZhangStop = 1;
  658. }
  659. if((++cOneTimes >= 2) || !bRunning || !X_DRV)
  660. {
  661. cStopFlag = 1;
  662. SetAlarmCode(100,MXC_NO_ALARM);
  663. // user_datas[75] = 50;
  664. if(!X_DRV)
  665. {
  666. if(MOTOR_MODE == 0)
  667. MXC_TuoDaiSongZhou = 1;
  668. else
  669. MXC_TuoDaiSongZhou = 0;
  670. }
  671. }
  672. cKaDaiDelay = dwTickCount + 1200;
  673. cGouZhenTime = dwTickCount + (unsigned long)300; //勾针延时退
  674. }
  675. MXC_bStop = 0;
  676. MXC_bSaveWorkData = 1;
  677. }
  678. if((cXiaChongStep == 0) && (((cStopFlag) != 0) || (MXC_KaDai_IN)))
  679. {
  680. bRunning = 0;
  681. bHandWork = 0;
  682. cStopFlag = 0;
  683. cAutoStep = 0;
  684. cMotorStep = 0;
  685. cXiaChongStep = 0;
  686. cLeftFenZhenStep = 0;
  687. cRightFenZhenStep = 0;
  688. MXC_XC_SongZhou = 0;
  689. MXC_XiaZhi_VAVLE = 0;
  690. MXC_LeftFenZhen_VAVLE = 0;
  691. MXC_RightFenZhen_VAVLE = 0;
  692. MXC_XiaChong_MOTOR = 0;
  693. MXC_ChaoSheng = 0;
  694. MXC_JiaoDao_OUT = 0;
  695. MXC_FenDai_VAVLE = 0;
  696. MXC_ChuDai_VAVLE = 0;
  697. MXC_GuDingGouZhen = 0;
  698. if(!X_DRV)
  699. {
  700. if(MOTOR_MODE == 0)
  701. MXC_TuoDaiSongZhou = 1;
  702. else
  703. MXC_TuoDaiSongZhou = 0;
  704. }
  705. if(MXC_KaDai_IN_UP)CuiQi_Start();
  706. MXC_XC_SongZhou = 1; // 刹车
  707. if(GouZMode != 0) //超声(固定)勾针
  708. MXC_GuDingGouZhen = 1;
  709. if(DC_MODE != 0)
  710. {
  711. if(X_DRV)cGuZhangStop = 1;
  712. }
  713. else
  714. AxisDecStop(X_AXIS);
  715. cGouZhenTime = dwTickCount + (unsigned long)300; //勾针延时退
  716. }
  717. }
  718. void JiaoDao(void)
  719. {
  720. if(cJiaoDaoStep == 1)
  721. {
  722. cChuiQiDelay = dwTickCount + 500;
  723. MXC_JiaoDao_OUT = 1;
  724. cJiaoDaoStep = 2;
  725. }
  726. else if((cJiaoDaoStep == 2) && (dwTickCount >= cChuiQiDelay))
  727. {
  728. MXC_JiaoDao_OUT = 0;
  729. cJiaoDaoStep = 0;
  730. }
  731. }
  732. void CuiQi_Start(void)
  733. {
  734. //启动吹气
  735. cChuiQiDelay = dwTickCount + (unsigned long)50 * PARAM_CHUIQI_TIME;
  736. MXC_ChuiQi_VAVLE = 1;
  737. MXC_XiChiChuiQi = 0;
  738. }
  739. void ChuiQiProc(void)
  740. {
  741. if(cChuiQiStep == 0)
  742. {
  743. }
  744. else if((cChuiQiStep == 1) && (dwTickCount >= cChuiQiDelay))
  745. {
  746. CuiQi_Start();
  747. cChuiQiStep = 0;
  748. }
  749. }
  750. void ShaChe_Output(void)
  751. {
  752. //启动吹气
  753. cShaCheTime = dwTickCount + (unsigned long)120;
  754. if(XiaCongMotorMode == 0)MXC_XC_SongZhou = 1;
  755. }
  756. void Output_XiaCi(void)//下止输出
  757. {
  758. if(MXC_XiaZhi_IN || (XIA_ZHI_ENABLE && cHMI_Test)) //下止选择
  759. {
  760. //下止输出
  761. cXiaZhiDelay = dwTickCount + 10 * PARAM_XIAZHI_TIME;
  762. MXC_XiaZhi_VAVLE = 1;
  763. }
  764. }
  765. //关下止动作
  766. void Close_XiaCi(void)
  767. {
  768. if((XiaMode != 0))//普通下止
  769. {
  770. if(MXC_GuoLian_IN_UP|| MXC_FenDai_IN_UP)
  771. MXC_FenDai_VAVLE = 1;
  772. if(bRunning)
  773. {
  774. if(MXC_GuoLian_IN_UP && MXC_XiaZhi_VAVLE)
  775. {
  776. cXiaZhiDelay = dwTickCount + 10 * PARAM_XIAZHI_DELAY_TIME;
  777. }
  778. if(MXC_GuoLian_IN && MXC_XiaZhi_VAVLE)
  779. {
  780. if(!MXC_ChaoSheng && (dwTickCount >= cXiaZhiDelay))
  781. {
  782. MXC_ChaoSheng = 1;
  783. cXiaZhiDelay = dwTickCount + (unsigned long)10 * PARAM_CHAOSHENG_TIME;
  784. }
  785. if(MXC_ChaoSheng && (dwTickCount >= cXiaZhiDelay))
  786. {
  787. MXC_FenDai_VAVLE = 0; //分带输出
  788. MXC_ChaoSheng = 0; //超声输出
  789. MXC_XiaZhi_VAVLE = 0; //下止阀
  790. }
  791. }
  792. }
  793. }
  794. else
  795. {
  796. //下止下冲电磁铁
  797. if((MXC_XiaZhi_VAVLE != 0) && (dwTickCount >= cXiaZhiDelay))
  798. {
  799. MXC_XiaZhi_VAVLE = 0;
  800. }
  801. }
  802. }
  803. unsigned long LengthCallPulse(unsigned long length)
  804. {
  805. return (length * 2000 / PARAM_DAILUN_LENGTH);
  806. }
  807. void NiLongXiuCiJi_Motor(void)
  808. {
  809. unsigned long ch;
  810. switch(cMotorStep)
  811. {
  812. case 0:
  813. return;
  814. break;
  815. // 过链 左分针退位 左到位
  816. case 1: if(MXC_LeftFenZhen_Origin_IN && (!MXC_LeftFenZhen_IN) && MXC_RightFenZhen_Origin_IN && (!MXC_RighttFenZhen_IN))
  817. {
  818. cAutoDelay = dwTickCount + (unsigned long)35; //延时检测
  819. MXC_LIHE_VAVLE = 1; //离合器
  820. //计算长度脉冲
  821. // 拉链长度
  822. ch = SET_ZIPPER_LENGTH;
  823. if(DC_MODE != 2)
  824. {
  825. ch += SET_REVISE_ZIPPER_LENGTH;
  826. ch += PARAM_DAOKOU_LENGTH;//模具长度(刀口长度)
  827. }
  828. cSetEncode = LengthCallPulse(ch);
  829. //慢速长度
  830. ch = LengthCallPulse(PARAM_LOWSPEED_LENGTH);
  831. //色标的定位长度
  832. cDinWeiTime = LengthCallPulse(PARAM_SEBIAO_DW_LENGTH);
  833. //色标提前检测距离
  834. cAddSetPulseNum = LengthCallPulse(PARAM_SEBIAO_TQ_LENGTH);
  835. cEncodePulse = 0;
  836. cInt1_OK = 0;
  837. if(DC_MODE == 0)
  838. {
  839. if((GouZMode == 0))//普通勾针(活动)过链
  840. {
  841. cMotorStep = 2;
  842. if(bFirst == 0)
  843. AxisMoveTwoPos(X_AXIS,PARAM_FIRST_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0);
  844. else
  845. AxisMoveTwoPos(X_AXIS,PARAM_SET_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0);
  846. }
  847. else //带下止型勾针
  848. {
  849. cMotorStep = 11;
  850. if(bFirst == 0)
  851. AxisMoveTwoPos(X_AXIS,PARAM_FIRST_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0);
  852. else
  853. AxisMoveTwoPos(X_AXIS,PARAM_SET_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0);
  854. cAutoDelay = dwTickCount + (unsigned long)70; //延时检测
  855. }
  856. cGuZhangStop = 0;
  857. cWorkPulseNum = 0;
  858. if(!MXC_GouZhen_VAVLE)
  859. {
  860. cMotorStep = 3;
  861. }
  862. }
  863. else if(DC_MODE == 1)
  864. {
  865. cMotorStep = 20;
  866. MXC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
  867. MXC_GuDingGouZhen = 1; //定位(活动勾针)电磁阀
  868. cAutoDelay = dwTickCount + 130; //要检测对射
  869. if(cWorkPulseNum >= cSetEncode)cMotorStep = 0;
  870. else
  871. {
  872. AxisMovePos(X_AXIS,PARAM_SET_SPEED,cSetEncode);
  873. }
  874. }
  875. else
  876. {
  877. if(cWorkPulseNum >= cSetEncode)cMotorStep = 0;
  878. else
  879. {
  880. AxisMoveTwoPos(X_AXIS,PARAM_SET_SPEED,cSetEncode - ch,PARAM_LOW_SPEED,9999999,0);
  881. }
  882. }
  883. }
  884. break;
  885. // step2-5 活动勾针定寸
  886. case 2:if((dwTickCount >= cAutoDelay))
  887. {
  888. MXC_GouZhen_VAVLE = 0;//定位电磁阀
  889. }
  890. if(!MXC_GouZhen_VAVLE && !MXC_GouZhen_IN)
  891. {
  892. if(!PWM_RUN_STATE)
  893. TuoDaiStartPWM(cStepNum);
  894. cStepMode = 1; //加速模式
  895. cMotorStep = 3;
  896. cAutoDelay = dwTickCount + (unsigned long)10000;
  897. }
  898. break;
  899. case 3:
  900. if(cStepNum > (cLowSpeadLimit + 1))
  901. {
  902. cAutoDelay = dwTickCount + (unsigned long)10000;
  903. }
  904. //减速信号方式 数控减速方式
  905. if(((IN04 != 0) && (user_datas[21] == 0)) || ((cPulseStepDEC >= cPulseCount) && (user_datas[21] == 1)))
  906. {
  907. user_datas[126] = cPulseCount;
  908. cSPDec = 3;
  909. cStepNum = cLowSpeadLimit+1;
  910. cPulseCount = cPulseStepDEC;
  911. cStepMode = 2; //减速模式
  912. cMotorStep = 4;
  913. cAutoDelay = dwTickCount + (unsigned long)10000;
  914. }
  915. if((MXC_GouZhen_IN)) //X003 到位信号也要停
  916. {
  917. cStepMode = 2; //减速模式
  918. cMotorStep = 4;
  919. CLRQ00; //离合器断开
  920. StopPWM(); //PWMTCR = 0x02; //在设置之前,先将定时器复位
  921. }
  922. else if((dwTickCount >= cAutoDelay) && (cStepNum <= cLowSpeadLimit))
  923. {
  924. cStopFlag = 1;
  925. user_datas[100] = 7; //分针不成功
  926. user_datas[75] = 5; //页面跳转
  927. MXC_bSaveWorkData = 1;
  928. }
  929. break;
  930. case 4:
  931. if(MXC_GouZhen_IN)
  932. {
  933. cMotorStep = 0;
  934. StopPWM();//PWMTCR = 0x02; //在设置之前,先将定时器复位
  935. }
  936. else if((dwTickCount >= cAutoDelay))
  937. {
  938. cStopFlag = 1;
  939. user_datas[100] = 7; //分针不成功
  940. user_datas[75] = 5; //页面跳转
  941. MXC_bSaveWorkData = 1;
  942. }
  943. /*
  944. //布带对射检测
  945. if(X14)
  946. {
  947. cBudaiCheckDelay = dwTickCount + 30000;
  948. }
  949. else if(dwTickCount >= cBudaiCheckDelay) //没布带了
  950. {
  951. cStopFlag = 1;
  952. user_datas[100] = 7; //分针不成功
  953. user_datas[75] = 5; //页面跳转
  954. MXC_GouZhen_VAVLE = 0;
  955. MXC_bSaveWorkData = 1;
  956. }
  957. */
  958. break;
  959. //以下为固定勾针方式
  960. case 11:
  961. if(XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
  962. {
  963. if(dwTickCount >= cAutoDelay)MXC_GuDingGouZhen = 0;
  964. if(!X21)
  965. {
  966. cSPDec =1; //减速度
  967. cStepMode = 2; //减速模式
  968. cMotorStep = 12;
  969. cAutoDelay = dwTickCount + (unsigned long)1500; //延时检测
  970. }
  971. }
  972. else
  973. { bFlag = X21;
  974. if(GuoLianCheckMode)
  975. bFlag = ~bFlag;
  976. if(bFlag)
  977. {
  978. cStepMode = 2; //减速模式
  979. cMotorStep = 12;
  980. cAutoDelay = dwTickCount + (unsigned long)user_datas[12]; //延时检测
  981. }
  982. }
  983. break;
  984. case 12:
  985. if(dwTickCount >= cAutoDelay)
  986. {
  987. if(Y15)
  988. {
  989. MXC_GuDingGouZhen = 0;
  990. cAutoDelay = dwTickCount + (unsigned long)1500; //延时检测
  991. }
  992. else if(!Y15)
  993. {
  994. cStopFlag = 1;
  995. user_datas[100] = 7; //没链停机
  996. user_datas[75] = 5; //页面跳转
  997. MXC_bSaveWorkData = 1;
  998. }
  999. }
  1000. if(XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
  1001. {
  1002. if(!IN21)
  1003. {
  1004. MXC_GuDingGouZhen = 0;
  1005. cMotorStep = 13;
  1006. cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机
  1007. }
  1008. }
  1009. else
  1010. {
  1011. if(GuoLianCheckMode)
  1012. bFlag = X21_UP;
  1013. else
  1014. bFlag = X21_DW;
  1015. if(bFlag)
  1016. {
  1017. MXC_GuDingGouZhen = 0;
  1018. cMotorStep = 13;
  1019. cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机
  1020. }
  1021. }
  1022. break;
  1023. case 13:
  1024. if((dwTickCount >= cAutoDelay))
  1025. {
  1026. if(XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
  1027. {
  1028. StopPWM();
  1029. if(X21)
  1030. {
  1031. cMotorStep = 0;
  1032. CLRQ00;
  1033. }
  1034. }
  1035. else
  1036. {
  1037. if(GuoLianCheckMode)
  1038. bFlag = !X21;
  1039. else
  1040. bFlag = X21;
  1041. if(!bFlag)
  1042. {
  1043. cMotorStep = 0;
  1044. StopPWM();
  1045. CLRQ00;
  1046. }
  1047. }
  1048. }
  1049. if(MXC_Zipper_IN)
  1050. {
  1051. cBudaiCheckDelay = dwTickCount + 30000;
  1052. }
  1053. else if(dwTickCount >= cBudaiCheckDelay) //没布带了
  1054. {
  1055. cStopFlag = 1;
  1056. SetAlarmCode(100,MXC_NO_ZIPPER_ALARM); //没拉链
  1057. // user_datas[75] = 5; //页面跳转
  1058. MXC_GouZhen_VAVLE = 0;
  1059. MXC_bSaveWorkData = 1;
  1060. }
  1061. break;
  1062. //伺服定寸
  1063. case 20:
  1064. if(!X_DRV)cMotorStep = 0;
  1065. //布带对射检测
  1066. if(MXC_Zipper_IN)
  1067. {
  1068. cAutoDelay = dwTickCount + 140;
  1069. }
  1070. else if(dwTickCount >= cAutoDelay) //没布带了
  1071. {
  1072. cStopFlag = 1;
  1073. SetAlarmCode(100,MXC_NO_ZIPPER_ALARM); //没拉链
  1074. // user_datas[75] = 5; //页面跳转
  1075. MXC_GouZhen_VAVLE = 0;
  1076. MXC_bSaveWorkData = 1;
  1077. }
  1078. break;
  1079. case 50:
  1080. cStopFlag = 1;
  1081. SetAlarmCode(100,MXC_NO_SEBIAO_ALARM); //
  1082. // user_datas[75] = 5; //页面跳转
  1083. MXC_bSaveWorkData = 1;
  1084. }
  1085. }
  1086. //下冲
  1087. void NiLongXiuCiJi_XiaC(void)
  1088. {
  1089. if(bRunning)
  1090. Close_XiaCi();
  1091. switch(cXiaChongStep)
  1092. {
  1093. case 0:
  1094. return;
  1095. break;
  1096. case 1:
  1097. cXiaChongStep = 2;
  1098. MXC_XC_SongZhou = 0;//cMidleCoil[2] &= ~Q01;//CLRY001; //刹车打开
  1099. cDelayTime4 = dwTickCount + (unsigned long)7; //刹车放开时间
  1100. //下止输出
  1101. if(bRunning)
  1102. Output_XiaCi();
  1103. break;
  1104. case 2:
  1105. if(dwTickCount >= cDelayTime4)
  1106. {
  1107. bPulseTatol_EN = 1;
  1108. cXiaChongStep = 3;
  1109. MXC_XiaChong_MOTOR = 1;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机
  1110. cDelayTime4 = dwTickCount + (unsigned long)ERRORTIME; //下冲最长时间
  1111. cPulseCount = 0;
  1112. cGuZhangStop = 0;
  1113. if(XiaCongMotorMode == 1)
  1114. {
  1115. cStepMode = 4; //计脉冲模式
  1116. cPulseCount = 2020;
  1117. cSPDec = 3;
  1118. cPulseStepCount = 0;
  1119. cStepSet = user_datas[29];
  1120. cPulseStepDEC = cStepSet * cSPDec + 250;
  1121. cSPAdd = 12;//user_datas[30];
  1122. cStepNum = user_datas[28];
  1123. cLowSpeadLimit = cStepNum + 3;
  1124. StartPWM(cStepNum);
  1125. MXC_ChuiQi_VAVLE = 1;
  1126. }
  1127. }
  1128. break;
  1129. case 3: //碰到右大微动,延时停
  1130. if((X10_UP))
  1131. {
  1132. cDelayTime4 = dwTickCount + (unsigned long)user_datas[5];//cSetPara[5];
  1133. cXiaChongStep = 4;
  1134. MXC_LeftFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q04;//CLRY004; //退左分针
  1135. MXC_RightFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q06;//CLRY006; //退右分针
  1136. cStepMode = 2; //减速模式
  1137. cGouZhenTime = dwTickCount + (unsigned long)150; //勾针延时退
  1138. MXC_GouZhen_VAVLE = 1;
  1139. MXC_GuDingGouZhen = 1;
  1140. }
  1141. else if(dwTickCount >= cDelayTime4) //自动停机
  1142. {
  1143. bPulseTatol_EN = 0;
  1144. StopPWM();
  1145. cXiaChongStep = 0;
  1146. cStopFlag = 1;
  1147. ShaChe_Output();//MXC_XC_SongZhou = 1;//cMidleCoil[2] |= Q01;//SETY001; //刹车
  1148. MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] &= ~Q00;//CLRY000; //下冲电机
  1149. user_datas[100] = 5; //下冲异常
  1150. user_datas[75] = 5; //页面跳转
  1151. MXC_LeftFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q04;//CLRY004; //退左分针
  1152. MXC_RightFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q06;//CLRY006; //退右分针
  1153. MXC_bSaveWorkData = 1;
  1154. }
  1155. // if(X14_DW)
  1156. // {
  1157. // }
  1158. break;
  1159. case 4:
  1160. // if(cStepNum <= cLowSpeadLimit)
  1161. // StopPWM();
  1162. if(dwTickCount >= cDelayTime4)
  1163. {
  1164. cXiaChongStep = 5;
  1165. bPulseTatol_EN = 0;
  1166. cWorkPulseNum = 0;
  1167. StopPWM();
  1168. MXC_XiaChong_MOTOR = 0; //延时刹车
  1169. cDelayTime4 = dwTickCount + (unsigned long)user_datas[3];//cSetPara[3];
  1170. }
  1171. break;
  1172. case 5:
  1173. if((dwTickCount >= cDelayTime4))
  1174. {
  1175. cXiaChongStep = 6;
  1176. ShaChe_Output();//MXC_XC_SongZhou = 1;//cMidleCoil[2] |= Q01;//SETY001;
  1177. cDelayTime4 = dwTickCount + (unsigned long)30;
  1178. }
  1179. break;
  1180. case 6:
  1181. if(!X17 && !MXC_XiaZhi_VAVLE && !MXC_ChaoSheng && (dwTickCount >= cDelayTime4))
  1182. {
  1183. cXiaChongStep = 0;
  1184. }
  1185. break;
  1186. }
  1187. }
  1188. //启动分针
  1189. void Start_FenZ(void)
  1190. {
  1191. cDelayTime5 = dwTickCount + 30;
  1192. cLeftFenZhenStep = 1;
  1193. cRightFenZhenStep = 0;
  1194. cRFengTimer = 0;
  1195. cLFengTimer = 0;
  1196. }
  1197. #define FenZhengErrorTime 5000
  1198. //分针
  1199. void NiLongXiuCiJi_FenZhengProc(void)
  1200. {
  1201. if(FenZSelect != 0)
  1202. {
  1203. cLeftFenZhenStep = 0;
  1204. cRightFenZhenStep = 0;
  1205. }
  1206. //右分针
  1207. switch(cLeftFenZhenStep)
  1208. {
  1209. case 0:
  1210. break;
  1211. case 1:
  1212. if(dwTickCount >= cDelayTime5)
  1213. {
  1214. cLeftFenZhenStep = 2;
  1215. MXC_RightFenZhen_VAVLE = 1;//cMidleCoil[2] |= Q06;//SETY006; //右分针电磁阀
  1216. cDelayTime5 = dwTickCount + (unsigned long)FenZhengErrorTime;
  1217. }
  1218. break;
  1219. case 2: //碰到右大微动,延时停
  1220. if(!MXC_RightFenZhen_Origin_IN) //右分针原点离开
  1221. {
  1222. cDelayTime5 = dwTickCount + 500;
  1223. cLeftFenZhenStep = 3;
  1224. // cRightFenZhenStep = 1; //左分针延时启动
  1225. cDelayTime6 = dwTickCount + (unsigned long)20;
  1226. }//右分针不下去
  1227. else if(dwTickCount >= cDelayTime5)
  1228. {
  1229. cStopFlag = 1;
  1230. user_datas[100] = 4; //分针不成功
  1231. user_datas[75] = 5; //页面跳转
  1232. MXC_bSaveWorkData = 1;
  1233. if(XiaCongMotorMode == 1)
  1234. {
  1235. MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机
  1236. }
  1237. }
  1238. break;
  1239. case 3:
  1240. if(MXC_RighttFenZhen_IN) //插针到位
  1241. {
  1242. cLeftFenZhenStep = 0;
  1243. cRightFenZhenStep = 1; //左分针延时启动
  1244. }
  1245. else if(dwTickCount >= cDelayTime5)
  1246. {
  1247. MXC_RightFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q06;//CLRY006; //右分针
  1248. cRFengTimer++;
  1249. //当右分针分不到位时,左分针也要重新分针
  1250. MXC_LeftFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q04;//CLRY004;
  1251. cRightFenZhenStep = 0;
  1252. if(cRFengTimer < 4)
  1253. {
  1254. cLeftFenZhenStep = 4;
  1255. cDelayTime5 = dwTickCount + FenZhengErrorTime;
  1256. }
  1257. else
  1258. {
  1259. cStopFlag = 1;
  1260. user_datas[100] = 4; //分针不成功
  1261. user_datas[75] = 5; //页面跳转
  1262. MXC_bSaveWorkData = 1;
  1263. if(XiaCongMotorMode == 1)
  1264. {
  1265. MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机
  1266. }
  1267. }
  1268. }
  1269. break;
  1270. case 4:
  1271. if(MXC_RightFenZhen_Origin_IN) //退到位
  1272. {
  1273. cLeftFenZhenStep = 5;
  1274. cDelayTime5 = dwTickCount + 150;
  1275. }
  1276. else if(dwTickCount >= cDelayTime5)
  1277. {
  1278. cStopFlag = 1;
  1279. user_datas[100] = 4; //分针不成功
  1280. user_datas[75] = 5; //页面跳转
  1281. MXC_bSaveWorkData = 1;
  1282. if(XiaCongMotorMode == 1)
  1283. {
  1284. MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机
  1285. }
  1286. }
  1287. break;
  1288. case 5:
  1289. if(dwTickCount >= cDelayTime5)
  1290. {
  1291. cDelayTime5 = dwTickCount + 30;
  1292. cLeftFenZhenStep = 1;
  1293. }
  1294. break;
  1295. }
  1296. //左分针
  1297. switch(cRightFenZhenStep)
  1298. {
  1299. case 0:
  1300. break;
  1301. case 1:
  1302. if(dwTickCount >= cDelayTime6)
  1303. {
  1304. cRightFenZhenStep = 2;
  1305. MXC_LeftFenZhen_VAVLE = 1;//cMidleCoil[2] |= Q04;//SETY004; //左分针电磁阀
  1306. cDelayTime6 = dwTickCount + (unsigned long)FenZhengErrorTime;
  1307. }
  1308. break;
  1309. case 2: //碰到右大微动,延时停
  1310. if(!MXC_LeftFenZhen_Origin_IN) //右分针原点离开
  1311. {
  1312. cDelayTime6 = dwTickCount + 500;
  1313. cRightFenZhenStep = 3;
  1314. }//左分针不下去
  1315. else if(dwTickCount >= cDelayTime6)
  1316. {
  1317. cStopFlag = 1;
  1318. user_datas[100] = 4; //分针不成功
  1319. user_datas[75] = 5; //页面跳转
  1320. MXC_bSaveWorkData = 1;
  1321. if(XiaCongMotorMode == 1)
  1322. {
  1323. MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机
  1324. }
  1325. }
  1326. break;
  1327. case 3:
  1328. if(MXC_LeftFenZhen_IN) //插针到位
  1329. cRightFenZhenStep = 0;
  1330. else if(dwTickCount >= cDelayTime6)
  1331. {
  1332. MXC_LeftFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q04;//CLRY004; //左分针
  1333. cLFengTimer++;
  1334. if(cLFengTimer < 6)
  1335. {
  1336. cRightFenZhenStep = 4;
  1337. cDelayTime6 = dwTickCount + FenZhengErrorTime;
  1338. if((cLFengTimer%2) == 0)
  1339. {
  1340. MXC_RightFenZhen_VAVLE = 0;//cMidleCoil[2] &= ~Q06;//CLRY006;
  1341. cLeftFenZhenStep = 0;
  1342. }
  1343. }
  1344. else
  1345. {
  1346. if(XiaCongMotorMode == 1)
  1347. {
  1348. MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机
  1349. }
  1350. cStopFlag = 1;
  1351. user_datas[100] = 4; //分针不成功
  1352. user_datas[75] = 5; //页面跳转
  1353. MXC_bSaveWorkData = 1;
  1354. }
  1355. }
  1356. break;
  1357. case 4:
  1358. if(MXC_LeftFenZhen_Origin_IN) //退到位
  1359. {
  1360. cRightFenZhenStep = 5;
  1361. cDelayTime6 = dwTickCount + 150;
  1362. }
  1363. else if(dwTickCount >= cDelayTime6)
  1364. {
  1365. cStopFlag = 1;
  1366. user_datas[100] = 4; //分针不成功
  1367. user_datas[75] = 5; //页面跳转
  1368. MXC_bSaveWorkData = 1;
  1369. if(XiaCongMotorMode == 1)
  1370. {
  1371. MXC_XiaChong_MOTOR = 0;//cMidleCoil[2] |= Q00;//SETY000; //下冲电机
  1372. }
  1373. }
  1374. break;
  1375. case 5:
  1376. if(dwTickCount >= 36)
  1377. {
  1378. cDelayTime6 = dwTickCount + 30;
  1379. if((cLFengTimer%2) == 0) //左边插两次都插不到,就退右边再同时插
  1380. {
  1381. cDelayTime5 = dwTickCount + 30;
  1382. cLeftFenZhenStep = 1;
  1383. cRFengTimer = 0;
  1384. cRightFenZhenStep = 0;
  1385. }
  1386. else
  1387. {
  1388. cRightFenZhenStep = 1;
  1389. }
  1390. }
  1391. break;
  1392. }
  1393. }
  1394. #endif