GLMXC_NiLong_StepJi.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037
  1. #include "global.h"
  2. #if CHANG_SHENG_GEI_LI_MACHINE==1
  3. void MXC_NiLongXiuCiJiCheckStart(void);
  4. void MXC_ShaChe_Output(void);
  5. void MXC_NiLongXiuCiJi_Motor(void);
  6. void MXC_NiLongXiuCiJi_XiaC(void);
  7. void MXC_Start_FenZ(void);
  8. void MXC_NiLongXiuCiJi_FenZhengProc(void);
  9. void MXC_ChuiQiProc(void);
  10. void MXC_JiaoDao(void);
  11. void MXC_ManualAction(void);
  12. void MXC_AutoAction(void);
  13. void MXC_NiLongXiuCiJi_GouZhenProc(void);
  14. void DianDanLenghtCheck(void);
  15. long MultLengthOffset(unsigned long zip_length);
  16. unsigned short DingDanCheckOk(void);
  17. unsigned char cLFengTimer,cRFengTimer,cGuZhangStop = 0;
  18. unsigned long cShaCheTime,cLaLianLine,cGouZhenTime;
  19. unsigned char cChuiQiStep = 0,cGouZhenResetOK;
  20. unsigned short cBudaiCheckDelay = 0;
  21. unsigned char bHandWork,bPulseTatol_EN,bFirst,cInt1_OK,cStopFlag,cOneTimes,cKey_Time;
  22. long cSetEncode,cTotal,cDinWeiTime,cAddSetPulseNum,cEncodePulse,cWorkPulseNum;
  23. unsigned long cZipperLength[2];
  24. unsigned char cCheckLengthOk=0,cDaoJu_Flag=0;
  25. unsigned char STOP_IN_FLAG,STOP_IN_FLAG_OLD,STOP_FILTER;
  26. unsigned char MXC_SingOneFlag = 0;
  27. unsigned char MXC_KD_Flag = 0,KD_GO_ON_FLAG = 0;
  28. long MXC_KD_pos = 0,save_pos_buff = 0;
  29. long zipper_length_buff;
  30. short *len_buf;
  31. short *offset_len;
  32. //故障报警
  33. void MXC_SetAlarmCode(unsigned alarm_code)
  34. {
  35. SetAlarmCode(MXC_ALARM_ADDR,alarm_code);
  36. MXC_bAlarmStop = 1;
  37. }
  38. //高速输入X31/X17外部色标信号中断
  39. void MXC_ExtiActionX31(void)
  40. {
  41. if(cSeBiaoEn && !cSeBiaoOk)
  42. {
  43. cSeBiaoOk = 1;
  44. cSeBiaoEn = 0;
  45. if(X_DRV)
  46. //SetRemainLength(X_AXIS, MXC_PARAM_SEBIAO_DW_LENGTH,MXC_PARAM_SB_OFFSET_SPEED);
  47. AxisMovePosAccDec(X_AXIS, MXC_PARAM_SB_OFFSET_SPEED,MXC_PARAM_SEBIAO_DW_LENGTH,
  48. MXC_PARAM_START_SPEED,MXC_PARAM_START_SPEED,
  49. 10,10,80);
  50. }
  51. DISPLAY_DATA2++;
  52. }
  53. //检测订单数据内是否还有可以加工的数据,返回订单序号
  54. unsigned short DingDanCheckOk(void)
  55. {
  56. unsigned short ch,i;
  57. for(ch=0;ch < (MXC_DingDanNum);ch++)
  58. {
  59. i = MXC_DingDan_NowNum;
  60. // 订单完成数量 //订单量 // 拉链长度
  61. if((GetData32bits(MXC_DingDanAddr + i*6+2) < GetData32bits(MXC_DingDanAddr + i*6+4)) && (GetData32bits(MXC_DingDanAddr + i*6) != 0))
  62. {
  63. //设置拉链长度
  64. SetData32bits(15, GetData32bits(MXC_DingDanAddr + i*6));
  65. //累计条数
  66. SetData32bits(76, GetData32bits(MXC_DingDanAddr + i*6+2)); //当前一般为0
  67. //设置加工条数
  68. SetData32bits(22, GetData32bits(MXC_DingDanAddr + i*6+4));
  69. MXC_SET_REVISE_ZIPPER_LENGTH = user_datas[i+MXC_DingDanOffsetAddr];
  70. return ch;
  71. }
  72. MXC_DingDan_NowNum++;
  73. if(MXC_DingDan_NowNum >= MXC_DingDanNum)
  74. MXC_DingDan_NowNum = 0;
  75. }
  76. return ch;//如ch = MXC_DingDanNum)无订单加工
  77. }
  78. //num订单序号设置订单数据植物入生产表
  79. void SetDingDanData(void)
  80. {
  81. unsigned short ch,i;
  82. i = MXC_DingDan_NowNum; //当前
  83. for(ch=0;ch < MXC_DingDanNum;ch++)
  84. {
  85. // 订单完成数量 //订单量
  86. if((GetData32bits(MXC_DingDanAddr + i*6+2) >= GetData32bits(MXC_DingDanAddr + i*6+4)) || (GetData32bits(MXC_DingDanAddr + i*6) == 0))
  87. { //勾针并且长度小于勾针最小长度
  88. if((MXC_DC_MODE != 0) || (MXC_ScanMa_LENGTH >= MXC_GouzhenMin_Length)) //伺服或色标可以直接输入
  89. {
  90. //设置拉链长度
  91. SetData32bits((MXC_DingDanAddr + i*6),MXC_ScanMa_LENGTH);
  92. //设置累计条数
  93. SetData32bits(MXC_DingDanAddr + i*6+2,0);
  94. //设置加工条数
  95. SetData32bits(MXC_DingDanAddr + i*6+4, MXC_ScanMa_Production);
  96. }
  97. break;
  98. }
  99. else
  100. {
  101. i++;
  102. if(i >= MXC_DingDanNum)
  103. i = 0;
  104. }
  105. }
  106. }
  107. long MultLengthOffset(unsigned long zip_length)
  108. {
  109. if(zip_length <= user_datas[MXC_MultLengthOffsetAddr])
  110. len_buf = &user_datas[MXC_MultOffsetAddr];
  111. else if(zip_length <= user_datas[MXC_MultLengthOffsetAddr+1])
  112. len_buf = &user_datas[MXC_MultOffsetAddr+1];
  113. else if(zip_length <= user_datas[MXC_MultLengthOffsetAddr+2])
  114. len_buf = &user_datas[MXC_MultOffsetAddr+2];
  115. else if(zip_length <= user_datas[MXC_MultLengthOffsetAddr+3])
  116. len_buf = &user_datas[MXC_MultOffsetAddr+3];
  117. else
  118. len_buf = &user_datas[MXC_MultOffsetAddr+4];
  119. return (*len_buf);
  120. }
  121. //订单完成条数增加
  122. void DingDanTotalAdd(void)
  123. {
  124. //把当前产量赋值到当前订单组
  125. SetData32bits(MXC_DingDanAddr + MXC_DingDan_NowNum*6+2,GetData32bits(76));
  126. }
  127. void DianDanLenghtCheck(void)
  128. {
  129. unsigned int i=0,ch = 0;
  130. //长度不能小于勾针长度
  131. ch = 0;
  132. if(MXC_DingDanSet130)
  133. {
  134. MXC_DingDanSet130 = 0;
  135. i = 0;
  136. ch = 1;
  137. }
  138. //长度不能小于勾针长度
  139. if(MXC_DingDanSet136)
  140. {
  141. MXC_DingDanSet136 = 0;
  142. i = 1;
  143. ch = 1;
  144. }
  145. //长度不能小于勾针长度
  146. if(MXC_DingDanSet142)
  147. {
  148. MXC_DingDanSet142 = 0;
  149. i = 2;
  150. ch = 1;
  151. }
  152. //长度不能小于勾针长度
  153. if(MXC_DingDanSet148)
  154. {
  155. MXC_DingDanSet148 = 0;
  156. i = 3;
  157. ch = 1;
  158. }
  159. if(MXC_DingDanSet154)
  160. {
  161. MXC_DingDanSet154 = 0;
  162. i = 4;
  163. ch = 1;
  164. }
  165. if((MXC_DC_MODE == 0) && ch) //在勾针定寸模式下不能勾针最小尺寸
  166. {
  167. if( GetData32bits(MXC_DingDanAddr + i*6) < MXC_GouzhenMin_Length)
  168. {
  169. SetData32bits(MXC_DingDanAddr + i*6, MXC_GouzhenMin_Length);
  170. }
  171. }
  172. }
  173. //上电订单检测
  174. void IntitDingDan(void)
  175. {
  176. if(MXC_DingDan_NowNum >= MXC_DingDanNum)
  177. MXC_DingDan_NowNum = 0;
  178. }
  179. void MXC_ExtiActionX20(void)
  180. {
  181. }
  182. void MXC_InitAction(void)
  183. {
  184. float length_buff,pulse_buff;
  185. //CalFreqTab_X_Free(25);
  186. length_buff = MXC_PARAM_DAILUN_LENGTH;
  187. pulse_buff = 2000;
  188. XGearRatio = pulse_buff/length_buff;
  189. if(MXC_USE_GZ_SERVO)
  190. MXC_StartFirst = 1; //上电第一次要重新定位
  191. MXC_Gouzhencurrent_L = 0; //上电当前位置要清零
  192. length_buff = MXC_PARAM_GouZhenLun_LENGTH; // 勾针电机一圈周长;
  193. pulse_buff = 2000; // 勾针电机细分
  194. YGearRatio = pulse_buff/length_buff;
  195. MXC_ProSpeed = 0; //生产速度
  196. MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
  197. MXC_TuoDaiSongZhou = MXC_SERVER_DISEN;
  198. //
  199. MXC_XIA_ZHI_ENABLE = 0;//0不带下止,带下止时强关掉
  200. if(MXC_XIA_ZHI_ENABLE)
  201. MXC_XiaZhi_MOTOR = 1;
  202. else
  203. MXC_XiaZhi_MOTOR = 0;
  204. SetAlarmCode(MXC_ALARM_ADDR,0); //警告清零
  205. //Y轴方向实际输出电平设置
  206. SetDirReverse(Y_AXIS,1);//方向输出的实际电平取反
  207. //订单初始华
  208. //IntitDingDan();
  209. STOP_IN_FLAG = MXC_STOP_IN;
  210. STOP_IN_FLAG_OLD = STOP_IN_FLAG;
  211. }
  212. void MXC_NiLongXiuCiJiAction(void)
  213. {
  214. InputPinConfig();
  215. MXC_NiLongXiuCiJiCheckStart(); //启动
  216. MXC_NiLongXiuCiJi_FenZhengProc(); //左右分针
  217. MXC_NiLongXiuCiJi_XiaC(); //下冲
  218. MXC_ChuiQiProc();
  219. MXC_NiLongXiuCiJi_Motor(); //拖带控制
  220. MXC_JiaoDao();
  221. MXC_ManualAction();
  222. MXC_AutoAction();
  223. MXC_NiLongXiuCiJi_GouZhenProc(); //勾针数控动作
  224. //订单植入
  225. /* if(MXC_Scan_Ma)
  226. {
  227. MXC_Scan_Ma = 0;
  228. SetDingDanData();
  229. }
  230. */
  231. OutputPinConfig();
  232. }
  233. void MXC_ManualAction(void)
  234. {
  235. long i;
  236. static unsigned char save_flg = 0;
  237. //清总产量
  238. if(MXC_bClear) //清总产量
  239. {
  240. MXC_bClear = 0;
  241. ClrcToTal(MXC_TOTAL_ADDR);
  242. // MXC_bSaveWorkData = 1;
  243. save_flg = 1;
  244. }
  245. if(save_flg)
  246. {
  247. if(!MXC_bSaveWorkData)
  248. {
  249. ClrcToTal(MXC_TOTAL_ADDR);
  250. if(MXC_DingDanWorkMode)
  251. {
  252. DingDanTotalAdd();
  253. }
  254. save_flg = 0;
  255. }
  256. }
  257. //当长度改变时,生产总量自动清零
  258. if(MXC_bChangeLength)
  259. {
  260. MXC_bChangeLength = 0;
  261. MXC_bClear = 1;
  262. }
  263. //加10
  264. if(MXC_bAddLength)
  265. {
  266. MXC_bAddLength = 0;
  267. i = MXC_SET_REVISE_ZIPPER_LENGTH;
  268. i += 10;
  269. SetData32bits(MXC_ZIPPER_LENGTH_ADDR,i);
  270. }
  271. //减10
  272. if(MXC_bDecLength)
  273. {
  274. MXC_bDecLength = 0;
  275. i = MXC_SET_REVISE_ZIPPER_LENGTH;
  276. i -= 10;
  277. SetData32bits(MXC_ZIPPER_LENGTH_ADDR,i);
  278. }
  279. //工作方式选择(数控定寸和勾针定寸) 
  280. if(MXC_bSetDCMode)
  281. {
  282. MXC_bSetDCMode = 0;
  283. if(!MXC_bRunning)
  284. {
  285. MXC_DC_MODE++;
  286. if(MXC_DC_MODE > 2)MXC_DC_MODE = 0;
  287. if(MXC_DC_MODE != 0)
  288. {
  289. MXC_GouZhen_VAVLE = 1;
  290. MXC_XIA_ZHI_ENABLE = 0;
  291. MXC_XiaZhi_MOTOR = 0;
  292. }
  293. }
  294. }
  295. //勾针方式选择(活动勾针和固定勾针) 
  296. if(MXC_bChangeGouZhenMode)
  297. {
  298. MXC_bChangeGouZhenMode = 0;
  299. if(!MXC_bRunning)
  300. {
  301. // MXC_GOU_ZHEN_MODE++;
  302. // if(MXC_GOU_ZHEN_MODE > 1)MXC_GOU_ZHEN_MODE = 0;
  303. }
  304. }
  305. //下止工作选择) 
  306. if(MXC_bChangeXiaZhiMode)
  307. {
  308. MXC_bChangeXiaZhiMode = 0;
  309. if(!MXC_bRunning)
  310. {
  311. MXC_XIA_ZHI_ENABLE++;
  312. if(MXC_XIA_ZHI_ENABLE > 2) MXC_XIA_ZHI_ENABLE = 0;
  313. if(MXC_XIA_ZHI_ENABLE)
  314. MXC_XiaZhi_MOTOR = 1;
  315. else
  316. MXC_XiaZhi_MOTOR = 0;
  317. }
  318. }
  319. if(MXC_bJiaoDao)
  320. {
  321. MXC_cJiaoDaoStep = 1;
  322. MXC_bJiaoDao = 0;
  323. }
  324. if(MXC_bChuiQi)
  325. {
  326. MXC_bChuiQi = 0;
  327. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  328. }
  329. if((MXC_bRunning) == 0) ////手动
  330. {
  331. if(MXC_ManXiaChong_UP || MXC_bXiaChong)
  332. {
  333. MXC_bXiaChong = 0;
  334. if(MXC_cXiaChongStep == 0)
  335. {
  336. MXC_cXiaChongStep = 1;
  337. MXC_DingDanJianGe_State = 0;
  338. }
  339. }
  340. if(MXC_cXiaChongStep == 0)
  341. {
  342. if(MXC_bLeftFenZhen)
  343. {
  344. MXC_bLeftFenZhen = 0;
  345. MXC_LeftFenZhen_VAVLE = ~MXC_LeftFenZhen_VAVLE;
  346. }
  347. if(MXC_bRightFenZhen)
  348. {
  349. MXC_bRightFenZhen = 0;
  350. MXC_RightFenZhen_VAVLE= ~MXC_RightFenZhen_VAVLE;
  351. }
  352. //点动下冲
  353. if((MXC_bDotXiaChong))
  354. {
  355. MXC_bDotXiaChong = 0;
  356. if(MXC_LeftFenZhen_IN && MXC_RighttFenZhen_IN)
  357. {
  358. if(MXC_XiaChongMotorMode == 0)
  359. {
  360. if(MXC_cXiaChongStep == 0)MXC_cXiaChongStep = 20;
  361. }
  362. else
  363. {
  364. if(MXC_cXiaChongStep == 0)MXC_cXiaChongStep = 40;
  365. }
  366. }
  367. else
  368. {
  369. MXC_SetAlarmCode(MXC_XIA_CHONG_ALARM); //下冲条件不满足
  370. }
  371. }
  372. if(MXC_bGouZhen)
  373. {
  374. MXC_bGouZhen = 0;
  375. if((MXC_GOU_ZHEN_MODE == 0))//普通勾针(活动)过链
  376. {
  377. MXC_cGouZhenTime = dwTickCount + 300;
  378. MXC_GouZhen_VAVLE = ~MXC_GouZhen_VAVLE;
  379. }
  380. }
  381. }
  382. if(MXC_bXiaZhi)
  383. {
  384. MXC_bXiaZhi = 0;
  385. if(MXC_XiaZhi_VAVLE)
  386. {
  387. MXC_XiaZhi_VAVLE = 0;
  388. MXC_ChaoSheng = 0;
  389. }
  390. else
  391. {
  392. if(MXC_XIA_ZHI_ENABLE) //下止选择
  393. {
  394. //下止输出
  395. MXC_cXiaZhiDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
  396. MXC_XiaZhi_VAVLE = 1;
  397. }
  398. }
  399. }
  400. if(MXC_DC_MODE != 0) //伺服定寸
  401. {
  402. MXC_GuDingGouZhen = 1;
  403. MXC_GouZhen_VAVLE = 1;
  404. }
  405. else if((MXC_GOU_ZHEN_MODE == 0) && !Y_DRV && (MXC_cGouZhenDWStep == 0))//普通勾针(活动)过链在勾针定电机动作情况下不能关
  406. {
  407. if(dwTickCount >= MXC_cGouZhenTime) MXC_GouZhen_VAVLE = 0;
  408. }
  409. if(MXC_bChuDai)
  410. {
  411. MXC_ChuDai_VAVLE = 1;
  412. }
  413. else
  414. {
  415. MXC_ChuDai_VAVLE = 0;
  416. }
  417. if(MXC_bTestMotor)
  418. {
  419. MXC_GouZhen_VAVLE = 1;
  420. MXC_cGouZhenTime = dwTickCount + 300;
  421. if(!X_DRV)
  422. {
  423. MXC_TuoDaiSongZhou = MXC_SERVER_EN;
  424. //AxisContinueMoveAcc(X_AXIS,10,MXC_DIR_P,MXC_PARAM_START_SPEED,MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
  425. }
  426. }
  427. else if(MXC_cMotorStep == 0)
  428. {
  429. //if(X_DRV)AxisDecStop(X_AXIS);
  430. }
  431. }
  432. //下止下冲电磁铁
  433. if((MXC_XiaZhi_VAVLE != 0) && (dwTickCount >= MXC_cXiaZhiDelay))
  434. {
  435. MXC_XiaZhi_VAVLE = 0;
  436. }
  437. }
  438. void MXC_AutoAction(void)
  439. {
  440. unsigned short ch;
  441. DISPLAY_DATA0 = MXC_cAutoStep;
  442. DISPLAY_DATA1 = MXC_cMotorStep;
  443. //DISPLAY_DATA2 = MXC_cLeftFenZhenStep;
  444. DISPLAY_DATA3 = dwRealPos;
  445. DISPLAY_DATA4 = cZipperLength[0];//MXC_cXiaChongStep;
  446. DISPLAY_DATA5 = cZipperLength[1];
  447. if(MXC_bRunning)
  448. {
  449. if((!MXC_Zipper_IN))
  450. MXC_ChuDai_VAVLE = 0;
  451. else
  452. MXC_ChuDai_VAVLE = 1;
  453. if((MXC_DC_MODE == 0) && (MXC_GOU_ZHEN_MODE == 0))
  454. {
  455. if(MXC_GouZhen_IN_UP)MXC_cGouZhenTime = 1;
  456. }
  457. else
  458. MXC_cGouZhenTime = 1;
  459. switch(MXC_cAutoStep)
  460. {
  461. case 0:
  462. break;
  463. case 1:
  464. if(dwTickCount >= MXC_cAutoDelay)
  465. {
  466. if(MXC_TuoDaiSongZhou == MXC_SERVER_DISEN)
  467. {
  468. MXC_TuoDaiSongZhou = MXC_SERVER_EN;
  469. MXC_cAutoDelay = dwTickCount + 200; //先锁轴
  470. }
  471. else
  472. MXC_cAutoDelay = dwTickCount;
  473. //要判断勾针是否已定位好
  474. if(MXC_cGouZhenDWStep == 0)
  475. {
  476. MXC_cAutoStep = 2;
  477. }
  478. }
  479. break;
  480. case 2:
  481. //左右分针要退到位,过链到位要离开
  482. if(!MXC_GouZhen_IN && MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN && (dwTickCount >= MXC_cAutoDelay))
  483. {
  484. //要判断勾针是否已定位好
  485. if(MXC_cGouZhenDWStep == 0)
  486. {
  487. MXC_cAutoStep = 3;
  488. MXC_cMotorStep = 1; //启动拖带
  489. }
  490. }
  491. break;
  492. case 3:
  493. //拖带已经完成
  494. if(MXC_cMotorStep == 0)
  495. {
  496. if(SingOneFlg)
  497. {
  498. dwZipCnt = 0;
  499. SingOneFlg = 0;
  500. MXC_cAutoStep = 0;
  501. MXC_bRunning = 0;
  502. }
  503. else
  504. {
  505. MXC_cAutoStep = 4;
  506. }
  507. }
  508. break;
  509. case 4:
  510. MXC_cAutoStep = 5;
  511. break;
  512. case 5:
  513. //左右分针都已完成
  514. if((MXC_cLeftFenZhenStep == 0) && (MXC_cRightFenZhenStep == 0) && (MXC_cXiaChongStep == 0))
  515. {
  516. if(MXC_SET_XIACHONG_DISEN==0)
  517. {
  518. MXC_cXiaChongStep = 1; //下冲电机启动
  519. MXC_cAutoStep = 6;
  520. }
  521. else
  522. {
  523. MXC_cAutoDelay = dwTickCount + MXC_PARAM_DELAY_XC;
  524. MXC_cAutoStep = 106;
  525. }
  526. }
  527. break;
  528. case 106:
  529. if(dwTickCount>=MXC_cAutoDelay)
  530. {
  531. MXC_GouZhen_VAVLE=1;
  532. MXC_cAutoStep = 6;
  533. }
  534. break;
  535. case 6: //下冲已完成
  536. if(((MXC_cXiaChongStep == 0) || (MXC_cXiaChongStep >= 5)) && !MXC_XiaZhi_VAVLE)
  537. {
  538. dwZipCnt++;
  539. AddToTal(MXC_TOTAL_ADDR); //计数增加和保存
  540. //条件满足的情况下对应产量也加1
  541. // DingDanTotalAdd();
  542. // MXC_DingDanJianGe = 0; //回到原来工作模式
  543. CalProSP(MXC_PROSPEED_ADDR);
  544. MXC_cAutoStep = 7;
  545. }
  546. break;
  547. case 7:
  548. if(MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN)
  549. {
  550. if(GetTotal(MXC_TOTAL_ADDR) >= MXC_SET_TOTAL)
  551. {
  552. if(MXC_DingDanWorkMode && MXC_USE_GZ_SERVO)
  553. {
  554. MXC_bSaveWorkData = 1;
  555. MXC_cAutoStep = 20;
  556. }
  557. else
  558. MXC_cAutoStep = 0;
  559. MXC_bRunning = 0;
  560. MXC_SingOneFlag = 1;
  561. MXC_SetAlarmCode(MXC_TOTAL_ALARM);
  562. }
  563. else
  564. MXC_cAutoStep = 8;
  565. }
  566. break;
  567. case 8:
  568. MXC_cAutoDelay = dwTickCount + MXC_PARAM_MOTOR_DELAY;
  569. if(MXC_SingOneFlag)
  570. {
  571. dwZipCnt = 0;
  572. MXC_SingOneFlag = 0;
  573. MXC_cAutoStep = 0;
  574. MXC_bRunning = 0;
  575. }
  576. else
  577. MXC_cAutoStep = 1;
  578. break;
  579. case 20:
  580. if(!MXC_bSaveWorkData)
  581. {
  582. //订单组自动赋值 在连续订单模式下才走下一组 0 是单一订单
  583. if(DingDanCheckOk() != (MXC_DingDanNum))
  584. {
  585. MXC_cAutoStep = 21;
  586. MXC_cAutoDelay = dwTickCount + 20;
  587. if(MXC_DC_MODE == 0) //勾针定寸情况下才要重新的定位勾针
  588. {
  589. //长度不一样先定位勾针
  590. if(MXC_SET_ZIPPER_LENGTH > MXC_Gouzhencurrent_L)
  591. ch = MXC_SET_ZIPPER_LENGTH - MXC_Gouzhencurrent_L;
  592. else
  593. ch = MXC_Gouzhencurrent_L - MXC_SET_ZIPPER_LENGTH;
  594. if(ch>2)
  595. MXC_cGouZhenDWStep = 1;
  596. }
  597. }
  598. else
  599. MXC_SetAlarmCode(MXC_TOTAL_ALARM);
  600. }
  601. break;
  602. case 21:
  603. if(dwTickCount >= MXC_cAutoDelay)
  604. {
  605. if(MXC_DingDanJianGe_Length) //间隔距离为0时直接返回
  606. {
  607. MXC_DingDanJianGe_State = 1;
  608. MXC_cMotorStep = 100;
  609. MXC_cAutoStep = 22;
  610. }
  611. else
  612. MXC_cAutoStep = 8;
  613. }
  614. break;
  615. case 22:
  616. if(MXC_cMotorStep == 0)
  617. {
  618. MXC_cXiaChongStep = 1;
  619. MXC_cAutoStep = 23;
  620. }
  621. break;
  622. case 23:
  623. if(MXC_cXiaChongStep == 0)
  624. {
  625. if(MXC_DC_MODE != 0)
  626. MXC_cAutoStep = 1;
  627. else
  628. MXC_cAutoStep = 30;
  629. }
  630. break;
  631. case 30:
  632. if(MXC_PARAM_GZ_RESET_MODE==0)
  633. MXC_cMotorStep = 200;
  634. MXC_cAutoStep = 31;
  635. break;
  636. case 31:
  637. if(MXC_cMotorStep == 0)
  638. {
  639. MXC_cAutoStep = 1;
  640. }
  641. break;
  642. }
  643. }
  644. }
  645. // 检测是否踏了脚踏开关
  646. void MXC_NiLongXiuCiJiCheckStart(void)
  647. {
  648. unsigned short ch;
  649. // 停止键 不能在工作,手动,停止过程中
  650. if((MXC_bRunning == 0) && (MXC_START_IN_UP || MXC_bStart || MXC_bNext))
  651. {
  652. MXC_bStart = 0;
  653. if(!MXC_LeftFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_START_LFZ_ORIGIN_ALARM); //没拉链
  654. else if(!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_START_RFZ_ORIGIN_ALARM);
  655. else if(!MXC_Zipper_IN)MXC_SetAlarmCode(MXC_START_NO_ZIPPER_ALARM);
  656. else if((MXC_PARAM_SEBIAO_DW_LENGTH > MXC_SET_ZIPPER_LENGTH) && (MXC_DC_MODE==2))MXC_SetAlarmCode(MXC_SEBIAO_ZIPPER_LENGTH_ALARM);
  657. else if(MXC_KaDai_IN)MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
  658. else
  659. {
  660. /* if(GetTotal(MXC_TOTAL_ADDR) >= MXC_SET_TOTAL)
  661. {
  662. //调入下一组数据,全部都没有的话警告停止
  663. if(DingDanCheckOk() >= (MXC_DingDanNum))
  664. {
  665. MXC_SetAlarmCode(MXC_TOTAL_ALARM);
  666. return;
  667. }
  668. }*/
  669. if(MXC_bNext)
  670. {
  671. SingOneFlg = 1;
  672. MXC_bNext = 0;
  673. }
  674. MXC_bRunning = 1;
  675. cGouZhenTime = 1;
  676. cCheckLengthOk = 0;
  677. cZipperLength[0] = 0;
  678. cZipperLength[1] = 0;
  679. zipper_length_buff=0;
  680. dwZipCnt = 0;
  681. //DISPLAY_DATA4=0;
  682. /*
  683. if((MXC_DingDanJianGe_State == 1) && MXC_DingDanWorkMode && MXC_USE_GZ_SERVO) //间隔链还没有打完情况下先打间隔链
  684. MXC_cAutoStep = 20;
  685. else
  686. */
  687. MXC_cAutoStep = 1;
  688. //第一次上电或长度不一样时启动必须先定位勾针
  689. //长度不一样先定位勾针
  690. //MXC_StartFirst = 1;
  691. offset_len = &MXC_SET_REVISE_ZIPPER_LENGTH;
  692. if((MXC_SET_ZIPPER_LENGTH + (*offset_len))> MXC_Gouzhencurrent_L)
  693. ch = MXC_SET_ZIPPER_LENGTH + MXC_SET_REVISE_ZIPPER_LENGTH - MXC_Gouzhencurrent_L;
  694. else
  695. ch = MXC_Gouzhencurrent_L - (MXC_SET_ZIPPER_LENGTH + (*offset_len));
  696. // 数控模式下不用走动勾针
  697. if((MXC_StartFirst ||(ch>1)) && (MXC_DC_MODE == 0)&& MXC_USE_GZ_SERVO)
  698. {
  699. MXC_cGouZhenDWStep = 1;
  700. //MXC_StartFirst = 1;
  701. }
  702. }
  703. }
  704. //卡带感应
  705. if(MXC_KaDai_IN && (dwTickCount >= MXC_cKaDaiDelay))
  706. {
  707. if(MXC_DC_MODE == 1)
  708. {
  709. if(X_DRV && MXC_bRunning && (MXC_cMotorStep == 20))
  710. {
  711. MXC_KD_Flag = 1;
  712. KD_GO_ON_FLAG = 1;
  713. }
  714. }
  715. MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
  716. MXC_cKaDaiDelay = dwTickCount + 2200;
  717. }
  718. if(MXC_KD_Flag)
  719. {
  720. if(!X_DRV)
  721. {
  722. MXC_KD_pos = dwRealPos;
  723. MXC_KD_Flag = 0;
  724. }
  725. }
  726. if(MXC_KaDai_IN_UP)
  727. {
  728. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  729. }
  730. //停止
  731. STOP_IN_FLAG_OLD = STOP_IN_FLAG;
  732. if(MXC_STOP_IN)
  733. {
  734. if(STOP_FILTER < 50)
  735. {
  736. STOP_FILTER++;
  737. }
  738. else
  739. STOP_IN_FLAG = 1;
  740. }
  741. else if(STOP_FILTER > 25)
  742. {
  743. STOP_FILTER--;
  744. }
  745. else
  746. STOP_IN_FLAG = 0;
  747. if(MXC_bStop)
  748. {
  749. MXC_bStop = 0;
  750. if(MXC_bRunning)MXC_SingOneFlag = 1;
  751. }
  752. if(((STOP_IN_FLAG && !STOP_IN_FLAG_OLD)))
  753. {
  754. MXC_bStop = 0;
  755. if(MXC_cGouZhenDWStep && STOP_IN_FLAG && (MXC_cXiaChongStep == 0))
  756. {
  757. AxisDecStop(Y_AXIS);
  758. MXC_cGouZhenDWStep = 0;
  759. }
  760. if(MXC_bRunning)
  761. {
  762. if(MXC_cXiaChongStep==0)
  763. {
  764. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  765. if(!MXC_XiaChong_MOTOR)MXC_XC_SongZhou = MXC_XC_SERVER_EN;
  766. }
  767. MXC_bRunning = 0;
  768. cStopFlag = 0;
  769. MXC_cAutoStep = 0;
  770. MXC_cMotorStep = 0;
  771. MXC_cDCPStep = 0;
  772. AxisDecStop(X_AXIS);
  773. //DISPLAY_DATA4++;
  774. MXC_cJiaoDaoStep = 0;
  775. SingOneFlg = 0;
  776. MXC_SingOneFlag = 0;
  777. MXC_KD_Flag = 0;
  778. KD_GO_ON_FLAG = 0;
  779. }
  780. else
  781. {
  782. MXC_bRunning = 0;
  783. cStopFlag = 0;
  784. MXC_cAutoStep = 0;
  785. MXC_cMotorStep = 0;
  786. MXC_cXiaChongStep = 0;
  787. MXC_cLeftFenZhenStep = 0;
  788. MXC_cRightFenZhenStep = 0;
  789. MXC_cJiaoDaoStep = 0;
  790. MXC_cDCPStep = 0;
  791. MXC_XiaZhi_VAVLE = 0;
  792. MXC_LeftFenZhen_VAVLE = 0;
  793. MXC_RightFenZhen_VAVLE = 0;
  794. MXC_XiaChong_MOTOR = 0;
  795. MXC_ChaoSheng = 0;
  796. MXC_JiaoDao_OUT = 0;
  797. MXC_ChuDai_VAVLE = 0;
  798. MXC_GuDingGouZhen = 0;
  799. SingOneFlg = 0;
  800. MXC_SingOneFlag = 0;
  801. MXC_KD_Flag = 0;
  802. KD_GO_ON_FLAG = 0;
  803. if(MXC_XiaChongMotorMode)
  804. MXC_XC_SongZhou = MXC_XC_SERVER_EN;
  805. else
  806. MXC_XC_ShaChe = MXC_SC_DISEN;
  807. if((MXC_cChuiQiStep == 0) &&(MXC_cXiaChongStep==0) )MXC_cChuiQiStep = 1;
  808. AxisDecStop(X_AXIS);
  809. //DISPLAY_DATA7++;
  810. SetAlarmCode(MXC_ALARM_ADDR,MXC_NO_ALARM);
  811. }
  812. }
  813. if(!MXC_bRunning && (MXC_cMotorStep==0) && (MXC_cXiaChongStep == 0))
  814. {
  815. if(!X_DRV)MXC_TuoDaiSongZhou = MXC_SERVER_DISEN;
  816. }
  817. if(MXC_bAlarmStop)
  818. {
  819. MXC_bAlarmStop = 0;
  820. MXC_bRunning = 0;
  821. MXC_cAutoStep = 0;
  822. MXC_cMotorStep = 0;
  823. MXC_cDCPStep = 0;
  824. MXC_SingOneFlag = 0;
  825. AxisDecStop(X_AXIS);
  826. if((GetAlarmCode(MXC_ALARM_ADDR) == MXC_XIA_CHONG_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_XC_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_FEN_ZHEN_ALARM))
  827. {
  828. MXC_cXiaChongStep = 0;
  829. MXC_XiaChong_MOTOR = 0;
  830. }
  831. }
  832. }
  833. void MXC_JiaoDao(void)
  834. {
  835. if(MXC_cJiaoDaoStep == 1)
  836. {
  837. MXC_cChuiQiDelay = dwTickCount + 500;
  838. MXC_JiaoDao_OUT = 1;
  839. MXC_cJiaoDaoStep = 2;
  840. }
  841. else if((MXC_cJiaoDaoStep == 2) && (dwTickCount >= MXC_cChuiQiDelay))
  842. {
  843. MXC_JiaoDao_OUT = 0;
  844. MXC_cJiaoDaoStep = 0;
  845. }
  846. }
  847. void MXC_ChuiQiProc(void)
  848. {
  849. //吹气
  850. if(MXC_XiaChong_IN_UP)
  851. {
  852. if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
  853. }
  854. switch (MXC_cDCPStep)
  855. {
  856. case 0:
  857. break;
  858. case 1:
  859. MXC_cDCPStep = 2;
  860. MXC_cDaoJuCheckDelay = dwTickCount + 3500;
  861. break;
  862. case 2:
  863. if(MXC_DingChuPian_IN_DW)
  864. {
  865. MXC_cDCPStep = 0;
  866. }
  867. else if((dwTickCount >= MXC_cDaoJuCheckDelay) && (MXC_DAO_JU_ALARM_EN == 0))
  868. MXC_SetAlarmCode(MXC_DAO_JU_ALARM);
  869. break;
  870. }
  871. switch(MXC_cChuiQiStep)
  872. {
  873. case 1:
  874. MXC_cChuiQiStep = 2;
  875. if(MXC_bRunning)MXC_cChuiQiDelay = dwTickCount+MXC_PARAM_DELAY_CHUIQI_TIME;
  876. break;
  877. case 2:
  878. if(dwTickCount >= MXC_cChuiQiDelay)
  879. {
  880. MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_CHUIQI_TIME;
  881. MXC_ChuiQi_VAVLE = 1;//
  882. MXC_cChuiQiStep = 3;
  883. }
  884. break;
  885. case 3:
  886. if(dwTickCount >= MXC_cChuiQiDelay)
  887. {
  888. MXC_ChuiQi_VAVLE = 0;//
  889. MXC_cChuiQiStep = 0;
  890. }
  891. break;
  892. }
  893. }
  894. void MXC_ShaChe_Output(void)
  895. {
  896. //启动吹气
  897. cShaCheTime = dwTickCount + (unsigned long)120;
  898. if(MXC_XiaChongMotorMode == 0)MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
  899. }
  900. void MXC_Output_XiaCi(void)//下止输出
  901. {
  902. if(MXC_XIA_ZHI_ENABLE) //下止选择
  903. {
  904. //下止输出
  905. MXC_cXiaZhiDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
  906. MXC_XiaZhi_VAVLE = 1;
  907. }
  908. }
  909. unsigned char ComPareLength(void)
  910. {
  911. if((cZipperLength[0] != 0) && (cZipperLength[1] != 0))
  912. {
  913. if(cZipperLength[0] > cZipperLength[1])
  914. {
  915. if((cZipperLength[0] - cZipperLength[1]) > 50)
  916. {
  917. return 0;
  918. }
  919. else
  920. return 1;
  921. }
  922. else
  923. {
  924. if((cZipperLength[1] - cZipperLength[0]) > 50)
  925. {
  926. return 0;
  927. }
  928. else
  929. return 1;
  930. }
  931. }
  932. else
  933. return 0;
  934. }
  935. void MXC_NiLongXiuCiJi_Motor(void)
  936. {
  937. static long save_buff,gou_zhen_buff;
  938. static unsigned long zipper_length;
  939. short *revise_buff;
  940. if(MXC_bRunning)
  941. {
  942. if(MXC_Zipper_IN)
  943. {
  944. MXC_cBudaiCheckDelay = dwTickCount + MXC_PARAM_MOTOR_ALARM_TIME;
  945. }
  946. else if(dwTickCount >= MXC_cBudaiCheckDelay) //没布带了
  947. {
  948. MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM); //没拉链
  949. }
  950. }
  951. dwRealPos = GetPos(X_AXIS);
  952. //当前位置脉冲
  953. dwYRealPos = GetPos(Y_AXIS);
  954. DISPLAY_DATA6 = zipper_length;
  955. DISPLAY_DATA7 = zipper_length_buff;
  956. switch(MXC_cMotorStep)
  957. {
  958. case 0:
  959. break;
  960. // 过链 左分针退位 左到位
  961. case 1: if(MXC_LeftFenZhen_Origin_IN && (!MXC_LeftFenZhen_IN) && MXC_RightFenZhen_Origin_IN && (!MXC_RighttFenZhen_IN))
  962. {
  963. SetPos(X_AXIS,0);
  964. //save_buff = dwRealPos;
  965. //DISPLAY_DATA2= save_buff;
  966. revise_buff = &user_datas[17];
  967. //save_pos_buff = dwRealPos;
  968. if(MXC_DC_MODE == 0) //钩针定寸
  969. {
  970. if(MXC_DEC_MODE) //减速方式:1数控模式 0感应方式
  971. {
  972. if(MXC_PARAM_AUTO_CHECK_MODE)//1为自动测长0为手动输入长度
  973. {
  974. if(cCheckLengthOk)
  975. {
  976. AxisMovePosAccDecNotStop(X_AXIS,MXC_PARAM_SET_SPEED,zipper_length-MXC_PARAM_LOWSPEED_LENGTH,
  977. MXC_PARAM_START_SPEED,MXC_PARAM_LOW_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,0);
  978. }
  979. else
  980. {
  981. if(cCheckLengthOk == 0)
  982. {
  983. cZipperLength[0] = cZipperLength[1];
  984. cZipperLength[1] = zipper_length_buff;
  985. if(ComPareLength())
  986. {
  987. cCheckLengthOk = 1;
  988. }
  989. }
  990. if(cCheckLengthOk)
  991. {
  992. zipper_length = cZipperLength[1];
  993. AxisMovePosAccDecNotStop(X_AXIS,MXC_PARAM_SET_SPEED,zipper_length-MXC_PARAM_LOWSPEED_LENGTH,
  994. MXC_PARAM_START_SPEED,MXC_PARAM_LOW_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,0);
  995. }
  996. else
  997. {
  998. AxisContinueMoveAcc(X_AXIS,MXC_PARAM_FIRST_SPEED,MXC_DIR_P,MXC_PARAM_START_SPEED,
  999. MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
  1000. }
  1001. }
  1002. }
  1003. else
  1004. {
  1005. if(dwZipCnt==0)
  1006. AxisContinueMoveAcc(X_AXIS,MXC_PARAM_FIRST_SPEED,MXC_DIR_P,MXC_PARAM_START_SPEED,MXC_PARAM_START_SPEED,
  1007. MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
  1008. else
  1009. {
  1010. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
  1011. //输入长度过大
  1012. if(zipper_length>zipper_length_buff && dwZipCnt>1)
  1013. zipper_length=zipper_length_buff;
  1014. AxisMovePosAccDecNotStop(X_AXIS,MXC_PARAM_SET_SPEED,zipper_length-MXC_PARAM_LOWSPEED_LENGTH,
  1015. MXC_PARAM_START_SPEED,MXC_PARAM_LOW_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,0);
  1016. }
  1017. }
  1018. MXC_cMotorStep = 3;
  1019. }
  1020. else // 感应方式
  1021. {
  1022. AxisContinueMove(X_AXIS,MXC_PARAM_SET_SPEED,MXC_DIR_P);
  1023. MXC_cMotorStep = 2;
  1024. }
  1025. }
  1026. else if(MXC_DC_MODE == 1) //电机定寸
  1027. {
  1028. if(KD_GO_ON_FLAG)
  1029. {
  1030. if(MXC_KD_pos > (MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH))
  1031. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
  1032. else
  1033. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - MXC_KD_pos;
  1034. KD_GO_ON_FLAG = 0;
  1035. }
  1036. else
  1037. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
  1038. MXC_cMotorStep = 20;
  1039. MXC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
  1040. MXC_GuDingGouZhen = 1; //定位(活动勾针)电磁阀
  1041. AxisMovePosAccDec(X_AXIS,MXC_PARAM_SET_SPEED,zipper_length,MXC_PARAM_START_SPEED,
  1042. MXC_PARAM_SHIFU_LOW_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,MXC_PARAM_SHIFU_LOWSPEED_LENGTH);
  1043. }
  1044. else //色标定寸
  1045. {
  1046. zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff);
  1047. if((dwZipCnt==0)||SingOneFlg)AxisContinueMoveAcc(X_AXIS,MXC_PARAM_SB_LOW_SPEED,MXC_DIR_P,MXC_PARAM_START_SPEED,
  1048. MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
  1049. else AxisContinueMoveAcc(X_AXIS,MXC_PARAM_SB_HIGH_SPEED,MXC_DIR_P,MXC_PARAM_START_SPEED,
  1050. MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
  1051. cSeBiaoOk = 0;
  1052. cSeBiaoEn = 0;
  1053. MXC_cMotorStep = 50;
  1054. }
  1055. MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
  1056. MXC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
  1057. }
  1058. break;
  1059. // step2-5 活动勾针定寸
  1060. case 2:
  1061. if((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0))MXC_GouZhen_VAVLE = 0;
  1062. if(MXC_DEC_MODE==0) // 感应模式
  1063. {
  1064. if(MXC_Dec_IN_DW)
  1065. {
  1066. AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  1067. MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
  1068. MXC_cMotorStep = 3;
  1069. }
  1070. }
  1071. if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  1072. break;
  1073. case 3:
  1074. if((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0))MXC_GouZhen_VAVLE = 0;
  1075. if(MXC_DEC_MODE) // 数控方式
  1076. {
  1077. if(MXC_PARAM_AUTO_CHECK_MODE)
  1078. {
  1079. if(cCheckLengthOk)
  1080. {
  1081. if((dwRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH))&&MXC_PARAM_GZ_RESET_MODE)MXC_GouZhen_VAVLE = 0;
  1082. }
  1083. else
  1084. {
  1085. if(dwTickCount >= MXC_cGouZhenTime)MXC_GouZhen_VAVLE = 0;
  1086. }
  1087. }
  1088. else
  1089. {
  1090. if((dwRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH))&&MXC_PARAM_GZ_RESET_MODE)MXC_GouZhen_VAVLE = 0;
  1091. if((dwZipCnt==0)&& (dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==1))MXC_GouZhen_VAVLE = 0;
  1092. }
  1093. if(MXC_GouZhen_IN)
  1094. {
  1095. MXC_GouZhen_VAVLE = 0;
  1096. MXC_cMotorStep = 4;
  1097. //AxisEgmStop(X_AXIS);
  1098. //再走一点拉紧
  1099. AxisMovePosAccDec(X_AXIS,MXC_PARAM_LOW_SPEED,6,MXC_PARAM_LOW_SPEED,MXC_PARAM_LOW_SPEED,
  1100. MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,0);
  1101. }
  1102. }
  1103. else // 感应方式
  1104. {
  1105. MXC_cMotorStep = 4;
  1106. }
  1107. if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  1108. break;
  1109. case 4:
  1110. if((dwTickCount >= MXC_cGouZhenTime)&&(MXC_PARAM_GZ_RESET_MODE==0))MXC_GouZhen_VAVLE = 0;
  1111. if(MXC_DEC_MODE) // 数控方式
  1112. {
  1113. if(!X_DRV)
  1114. {
  1115. MXC_cMotorStep = 0;
  1116. zipper_length_buff=dwRealPos;
  1117. }
  1118. }
  1119. else // 感应方式
  1120. {
  1121. if(MXC_GouZhen_IN)
  1122. {
  1123. MXC_cMotorStep = 5;
  1124. AxisEgmStop(X_AXIS);
  1125. }
  1126. }
  1127. if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  1128. break;
  1129. case 5:
  1130. if(MXC_DEC_MODE) // 数控方式
  1131. {
  1132. }
  1133. else // 感应方式
  1134. {
  1135. if(!X_DRV)
  1136. {
  1137. MXC_cMotorStep = 0;
  1138. }
  1139. }
  1140. if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  1141. break;
  1142. /*
  1143. case 11://以下为固定勾针方式
  1144. if(MXC_XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
  1145. {
  1146. if(dwTickCount >= MXC_cAutoDelay)MXC_GuDingGouZhen = 0;
  1147. if(!MXC_GuoLian_IN)
  1148. {
  1149. AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  1150. MXC_cMotorStep = 12;
  1151. MXC_cAutoDelay = dwTickCount + (unsigned long)1500; //延时检测
  1152. }
  1153. }
  1154. else
  1155. {
  1156. if(MXC_GuoLianCheckMode)
  1157. {
  1158. if(!MXC_GuoLian_IN)
  1159. {
  1160. AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  1161. MXC_cMotorStep = 12;
  1162. MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[12]; //延时检测
  1163. }
  1164. }
  1165. else
  1166. {
  1167. if(MXC_GuoLian_IN)
  1168. {
  1169. AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  1170. MXC_cMotorStep = 12;
  1171. MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[12]; //延时检测
  1172. }
  1173. }
  1174. }
  1175. break;
  1176. case 12:
  1177. if(dwTickCount >= MXC_cAutoDelay)
  1178. {
  1179. if(MXC_GuDingGouZhen)
  1180. {
  1181. MXC_GuDingGouZhen = 0;
  1182. MXC_cAutoDelay = dwTickCount + (unsigned long)1500; //延时检测
  1183. }
  1184. else if(!MXC_GuDingGouZhen)
  1185. {
  1186. // MXC_SetAlarmCode(MXC_GU_DING_GOUZHEN_ALARM);
  1187. }
  1188. }
  1189. if(MXC_XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
  1190. {
  1191. if(MXC_GuoLian_IN)
  1192. {
  1193. MXC_GuDingGouZhen = 0;
  1194. MXC_cMotorStep = 13;
  1195. MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机
  1196. }
  1197. }
  1198. else
  1199. {
  1200. if(MXC_GuoLianCheckMode)
  1201. {
  1202. if(MXC_GuoLian_IN_UP)
  1203. {
  1204. MXC_GuDingGouZhen = 0;
  1205. MXC_cMotorStep = 13;
  1206. MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机
  1207. }
  1208. }
  1209. else
  1210. {
  1211. if(MXC_GuoLian_IN_DW)
  1212. {
  1213. MXC_GuDingGouZhen = 0;
  1214. MXC_cMotorStep = 13;
  1215. MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机
  1216. }
  1217. }
  1218. }
  1219. break;
  1220. case 13:
  1221. if((dwTickCount >= MXC_cAutoDelay))
  1222. {
  1223. if(MXC_XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
  1224. {
  1225. AxisEgmStop(X_AXIS);
  1226. if(MXC_GuoLian_IN)
  1227. {
  1228. MXC_cMotorStep = 0;
  1229. MXC_LIHE_VAVLE = 0;
  1230. }
  1231. }
  1232. else
  1233. {
  1234. if(MXC_GuoLianCheckMode)
  1235. {
  1236. if(MXC_GuoLian_IN)
  1237. {
  1238. MXC_cMotorStep = 0;
  1239. AxisEgmStop(X_AXIS);
  1240. MXC_LIHE_VAVLE = 0;
  1241. }
  1242. }
  1243. else
  1244. {
  1245. if(!MXC_GuoLian_IN)
  1246. {
  1247. MXC_cMotorStep = 0;
  1248. AxisEgmStop(X_AXIS);
  1249. MXC_LIHE_VAVLE = 0;
  1250. }
  1251. }
  1252. }
  1253. }
  1254. break;
  1255. */
  1256. //伺服定寸
  1257. case 20:
  1258. if(!X_DRV)MXC_cMotorStep = 0;
  1259. else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
  1260. break;
  1261. case 50:
  1262. if(dwZipCnt==0)
  1263. {
  1264. cSeBiaoOk = 0;
  1265. cSeBiaoEn = 1;
  1266. MXC_cMotorStep = 51;
  1267. }
  1268. else
  1269. {
  1270. if((dwRealPos + MXC_PARAM_SEBIAO_LOWSPEED_LENGTH) >= (zipper_length -MXC_PARAM_SEBIAO_DW_LENGTH))
  1271. AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  1272. if((dwRealPos + MXC_PARAM_SEBIAO_TQ_LENGTH) >= (zipper_length - MXC_PARAM_SEBIAO_DW_LENGTH))
  1273. {
  1274. cSeBiaoOk = 0;
  1275. cSeBiaoEn = 1;
  1276. MXC_cMotorStep = 51;
  1277. }
  1278. else if(dwRealPos > (zipper_length + MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  1279. }
  1280. break;
  1281. case 51:
  1282. if(dwZipCnt!=0)
  1283. {
  1284. if(dwRealPos >= (zipper_length - MXC_PARAM_SEBIAO_LOWSPEED_LENGTH)) AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
  1285. if(dwRealPos > (zipper_length + MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  1286. }
  1287. if(!X_DRV)
  1288. {
  1289. if(dwZipCnt!=0)
  1290. {
  1291. if(dwRealPos < (zipper_length - MXC_ERROR_LENGTH))MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  1292. }
  1293. MXC_cMotorStep = 0;
  1294. }
  1295. else if(dwTickCount >= MXC_cMotorDelay)MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
  1296. break;
  1297. /* case 100:
  1298. //算出间隔脉冲
  1299. zipper_length = MXC_DingDanJianGe_Length + MXC_PARAM_DAOKOU_LENGTH;
  1300. AxisMovePosAccDec(X_AXIS,MXC_PARAM_SET_SPEED/2,zipper_length,MXC_PARAM_START_SPEED/2,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
  1301. MXC_cMotorStep = 101;
  1302. break;
  1303. case 101:
  1304. if(!X_DRV)
  1305. {
  1306. MXC_cMotorStep = 0;
  1307. }
  1308. break;
  1309. case 200:
  1310. //先把拉链
  1311. zipper_length = MXC_SET_ZIPPER_LENGTH;
  1312. //把速度降下来
  1313. AxisMovePosAccDec(X_AXIS,MXC_PARAM_SET_SPEED/2,zipper_length,MXC_PARAM_START_SPEED/2,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
  1314. MXC_cMotorStep = 201;
  1315. break;
  1316. case 201:
  1317. if(!X_DRV)
  1318. {
  1319. MXC_cMotorStep = 0;
  1320. }
  1321. break; */
  1322. }
  1323. }
  1324. //下冲
  1325. void MXC_NiLongXiuCiJi_XiaC(void)
  1326. {
  1327. static unsigned char xia_zhi_flg = 0;
  1328. static unsigned long delay_gz_back;
  1329. static unsigned char gz_back_flg = 0;
  1330. if((MXC_XIA_ZHI_ENABLE == 2) && MXC_bRunning)
  1331. {
  1332. if((dwTickCount >= delay_gz_back) &&gz_back_flg)
  1333. {
  1334. MXC_GouZhen_VAVLE = 1;
  1335. gz_back_flg = 0;
  1336. MXC_cGouZhenTime = dwTickCount + 300;
  1337. }
  1338. }
  1339. switch(MXC_cXiaChongStep)
  1340. {
  1341. case 0:
  1342. return;
  1343. break;
  1344. case 1:
  1345. {
  1346. MXC_DingDanJianGe_State = 0;
  1347. if((MXC_XIA_ZHI_ENABLE == 2) && MXC_bRunning)
  1348. {
  1349. MXC_cXiaChongStep = 7;
  1350. delay_gz_back = dwTickCount + MXC_PARAM_DELAY_GOUZHEN_BACK;
  1351. gz_back_flg = 1;
  1352. xia_zhi_flg = 0;
  1353. MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_DELAY_XC;
  1354. }
  1355. else
  1356. {
  1357. gz_back_flg = 0;
  1358. MXC_cRightFenZhenStep = 1;
  1359. if(MXC_cDCPStep == 0)
  1360. MXC_cDCPStep = 1;
  1361. MXC_cLeftFenZhenStep = 0;
  1362. cRFengTimer = 0;
  1363. cLFengTimer = 0;
  1364. MXC_cXiaChongStep = 2;
  1365. }
  1366. }
  1367. break;
  1368. case 2:
  1369. if((MXC_cRightFenZhenStep==0) && (MXC_cLeftFenZhenStep==0))
  1370. {
  1371. if(MXC_XiaChongMotorMode)
  1372. MXC_XC_SongZhou = MXC_XC_SERVER_EN;
  1373. else
  1374. MXC_XC_ShaChe = MXC_SC_DISEN;
  1375. MXC_XC_SongZhou = MXC_XC_SERVER_DISEN; //刹车打开
  1376. if(MXC_bRunning)
  1377. {
  1378. MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_DELAY_XC;
  1379. }
  1380. MXC_cXiaChongStep = 3;
  1381. }
  1382. break;
  1383. case 3:
  1384. if(dwTickCount >= MXC_cXiaChongDelay)
  1385. {
  1386. MXC_cXiaChongStep = 4;
  1387. MXC_XiaChong_MOTOR = 1; //下冲电机
  1388. if(MXC_bRunning)
  1389. {
  1390. MXC_Output_XiaCi();//下止输出
  1391. xia_zhi_flg = 1;
  1392. }
  1393. MXC_cXiaChongDelay = dwTickCount + (unsigned long)ERRORTIME; //下冲最长时间
  1394. // if(MXC_XiaChongMotorMode == 1)
  1395. // {
  1396. // AxisMoveTwoPos(Y_AXIS,MXC_XiaChongSpeed,2000,MXC_XiaChongLowSpeed,9999999,0);
  1397. // }
  1398. }
  1399. break;
  1400. case 4: //碰到右大微动,延时停
  1401. if(MXC_XiaChong_IN_UP)
  1402. {
  1403. MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_XC_DELAY;
  1404. MXC_cXiaChongStep = 5;
  1405. MXC_LeftFenZhen_VAVLE = 0; //退左分针
  1406. MXC_RightFenZhen_VAVLE = 0; //退右分针
  1407. MXC_GouZhen_VAVLE = 1;
  1408. MXC_cGouZhenTime = dwTickCount + 300;
  1409. }
  1410. else if(dwTickCount >= MXC_cXiaChongDelay) //自动停机
  1411. {
  1412. MXC_cXiaChongStep = 0;
  1413. // MXC_ShaChe_Output();////刹车
  1414. MXC_XiaChong_MOTOR = 0;// //下冲电机
  1415. MXC_SetAlarmCode(MXC_XC_ALARM);
  1416. MXC_LeftFenZhen_VAVLE = 0; //退左分针
  1417. MXC_RightFenZhen_VAVLE = 0; //退右分针
  1418. // AxisEgmStop(Y_AXIS);
  1419. }
  1420. break;
  1421. case 5:
  1422. if(dwTickCount >= MXC_cXiaChongDelay)
  1423. {
  1424. // AxisEgmStop(Y_AXIS);
  1425. MXC_XiaChong_MOTOR = 0; //延时刹车
  1426. if(MXC_PARAM_SC_MODE)
  1427. {
  1428. MXC_cXiaChongStep = 0;
  1429. }
  1430. else
  1431. {
  1432. MXC_cXiaChongStep = 6;
  1433. }
  1434. // MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_SC_DELAY;
  1435. }
  1436. break;
  1437. case 6:
  1438. // if((dwTickCount >= MXC_cXiaChongDelay))
  1439. {
  1440. MXC_cXiaChongStep = 7;
  1441. MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_SC_DELAY;
  1442. // MXC_ShaChe_Output();
  1443. }
  1444. break;
  1445. case 7:
  1446. if((dwTickCount >= MXC_cXiaChongDelay)&& !MXC_XiaZhi_VAVLE)
  1447. {
  1448. MXC_cXiaChongStep = 0;
  1449. if(MXC_bRunning && !xia_zhi_flg)
  1450. {
  1451. MXC_Output_XiaCi();//下止输出
  1452. }
  1453. MXC_cXiaChongDelay = dwTickCount;
  1454. MXC_XC_SongZhou = MXC_XC_SERVER_EN;
  1455. }
  1456. break;
  1457. case 20: // 点动普通下冲动作
  1458. MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
  1459. MXC_cXiaChongDelay = dwTickCount + 50;
  1460. MXC_cXiaChongStep = 21;
  1461. break;
  1462. case 21:
  1463. if((dwTickCount >= MXC_cXiaChongDelay))
  1464. {
  1465. MXC_XiaChong_MOTOR = 1;
  1466. MXC_cXiaChongDelay = dwTickCount + 50;
  1467. MXC_cXiaChongStep = 22;
  1468. }
  1469. break;
  1470. case 22:
  1471. if((dwTickCount >= MXC_cXiaChongDelay))
  1472. {
  1473. MXC_XiaChong_MOTOR = 0;
  1474. MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
  1475. if(MXC_XiaChongMotorMode)
  1476. MXC_cXiaChongStep = 0;
  1477. else
  1478. {
  1479. MXC_cXiaChongDelay = dwTickCount + 150;
  1480. MXC_cXiaChongStep = 23;
  1481. }
  1482. }
  1483. break;
  1484. case 23:
  1485. if((dwTickCount >= MXC_cXiaChongDelay))
  1486. {
  1487. MXC_XC_SongZhou = MXC_XC_SERVER_EN;
  1488. MXC_cXiaChongStep = 0;
  1489. }
  1490. break;
  1491. case 40: // 点动电机下冲动作
  1492. MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
  1493. MXC_cXiaChongDelay = dwTickCount + 50;
  1494. MXC_cXiaChongStep = 41;
  1495. break;
  1496. case 41:
  1497. if(!Y_DRV)AxisMovePos(Y_AXIS,20,10);
  1498. MXC_cXiaChongStep = 42;
  1499. break;
  1500. case 42:
  1501. if(!Y_DRV)
  1502. {
  1503. MXC_cXiaChongStep = 0;
  1504. }
  1505. break;
  1506. }
  1507. }
  1508. //分针
  1509. void MXC_NiLongXiuCiJi_FenZhengProc(void)
  1510. {
  1511. if(MXC_FenZSelect==0)
  1512. {
  1513. MXC_cLeftFenZhenStep = 0;
  1514. MXC_cRightFenZhenStep = 0;
  1515. }
  1516. //右分针
  1517. switch(MXC_cRightFenZhenStep)
  1518. {
  1519. case 0:
  1520. break;
  1521. case 1:
  1522. MXC_cFenZhenRightDelay = MXC_PARAM_R_FZ_DELAY+dwTickCount;
  1523. MXC_cRightFenZhenStep = 2;
  1524. break;
  1525. case 2:
  1526. if(dwTickCount >= MXC_cFenZhenRightDelay)
  1527. {
  1528. MXC_cRightFenZhenStep = 3;
  1529. MXC_RightFenZhen_VAVLE = 1;//右分针电磁阀
  1530. MXC_cFenZhenRightDelay = dwTickCount + FenZhengErrorTime;
  1531. }
  1532. break;
  1533. case 3: //碰到右大微动,延时停
  1534. if(!MXC_RightFenZhen_Origin_IN) //右分针原点离开
  1535. {
  1536. MXC_cFenZhenRightDelay = dwTickCount + FenZhengErrorTime;
  1537. MXC_cRightFenZhenStep = 4;
  1538. }//右分针不下去
  1539. else if(dwTickCount >= MXC_cFenZhenRightDelay)
  1540. {
  1541. MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
  1542. MXC_cRightFenZhenStep = 0;
  1543. MXC_RightFenZhen_VAVLE = 0;
  1544. }
  1545. break;
  1546. case 4:
  1547. if(MXC_RighttFenZhen_IN) //插针到位
  1548. {
  1549. MXC_cRightFenZhenStep = 0;
  1550. MXC_cLeftFenZhenStep = 1; //左分针延时启动
  1551. }
  1552. else if(dwTickCount >= MXC_cFenZhenRightDelay)
  1553. {
  1554. MXC_RightFenZhen_VAVLE = 0;//右分针
  1555. cRFengTimer++;
  1556. //当右分针分不到位时,左分针也要重新分针
  1557. MXC_LeftFenZhen_VAVLE = 0;
  1558. MXC_cRightFenZhenStep = 0;
  1559. if(cRFengTimer < 4)
  1560. {
  1561. MXC_cRightFenZhenStep = 5;
  1562. MXC_cFenZhenRightDelay = dwTickCount + FenZhengErrorTime;
  1563. }
  1564. else
  1565. {
  1566. MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
  1567. MXC_cRightFenZhenStep = 0;
  1568. MXC_RightFenZhen_VAVLE = 0;
  1569. }
  1570. }
  1571. break;
  1572. case 5:
  1573. if(MXC_RightFenZhen_Origin_IN) //退到位
  1574. {
  1575. MXC_cRightFenZhenStep = 6;
  1576. }
  1577. else if(dwTickCount >= MXC_cFenZhenRightDelay)
  1578. {
  1579. MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
  1580. MXC_RightFenZhen_VAVLE = 0;
  1581. MXC_cRightFenZhenStep = 0;
  1582. }
  1583. break;
  1584. case 6:
  1585. {
  1586. MXC_cRightFenZhenStep = 1;
  1587. }
  1588. break;
  1589. }
  1590. //左分针
  1591. switch(MXC_cLeftFenZhenStep)
  1592. {
  1593. case 0:
  1594. break;
  1595. case 1:
  1596. MXC_cFenZhenLeftDelay = MXC_PARAM_L_FZ_DELAY+dwTickCount;
  1597. MXC_cLeftFenZhenStep = 2;
  1598. break;
  1599. case 2:
  1600. if(dwTickCount >= MXC_cFenZhenLeftDelay)
  1601. {
  1602. MXC_cLeftFenZhenStep = 3;
  1603. MXC_LeftFenZhen_VAVLE = 1; //左分针电磁阀
  1604. MXC_cFenZhenLeftDelay = dwTickCount + FenZhengErrorTime;
  1605. }
  1606. break;
  1607. case 3: //离开左分针原点
  1608. if(!MXC_LeftFenZhen_Origin_IN) //左分针原点离开
  1609. {
  1610. MXC_cFenZhenLeftDelay = dwTickCount + FenZhengErrorTime;
  1611. MXC_cLeftFenZhenStep = 4;
  1612. }//左分针不下去
  1613. else if(dwTickCount >= MXC_cFenZhenLeftDelay)
  1614. {
  1615. MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
  1616. MXC_cLeftFenZhenStep = 0;
  1617. MXC_LeftFenZhen_VAVLE = 0;
  1618. }
  1619. break;
  1620. case 4:
  1621. if(MXC_LeftFenZhen_IN) //插针到位
  1622. MXC_cLeftFenZhenStep = 0;
  1623. else if(dwTickCount >= MXC_cFenZhenLeftDelay)
  1624. {
  1625. MXC_LeftFenZhen_VAVLE = 0;//左分针
  1626. cLFengTimer++;
  1627. if(cLFengTimer < 6)
  1628. {
  1629. MXC_cLeftFenZhenStep = 5;
  1630. MXC_cFenZhenLeftDelay = dwTickCount + FenZhengErrorTime;
  1631. if((cLFengTimer%2) == 0)
  1632. {
  1633. MXC_RightFenZhen_VAVLE = 0;
  1634. MXC_cRightFenZhenStep = 0;
  1635. }
  1636. }
  1637. else
  1638. {
  1639. MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
  1640. MXC_cLeftFenZhenStep = 0;
  1641. MXC_LeftFenZhen_VAVLE = 0;
  1642. }
  1643. }
  1644. break;
  1645. case 5:
  1646. if(MXC_LeftFenZhen_Origin_IN) //退到位
  1647. {
  1648. MXC_cLeftFenZhenStep = 6;
  1649. }
  1650. else if(dwTickCount >= MXC_cFenZhenLeftDelay)
  1651. {
  1652. MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
  1653. MXC_cLeftFenZhenStep = 0;
  1654. MXC_LeftFenZhen_VAVLE = 0;
  1655. }
  1656. break;
  1657. case 6:
  1658. if((cLFengTimer%2) == 0) //左边插两次都插不到,就退右边再同时插
  1659. {
  1660. MXC_cRightFenZhenStep = 1;
  1661. cRFengTimer = 0;
  1662. MXC_cLeftFenZhenStep = 0;
  1663. }
  1664. else
  1665. {
  1666. MXC_cLeftFenZhenStep = 1;
  1667. }
  1668. break;
  1669. }
  1670. }
  1671. //勾针复位定位动作
  1672. void MXC_NiLongXiuCiJi_GouZhenProc(void)
  1673. {
  1674. static unsigned char kk;
  1675. static unsigned long last_set_length;
  1676. long ch;
  1677. //当前勾针位置为脉冲位置加偏移量
  1678. MXC_Gouzhencurrent_L = dwYRealPos;
  1679. //DISPLAY_DATA7 = dwYRealPos;
  1680. if(!MXC_bRunning) //在手动状态下才点动勾针
  1681. {
  1682. if((MXC_cXiaChongStep == 0) && (MXC_cGouZhenDWStep == 0))
  1683. {
  1684. //输入变化自动定位
  1685. if(last_set_length != MXC_SET_ZIPPER_LENGTH)
  1686. {
  1687. last_set_length=MXC_SET_ZIPPER_LENGTH;
  1688. if(MXC_USE_GZ_SERVO)
  1689. MXC_cGouZhenDWStep = 1;
  1690. //MXC_StartFirst=1;
  1691. kk=0;
  1692. }
  1693. //勾针定位
  1694. if(MXC_GouZhenlocation)
  1695. {
  1696. MXC_GouZhenlocation = 0;
  1697. MXC_cGouZhenDWStep = 1;
  1698. MXC_StartFirst=1;
  1699. kk = 0;
  1700. }
  1701. if(MXC_ShaChe)
  1702. {
  1703. MXC_ShaChe = 0;
  1704. if(!Y_DRV)
  1705. {
  1706. MXC_GouzhenShaChe = !MXC_GouzhenShaChe; //刹车取反
  1707. }
  1708. }
  1709. if(MXC_GouZhenforward && !MXC_GouZhenforward_IN && !Y_DRV) //勾针前移 限位开关不能输入
  1710. {
  1711. if(!MXC_GouzhenShaChe || !MXC_GouZhen_VAVLE)
  1712. MXC_cGouZhenMotorDelay = dwTickCount + 150;
  1713. MXC_GouzhenShaChe = 1; //刹车松开
  1714. //MXC_GouzhenMotor_DR = MXC_GZ_DIR_P;
  1715. MXC_GouZhen_VAVLE = 1;
  1716. MXC_cGouZhenTime = dwTickCount + 400;
  1717. kk = 0;
  1718. //先松开刹车延时动电机
  1719. if(dwTickCount >= MXC_cGouZhenMotorDelay)
  1720. {
  1721. if(!Y_DRV)
  1722. {
  1723. AxisContinueMoveAcc(Y_AXIS,MXC_GouzhenSpeed_Hand_SPEED,MXC_GZ_DIR_N,MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,0);
  1724. }
  1725. }
  1726. }
  1727. if(MXC_GouZhenforward_IN)
  1728. {
  1729. MXC_GouZhenforward = 0;
  1730. }
  1731. if(MXC_GouZhenback && !MXC_GouZhenback_IN && !Y_DRV) //勾针后移 限位开关不能输入
  1732. {
  1733. if(!MXC_GouzhenShaChe || !MXC_GouZhen_VAVLE)
  1734. MXC_cGouZhenMotorDelay = dwTickCount + 150;
  1735. MXC_GouzhenShaChe = 1; //刹车松开
  1736. //MXC_GouzhenMotor_DR = MXC_GZ_DIR_N;
  1737. MXC_GouZhen_VAVLE = 1;
  1738. MXC_cGouZhenTime = dwTickCount + 400;
  1739. kk = 0;
  1740. //先松开刹车延时动电机
  1741. if(dwTickCount >= MXC_cGouZhenMotorDelay)
  1742. {
  1743. if(!Y_DRV)
  1744. {
  1745. AxisContinueMoveAcc(Y_AXIS,MXC_GouzhenSpeed_Hand_SPEED,MXC_GZ_DIR_P,MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,0);
  1746. }
  1747. }
  1748. }
  1749. if(MXC_GouZhenback_IN || ((dwYRealPos >= GetData32bits(MXC_N_LIMIT_LENGTH_ADDR)) && !MXC_StartFirst))
  1750. {
  1751. MXC_GouZhenback = 0;
  1752. }
  1753. if((!MXC_GouZhenforward && !MXC_GouZhenback) && (kk == 0))
  1754. {
  1755. if(Y_DRV)
  1756. {
  1757. if(MXC_GouzhenShaChe)
  1758. {
  1759. kk = 1;
  1760. MXC_cGouZhenMotorDelay = dwTickCount + 450;
  1761. }
  1762. }
  1763. AxisEgmStop(Y_AXIS); //立即停
  1764. MXC_GouZhenback = 0;
  1765. MXC_GouZhenforward = 0;
  1766. }
  1767. //电机停止后延时刹车
  1768. if(kk && (dwTickCount >= MXC_cGouZhenMotorDelay))
  1769. {
  1770. kk = 0;
  1771. MXC_GouzhenShaChe = 0; //刹车
  1772. }
  1773. }
  1774. }
  1775. switch(MXC_cGouZhenDWStep)
  1776. {
  1777. case 1:
  1778. MXC_cGouZhenMotorDelay = dwTickCount + 160;
  1779. MXC_GouZhen_VAVLE = 1;
  1780. MXC_GouzhenShaChe = 1; //刹车松开
  1781. MXC_cGouZhenDWStep = 2;
  1782. break;
  1783. case 2: //先回前点
  1784. if(dwTickCount >= MXC_cGouZhenMotorDelay)
  1785. {
  1786. if(!MXC_GouZhenforward_IN)
  1787. {
  1788. if((!MXC_StartFirst))
  1789. {
  1790. offset_len = &MXC_SET_REVISE_ZIPPER_LENGTH;
  1791. ch = (MXC_SET_ZIPPER_LENGTH + MultLengthOffset(MXC_SET_ZIPPER_LENGTH)+(*offset_len) - MXC_GouzhenMin_Length); //算出脉冲
  1792. if(ch < 0)
  1793. {
  1794. MXC_SetAlarmCode(MXC_GOUZHEN_MIN_LENGTH_ALARM);
  1795. MXC_cGouZhenDWStep = 0;
  1796. }
  1797. else
  1798. {
  1799. ch = ch - MXC_Gouzhencurrent_L;
  1800. //DISPLAY_DATA1=ch;
  1801. //DISPLAY_DATA2=MXC_Gouzhencurrent_L;
  1802. // if(ch < 0)
  1803. // MXC_GouzhenMotor_DR = MXC_GZ_DIR_P;
  1804. // else
  1805. // MXC_GouzhenMotor_DR = MXC_GZ_DIR_N;
  1806. //
  1807. // SetDir(Y_AXIS,MXC_GouzhenMotor_DR);
  1808. AxisMovePos(Y_AXIS,MXC_GouzhenSpeed_Auto_SPEED,ch);
  1809. MXC_cGouZhenDWStep = 7;
  1810. }
  1811. }
  1812. else //等于0时就是第一次, 走手动速度
  1813. {
  1814. //MXC_GouzhenMotor_DR = MXC_GZ_DIR_P;
  1815. if(!Y_DRV)AxisContinueMoveAcc(Y_AXIS,MXC_GouzhenSpeed_Hand_SPEED,MXC_GZ_DIR_N,MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,0);
  1816. MXC_cGouZhenDWStep = 3;
  1817. }
  1818. }
  1819. else //已在原点直接后移
  1820. {
  1821. MXC_cGouZhenDWStep = 4;
  1822. MXC_GouzhenMotor_DR = MXC_GZ_DIR_N; //变为后移方向
  1823. }
  1824. }
  1825. break;
  1826. case 3:
  1827. if(MXC_GouZhenforward_IN) //感应前点 延时后移
  1828. {
  1829. MXC_cGouZhenDWStep = 4;
  1830. AxisEgmStop(Y_AXIS);
  1831. MXC_cGouZhenMotorDelay = dwTickCount + 50;
  1832. }
  1833. break;
  1834. case 4:
  1835. if(dwTickCount >= MXC_cGouZhenMotorDelay)
  1836. {
  1837. //MXC_GouzhenMotor_DR = MXC_GZ_DIR_N; //变为后移方向
  1838. ch = 5;
  1839. AxisContinueMoveAcc(Y_AXIS,ch,MXC_GZ_DIR_P,MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED,0); //匀速离开零点位置
  1840. MXC_cGouZhenDWStep = 5;
  1841. }
  1842. break;
  1843. case 5:
  1844. if(!MXC_GouZhenforward_IN)
  1845. {
  1846. MXC_cGouZhenDWStep = 6;
  1847. AxisDecStop(Y_AXIS);
  1848. }
  1849. break;
  1850. case 6:
  1851. if(!Y_DRV)
  1852. {
  1853. SetPos(Y_AXIS, 0); //回到原点位置清零
  1854. //MXC_GouzhenMotor_DR = MXC_GZ_DIR_N; //变为后移方向
  1855. offset_len = &MXC_SET_REVISE_ZIPPER_LENGTH;
  1856. if((MXC_SET_ZIPPER_LENGTH+(*offset_len)+ MultLengthOffset(MXC_SET_ZIPPER_LENGTH)) >= MXC_GouzhenMin_Length)
  1857. {
  1858. ch = (MXC_SET_ZIPPER_LENGTH + (*offset_len) + MultLengthOffset(MXC_SET_ZIPPER_LENGTH) - MXC_GouzhenMin_Length); //算出脉冲
  1859. //SetDir(Y_AXIS,MXC_GouzhenMotor_DR);
  1860. AxisMovePos(Y_AXIS,MXC_GouzhenSpeed_Auto_SPEED,ch);
  1861. MXC_cGouZhenDWStep = 7;
  1862. }
  1863. else
  1864. {
  1865. MXC_SetAlarmCode(MXC_GOUZHEN_MIN_LENGTH_ALARM);
  1866. MXC_cGouZhenDWStep = 0;
  1867. }
  1868. }
  1869. break;
  1870. case 7:
  1871. if(!Y_DRV)
  1872. {
  1873. MXC_cGouZhenDWStep = 8;
  1874. MXC_cGouZhenMotorDelay = dwTickCount + 420;
  1875. }
  1876. else if((MXC_GouzhenMotor_DR == MXC_GZ_DIR_N) && (MXC_GouZhenback_IN || ((dwYRealPos >= GetData32bits(MXC_N_LIMIT_LENGTH_ADDR)) && !MXC_StartFirst)))
  1877. {
  1878. AxisEgmStop(Y_AXIS); //立即停
  1879. MXC_cGouZhenDWStep = 8;
  1880. MXC_SetAlarmCode(MXC_GOUZHEN_MORE_ALARM);
  1881. MXC_cGouZhenMotorDelay = dwTickCount + 420;
  1882. }
  1883. break;
  1884. case 8:
  1885. if(dwTickCount>= MXC_cGouZhenMotorDelay)
  1886. {
  1887. MXC_GouzhenShaChe = 0; //刹车
  1888. MXC_cGouZhenDWStep = 0;
  1889. MXC_StartFirst = 0;
  1890. }
  1891. break;
  1892. }
  1893. }
  1894. #endif