JHMXC_NiLong_StepJi.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  1. #include "global.h"
  2. #if JIN_HONG_MACHINE==1
  3. void MXC_InitAction(void);
  4. void MXC_Action(void);
  5. void MXC_CheckStart(void);
  6. void MXC_ManualAction(void);
  7. void MXC_DC_AutoAction(void);
  8. void MXC_DC_Motor(void);
  9. void MXC_XiaChong(void);
  10. void MXC_ChuiQi(void);
  11. void MXC_FenZhen(void);
  12. void MXC_DC_SongDai(void);
  13. void MXC_DC_ShaChe(void);
  14. void MXC_DC_XC_BuJin_motor(void);
  15. void MXC_ExtiAcitionX20(void);
  16. unsigned long cZipperLength[2];
  17. #define SB_CHECK_IN !PAin(15)
  18. //故障报警
  19. void MXC_SetAlarmCode(unsigned alarm_code)
  20. {
  21. SetAlarmCode(MXC_ALARM_ADDR,alarm_code);
  22. MXC_DC_bAlarmStop = 1;
  23. }
  24. //X20中断
  25. void MXC_ExtiAcitionX20(void)
  26. {
  27. if (cSeBiaoEn && !cSeBiaoOk)
  28. {
  29. cSeBiaoOk = 1;
  30. MXC_SB_SaveLength = GetPos(X_AXIS);
  31. MXC_SB_ENCODE_MIN=dwEnRealPos;
  32. //MXC_Clear_Servo_Pos=1;
  33. }
  34. }
  35. void MXC_SBCHECK_PROC(void)
  36. {
  37. static unsigned short flitering=0;
  38. if(SB_CHECK_IN)
  39. {
  40. flitering++;
  41. if(flitering>=2)
  42. {
  43. if (cSeBiaoEn && !cSeBiaoOk)
  44. {
  45. cSeBiaoOk = 1;
  46. MXC_SB_SaveLength = GetPos(X_AXIS);
  47. MXC_SB_ENCODE_MIN=dwEnRealPos;
  48. }
  49. }
  50. }
  51. else
  52. {
  53. flitering=0;
  54. }
  55. }
  56. unsigned char ComPareLength(void)//前后拉链对比
  57. {
  58. if ((cZipperLength[0] != 0) && (cZipperLength[1] != 0))
  59. {
  60. if (cZipperLength[0] > cZipperLength[1])
  61. {
  62. if ((cZipperLength[0] - cZipperLength[1]) > 50)
  63. {
  64. return 0;
  65. }
  66. else
  67. return 1;
  68. }
  69. else
  70. {
  71. if ((cZipperLength[1] - cZipperLength[0]) > 50)
  72. {
  73. return 0;
  74. }
  75. else
  76. return 1;
  77. }
  78. }
  79. else
  80. return 0;
  81. }
  82. void MXC_JiaoDao(void)
  83. {
  84. if (MXC_cJiaoDaoStep == 1)
  85. {
  86. MXC_cJiaoDaoDelay = dwTickCount + 500;
  87. MXC_SeBiao_JiaoDao = 1;
  88. MXC_cJiaoDaoStep = 2;
  89. }
  90. else if ((MXC_cJiaoDaoStep == 2) && (dwTickCount >= MXC_cJiaoDaoDelay))
  91. {
  92. MXC_SeBiao_JiaoDao = 0;
  93. MXC_cJiaoDaoStep = 0;
  94. }
  95. }
  96. //步进电机下冲
  97. void MXC_DC_XC_BuJin_motor(void)
  98. {
  99. switch(MXC_cXiaChongStep)
  100. {
  101. case 0:
  102. break;
  103. case 1:
  104. if(GetEn(Z_AXIS) == XC_MOTOR_DISEN)
  105. {
  106. SetEn(Z_AXIS,XC_MOTOR_EN);
  107. MXC_BUJIN_XC_Delay = dwTickCount + 170;
  108. }
  109. MXC_cXiaChongStep = 2;
  110. MXC_cRightFZStep = 1;//启动右分针
  111. MXC_cLeftFZStep = 0;
  112. break;
  113. case 2:
  114. if((MXC_cRightFZStep == 0) && (MXC_cLeftFZStep == 0) && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN )
  115. {
  116. SetPos(Z_AXIS, 0);
  117. if (MXC_DC_bRunning)
  118. {
  119. MXC_BUJIN_XC_Delay = dwTickCount + MXC_PARAM_DELAY_XC;
  120. }
  121. MXC_cXiaChongStep = 3;
  122. }
  123. break;
  124. case 3:
  125. if(dwTickCount >= MXC_BUJIN_XC_Delay)
  126. {
  127. MXC_cXiaChongStep = 4;
  128. if(MXC_DC_bRunning) MXC_GouZhen_VAVLE = 1;
  129. AxisMovePosAccDecNotStop(Z_AXIS,MXC_DC_XC_MOTOR_HIGH_SPEED,2000,
  130. 1200,MXC_DC_XC_MOTOR_LOW_SPEED,
  131. 100,100,MXC_DC_XC_MOTOR_LOW_LENGTH);
  132. MXC_BUJIN_XC_Delay = dwTickCount + MXC_XIACHONG_EEROR_TIME;
  133. }
  134. break;
  135. case 4:
  136. if(MXC_XiaChong_IN_UP)
  137. {
  138. SetEncodePos(ENCODE_X22X23, 0);
  139. AxisMovePosAccDec(Z_AXIS,MXC_DC_XC_MOTOR_LOW_SPEED,MXC_DC_XC_MOTOR_GO_LENGTH,
  140. 1200,MXC_DC_XC_MOTOR_LOW_SPEED,
  141. 100,100,MXC_DC_XC_MOTOR_GO_LENGTH/3);
  142. MXC_LeftFenZhen_VAVLE = 0;
  143. MXC_RightFenZhen_VAVLE = 0;
  144. MXC_cXiaChongStep = 5;
  145. MXC_BUJIN_XC_Delay = dwTickCount;
  146. }
  147. else if(dwTickCount >= MXC_BUJIN_XC_Delay)//步进异常
  148. {
  149. MXC_SetAlarmCode(MXC_XC_ALARM);
  150. MXC_LeftFenZhen_VAVLE = 0;
  151. MXC_RightFenZhen_VAVLE = 0;
  152. MXC_cXiaChongStep = 0;
  153. }
  154. break;
  155. case 5:
  156. if(dwTickCount >= MXC_BUJIN_XC_Delay && !Z_DRV)
  157. {
  158. MXC_MOTOR_DATA_Num++;
  159. if(MXC_MOTOR_DATA_Num > 99)
  160. MXC_MOTOR_DATA_Num = 0;
  161. if(!MXC_DC_bRunning){
  162. SetEncodePos(ENCODE_X22X23, 0);
  163. SetPos(X_AXIS, 0);
  164. }
  165. MXC_cXiaChongStep = 0;
  166. }
  167. break;
  168. }
  169. }
  170. void MXC_InitAction(void)
  171. {
  172. float length_buff,pulse_buff;
  173. length_buff = MXC_MXC_PARAM_DAILUN_LENGTH;
  174. pulse_buff = MXC_MXC_PARAM_CYCLE_PULSE;
  175. XGearRatio = pulse_buff/length_buff;
  176. length_buff = MXC_BM_LENGTH;
  177. pulse_buff = MXC_BM_CYCLE_PULSE * 4;
  178. SetEncodeGearRatio(ENCODE_X22X23, pulse_buff/length_buff);
  179. ZGearRatio = 1;//z轴用脉冲数做单位
  180. SetEn(X_AXIS,DC_Motor_DISEN);
  181. SetEn(Y_AXIS,XZ_Motor_DISEN);
  182. SetDirReverse(X_AXIS, MXC_DC_Reverse_EN);
  183. MXC_STOP_IN_FLAG = MXC_STOP_IN;
  184. MXC_STOP_IN_FLAG_OLD = MXC_STOP_IN_FLAG;
  185. MXC_SaveLength = 0;
  186. //外部中断配置
  187. USE_X20_EXTI = 1;
  188. X20EXTI_DIR = 0;
  189. //设置X轴的加速模式
  190. axis_set_parameter(axis_x,AXIS_ACCDEC_MODE,4);
  191. //只有编码器的情况长度由编码器值确定
  192. SetEncode_enable(ENCODE_X22X23);
  193. MXC_DC_KongWei_Length = MXC_PARAM_DAOKOU_LENGTH;
  194. }
  195. void MXC_Action(void)
  196. {
  197. MXC_CheckStart(); //启动
  198. MXC_ManualAction();
  199. MXC_DC_AutoAction();
  200. MXC_DC_Motor(); //定寸电机控制
  201. if(!MXC_DC_XC_MODE)
  202. MXC_XiaChong(); //下冲
  203. else if(MXC_DC_XC_MODE)
  204. MXC_DC_XC_BuJin_motor();
  205. MXC_DC_ShaChe();
  206. MXC_FenZhen(); //分针
  207. MXC_ChuiQi(); //吹气
  208. MXC_DC_SongDai(); //送带控制
  209. MXC_JiaoDao(); //色标教导
  210. //servo_com_run();
  211. }
  212. void MXC_DC_SongDai(void)
  213. {
  214. if(!MXC_SongDai_MOTOR)
  215. {
  216. MXC_SongDai_LongTime = dwTickCount;
  217. }
  218. else//送带一直输出无法触发送带到位
  219. {
  220. if((dwTickCount - MXC_SongDai_LongTime) >= MXC_PARAM_SD_Pretect_TIME)
  221. {
  222. if(!MXC_DC_bRunning)
  223. {
  224. MXC_PARAM_SongDai_Switch = 0;
  225. MXC_SetAlarmCode(MXC_DC_SONGDAI_ALARM);
  226. }
  227. else
  228. {
  229. MXC_SongDai_MOTOR = 0;
  230. MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay;
  231. }
  232. }
  233. }
  234. }
  235. void MXC_ManualAction(void)
  236. {
  237. char i;
  238. short *revise_buff;
  239. revise_buff =(short *)( &user_datas[17]);
  240. if(MXC_DATA_Clean)
  241. {
  242. i = 0;
  243. while(i < 100)
  244. {
  245. user_datas[200 + i] = 0;
  246. i++;
  247. }
  248. MXC_DATA_Clean = 0;
  249. MXC_MOTOR_DATA_Num = 0;
  250. }
  251. //清总产量
  252. if(MXC_bClear)
  253. {
  254. MXC_bClear = 0;
  255. ClrcToTal(MXC_DC_TOTAL_ADDR);
  256. }
  257. if(MXC_bAddLength)
  258. {
  259. MXC_bAddLength=0;
  260. *revise_buff += 5;
  261. }
  262. if(MXC_bDecLength)
  263. {
  264. MXC_bDecLength=0;
  265. *revise_buff -= 5;
  266. }
  267. //当长度改变时,生产总量自动清零
  268. if(MXC_bChangeLength)
  269. {
  270. MXC_bChangeLength = 0;
  271. MXC_SaveLength = 0;
  272. MXC_bClear = 1;
  273. }
  274. //工作方式选择(数控定寸和勾针定寸) 
  275. if (MXC_bSetDCMode)
  276. {
  277. MXC_bSetDCMode = 0;
  278. if (!MXC_DC_bRunning)
  279. {
  280. MXC_DC_MODE++;
  281. if (MXC_DC_MODE > 2)
  282. MXC_DC_MODE = 0;
  283. if (MXC_DC_MODE != 0)
  284. {
  285. MXC_GouZhen_VAVLE = 1;
  286. }
  287. }
  288. }
  289. //有链感应
  290. if (MXC_DC_bRunning)//检测拉链,由于拉链有间隙,故需要延迟检测
  291. {
  292. if (MXC_Zipper_IN)
  293. {
  294. MXC_cBudaiCheckDelay = dwTickCount + MXC_PARAM_BUDAI_ALARM_TIME;
  295. }
  296. else if (dwTickCount >= MXC_cBudaiCheckDelay)
  297. {
  298. MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM); //没拉链
  299. }
  300. }
  301. if(MXC_PARAM_SongDai_Switch)
  302. {
  303. if(!MXC_SongDai_IN && MXC_Zipper_IN && (dwTickCount >= MXC_cSongDaiDelay))
  304. {
  305. MXC_SongDai_MOTOR = 1;
  306. }
  307. else if(MXC_SongDai_IN)
  308. {
  309. MXC_SongDai_MOTOR = 0;
  310. MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay;
  311. }
  312. }
  313. else
  314. {
  315. MXC_SongDai_MOTOR = 0;
  316. MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay;
  317. }
  318. if((MXC_DC_bRunning) == 0) ////手动
  319. {
  320. //送带
  321. if(MXC_bSongDai)
  322. {
  323. MXC_SongDai_MOTOR = 1;
  324. }
  325. //顶刀保护
  326. if(MXC_bDingDao_Baohu)
  327. {
  328. MXC_bDingDao_Baohu = 0;
  329. MXC_DingDao_BaoHu_VAVLE = ~MXC_DingDao_BaoHu_VAVLE;
  330. }
  331. //吹气
  332. if (MXC_bChuiQi)
  333. {
  334. MXC_bChuiQi = 0;
  335. if (MXC_cChuiQiStep == 0)
  336. MXC_cChuiQiStep = 1;
  337. }
  338. //定寸电机拖带
  339. if(MXC_bDCTD_P)
  340. {
  341. if(!X_DRV)
  342. {
  343. // MXC_TuoDaiSongZhou= MXC_SERVER_EN;
  344. SetEn(X_AXIS, DC_Motor_EN);
  345. AxisContinueMoveAcc(X_AXIS, MXC_DC_PARAM_MUL_SPEED, MXC_DC_DIR_P, 1200,
  346. 1200, 120, 120);
  347. }
  348. }
  349. if(X_DRV && !MXC_bDCTD_P && !MXC_DC_bRunning && (MXC_DC_cMotorStep == 0))
  350. {
  351. AxisEgmStop(X_AXIS);
  352. }
  353. //下冲电机正转
  354. if(MXC_bXCDJ_P)
  355. {
  356. if(!Z_DRV)
  357. {
  358. SetEn(Z_AXIS, XC_MOTOR_EN);
  359. AxisContinueMoveAcc(Z_AXIS, 3000, MXC_XC_DIR_P, 1200,
  360. 1200, 120, 120);
  361. }
  362. }
  363. if(Z_DRV && !MXC_bXCDJ_P && !MXC_DC_bRunning && (MXC_cXiaChongStep == 0))
  364. {
  365. // SetEn(Z_AXIS, XC_MOTOR_DISEN);
  366. AxisEgmStop(Z_AXIS);
  367. }
  368. //分针+下冲
  369. if (MXC_ManXiaChong_UP || MXC_bXiaChong)
  370. {
  371. MXC_bXiaChong = 0;
  372. if (MXC_cXiaChongStep == 0)
  373. MXC_cXiaChongStep = 1;
  374. }
  375. //下冲单一动作
  376. if (MXC_cXiaChongStep == 0)
  377. {
  378. if (MXC_bLeftFenZhen)
  379. {
  380. MXC_bLeftFenZhen = 0;
  381. MXC_LeftFenZhen_VAVLE = ~MXC_LeftFenZhen_VAVLE;
  382. }
  383. if (MXC_bRightFenZhen)
  384. {
  385. MXC_bRightFenZhen = 0;
  386. MXC_RightFenZhen_VAVLE = ~MXC_RightFenZhen_VAVLE;
  387. }
  388. if(MXC_bDotXiaChong && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN)
  389. {
  390. MXC_bDotXiaChong = 0;
  391. if(MXC_cXiaChongStep == 0)
  392. MXC_cXiaChongStep = 1;
  393. }
  394. }
  395. if(MXC_bSeBiaoJiaoDao)
  396. {
  397. MXC_bSeBiaoJiaoDao = 0;
  398. MXC_cJiaoDaoStep = 1;
  399. }
  400. if(MXC_bGouZhen && MXC_DC_MODE == 0)
  401. {
  402. MXC_bGouZhen = 0;
  403. MXC_GouZhen_VAVLE = ~MXC_GouZhen_VAVLE;
  404. }
  405. if (MXC_DC_MODE != 0) //非钩针模式
  406. {
  407. MXC_GouZhen_VAVLE = 1;
  408. }
  409. }
  410. }
  411. void MXC_DC_AutoAction(void)
  412. {
  413. if(MXC_MOTOR_DATA_Num <= 99)user_datas[420+MXC_MOTOR_DATA_Num] = MXC_ENCODE_FENZHEN_Lenth;
  414. dwZRealPos = GetPos(Z_AXIS);
  415. //DISPLAY_DATA0 = cCheckLengthOk;//Cur_DC_length;//MXC_cXiaChongStep;//MXC_DC_cAutoStep;
  416. //DISPLAY_DATA1 = MXC_bSeBiao_CheckOK;//cZipperLength[0];//Cur_XZ_length;//MXC_XZ_cAutoStep;
  417. DISPLAY_DATA2 = MXC_bSeBiao_CheckOK;//cZipperLength[1];//
  418. DISPLAY_DATA3 = MXC_DC_cAutoStep;//MXC_XZ_cMotorStep;
  419. DISPLAY_DATA4 = MXC_SB_ENCODE_MIN;//MXC_DC_cMotorStep;
  420. DISPLAY_DATA5 = MXC_SB_SaveLength;//MXC_cXiaChongStep;
  421. DISPLAY_DATA6 = dwXRealPos;
  422. DISPLAY_DATA7 = dwEnRealPos;
  423. if(MXC_DC_bRunning)
  424. {
  425. switch(MXC_DC_cAutoStep)
  426. {
  427. case 0:
  428. break;
  429. case 1:
  430. if(dwTickCount >= MXC_DC_cAutoDelay)
  431. {
  432. SetEn(X_AXIS, DC_Motor_EN);
  433. MXC_DC_cAutoDelay = dwTickCount + 700; //先锁轴;
  434. MXC_DC_cAutoStep = 2;
  435. }
  436. break;
  437. case 2:
  438. //左右分针要退到位,过链到位要离开
  439. if((dwTickCount >= MXC_DC_cAutoDelay) && !MXC_RighttFenZhen_IN && !MXC_LeftFenZhen_IN && MXC_RightFenZhen_Origin_IN
  440. && MXC_LeftFenZhen_Origin_IN)
  441. {
  442. switch(MXC_DC_MODE)
  443. {
  444. case MXC_DC_SF_MODE:MXC_DC_cMotorStep = 1; break; //伺服
  445. case MXC_DC_GZ_MODE:MXC_DC_cMotorStep = 20;break; //钩针
  446. case MXC_DC_SB_MODE:MXC_DC_cMotorStep = 40;break; //色标
  447. //case MXC_DC_BMQ_MODE:MXC_DC_cMotorStep = 60; break; //编码器
  448. }
  449. MXC_DC_cAutoStep = 3;
  450. }
  451. else if(dwTickCount >= MXC_DC_cAutoDelay + MXC_ERRORTIME)
  452. {
  453. if (MXC_RighttFenZhen_IN)MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
  454. if (MXC_LeftFenZhen_IN)MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
  455. if (!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
  456. if (!MXC_LeftFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
  457. }
  458. break;
  459. case 3:
  460. //拖带已经完成
  461. if(MXC_DC_cMotorStep == 0)
  462. {
  463. MXC_cXiaChongStep = 1;
  464. MXC_DC_cAutoStep = 4;
  465. }
  466. break;
  467. case 4://下冲完成
  468. if((MXC_cXiaChongStep == 0) || (MXC_cXiaChongStep >= 5))
  469. {
  470. dwZipCnt++;
  471. MXC_DC_cAutoStep = 5;
  472. //除齿判断
  473. if(MXC_CRUKONGWEILENGTH >= MXC_DC_KongWei_Length || MXC_DC_MODE==0 || MXC_DC_MODE==2)
  474. {
  475. MXC_CRUKONGWEILENGTH = 0;
  476. if(!MXC_DC_SingOneFlag)
  477. {
  478. AddToTal(MXC_DC_TOTAL_ADDR);
  479. CalProSP(MXC_DC_PROSPEED_ADDR);
  480. }
  481. MXC_DC_cAutoStep = 5;
  482. }
  483. else
  484. {
  485. MXC_DC_cAutoStep = 2;
  486. MXC_DC_cAutoDelay = dwTickCount;
  487. }
  488. }
  489. break;
  490. case 5:
  491. if(GetTotal(MXC_DC_TOTAL_ADDR) >= MXC_SET_TOTAL)
  492. {
  493. MXC_SetAlarmCode(MXC_TOTAL_ALARM);
  494. MXC_DC_cAutoStep = 0;
  495. }
  496. else
  497. MXC_DC_cAutoStep = 6;
  498. break;
  499. case 6:
  500. MXC_DC_cAutoStep = 2;
  501. //MXC_Clear_Servo_Pos=0;
  502. MXC_DC_cAutoDelay = dwTickCount+1;
  503. if(MXC_DC_SingOneFlag || MXC_DC_Single_Stop)
  504. {
  505. dwZipCnt = 0;
  506. MXC_DC_bAlarmStop = 1;
  507. MXC_DC_SingOneFlag = 0;
  508. MXC_DC_cAutoStep = 0;
  509. MXC_DC_bRunning = 0;
  510. MXC_DC_Single_Stop = 0;
  511. }
  512. break;
  513. }
  514. }
  515. }
  516. // 检测是否踏了脚踏开关
  517. void MXC_CheckStart(void)
  518. {
  519. // 开始键
  520. if((MXC_START_IN_UP || MXC_DC_bStart || MXC_DC_bStart_Single))
  521. {
  522. if(MXC_DC_bStart_Single)
  523. {
  524. MXC_DC_bStart = 1;
  525. MXC_DC_SingOneFlag = 1;
  526. MXC_DC_bStart_Single = 0;
  527. }
  528. if(MXC_START_IN_UP || MXC_DC_bStart)
  529. {
  530. //定寸启动
  531. if(!MXC_DC_bRunning)
  532. {
  533. if (MXC_KaDai_IN)MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
  534. else if (!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_START_RFZ_ORIGIN_ALARM);
  535. else if (!MXC_Zipper_IN)MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM);
  536. else
  537. {
  538. dwZipCnt = 0;
  539. cZipperLength[0] = 0;
  540. cZipperLength[1] = 0;
  541. MXC_DC_cAutoStep = 1;
  542. MXC_DC_bRunning = 1;
  543. MXC_DC_cAutoDelay = dwTickCount;
  544. MXC_DC_cMotorDelay = dwTickCount;
  545. MXC_cXiaChongDelay = dwTickCount;
  546. MXC_cChuiQiDelay = dwTickCount;
  547. MXC_CRUKONGWEILENGTH=0;
  548. MXC_ENCODE_FENZHEN_Lenth = 0;
  549. cSeBiaoOk=0;
  550. }
  551. }
  552. cCheckLengthOk = 0;
  553. MXC_bSeBiao_Check=0;
  554. MXC_PARAM_SongDai_Switch = 1;
  555. }
  556. MXC_DC_bStart = 0;
  557. MXC_DC_bStart_Single = 0;
  558. }
  559. //卡带感应
  560. if(MXC_KaDai_IN)
  561. {
  562. MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
  563. }
  564. else
  565. {
  566. if((GetAlarmCode(MXC_ALARM_ADDR) == MXC_KA_DAI_ALARM))
  567. SetAlarmCode(MXC_ALARM_ADDR,0);
  568. }
  569. if(MXC_KaDai_IN_UP)
  570. {
  571. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  572. }
  573. //停止
  574. MXC_STOP_IN_FLAG_OLD = MXC_STOP_IN_FLAG;
  575. if(MXC_STOP_IN)
  576. {
  577. if(MXC_STOP_FILTER < 50)
  578. {
  579. MXC_STOP_FILTER++;
  580. }
  581. else
  582. MXC_STOP_IN_FLAG = 1;
  583. }
  584. else if(MXC_STOP_FILTER > 25)
  585. {
  586. MXC_STOP_FILTER--;
  587. }
  588. else
  589. MXC_STOP_IN_FLAG = 0;
  590. //停止键
  591. if(MXC_STOP_IN_FLAG && !MXC_STOP_IN_FLAG_OLD || MXC_bStop)
  592. {
  593. MXC_bStop = 0;
  594. MXC_bSeBiao_Check=0;
  595. if(MXC_DC_bRunning)
  596. {
  597. if(MXC_DC_cMotorStep==0 && MXC_cXiaChongStep!=0)
  598. {
  599. MXC_DC_Single_Stop = 1;
  600. }
  601. else
  602. {
  603. if(MXC_cXiaChongStep==0)
  604. {
  605. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  606. }
  607. MXC_DC_SingOneFlag = 0;
  608. MXC_DC_bRunning = 0;
  609. MXC_DC_cAutoStep = 0;
  610. MXC_DC_cMotorStep = 0;
  611. MXC_cXiaChongStep = 0;
  612. AxisEgmStop(X_AXIS);
  613. AxisEgmStop(Z_AXIS);
  614. //MXC_cJiaoDaoStep = 0;
  615. MXC_Zipper_cnt = 0;
  616. //输出
  617. MXC_LeftFenZhen_VAVLE = 0;
  618. MXC_SongDai_MOTOR = 0;
  619. MXC_RightFenZhen_VAVLE = 0;
  620. MXC_DingDao_BaoHu_VAVLE = 0;
  621. MXC_PARAM_SongDai_Switch = 0;
  622. cSeBiaoOk=0;
  623. if(MXC_DC_MODE==0)
  624. MXC_GouZhen_VAVLE = 0;
  625. }
  626. }
  627. else
  628. {
  629. MXC_DC_SingOneFlag = 0;
  630. MXC_DC_bRunning = 0;
  631. MXC_DC_cAutoStep = 0;
  632. MXC_DC_cMotorStep = 0;
  633. MXC_cXiaChongStep = 0;
  634. MXC_cXiaChongStep = 0;
  635. MXC_cRightFZStep = 0;
  636. MXC_cLeftFZStep = 0;
  637. SetEn(X_AXIS,DC_Motor_DISEN);
  638. SetEn(Z_AXIS,XC_MOTOR_DISEN);
  639. if((MXC_cChuiQiStep == 0) &&(MXC_cXiaChongStep==0))MXC_cChuiQiStep = 1;
  640. AxisEgmStop(X_AXIS);
  641. AxisEgmStop(Z_AXIS);
  642. MXC_SetAlarmCode(MXC_NO_ALARM);
  643. //输出
  644. if(MXC_cXiaChongStep == 0)
  645. {
  646. MXC_XiaChong_MOTOR = 0;
  647. }
  648. MXC_LeftFenZhen_VAVLE = 0;
  649. MXC_SongDai_MOTOR = 0;
  650. MXC_RightFenZhen_VAVLE = 0;
  651. MXC_DingDao_BaoHu_VAVLE = 0;
  652. MXC_PARAM_SongDai_Switch = 0;
  653. MXC_MOTOR_DATA_Num = 0;
  654. cSeBiaoOk=0;
  655. if(MXC_DC_MODE==0)
  656. MXC_GouZhen_VAVLE = 0;
  657. }
  658. }
  659. if(MXC_DC_bAlarmStop)
  660. {
  661. MXC_DC_bAlarmStop = 0;
  662. MXC_DC_bRunning = 0;
  663. MXC_DC_cAutoStep = 0;
  664. MXC_DC_cMotorStep = 0;
  665. MXC_cXiaChongStep = 0;
  666. MXC_cRightFZStep = 0;
  667. MXC_cLeftFZStep = 0;
  668. MXC_DC_SingOneFlag = 0;
  669. MXC_cXiaChongStep = 0;
  670. MXC_XiaChong_MOTOR = 0;
  671. MXC_LeftFenZhen_VAVLE = 0;
  672. MXC_RightFenZhen_VAVLE = 0;
  673. MXC_DingDao_BaoHu_VAVLE = 0;
  674. MXC_cShaCheStep = 1;
  675. AxisEgmStop(X_AXIS);
  676. }
  677. }
  678. void MXC_ChuiQi(void)
  679. {
  680. //吹气
  681. if(MXC_XiaChong_IN_DW && !MXC_DC_XC_MODE)
  682. {
  683. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  684. MXC_cDDBH_Step = 1;
  685. }
  686. if(MXC_DC_XC_MODE)
  687. {
  688. if(PosToPulse(Z_AXIS,GetPos(Z_AXIS)) >= MXC_DC_XC_CHUIQI_PULSE && PosToPulse(Z_AXIS,GetPos(Z_AXIS)) <= MXC_DC_XC_CHUIQI_PULSE + 30)
  689. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  690. if(PosToPulse(Z_AXIS,GetPos(Z_AXIS)) >= MXC_DC_XC_DINDAO_PULSE && PosToPulse(Z_AXIS,GetPos(Z_AXIS)) <= MXC_DC_XC_DINDAO_PULSE + 30)
  691. if(MXC_cDDBH_Step == 0)MXC_cDDBH_Step = 1;
  692. }
  693. switch(MXC_cChuiQiStep)
  694. {
  695. case 1:
  696. MXC_cChuiQiStep = 2;
  697. MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_DELAY_CHUIQI_TIME;
  698. break;
  699. case 2:
  700. if(dwTickCount >= MXC_cChuiQiDelay)
  701. {
  702. MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_CHUIQI_TIME;
  703. MXC_ChuiQi_VAVLE = 1;//
  704. MXC_cChuiQiStep = 3;
  705. }
  706. break;
  707. case 3:
  708. if(dwTickCount >= MXC_cChuiQiDelay)
  709. {
  710. MXC_ChuiQi_VAVLE = 0;//
  711. MXC_cChuiQiStep = 0;
  712. }
  713. break;
  714. }
  715. switch (MXC_cDDBH_Step)
  716. {
  717. case 1:
  718. MXC_cDDBH_Step = 2;
  719. MXC_cDDBHDelay = dwTickCount + MXC_PARAM_DDBH_delay;
  720. break;
  721. case 2:
  722. if(dwTickCount >= MXC_cDDBHDelay)
  723. {
  724. MXC_cDDBH_Step = 3;
  725. MXC_DingDao_BaoHu_VAVLE = 1;
  726. MXC_cDDBHDelay = dwTickCount + MXC_DDBH_TIME;
  727. }
  728. break;
  729. case 3:
  730. if(dwTickCount >= MXC_cDDBHDelay)
  731. {
  732. MXC_cDDBH_Step = 0;
  733. MXC_DingDao_BaoHu_VAVLE = 0;
  734. }
  735. break;
  736. }
  737. }
  738. void MXC_DC_Motor(void)
  739. {
  740. static long zipper_length;
  741. short *revise_buff;
  742. unsigned long cmp=0;
  743. unsigned long cyclenum=0;
  744. dwXRealPos = GetPos(X_AXIS);
  745. dwEnRealPos = GetEncodePos(ENCODE_X22X23);
  746. revise_buff = (short *)(&user_datas[17]);
  747. switch(MXC_DC_cMotorStep)
  748. {
  749. case 0:
  750. break;
  751. //电机定寸模式
  752. case 1:
  753. if(dwEnRealPos>(MXC_SET_ZIPPER_LENGTH + MXC_PARAM_DAOKOU_LENGTH) && MXC_CRUKONGWEILENGTH==0)
  754. {
  755. MXC_DC_cMotorStep = 0;
  756. MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH;
  757. MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  758. SetEncodePos(ENCODE_X22X23, 0);
  759. }
  760. else
  761. {
  762. MXC_DC_cMotorStep = 2;
  763. MXC_DC_cMotorDelay = dwTickCount;
  764. SetPos(X_AXIS, 0);
  765. }
  766. break;
  767. case 2:
  768. if(dwTickCount >= MXC_DC_cMotorDelay)
  769. {
  770. if(MXC_CRUKONGWEILENGTH==0)//MXC_CRUKONGWEILENGTH 记录已除齿长度
  771. {
  772. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - dwEnRealPos;
  773. MXC_CRUKONGWEILENGTH=MXC_PARAM_DAOKOU_LENGTH;
  774. }
  775. else if(MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH>=MXC_PARAM_DAOKOU_LENGTH)
  776. {
  777. zipper_length=MXC_PARAM_DAOKOU_LENGTH;
  778. MXC_CRUKONGWEILENGTH+=zipper_length;
  779. }
  780. else
  781. {
  782. zipper_length=MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH;
  783. MXC_CRUKONGWEILENGTH+=zipper_length;
  784. }
  785. if(zipper_length>MXC_MXC_PARAM_DAILUN_LENGTH)
  786. {
  787. cmp=MXC_PARAM_LENGTH_CMP;
  788. cyclenum=zipper_length/MXC_MXC_PARAM_DAILUN_LENGTH;
  789. zipper_length=zipper_length+(zipper_length*cyclenum*cmp)/((cyclenum+1)*MXC_MXC_PARAM_DAILUN_LENGTH);
  790. DISPLAY_DATA0=zipper_length;
  791. }
  792. AxisMovePosAccDec(X_AXIS, MXC_PARAM_SK_HIGH_SPEED, zipper_length, 1000,
  793. MXC_PARAM_SK_SLOW_SPEED, 150, 150, MXC_PARAM_SK_SLOW_LENGTH);
  794. MXC_DC_cMotorStep = 3;
  795. MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  796. }
  797. break;
  798. case 3:
  799. if(!X_DRV)
  800. {
  801. if(MXC_MOTOR_DATA_Num<=99)user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos;
  802. //SetEncodePos(ENCODE_X22X23, 0);
  803. MXC_DC_cMotorStep = 4;
  804. MXC_DC_cMotorDelay = dwTickCount + 20;
  805. }
  806. else if(dwTickCount >= MXC_DC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  807. break;
  808. case 4:
  809. if(dwTickCount >= MXC_DC_cMotorDelay)
  810. {
  811. MXC_DC_cMotorStep = 0;
  812. }
  813. break;
  814. //钩针定寸 step20-24
  815. case 20:
  816. if (MXC_DEC_MODE) //减速方式:1数控模式 0感应方式
  817. {
  818. SetPos(X_AXIS, 0);
  819. if (MXC_PARAM_AUTO_CHECK_MODE) //1为自动测长0为手动输入长度
  820. {
  821. if (cCheckLengthOk)
  822. {
  823. if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH)
  824. {
  825. AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED,
  826. zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH,
  827. 2000, MXC_DC_PARAM_LOW_SPEED, 150,
  828. 150, 0);
  829. }
  830. else
  831. {
  832. AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length,
  833. 1000, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0);
  834. }
  835. }
  836. else
  837. {
  838. if (cCheckLengthOk == 0)
  839. {
  840. cZipperLength[0] = cZipperLength[1];
  841. cZipperLength[1] = zipper_length_buff;
  842. if (ComPareLength())//返回1,前后拉链没有明显变化
  843. {
  844. cCheckLengthOk = 1;
  845. }
  846. }
  847. if (cCheckLengthOk)
  848. {
  849. zipper_length = cZipperLength[1];
  850. if (zipper_length > MXC_PARAM_DAOKOU_LENGTH)
  851. {
  852. SetData32bits(MXC_XC_ZIPPER_LENGTH_ADDR, zipper_length - MXC_PARAM_DAOKOU_LENGTH);
  853. }
  854. if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH)
  855. {
  856. AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED,
  857. zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH,
  858. 2000, MXC_DC_PARAM_LOW_SPEED, 100,
  859. 100, 100);
  860. }
  861. else
  862. {
  863. AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length,
  864. 1000, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0);
  865. }
  866. }
  867. else
  868. {
  869. AxisContinueMoveAcc(X_AXIS, MXC_PARAM_FIRST_SPEED, MXC_DC_DIR_P, 1200,
  870. 800, 80, 120);
  871. }
  872. }
  873. }
  874. else//手动输入长度模式
  875. {
  876. if (dwZipCnt == 0)
  877. AxisContinueMoveAcc(X_AXIS, MXC_PARAM_FIRST_SPEED, MXC_DC_DIR_P, 1200, 1200,
  878. 80, 120);
  879. else
  880. {
  881. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
  882. //输入长度过大
  883. if (zipper_length > zipper_length_buff && dwZipCnt > 1)
  884. zipper_length = zipper_length_buff;
  885. if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH)
  886. {
  887. AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED,
  888. zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH,
  889. 1000, MXC_DC_PARAM_LOW_SPEED, MXC_DC_PARAM_SET_SPEED / 300,
  890. MXC_DC_PARAM_SET_SPEED / 300, 0);
  891. }
  892. else
  893. {
  894. AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length,
  895. 800, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0);
  896. }
  897. }
  898. }
  899. MXC_DC_cMotorStep = 22;
  900. }
  901. else // 感应方式
  902. {
  903. AxisContinueMoveAcc(X_AXIS, MXC_DC_PARAM_SET_SPEED, MXC_DC_DIR_P,1000,1000,30,30);
  904. MXC_DC_cMotorStep = 21;
  905. }
  906. MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
  907. MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  908. break;
  909. case 21:
  910. //if ((dwTickCount >= MXC_cGouZhenTime))
  911. // MXC_GouZhen_VAVLE = 0;
  912. if (MXC_DEC_MODE == 0) // 感应模式
  913. {
  914. if (MXC_JianSu_IN_DW)
  915. {
  916. AxisChangeSpeedDirect(X_AXIS, MXC_DC_PARAM_LOW_SPEED);
  917. //MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
  918. MXC_DC_cMotorStep = 23;
  919. }
  920. if (MXC_GouZhen_IN)
  921. {
  922. MXC_DC_cMotorStep = 24;
  923. AxisEgmStop(X_AXIS);
  924. }
  925. }
  926. if (dwTickCount >= MXC_DC_cMotorDelay)
  927. MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  928. break;
  929. case 22:
  930. // if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0))
  931. // MXC_GouZhen_VAVLE = 0;
  932. if (MXC_DEC_MODE) // 数控方式
  933. {
  934. if (MXC_PARAM_AUTO_CHECK_MODE)///1为自动测长0为手动输入长度
  935. {
  936. if (cCheckLengthOk)
  937. {
  938. if ((dwXRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH)) && MXC_PARAM_GZ_RESET_MODE)
  939. MXC_GouZhen_VAVLE = 0;
  940. }
  941. else
  942. {
  943. if (dwTickCount >= MXC_cGouZhenTime)
  944. MXC_GouZhen_VAVLE = 0;
  945. }
  946. }
  947. else
  948. {
  949. if ((dwXRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH)) && MXC_PARAM_GZ_RESET_MODE)
  950. MXC_GouZhen_VAVLE = 0;
  951. if ((dwZipCnt == 0) && (dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 1))
  952. MXC_GouZhen_VAVLE = 0;
  953. }
  954. if (MXC_JianSu_IN_DW)
  955. {
  956. if (cCheckLengthOk)
  957. {
  958. ;
  959. }
  960. else
  961. {
  962. AxisChangeSpeedDirect(X_AXIS, MXC_DC_PARAM_LOW_SPEED);
  963. }
  964. }
  965. if (MXC_GouZhen_IN_UP)
  966. {
  967. MXC_GouZhen_VAVLE = 0;
  968. MXC_DC_cMotorStep = 23;
  969. AxisEgmStop(X_AXIS);
  970. }
  971. }
  972. if (dwTickCount >= MXC_DC_cMotorDelay)
  973. MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  974. break;
  975. case 23:
  976. if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0))
  977. MXC_GouZhen_VAVLE = 0;
  978. if (MXC_DEC_MODE) // 数控方式
  979. {
  980. if (!X_DRV)
  981. {
  982. MXC_DC_cMotorStep = 0;
  983. zipper_length_buff = dwXRealPos;
  984. }
  985. }
  986. else // 感应方式
  987. {
  988. if (MXC_GouZhen_IN)
  989. {
  990. MXC_DC_cMotorStep = 24;
  991. AxisEgmStop(X_AXIS);
  992. }
  993. }
  994. if (dwTickCount >= MXC_DC_cMotorDelay)
  995. MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  996. break;
  997. case 24:
  998. if (!X_DRV)
  999. {
  1000. MXC_DC_cMotorStep = 0;
  1001. }
  1002. if (dwTickCount >= MXC_DC_cMotorDelay)
  1003. MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  1004. break;
  1005. //色标定寸 step 40-42
  1006. case 40:
  1007. SetPos(X_AXIS, 0);
  1008. MCX_SB_ENCODE_END=dwEnRealPos;
  1009. SetEncodePos(ENCODE_X22X23, 0);
  1010. if ((dwZipCnt == 0) || SingOneFlg)
  1011. {
  1012. AxisContinueMoveAcc(X_AXIS, 1000, MXC_DC_DIR_P, 1000,
  1013. 1000, 10, 10);
  1014. MXC_DC_cMotorStep = 41;
  1015. }
  1016. else
  1017. {
  1018. zipper_length=MXC_SET_ZIPPER_LENGTH+ (*revise_buff)-MXC_DC_PARAM_SEBIAO_DW_LENGTH;
  1019. if(zipper_length>MXC_MXC_PARAM_DAILUN_LENGTH)
  1020. {
  1021. cmp=MXC_PARAM_LENGTH_CMP;
  1022. cyclenum=zipper_length/MXC_MXC_PARAM_DAILUN_LENGTH;
  1023. zipper_length=zipper_length+(zipper_length*cyclenum*cmp)/((cyclenum+1)*MXC_MXC_PARAM_DAILUN_LENGTH);
  1024. }
  1025. if(zipper_length>0)
  1026. {
  1027. AxisMovePosAccDecNotStop(X_AXIS,MXC_PARAM_SB_HIGH_SPEED,zipper_length,
  1028. 1500,MXC_PARAM_SB_LOW_SPEED,100,100,
  1029. PosToPulse(X_AXIS,MXC_PARAM_SEBIAO_LOWSPEED_LENGTH));
  1030. }
  1031. else
  1032. {
  1033. MXC_SetAlarmCode(MXC_ZIPPER_SB_LENGTH_ALARM);
  1034. }
  1035. MXC_DC_cMotorStep = 41;
  1036. }
  1037. cSeBiaoOk = 0;
  1038. cSeBiaoEn = 0;
  1039. MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  1040. break;
  1041. case 41://使能色标位置
  1042. if (dwZipCnt == 0)
  1043. {
  1044. cSeBiaoOk = 0;
  1045. cSeBiaoEn = 1;
  1046. MXC_DC_cMotorStep = 42;
  1047. }
  1048. else
  1049. {
  1050. if (dwXRealPos>=zipper_length-MXC_PARAM_SEBIAO_LOWSPEED_LENGTH)
  1051. {
  1052. if ((dwXRealPos+MXC_PARAM_SEBIAO_TQ_LENGTH) >= zipper_length+MXC_PARAM_First_CMP)
  1053. {
  1054. cSeBiaoOk = 0;//开启色标中断
  1055. cSeBiaoEn = 1;//色标中断使能
  1056. MXC_DC_cMotorStep = 42;
  1057. MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  1058. }
  1059. else if (dwXRealPos > (zipper_length + MXC_PARAM_SEBIAO_ERROR_LENGTH+MXC_PARAM_First_CMP))
  1060. {
  1061. MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  1062. }
  1063. }
  1064. }
  1065. break;
  1066. case 42://色标定位
  1067. if(cSeBiaoOk && cSeBiaoEn)
  1068. {
  1069. cSeBiaoEn = 0;
  1070. if (dwZipCnt == 0)
  1071. {
  1072. zipper_length= MXC_DC_PARAM_SEBIAO_DW_LENGTH-(MXC_SB_SaveLength-MXC_SB_ENCODE_MIN);
  1073. AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SB_OFFSET_SPEED,
  1074. MXC_DC_PARAM_SEBIAO_DW_LENGTH,
  1075. 800, 800,
  1076. 120, 100, 50);
  1077. MXC_DC_cMotorStep = 44;
  1078. MXC_Clear_Servo_Pos=1;
  1079. }
  1080. else
  1081. {
  1082. zipper_length= MXC_DC_PARAM_SEBIAO_DW_LENGTH-MXC_PARAM_First_CMP;
  1083. AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SB_OFFSET_SPEED,
  1084. zipper_length,
  1085. 800, 800,
  1086. 120, 100, 50);
  1087. MXC_DC_cMotorStep = 44;
  1088. MCX_XPOS_BUFF=dwXRealPos;
  1089. DISPLAY_DATA0=dwXRealPos-MXC_SB_SaveLength;
  1090. }
  1091. }
  1092. break;
  1093. case 44://色标定位
  1094. if (dwZipCnt == 0&&!X_DRV)
  1095. {
  1096. MXC_DC_cMotorStep = 45;
  1097. MXC_bSeBiao_Check=1;//第一条,屏幕弹出小窗口,人工确认色标定位位置
  1098. MXC_bSeBiao_CheckOK=0;
  1099. MXC_bSeBiao_CheckStop=0;
  1100. MXC_Clear_Servo_Pos=0;
  1101. }
  1102. else if(!X_DRV)
  1103. {
  1104. MXC_DC_cMotorStep = 0;
  1105. }
  1106. else if (dwTickCount >= MXC_DC_cMotorDelay)
  1107. {
  1108. MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  1109. }
  1110. break;
  1111. case 45:
  1112. if(MXC_bSeBiao_CheckOK)//人工确认位置色标定位位置正确
  1113. {
  1114. MXC_bSeBiao_CheckOK=0;
  1115. MXC_DC_cMotorStep = 0;
  1116. MXC_bSeBiao_Check=0;
  1117. }
  1118. if(MXC_bSeBiao_CheckStop)//位置不正确,停止
  1119. {
  1120. MXC_bSeBiao_CheckStop=0;
  1121. dwZipCnt = 0;
  1122. MXC_DC_bAlarmStop = 1;
  1123. MXC_DC_SingOneFlag = 0;
  1124. MXC_DC_cAutoStep = 0;
  1125. MXC_DC_bRunning = 0;
  1126. MXC_bSeBiao_Check=0;
  1127. }
  1128. break;
  1129. #if 0
  1130. //编码器定位
  1131. case 60:
  1132. if(dwEnRealPos>(MXC_SET_ZIPPER_LENGTH+MXC_PARAM_DAOKOU_LENGTH) && MXC_CRUKONGWEILENGTH==0)
  1133. {
  1134. MXC_DC_cMotorStep = 64;
  1135. MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH;
  1136. MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  1137. }
  1138. else
  1139. {
  1140. MXC_DC_cMotorStep = 61;
  1141. MXC_DC_cMotorDelay = dwTickCount;
  1142. SetPos(X_AXIS, 0);
  1143. }
  1144. break;
  1145. case 61:
  1146. if(dwTickCount >= MXC_DC_cMotorDelay)
  1147. {
  1148. SetPos(X_AXIS, 0);
  1149. if(MXC_CRUKONGWEILENGTH==0)
  1150. {
  1151. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - dwEnRealPos ;//- MXC_ENCODE_FENZHEN_Lenth/3;//-(MXC_ENCODE_FENZHEN_Lenth); //
  1152. MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH;
  1153. }
  1154. else if(MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH>=MXC_PARAM_DAOKOU_LENGTH)
  1155. {
  1156. zipper_length=MXC_PARAM_DAOKOU_LENGTH;
  1157. MXC_CRUKONGWEILENGTH+=zipper_length;
  1158. }
  1159. else
  1160. {
  1161. zipper_length=MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH;
  1162. MXC_CRUKONGWEILENGTH+=zipper_length;
  1163. }
  1164. if(zipper_length<1400)
  1165. {
  1166. if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH)
  1167. {
  1168. AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SET_SPEED * 3 / 4 + 600, zipper_length, 1200, MXC_DC_PARAM_LOW_SPEED, MXC_DC_PARAM_SET_SPEED/300, MXC_DC_PARAM_SET_SPEED/300, PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH)); //1200 600
  1169. }
  1170. else
  1171. {
  1172. AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length, 1200,
  1173. MXC_DC_PARAM_LOW_SPEED, 50, 50, 0); //1200 600
  1174. }
  1175. }
  1176. else if(zipper_length<2400)
  1177. {
  1178. AxisMovePosAccDec(X_AXIS,MXC_DC_PARAM_SET_SPEED*7/8,zipper_length,1200,MXC_DC_PARAM_LOW_SPEED,MXC_DC_PARAM_SET_SPEED/300,MXC_DC_PARAM_SET_SPEED/300,PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH));//1200 600
  1179. }
  1180. else
  1181. {
  1182. AxisMovePosAccDec(X_AXIS,MXC_DC_PARAM_SET_SPEED,zipper_length,1200,MXC_DC_PARAM_LOW_SPEED,MXC_DC_PARAM_SET_SPEED/300,MXC_DC_PARAM_SET_SPEED/300,PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH));//1200 600
  1183. }
  1184. MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  1185. MXC_DC_cMotorStep = 62;
  1186. }
  1187. break;
  1188. case 62:
  1189. if(!X_DRV)//||(dwEnRealPos>=dwXRealPos)&&(dwXRealPos>=MXC_PARAM_DAOKOU_LENGTH))
  1190. {
  1191. //AxisEgmStop(X_AXIS);
  1192. MXC_DC_cMotorStep = 63;
  1193. MXC_DC_cMotorDelay = dwTickCount+0;
  1194. }
  1195. else if(dwTickCount >= MXC_DC_cMotorDelay)
  1196. MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  1197. break;
  1198. case 63:
  1199. if(dwTickCount >= MXC_DC_cMotorDelay)
  1200. {
  1201. // if(MXC_MOTOR_DATA_Num<=99)user_datas[420+MXC_MOTOR_DATA_Num] = dwEnRealPos;
  1202. if(dwEnRealPos<dwXRealPos)
  1203. {
  1204. zipper_length=(dwXRealPos-dwEnRealPos);
  1205. AxisMovePosAccDec(X_AXIS,800,zipper_length,800,800,10,10,0);
  1206. }
  1207. MXC_DC_cMotorStep = 64;
  1208. }
  1209. break;
  1210. case 64:
  1211. if(!X_DRV)
  1212. {
  1213. if(MXC_MOTOR_DATA_Num<=99)user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos;
  1214. MXC_DC_cMotorDelay = dwTickCount;
  1215. MXC_DC_cMotorStep = 0;
  1216. //SetEncodePos(ENCODE_X22X23, 0);
  1217. }
  1218. // else if(dwTickCount >= MXC_DC_cMotorDelay)
  1219. // MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM, MXC_ALARM_DC);
  1220. break;
  1221. case 65:
  1222. if(dwXRealPos<=zipper_length-500)//剩余长度小于5CM
  1223. {
  1224. AxisMovePosAccDec(X_AXIS,1000,300,600,600,20,20,0);
  1225. MXC_DC_cMotorStep = 66;
  1226. }
  1227. else
  1228. {
  1229. MXC_DC_cMotorStep = 62;
  1230. }
  1231. break;
  1232. case 66:
  1233. if(!X_DRV)
  1234. {
  1235. MXC_DC_cAutoStep=2;
  1236. MXC_DC_cMotorStep=0;
  1237. MXC_CRUKONGWEILENGTH=0;
  1238. }
  1239. break;
  1240. #endif
  1241. }
  1242. }
  1243. //下冲
  1244. void MXC_XiaChong(void)
  1245. {
  1246. switch(MXC_cXiaChongStep)
  1247. {
  1248. case 0:
  1249. break;
  1250. case 1:
  1251. MXC_cXiaChongStep = 2;
  1252. MXC_cRightFZStep = 1;//启动右分针
  1253. MXC_cLeftFZStep = 0;
  1254. break;
  1255. case 2:
  1256. if((MXC_cRightFZStep == 0) && (MXC_cLeftFZStep == 0) && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN)
  1257. {
  1258. MXC_XC_ShaChe = 0;//打开刹车
  1259. if (MXC_DC_bRunning)
  1260. {
  1261. MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_DELAY_XC;
  1262. }
  1263. MXC_cXiaChongStep = 3;
  1264. }
  1265. break;
  1266. case 3:
  1267. if(dwTickCount >= MXC_cXiaChongDelay)
  1268. {
  1269. MXC_cXiaChongStep = 4;
  1270. MXC_XiaChong_MOTOR = 1;
  1271. if(MXC_DC_bRunning) MXC_GouZhen_VAVLE = 1;
  1272. MXC_cXiaChongDelay = dwTickCount + MXC_XIACHONG_EEROR_TIME;
  1273. }
  1274. break;
  1275. case 4:
  1276. if(MXC_XiaChong_IN_UP)
  1277. {
  1278. SetEncodePos(ENCODE_X22X23, 0);
  1279. // if(MXC_MOTOR_DATA_Num<=99)user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos;
  1280. MXC_LeftFenZhen_VAVLE = 0;
  1281. MXC_RightFenZhen_VAVLE = 0;
  1282. MXC_cXiaChongStep = 5;
  1283. MXC_cShaCheStep = 1;
  1284. MXC_cXiaChongDelay = dwTickCount + MXC_XC_Stop_Delay;
  1285. }
  1286. else if(dwTickCount >= MXC_cXiaChongDelay)//感应异常
  1287. {
  1288. MXC_SetAlarmCode(MXC_XC_ALARM);
  1289. MXC_LeftFenZhen_VAVLE = 0;
  1290. MXC_RightFenZhen_VAVLE = 0;
  1291. MXC_cXiaChongStep = 0;
  1292. MXC_XiaChong_MOTOR = 0;
  1293. MXC_cShaCheStep = 1;
  1294. }
  1295. break;
  1296. case 5:
  1297. if(dwTickCount >= MXC_cXiaChongDelay)
  1298. {
  1299. // user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos;
  1300. MXC_MOTOR_DATA_Num++;
  1301. if(MXC_MOTOR_DATA_Num > 99)
  1302. MXC_MOTOR_DATA_Num = 0;
  1303. if(!MXC_DC_bRunning){
  1304. SetEncodePos(ENCODE_X22X23, 0);
  1305. SetPos(X_AXIS, 0);
  1306. }
  1307. MXC_XiaChong_MOTOR = 0;
  1308. MXC_cXiaChongStep = 0;
  1309. }
  1310. break;
  1311. }
  1312. }
  1313. void MXC_DC_ShaChe(void)
  1314. {
  1315. //刹车
  1316. switch(MXC_cShaCheStep)
  1317. {
  1318. case 1:
  1319. MXC_cShaCheStep = 2;
  1320. MXC_cShaCheDelay = dwTickCount + MXC_PARAM_ShaChe_Delay;
  1321. break;
  1322. case 2:
  1323. if(dwTickCount >= MXC_cShaCheDelay)
  1324. {
  1325. MXC_cShaCheStep = 3;
  1326. MXC_cShaCheDelay = dwTickCount + MXC_PARAM_ShaChe_TIME;
  1327. MXC_XC_ShaChe = 1;
  1328. }
  1329. break;
  1330. case 3:
  1331. if(dwTickCount >= MXC_cShaCheDelay)
  1332. {
  1333. MXC_XC_ShaChe = 0;
  1334. MXC_cShaCheStep = 0;
  1335. }
  1336. break;
  1337. }
  1338. }
  1339. void MXC_FenZhen(void)
  1340. {
  1341. switch (MXC_cRightFZStep)
  1342. {
  1343. case 0:
  1344. break;
  1345. case 1:
  1346. MXC_cRightFZ_Delay = MXC_RightFZ_Delay + dwTickCount;
  1347. MXC_cRightFZStep = 2;
  1348. break;
  1349. case 2:
  1350. if (dwTickCount >= MXC_cRightFZ_Delay)
  1351. {
  1352. MXC_cRightFZStep = 3;
  1353. MXC_RightFenZhen_VAVLE = 1; //右分针电磁阀
  1354. MXC_cRightFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME;
  1355. }
  1356. break;
  1357. case 3:
  1358. if (!MXC_RightFenZhen_Origin_IN) //右分针原点离开
  1359. {
  1360. MXC_cRightFZ_Delay = dwTickCount + MXC_DC_RightFZ_AGAIN_TIME;
  1361. MXC_cRightFZStep = 4;
  1362. } //右分针不下去
  1363. else if (dwTickCount >= MXC_cRightFZ_Delay)
  1364. {
  1365. MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);//警告暂停 分针下冲步骤都清零
  1366. MXC_RightFenZhen_VAVLE = 0;
  1367. }
  1368. break;
  1369. case 4:
  1370. if (MXC_RighttFenZhen_IN) //插针到位
  1371. {
  1372. MXC_ENcode_Cul = dwEnRealPos;
  1373. MXC_cRFengTimer = 0;
  1374. MXC_cRightFZStep = 0;
  1375. MXC_cLeftFZStep = 1; //左分针延时启动
  1376. }
  1377. else if (dwTickCount >= MXC_cRightFZ_Delay)
  1378. {
  1379. MXC_RightFenZhen_VAVLE = 0; //右分针
  1380. MXC_cRFengTimer++;
  1381. //当右分针分不到位时,左分针也要重新分针
  1382. MXC_LeftFenZhen_VAVLE = 0;
  1383. MXC_cRightFZStep = 0;
  1384. if (MXC_cRFengTimer < 4)//times 次数
  1385. {
  1386. MXC_cRightFZStep = 5;
  1387. MXC_cRightFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME;
  1388. }
  1389. else
  1390. {
  1391. MXC_cRFengTimer = 0;
  1392. MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
  1393. MXC_cRightFZStep = 0;
  1394. MXC_RightFenZhen_VAVLE = 0;
  1395. }
  1396. }
  1397. break;
  1398. //5-6重新下右分针
  1399. case 5:
  1400. if (MXC_RightFenZhen_Origin_IN) //退到位
  1401. {
  1402. MXC_cRightFZStep = 2;
  1403. }
  1404. else if (dwTickCount >= MXC_cRightFZ_Delay)
  1405. {
  1406. MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
  1407. MXC_RightFenZhen_VAVLE = 0;
  1408. }
  1409. break;
  1410. }
  1411. //左分针
  1412. switch (MXC_cLeftFZStep)
  1413. {
  1414. case 0:
  1415. break;
  1416. case 1:
  1417. MXC_cLeftFZ_Delay = MXC_LeftFZ_Delay + dwTickCount;
  1418. MXC_cLeftFZStep = 2;
  1419. break;
  1420. case 2:
  1421. if (dwTickCount >= MXC_cLeftFZ_Delay)
  1422. {
  1423. MXC_cLeftFZStep = 3;
  1424. MXC_LeftFenZhen_VAVLE = 1; //左分针电磁阀
  1425. MXC_cLeftFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME;
  1426. }
  1427. break;
  1428. case 3: //离开左分针原点
  1429. if (!MXC_LeftFenZhen_Origin_IN) //左分针原点离开
  1430. {
  1431. MXC_cLeftFZ_Delay = dwTickCount + MXC_DC_LeftFZ_AGAIN_TIME;
  1432. MXC_cLeftFZStep = 4;
  1433. } //左分针不下去
  1434. else if (dwTickCount >= MXC_cLeftFZ_Delay)
  1435. {
  1436. MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
  1437. MXC_LeftFenZhen_VAVLE = 0;
  1438. }
  1439. break;
  1440. case 4:
  1441. if (MXC_LeftFenZhen_IN) //左插针到位
  1442. {
  1443. MXC_ENCODE_FENZHEN_Lenth = dwEnRealPos - MXC_ENcode_Cul;
  1444. MXC_cLFengTimer = 0;
  1445. MXC_cLeftFZStep = 0;
  1446. }
  1447. else if (dwTickCount >= MXC_cLeftFZ_Delay)
  1448. {
  1449. MXC_LeftFenZhen_VAVLE = 0; //左分针
  1450. MXC_cLFengTimer++;
  1451. if (MXC_cLFengTimer < 6)
  1452. {
  1453. MXC_cLeftFZStep = 5;
  1454. MXC_cLeftFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME;
  1455. if ((MXC_cLFengTimer % 2) == 0)
  1456. {
  1457. MXC_RightFenZhen_VAVLE = 0;
  1458. MXC_cRightFZStep = 0;
  1459. }
  1460. }
  1461. else
  1462. {
  1463. MXC_cLFengTimer = 0;
  1464. MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
  1465. MXC_cLeftFZStep = 0;
  1466. MXC_LeftFenZhen_VAVLE = 0;
  1467. }
  1468. }
  1469. break;
  1470. //5-6重新下左分针
  1471. case 5:
  1472. if (MXC_LeftFenZhen_Origin_IN) //退到位
  1473. {
  1474. MXC_cLeftFZStep = 6;
  1475. }
  1476. else if (dwTickCount >= MXC_cLeftFZ_Delay)
  1477. {
  1478. MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
  1479. MXC_cLeftFZStep = 0;
  1480. MXC_LeftFenZhen_VAVLE = 0;
  1481. }
  1482. break;
  1483. case 6:
  1484. if ((MXC_cLFengTimer % 2) == 0) //左边插两次都插不到,就退右边再同时插
  1485. {
  1486. if(MXC_RightFenZhen_Origin_IN)
  1487. {
  1488. MXC_cRightFZStep = 1;
  1489. MXC_cRFengTimer = 0;
  1490. MXC_cLeftFZStep = 0;
  1491. }
  1492. }
  1493. else
  1494. {
  1495. MXC_cLeftFZStep = 2;
  1496. }
  1497. break;
  1498. }
  1499. }
  1500. #endif