HYMXC_NiLong_StepJi.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  1. #include "global.h"
  2. #if HONG_YE_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