XDJinShuDinCun.c 31 KB

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