JHJinShuDinCun.c 33 KB

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