TYJinShuDinCun.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. #include "global.h"
  2. #if TONG_YONG_MACHINE
  3. void JSDC_CheckStart(void);
  4. void JSDC_Motor(void);
  5. void JSDC_XiaChong(void);
  6. void JSDC_FenZhen(void);
  7. void JSDC_ChuiQi(void);
  8. void JSDC_ManualAction(void);
  9. void JSDC_AutoAction(void);
  10. unsigned char JSDC_CheckPos(void);
  11. unsigned char JSDC_cLFengTimer,JSDC_cRFengTimer;
  12. unsigned long JSDC_cZipperLength[2];
  13. unsigned char JSDC_cCheckLengthOk=0;
  14. unsigned char JSDC_STOP_IN_FLAG,JSDC_STOP_IN_FLAG_OLD,JSDC_STOP_FILTER;
  15. unsigned char JSDC_SingOneFlag = 0,JSDC_FirstFlg = 0;
  16. unsigned char JSDC_cAlarmStopFlg = 0;
  17. long JSDC_dwEncPos = 0;
  18. long JSDC_SaveLength = 0;
  19. //故障报警
  20. void JSDC_SetAlarmCode(unsigned alarm_code)
  21. {
  22. SetAlarmCode(JSDC_ALARM_ADDR,alarm_code);
  23. JSDC_bAlarmStop = 1;
  24. JSDC_cAlarmStopFlg = 1;
  25. }
  26. //高速输入X20外部色标信号中断
  27. void JSDC_ExtiActionX20(void)
  28. {
  29. }
  30. void JSDC_InitAction(void)
  31. {
  32. float length_buff,pulse_buff;
  33. CalFreqTab_X_Free(25);
  34. length_buff = JSDC_PARAM_DAILUN_LENGTH;
  35. pulse_buff = JSDC_PARAM_CYCLE_PULSE;
  36. XGearRatio = pulse_buff/length_buff;
  37. length_buff = JSDC_BM_LENGTH;
  38. pulse_buff = 1000;
  39. BMGearRatio = pulse_buff/length_buff;
  40. JSDC_SZ_OUT = JSDC_SERVER_DISEN;
  41. JSDC_STOP_IN_FLAG = STOP_IN;
  42. JSDC_STOP_IN_FLAG_OLD = JSDC_STOP_IN_FLAG;
  43. JSDC_SaveLength = 0;
  44. }
  45. void JSDC_Action(void)
  46. {
  47. JSDC_CheckStart(); //启动
  48. JSDC_FenZhen(); //左分针
  49. JSDC_XiaChong(); //下冲
  50. JSDC_ChuiQi();
  51. JSDC_Motor(); //拖带控制
  52. JSDC_ManualAction();
  53. JSDC_AutoAction();
  54. }
  55. void JSDC_ManualAction(void)
  56. {
  57. long i;
  58. //清总产量
  59. if(JSDC_bClear) //清总产量
  60. {
  61. JSDC_bClear = 0;
  62. ClrcToTal(JSDC_TOTAL_ADDR);
  63. JSDC_bSaveWorkData = 1;
  64. }
  65. //加10
  66. if(JSDC_bAddLength)
  67. {
  68. JSDC_bAddLength = 0;
  69. i = JSDC_SET_ZIPPER_ALL_LENGTH;
  70. i += 10;
  71. SetData32bits(20,i);
  72. JSDC_SaveLength = 0;
  73. }
  74. //减10
  75. if(JSDC_bDecLength)
  76. {
  77. JSDC_bDecLength = 0;
  78. i = JSDC_SET_ZIPPER_ALL_LENGTH;
  79. i -= 10;
  80. SetData32bits(20,i);
  81. JSDC_SaveLength = 0;
  82. }
  83. //工作方式选择(数控定寸和勾针定寸) 
  84. if(JSDC_bSetDCMode)
  85. {
  86. JSDC_bSetDCMode = 0;
  87. JSDC_SaveLength = 0;
  88. if(JSDC_DC_MODE != 0)
  89. {
  90. JSDC_GouZhen_VAVLE = 1;
  91. JSDC_cGouZhenTime = 300;
  92. }
  93. if(JSDC_DC_MODE == JSDC_DC_SF_MODE)
  94. {
  95. MV_Set_Command_Pos_CPU(X_AXIS,0);
  96. }
  97. }
  98. if(JSDC_bSetLengthCM)
  99. {
  100. JSDC_bSetLengthCM = 0;
  101. SetData32bits(18,CalInch(JSDC_SET_ZIPPER_LENGTH));
  102. JSDC_PARAM_KONG_WEI_LENGTH_INCH = CalInch(JSDC_PARAM_KONG_WEI_LENGTH);
  103. SetData32bits(20, JSDC_SET_ZIPPER_LENGTH + JSDC_PARAM_KONG_WEI_LENGTH);
  104. SetData32bits(22,CalInch(JSDC_SET_ZIPPER_ALL_LENGTH));
  105. JSDC_SaveLength = 0;
  106. JSDC_bClear = 1;
  107. }
  108. if(JSDC_bSetLengthINCH)
  109. {
  110. JSDC_bSetLengthINCH = 0;
  111. SetData32bits(15,CalLengthCM(JSDC_SET_ZIPPER_LENGTH_INCH));
  112. JSDC_PARAM_KONG_WEI_LENGTH = CalInch(JSDC_PARAM_KONG_WEI_LENGTH_INCH);
  113. SetData32bits(20, JSDC_SET_ZIPPER_LENGTH + JSDC_PARAM_KONG_WEI_LENGTH);
  114. SetData32bits(22,CalInch(JSDC_SET_ZIPPER_ALL_LENGTH));
  115. JSDC_SaveLength = 0;
  116. JSDC_bClear = 1;
  117. }
  118. if((JSDC_bRunning) == 0) ////手动
  119. {
  120. if(JSDC_bXiaChong)
  121. {
  122. JSDC_bXiaChong = 0;
  123. JSDC_SaveLength = 0;
  124. if(JSDC_cXiaChongStep == 0)JSDC_cXiaChongStep = 1;
  125. }
  126. if(JSDC_bLeftFenZhen)
  127. {
  128. JSDC_bLeftFenZhen = 0;
  129. if(JSDC_cXiaChongStep == 0) JSDC_LeftFenZhen_VAVLE = ~JSDC_LeftFenZhen_VAVLE;
  130. }
  131. if(JSDC_bRightFenZhen)
  132. {
  133. JSDC_bRightFenZhen = 0;
  134. if(JSDC_cXiaChongStep == 0) JSDC_RightFenZhen_VAVLE = ~JSDC_RightFenZhen_VAVLE;
  135. }
  136. //点动下冲
  137. if((JSDC_bDotXiaChong))
  138. {
  139. JSDC_bDotXiaChong = 0;
  140. if(JSDC_cXiaChongStep == 0)JSDC_cXiaChongStep = 20;
  141. }
  142. if(JSDC_bGouZhen)
  143. {
  144. JSDC_bGouZhen = 0;
  145. JSDC_cGouZhenTime = dwTickCount + 300;
  146. JSDC_GouZhen_VAVLE = ~JSDC_GouZhen_VAVLE;
  147. }
  148. if(JSDC_DC_MODE != 0) //伺服定寸
  149. {
  150. JSDC_GouZhen_VAVLE = 1;
  151. }
  152. else
  153. {
  154. if(dwTickCount >= JSDC_cGouZhenTime) JSDC_GouZhen_VAVLE = 0;
  155. }
  156. if(JSDC_bTestMotor)
  157. {
  158. if(!X_DRV && JSDC_CheckPos())
  159. {
  160. MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P, 10,1,5,5);
  161. if(JSDC_cSDStep == 0)JSDC_cSDStep = 1;
  162. }
  163. }
  164. else
  165. {
  166. if(X_DRV)
  167. {
  168. AxisDecStop(X_AXIS);
  169. JSDC_cSDStep = 0;
  170. }
  171. }
  172. if(JSDC_bYD)
  173. {
  174. JSDC_bYD = 0;
  175. JSDC_YD_VAVLE = ~JSDC_YD_VAVLE;
  176. }
  177. if(JSDC_bChuiQi)
  178. {
  179. JSDC_bChuiQi = 0;
  180. JSDC_ChuiQi_VAVLE = 1;
  181. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  182. }
  183. }
  184. }
  185. void JSDC_AutoAction(void)
  186. {
  187. DISPLAY_DATA0 = JSDC_cAutoStep;
  188. // DISPLAY_DATA1 = JSDC_cZipperLength[0];//JSDC_cMotorStep;
  189. // DISPLAY_DATA2 = JSDC_cZipperLength[1];
  190. // DISPLAY_DATA3 = JSDC_cRightFenZhenStep;
  191. DISPLAY_DATA4 = JSDC_cCheckLengthOk;//JSDC_cXiaChongStep;
  192. DISPLAY_DATA5 = dwRealPos;
  193. DISPLAY_DATA6 = JSDC_dwEncPos;
  194. if(JSDC_bRunning)
  195. {
  196. switch(JSDC_cAutoStep)
  197. {
  198. case 0:
  199. break;
  200. case 1:
  201. if(dwTickCount >= JSDC_cAutoDelay)
  202. {
  203. JSDC_cAutoStep = 2;
  204. }
  205. break;
  206. case 2:
  207. //左右分针要退到位,过链到位要离开
  208. if(dwTickCount >= JSDC_cAutoDelay)
  209. {
  210. JSDC_cAutoStep = 3;
  211. switch(JSDC_DC_MODE)
  212. {
  213. case JSDC_DC_SF_MODE:JSDC_cMotorStep = 20; break; //伺服
  214. case JSDC_DC_BMQ_MODE:JSDC_cMotorStep = 60; break; //编码器
  215. default:JSDC_cMotorStep = 1; //启动拖带 ;//勾针
  216. }
  217. }
  218. break;
  219. case 3:
  220. //拖带已经完成
  221. if(JSDC_cMotorStep == 0)
  222. {
  223. {
  224. JSDC_cAutoStep = 4;
  225. }
  226. }
  227. break;
  228. case 4:
  229. JSDC_cAutoStep = 5;
  230. break;
  231. case 5:
  232. if(JSDC_cXiaChongStep == 0)
  233. {
  234. JSDC_cXiaChongStep = 1; //下冲电机启动
  235. JSDC_cAutoStep = 6;
  236. }
  237. break;
  238. case 6: //下冲已完成
  239. if((JSDC_cXiaChongStep == 0) || (JSDC_cXiaChongStep == 5))
  240. {
  241. if(JSDC_DC_MODE == JSDC_DC_BMQ_MODE)
  242. {
  243. JSDC_SaveLength += JSDC_PARAM_DAOKOU_LENGTH;
  244. if(JSDC_SaveLength >= JSDC_PARAM_KONG_WEI_LENGTH)
  245. {
  246. dwZipCnt++;
  247. JSDC_SaveLength = 0;
  248. SetEncodePos(0);
  249. AddToTal(JSDC_TOTAL_ADDR); //计数增加和保存
  250. CalProSP(JSDC_PROSPEED_ADDR);
  251. JSDC_cAutoStep = 7;
  252. }
  253. else
  254. {
  255. if((JSDC_PARAM_KONG_WEI_LENGTH - JSDC_SaveLength) >= JSDC_PARAM_DAOKOU_LENGTH)
  256. {
  257. JSDC_cAutoStep = 2;
  258. }
  259. else
  260. {
  261. JSDC_SaveLength = JSDC_PARAM_KONG_WEI_LENGTH - JSDC_PARAM_DAOKOU_LENGTH;
  262. JSDC_cAutoStep = 2;
  263. }
  264. }
  265. }
  266. else
  267. {
  268. dwZipCnt++;
  269. JSDC_SaveLength = 0;
  270. AddToTal(JSDC_TOTAL_ADDR); //计数增加和保存
  271. CalProSP(JSDC_PROSPEED_ADDR);
  272. JSDC_cAutoStep = 7;
  273. }
  274. }
  275. break;
  276. case 7:
  277. if(!JSDC_GouZhen_IN)
  278. {
  279. if(GetTotal(JSDC_TOTAL_ADDR) >= JSDC_SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
  280. JSDC_cAutoStep = 8;
  281. }
  282. break;
  283. case 8:
  284. JSDC_cAutoDelay = dwTickCount + JSDC_PARAM_MOTOR_DELAY;
  285. JSDC_cAutoStep = 1;
  286. if(JSDC_SingOneFlag)
  287. {
  288. dwZipCnt = 0;
  289. JSDC_SingOneFlag = 0;
  290. JSDC_cAutoStep = 0;
  291. JSDC_bRunning = 0;
  292. }
  293. break;
  294. }
  295. }
  296. }
  297. // 检测是否踏了脚踏开关
  298. void JSDC_CheckStart(void)
  299. {
  300. // 停止键 不能在工作,手动,停止过程中
  301. if((JSDC_bRunning == 0) && (START_IN_UP || JSDC_bStart || JSDC_bNext))
  302. {
  303. if(GetTotal(JSDC_TOTAL_ADDR) >= JSDC_SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
  304. else if((JSDC_PARAM_SEBIAO_DW_LENGTH > JSDC_SET_ZIPPER_LENGTH) && (JSDC_DC_MODE==2))JSDC_SetAlarmCode(JSDC_SEBIAO_ZIPPER_LENGTH_ALARM);
  305. else if(JSDC_KaDai_IN)JSDC_SetAlarmCode(JSDC_KA_DAI_ALARM);
  306. else
  307. {
  308. if(JSDC_bNext)
  309. {
  310. JSDC_SingOneFlag = 1;
  311. JSDC_bNext = 0;
  312. }
  313. JSDC_bRunning = 1;
  314. JSDC_cAutoStep = 1;
  315. if(JSDC_cSDStep == 0)JSDC_cSDStep = 1;
  316. JSDC_cGouZhenTime = 1;
  317. JSDC_cCheckLengthOk = 0;
  318. JSDC_cZipperLength[0] = 0;
  319. JSDC_cZipperLength[1] = 0;
  320. dwZipCnt = 0;
  321. JSDC_cAutoDelay = dwTickCount;
  322. JSDC_cMotorDelay = dwTickCount;
  323. JSDC_cXiaChongDelay = dwTickCount;
  324. }
  325. JSDC_bStart = 0;
  326. }
  327. //卡带感应
  328. if(JSDC_KaDai_IN && (dwTickCount >= JSDC_cKaDaiDelay))
  329. {
  330. JSDC_SetAlarmCode(JSDC_KA_DAI_ALARM);
  331. JSDC_cKaDaiDelay = dwTickCount + 2200;
  332. }
  333. else
  334. {
  335. if(GetAlarmCode(JSDC_ALARM_ADDR) == JSDC_KA_DAI_ALARM)SetAlarmCode(JSDC_ALARM_ADDR,0);
  336. }
  337. if(JSDC_KaDai_IN_UP)
  338. {
  339. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  340. }
  341. //停止
  342. JSDC_STOP_IN_FLAG_OLD = JSDC_STOP_IN_FLAG;
  343. if(STOP_IN)
  344. {
  345. if(JSDC_STOP_FILTER < 50)
  346. {
  347. JSDC_STOP_FILTER++;
  348. }
  349. else
  350. JSDC_STOP_IN_FLAG = 1;
  351. }
  352. else if(JSDC_STOP_FILTER > 25)
  353. {
  354. JSDC_STOP_FILTER--;
  355. }
  356. else
  357. JSDC_STOP_IN_FLAG = 0;
  358. if(JSDC_bStop)
  359. {
  360. JSDC_bStop = 0;
  361. if(JSDC_bRunning)JSDC_SingOneFlag = 1;
  362. }
  363. if(((JSDC_STOP_IN_FLAG && !JSDC_STOP_IN_FLAG_OLD)))
  364. {
  365. JSDC_bStop = 0;
  366. if(JSDC_bRunning)
  367. {
  368. if(JSDC_cXiaChongStep==0)
  369. {
  370. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  371. // if(!JSDC_XiaChong_MOTOR)JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
  372. }
  373. JSDC_bRunning = 0;
  374. JSDC_cAutoStep = 0;
  375. JSDC_cMotorStep = 0;
  376. JSDC_cSDStep = 0;
  377. JSDC_cSDStep = 0;
  378. AxisDecStop(X_AXIS);
  379. JSDC_cJiaoDaoStep = 0;
  380. JSDC_SingOneFlag = 0;
  381. }
  382. else
  383. {
  384. JSDC_bRunning = 0;
  385. JSDC_cAutoStep = 0;
  386. JSDC_cMotorStep = 0;
  387. JSDC_cXiaChongStep = 0;
  388. JSDC_cLeftFenZhenStep = 0;
  389. JSDC_cJiaoDaoStep = 0;
  390. JSDC_cSDStep = 0;
  391. JSDC_LeftFenZhen_VAVLE = 0;
  392. JSDC_SingOneFlag = 0;
  393. if((JSDC_cChuiQiStep == 0) &&(JSDC_cXiaChongStep==0))JSDC_cChuiQiStep = 1;
  394. AxisDecStop(X_AXIS);
  395. SetAlarmCode(JSDC_ALARM_ADDR,JSDC_NO_ALARM);
  396. }
  397. }
  398. if(JSDC_bAlarmStop)
  399. {
  400. JSDC_bAlarmStop = 0;
  401. JSDC_bRunning = 0;
  402. JSDC_cAutoStep = 0;
  403. JSDC_cMotorStep = 0;
  404. JSDC_cLeftFenZhenStep = 0;
  405. JSDC_LeftFenZhen_VAVLE = 0;
  406. JSDC_SingOneFlag = 0;
  407. JSDC_cSDStep = 0;
  408. AxisDecStop(X_AXIS);
  409. }
  410. }
  411. void JSDC_ChuiQi(void)
  412. {
  413. //吹气
  414. if(JSDC_XiaChong_IN_UP)
  415. {
  416. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  417. }
  418. switch(JSDC_cChuiQiStep)
  419. {
  420. case 1:
  421. JSDC_cChuiQiStep = 2;
  422. if(JSDC_bRunning)JSDC_cChuiQiDelay = dwTickCount+JSDC_PARAM_DELAY_CHUIQI_TIME;
  423. break;
  424. case 2:
  425. if(dwTickCount >= JSDC_cChuiQiDelay)
  426. {
  427. JSDC_cChuiQiDelay = dwTickCount + JSDC_PARAM_CHUIQI_TIME;
  428. JSDC_ChuiQi_VAVLE = 1;//
  429. JSDC_cChuiQiStep = 3;
  430. }
  431. break;
  432. case 3:
  433. if(dwTickCount >= JSDC_cChuiQiDelay)
  434. {
  435. JSDC_ChuiQi_VAVLE = 0;//
  436. JSDC_cChuiQiStep = 0;
  437. }
  438. break;
  439. }
  440. }
  441. unsigned char JSDC_ComPareLength(void)
  442. {
  443. if((JSDC_cZipperLength[0] != 0) && (JSDC_cZipperLength[1] != 0))
  444. {
  445. if(JSDC_cZipperLength[0] > JSDC_cZipperLength[1])
  446. {
  447. if((JSDC_cZipperLength[0] - JSDC_cZipperLength[1]) > 200)
  448. {
  449. return 0;
  450. }
  451. else
  452. return 1;
  453. }
  454. else
  455. {
  456. if((JSDC_cZipperLength[1] - JSDC_cZipperLength[0]) > 200)
  457. {
  458. return 0;
  459. }
  460. else
  461. return 1;
  462. }
  463. }
  464. else
  465. return 0;
  466. }
  467. unsigned char JSDC_CheckPos(void)
  468. {
  469. unsigned long zipper_length;
  470. if(JSDC_DC_MODE == JSDC_DC_GZ_MODE)
  471. {
  472. if(JSDC_GouZhen_IN)
  473. return 0;
  474. else
  475. return 1;
  476. }
  477. else
  478. {
  479. zipper_length = JSDC_SET_ZIPPER_ALL_LENGTH-JSDC_PARAM_KONG_WEI_LENGTH+JSDC_PARAM_DAOKOU_LENGTH;
  480. if(JSDC_dwEncPos >= zipper_length)return 0;
  481. else
  482. return 1;
  483. }
  484. }
  485. void JSDC_Motor(void)
  486. {
  487. static long save_buff,zipper_length_buff;
  488. static unsigned long zipper_length;
  489. dwRealPos = GetPos(X_AXIS);
  490. JSDC_dwEncPos = GetEncodePos();
  491. DISPLAY_DATA1 = dwRealPos - save_buff;
  492. DISPLAY_DATA2 = (zipper_length - JSDC_PARAM_LOWSPEED_LENGTH);
  493. if(JSDC_DC_MODE == JSDC_DC_GZ_MODE)
  494. SetData32bits(24,0);
  495. else
  496. SetData32bits(24,JSDC_dwEncPos);
  497. if(!JSDC_bRunning)
  498. {
  499. if(JSDC_CheckPos() == 0)AxisEgmStop(X_AXIS);
  500. }
  501. switch(JSDC_cMotorStep)
  502. {
  503. case 0:
  504. break;
  505. case 1:
  506. if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
  507. {
  508. JSDC_SZ_OUT = JSDC_SERVER_EN;
  509. JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
  510. }
  511. JSDC_cMotorStep = 2;
  512. break;
  513. case 2://勾针模式
  514. if(dwTickCount >= JSDC_cMotorDelay)
  515. {
  516. save_buff = dwRealPos;
  517. if(JSDC_cCheckLengthOk)
  518. {
  519. MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_SET_SPEED,1,5,1);
  520. }
  521. else
  522. {
  523. if(JSDC_cCheckLengthOk == 0)
  524. {
  525. JSDC_cZipperLength[0] = JSDC_cZipperLength[1];
  526. JSDC_cZipperLength[1] = dwRealPos - zipper_length_buff;
  527. zipper_length_buff = dwRealPos;
  528. if(JSDC_ComPareLength())
  529. {
  530. JSDC_cCheckLengthOk = 1;
  531. }
  532. }
  533. if(JSDC_cCheckLengthOk)zipper_length = JSDC_cZipperLength[1];
  534. MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_FIRST_SPEED,1,5,1);
  535. }
  536. JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
  537. JSDC_cGouZhenTime = dwTickCount + 300;
  538. JSDC_cMotorStep = 3;
  539. }
  540. break;
  541. case 3:
  542. if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
  543. if(JSDC_cCheckLengthOk)
  544. {
  545. if(((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_GZ_LENGTH))&&JSDC_PARAM_GZ_RESET_MODE)JSDC_GouZhen_VAVLE = 0;
  546. if((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_LOWSPEED_LENGTH))
  547. {
  548. AxisChangeSpeed(X_AXIS,JSDC_PARAM_LOW_SPEED);
  549. JSDC_cMotorStep = 4;
  550. }
  551. }
  552. else
  553. {
  554. if(JSDC_GouZhen_IN)
  555. {
  556. JSDC_GouZhen_VAVLE = 0;
  557. JSDC_cMotorStep = 5;
  558. AxisEgmStop(X_AXIS);
  559. }
  560. else
  561. {
  562. if(dwTickCount >= JSDC_cGouZhenTime)JSDC_GouZhen_VAVLE = 0;
  563. JSDC_cMotorStep = 4;
  564. }
  565. }
  566. if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  567. break;
  568. case 4:
  569. if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
  570. if(((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_GZ_LENGTH))&&JSDC_PARAM_GZ_RESET_MODE &&JSDC_cCheckLengthOk)JSDC_GouZhen_VAVLE = 0;
  571. if(JSDC_GouZhen_IN)
  572. {
  573. JSDC_GouZhen_VAVLE = 0;
  574. JSDC_cMotorStep = 5;
  575. AxisEgmStop(X_AXIS);
  576. }
  577. if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  578. break;
  579. case 5:
  580. if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
  581. if(!X_DRV)
  582. {
  583. JSDC_cMotorStep = 0;
  584. JSDC_cMotorDelay = dwTickCount;
  585. }
  586. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  587. break;
  588. case 20:
  589. if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
  590. {
  591. JSDC_SZ_OUT = JSDC_SERVER_EN;
  592. JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
  593. }
  594. JSDC_cMotorStep = 21;
  595. break;
  596. case 21:
  597. if(dwTickCount >= JSDC_cMotorDelay) //电机定寸模式
  598. {
  599. if(JSDC_cAlarmStopFlg)
  600. {
  601. zipper_length = JSDC_SET_ZIPPER_ALL_LENGTH-JSDC_PARAM_KONG_WEI_LENGTH+JSDC_PARAM_DAOKOU_LENGTH;
  602. JSDC_cAlarmStopFlg = 0;
  603. }
  604. else
  605. {
  606. zipper_length = JSDC_SET_ZIPPER_ALL_LENGTH-JSDC_PARAM_KONG_WEI_LENGTH+JSDC_PARAM_DAOKOU_LENGTH;
  607. if((0 - dwRealPos) > zipper_length)
  608. zipper_length = JSDC_SET_ZIPPER_ALL_LENGTH-JSDC_PARAM_KONG_WEI_LENGTH+JSDC_PARAM_DAOKOU_LENGTH;
  609. else
  610. zipper_length = JSDC_SET_ZIPPER_ALL_LENGTH-JSDC_PARAM_KONG_WEI_LENGTH+JSDC_PARAM_DAOKOU_LENGTH - (0 - dwRealPos);
  611. }
  612. AxisMovePosAccDec(X_AXIS,JSDC_PARAM_SET_SPEED,zipper_length,1,5,1);
  613. JSDC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
  614. JSDC_cMotorStep = 22;
  615. JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
  616. }
  617. break;
  618. case 22:
  619. if(!X_DRV)
  620. {
  621. MV_Set_Command_Pos_CPU(X_AXIS,0);
  622. JSDC_cMotorStep = 0;
  623. JSDC_cMotorDelay = dwTickCount;
  624. }
  625. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  626. break;
  627. case 60:
  628. if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
  629. {
  630. JSDC_SZ_OUT = JSDC_SERVER_EN;
  631. JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
  632. }
  633. JSDC_cMotorStep = 61;
  634. break;
  635. case 61:
  636. if(dwTickCount >= JSDC_cMotorDelay)
  637. {
  638. save_buff = JSDC_dwEncPos;
  639. zipper_length = JSDC_SET_ZIPPER_ALL_LENGTH-JSDC_PARAM_KONG_WEI_LENGTH+JSDC_PARAM_DAOKOU_LENGTH + JSDC_SaveLength;
  640. MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_SET_SPEED,1,5,1);
  641. JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
  642. JSDC_cMotorStep = 62;
  643. }
  644. break;
  645. case 62:
  646. if((JSDC_dwEncPos) >= (zipper_length - JSDC_PARAM_LOWSPEED_LENGTH))
  647. {
  648. AxisChangeSpeed(X_AXIS,JSDC_PARAM_LOW_SPEED);
  649. JSDC_cMotorStep = 63;
  650. }
  651. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  652. break;
  653. case 63:
  654. if((JSDC_dwEncPos) >= zipper_length)
  655. {
  656. JSDC_cMotorStep = 64;
  657. AxisEgmStop(X_AXIS);
  658. }
  659. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  660. break;
  661. case 64:
  662. if(!X_DRV)
  663. {
  664. JSDC_cMotorStep = 0;
  665. JSDC_cMotorDelay = dwTickCount;
  666. }
  667. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  668. break;
  669. }
  670. }
  671. //下冲
  672. void JSDC_XiaChong(void)
  673. {
  674. switch(JSDC_cXiaChongStep)
  675. {
  676. case 0:
  677. return;
  678. break;
  679. case 1:
  680. JSDC_cXiaChongStep = 2;
  681. break;
  682. case 2:
  683. JSDC_XC_ShaChe = JSDC_SC_DISEN;
  684. if(JSDC_bRunning)JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_DELAY_XC;
  685. JSDC_cXiaChongStep = 3;
  686. break;
  687. case 3:
  688. if(dwTickCount >= JSDC_cXiaChongDelay)
  689. {
  690. JSDC_cLeftFenZhenStep = 1;
  691. JSDC_cXiaChongStep = 4;
  692. JSDC_XiaChong_MOTOR = 1; //下冲电机
  693. if(!JSDC_bRunning)SetEncodePos(0);
  694. JSDC_cXiaChongDelay = dwTickCount + (unsigned long)JSDC_ERRORTIME; //下冲最长时间
  695. if(JSDC_XiaChongMotorMode == 1)
  696. {
  697. AxisMoveTwoPos(Y_AXIS,JSDC_XiaChongSpeed,2000,JSDC_XiaChongLowSpeed,9999999,0);
  698. }
  699. }
  700. break;
  701. case 4: //碰到右大微动,延时停
  702. if(JSDC_XiaChong_IN_UP)
  703. {
  704. JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_XC_DELAY;
  705. JSDC_cXiaChongStep = 5;
  706. JSDC_LeftFenZhen_VAVLE = 0; //退左分针
  707. JSDC_RightFenZhen_VAVLE = 0; //退左分针
  708. if(JSDC_bRunning)
  709. {
  710. MXC_GouZhen_VAVLE = 1;
  711. MXC_cGouZhenTime = dwTickCount + 300;
  712. }
  713. }
  714. else if(dwTickCount >= JSDC_cXiaChongDelay) //自动停机
  715. {
  716. JSDC_cXiaChongStep = 0;
  717. JSDC_XiaChong_MOTOR = 0;// //下冲电机
  718. JSDC_SetAlarmCode(JSDC_XC_ALARM);
  719. }
  720. break;
  721. case 5:
  722. if(dwTickCount >= JSDC_cXiaChongDelay)
  723. {
  724. AxisEgmStop(Y_AXIS);
  725. JSDC_XiaChong_MOTOR = 0; //延时刹车
  726. if(JSDC_PARAM_SC_MODE)
  727. {
  728. JSDC_cXiaChongStep = 0;
  729. }
  730. else
  731. {
  732. JSDC_cXiaChongStep = 6;
  733. }
  734. }
  735. break;
  736. case 6:
  737. {
  738. JSDC_cXiaChongStep = 7;
  739. JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_SC_DELAY;
  740. }
  741. break;
  742. case 7:
  743. if((dwTickCount >= JSDC_cXiaChongDelay))
  744. {
  745. JSDC_cXiaChongStep = 8;
  746. JSDC_cXiaChongDelay = dwTickCount+ 150;
  747. // JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
  748. JSDC_XC_ShaChe = JSDC_SC_EN;
  749. }
  750. break;
  751. case 8:
  752. if((dwTickCount >= JSDC_cXiaChongDelay))
  753. {
  754. JSDC_cXiaChongStep = 0;
  755. if(!JSDC_bRunning)MV_Set_Command_Pos_CPU(X_AXIS,0);
  756. // JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
  757. JSDC_XC_ShaChe = JSDC_SC_DISEN;
  758. }
  759. break;
  760. case 20: // 点动普通下冲动作
  761. // JSDC_XC_SongZhou = JSDC_SERVER_EN;
  762. JSDC_XC_ShaChe = JSDC_SC_DISEN;
  763. JSDC_cXiaChongDelay = dwTickCount + 50;
  764. JSDC_cXiaChongStep = 21;
  765. break;
  766. case 21:
  767. if((dwTickCount >= JSDC_cXiaChongDelay))
  768. {
  769. JSDC_XiaChong_MOTOR = 1;
  770. JSDC_cXiaChongDelay = dwTickCount + 50;
  771. JSDC_cXiaChongStep = 22;
  772. }
  773. break;
  774. case 22:
  775. if((dwTickCount >= JSDC_cXiaChongDelay))
  776. {
  777. JSDC_XiaChong_MOTOR = 0;
  778. // JSDC_XC_SongZhou = JSDC_SERVER_EN;
  779. if(JSDC_XiaChongMotorMode)
  780. JSDC_cXiaChongStep = 0;
  781. else
  782. {
  783. JSDC_XC_ShaChe = JSDC_SC_EN;
  784. JSDC_cXiaChongDelay = dwTickCount + 150;
  785. JSDC_cXiaChongStep = 23;
  786. }
  787. }
  788. break;
  789. case 23:
  790. if((dwTickCount >= JSDC_cXiaChongDelay))
  791. {
  792. //JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
  793. JSDC_XC_ShaChe = JSDC_SC_DISEN;
  794. JSDC_cXiaChongStep = 0;
  795. }
  796. break;
  797. case 40: // 点动电机下冲动作
  798. //JSDC_XC_SongZhou = JSDC_SERVER_EN;
  799. JSDC_cXiaChongDelay = dwTickCount + 50;
  800. JSDC_cXiaChongStep = 41;
  801. break;
  802. case 41:
  803. if(!Y_DRV)AxisMovePos(Y_AXIS,20,10);
  804. JSDC_cXiaChongStep = 42;
  805. break;
  806. case 42:
  807. if(!Y_DRV)
  808. {
  809. JSDC_cXiaChongStep = 0;
  810. }
  811. break;
  812. }
  813. }
  814. //分针
  815. void JSDC_FenZhen(void)
  816. {
  817. if(!JSDC_PARAM_FZ_SELECT)JSDC_cLeftFenZhenStep = 0;
  818. //左分针
  819. switch(JSDC_cLeftFenZhenStep)
  820. {
  821. case 0:
  822. break;
  823. case 1:
  824. JSDC_cLeftFenZhenStep = 2;
  825. break;
  826. case 2:
  827. if(dwTickCount >= JSDC_cFenZhenLeftDelay)
  828. {
  829. JSDC_RightFenZhen_VAVLE = 1;
  830. JSDC_cFenZhenLeftDelay = JSDC_PARAM_YD_DELAY+dwTickCount;
  831. JSDC_cLeftFenZhenStep = 3;
  832. }
  833. break;
  834. case 3:
  835. if(dwTickCount >= JSDC_cFenZhenLeftDelay)
  836. {
  837. JSDC_YD_VAVLE = 1;
  838. JSDC_cFenZhenLeftDelay = JSDC_FenZhengErrorTime+dwTickCount;
  839. JSDC_cLeftFenZhenStep = 4;
  840. }
  841. break;
  842. case 4:
  843. if(JSDC_LeftFenZhen_IN)
  844. {
  845. JSDC_cLFengTimer = 0;
  846. JSDC_cFenZhenLeftDelay = JSDC_PARAM_L_FZ_DELAY+dwTickCount;
  847. JSDC_cLeftFenZhenStep = 5;
  848. }
  849. else if(dwTickCount >= JSDC_cFenZhenLeftDelay)
  850. {
  851. JSDC_cLFengTimer++;
  852. JSDC_YD_VAVLE = 0;
  853. JSDC_RightFenZhen_VAVLE = 0;
  854. if(JSDC_cLFengTimer >= 3)
  855. {
  856. JSDC_cLFengTimer = 0;
  857. JSDC_SetAlarmCode(JSDC_LFZ_LIMIT_ALARM);
  858. }
  859. else
  860. {
  861. JSDC_cLeftFenZhenStep = 1;
  862. JSDC_cFenZhenLeftDelay = 250+dwTickCount;
  863. }
  864. }
  865. break;
  866. case 5:
  867. if(dwTickCount >= JSDC_cFenZhenLeftDelay)
  868. {
  869. JSDC_cLeftFenZhenStep = 0;
  870. }
  871. break;
  872. }
  873. }
  874. #endif