JHNiLongShangChiJi.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. #include "global.h"
  2. #if JIN_HONG_MACHINE == 1
  3. //锦泓尼龙上齿机
  4. void NiLongShangChiJi_ManualAction(void);
  5. void NiLongShangChiJi_AutoAction(void);
  6. void NiLongShangChiJi_StepCheckStart(void);
  7. void NiLongShangChiJi_Motor(void);
  8. void NiLongShangChiJi_Action(void);
  9. void SC_FengDai(void);
  10. void SC_SetAlarmCode(unsigned alarm_code)
  11. {
  12. SetAlarmCode(SC_ALARM_ADDR,alarm_code);
  13. bAlarmStop = 1;
  14. }
  15. void NiLongShangChiJi_InitAction(void)
  16. {
  17. float length_buff,pulse_buff;
  18. // axis_x->speed_unit = 1; //速度频率倍率单位
  19. // CalFreqTab_X_Free(25);
  20. length_buff = SC_PARAM_CYCLE_LENGTH;
  21. pulse_buff = SC_PARAM_CYCLE_PULSE;
  22. XGearRatio = pulse_buff/length_buff;
  23. // YGearRatio = 1;
  24. }
  25. void NiLongShangChiJi_Action(void)
  26. {
  27. //数据监控
  28. dwRealPos = GetPos(X_AXIS);
  29. user_datas[121] = SC_MotorStep;
  30. user_datas[122] = SC_AutoStep;
  31. user_datas[123] = dwRealPos;
  32. user_datas[124]=SC_FengDai_Step;
  33. user_datas[125]=SC_PARAM_LT_TOTAL;
  34. NiLongShangChiJi_StepCheckStart(); // 调用脚踏开关检测程序
  35. NiLongShangChiJi_Motor();
  36. SC_FengDai();
  37. NiLongShangChiJi_ManualAction();
  38. NiLongShangChiJi_AutoAction();
  39. }
  40. void NiLongShangChiJi_ManualAction(void)
  41. {
  42. if(!SC_FIRST_RUN)
  43. {
  44. if(dwTickCount >= SC_SongSiDelay)
  45. {
  46. if(SC_ChengXing_ORIGIN_IN_UP)
  47. {
  48. SC_SongSiDelay = dwTickCount + 500;
  49. SC_SongSi_VAVLE = 1;
  50. }
  51. else
  52. {
  53. SC_SongSi_VAVLE = 0;
  54. }
  55. }
  56. }
  57. if(SC_ChengXing_ORIGIN_IN)
  58. {
  59. SC_FIRST_RUN =0;
  60. }
  61. if(bRunning == 0)
  62. {
  63. if(!SC_SUOZHOU)
  64. {
  65. SC_SZ_OUT=1;// 开机默认松轴
  66. }
  67. //手动钩针
  68. if(SC_bGouZhen)
  69. {
  70. SC_bGouZhen = 0;
  71. SC_GouZhen_VAVLE = ~SC_GouZhen_VAVLE;
  72. }
  73. //手动压带
  74. if(SC_bYaDai)
  75. {
  76. SC_bYaDai = 0;
  77. if(!SC_YaDai_VAVLE)
  78. SC_YaDai_VAVLE =1;
  79. else if(SC_YaDai_VAVLE && SC_ChengXing_ORIGIN_IN)
  80. SC_YaDai_VAVLE=0;
  81. }
  82. if(SC_bXiaChong)
  83. {
  84. SC_bXiaChong=0;
  85. SC_XiaChong_VAVLE=1;
  86. }
  87. if(SC_XiaChong_VAVLE)
  88. {
  89. if(SC_XIAYA_IN_UP)
  90. {
  91. SC_XIAYA=1;
  92. SC_XiaChongDelay=dwTickCount + SC_PARAM_XiaChong_BACK_DELAY;
  93. }
  94. }
  95. if(SC_XIAYA)
  96. {
  97. if(dwTickCount >= SC_XiaChongDelay)
  98. {
  99. SC_XIAYA=0;
  100. SC_XiaChong_VAVLE=0;
  101. }
  102. }
  103. //手动下压
  104. if(SC_bXiaYa)
  105. {
  106. SC_bXiaYa = 0;
  107. if(SC_XiaYa_VAVLE)
  108. SC_XiaYa_VAVLE = 0;
  109. else if(!SC_XiaYa_VAVLE && SC_ChengXing_IN)
  110. SC_XiaYa_VAVLE=1;
  111. }
  112. //手动成型
  113. if(SC_bChengXing)
  114. {
  115. SC_bChengXing = 0;
  116. if(SC_ChengXing_VAVLE)
  117. SC_ChengXing_VAVLE =0;
  118. else if(!SC_ChengXing_VAVLE && SC_YADAI_IN)
  119. SC_ChengXing_VAVLE=1;
  120. }
  121. //手动拖带
  122. if(SC_bTuoDai)
  123. {
  124. if(!X_DRV)
  125. {
  126. SC_SZ_OUT=0;
  127. SetDir(X_AXIS, SC_DIR_P);
  128. AxisContinueMove(X_AXIS,20,SC_DIR_P);
  129. }
  130. }
  131. if((SC_MotorStep == 0) && !SC_bTuoDai && (SC_AutoStep == 0))
  132. {
  133. if(X_DRV)AxisEgmStop(X_AXIS);
  134. }
  135. }
  136. }
  137. void NiLongShangChiJi_AutoAction(void)
  138. {
  139. if(bRunning)
  140. {
  141. #if 1
  142. switch(SC_AutoStep)
  143. {
  144. case 1:
  145. if(dwTickCount >= SC_AutoDelay)
  146. {
  147. SC_AutoStep = 2;
  148. SC_MotorStep = 1;
  149. }
  150. break;
  151. case 2:
  152. if(SC_MotorStep == 0) //电机定位完成
  153. {
  154. if(SC_ZipCnt == 1)
  155. SC_Zipper_Length = dwRealPos;
  156. SC_AutoDelay=dwTickCount + 30;
  157. SC_AutoStep = 3;
  158. }
  159. break;
  160. case 3:
  161. if(dwTickCount >= SC_AutoDelay)
  162. {
  163. SC_AutoDelay=dwTickCount + VAVLE_ALARM_TIME;
  164. if(SC_PARAM_FANZHUAN_MODE)
  165. SC_MotorStep=10;
  166. SC_AutoStep = 4;
  167. }
  168. break;
  169. case 4:
  170. if((SC_GZ_IN && (SC_GOUZHEN_ON || SC_PARAM_Mator_Mode) && SC_YADAI_IN) && SC_PARAM_FANZHUAN_MODE) //反转完成
  171. {
  172. SC_AutoStep = 5;
  173. SC_AutoDelay=dwTickCount+VAVLE_ALARM_TIME;
  174. }
  175. else if((SC_GZ_IN && (SC_GOUZHEN_ON || SC_PARAM_Mator_Mode) && SC_YADAI_IN) && !SC_PARAM_FANZHUAN_MODE)
  176. {
  177. SC_AutoStep = 6;
  178. SC_AutoDelay=dwTickCount + 10;
  179. }
  180. else if(dwTickCount >= SC_AutoDelay)
  181. {
  182. SC_SetAlarmCode(SC_GOUZHEN_IN_ALARM);
  183. }
  184. break;
  185. case 5:
  186. if(!SC_GZ_IN)
  187. {
  188. SC_AutoStep = 6;
  189. SC_AutoDelay=dwTickCount + SC_PARAM_NOGZ_DELAY;
  190. }
  191. else if(dwTickCount >= SC_AutoDelay)
  192. {
  193. SC_SetAlarmCode(SC_GOUZHEN_BCAK_ALARM);
  194. }
  195. break;
  196. case 6:
  197. if(dwTickCount >= SC_AutoDelay)
  198. {
  199. if(SC_PARAM_Mator_Mode)
  200. SC_XiaChong_VAVLE=1;
  201. else
  202. SC_ChengXing_VAVLE=1;
  203. SC_AutoStep = 7;
  204. SC_AutoDelay=dwTickCount+VAVLE_ALARM_TIME;
  205. }
  206. break;
  207. case 7:
  208. if(SC_PARAM_Mator_Mode)
  209. {
  210. if(SC_XIAYA_IN_UP)
  211. {
  212. SC_AutoStep = 8;
  213. SC_AutoDelay=dwTickCount + SC_PARAM_XiaChong_BACK_DELAY;
  214. }
  215. else if(dwTickCount >= SC_AutoDelay)
  216. {
  217. SC_SetAlarmCode(SC_CHENGXING_IN_ALARM);
  218. }
  219. }
  220. else
  221. {
  222. if(SC_ChengXing_IN)
  223. {
  224. SC_XiaYa_VAVLE=1;
  225. SC_AutoDelay=dwTickCount + SC_PARAM_ChengXing_BACK_DELAY;
  226. SC_AutoStep = 8;
  227. }
  228. else if(dwTickCount >= SC_AutoDelay)
  229. {
  230. SC_SetAlarmCode(SC_CHENGXING_IN_ALARM);
  231. }
  232. }
  233. break;
  234. case 8:
  235. if(dwTickCount >= SC_AutoDelay && (SC_XIAYA_IN || SC_PARAM_Mator_Mode))
  236. {
  237. if(SC_PARAM_Mator_Mode)
  238. {
  239. SC_AutoDelay=dwTickCount + SC_PARAM_ChengXing_BACK_DELAY;
  240. SC_XiaChong_VAVLE=0;
  241. }
  242. SC_XiaYa_VAVLE=0;
  243. if(!SC_PARAM_YAJINCISHU)
  244. {
  245. SC_ChengXing_VAVLE=0;
  246. SC_AutoStep = 9;
  247. }
  248. else
  249. {
  250. SC_AutoDelay=dwTickCount + 100;
  251. SC_AutoStep = 101;
  252. }
  253. }
  254. break;
  255. case 101:
  256. if(dwTickCount >= SC_AutoDelay)
  257. {
  258. SC_XiaYa_VAVLE=1;
  259. SC_AutoDelay=dwTickCount + 100;
  260. SC_AutoStep = 102;
  261. }
  262. break;
  263. case 102:
  264. if(dwTickCount >= SC_AutoDelay)
  265. {
  266. SC_XiaYa_VAVLE=0;
  267. SC_ChengXing_VAVLE=0;
  268. SC_AutoStep = 9;
  269. }
  270. break;
  271. case 9:
  272. if(SC_PARAM_Mator_Mode)
  273. {
  274. if(dwTickCount >= SC_AutoDelay)
  275. {
  276. SC_YaDai_VAVLE=0;
  277. SC_GouZhen_VAVLE=0;
  278. SC_AutoStep = 10;
  279. }
  280. }
  281. else
  282. {
  283. if(SC_ChengXing_ORIGIN_IN)
  284. {
  285. SC_YaDai_VAVLE=0;
  286. SC_GouZhen_VAVLE=0;
  287. SC_AutoStep = 10;
  288. }
  289. }
  290. break;
  291. case 10:
  292. if((SC_ChengXing_ORIGIN_IN || SC_PARAM_Mator_Mode) && !SC_GZ_IN && !SC_GOUZHEN_ON)
  293. {
  294. SC_ZipCnt++;
  295. if(SC_ZipCnt > 2)
  296. SC_ZipCnt = 3;
  297. if(!SC_Singleone)
  298. {
  299. SC_AutoStep = 1;
  300. AddToTal(SC_TOTAL_ADDR);
  301. AddToTal(SC_WORKTOTAL_ADDR);
  302. CalProSP(SC_PROSPEED_ADDR);
  303. }
  304. else
  305. {
  306. SC_AutoStep = 0;
  307. SC_Singleone=0;
  308. }
  309. SC_AutoDelay = dwTickCount + SC_PARAM_TD_TIME;
  310. }
  311. break;
  312. }
  313. #endif
  314. }
  315. }
  316. void SC_FengDai(void)
  317. {
  318. switch(SC_FengDai_Step)
  319. {
  320. case 1://不返转
  321. if(!SC_PARAM_FANZHUAN_MODE)
  322. {//拉头数
  323. if(SC_PARAM_LT_TOTAL >= SC_PARAM_SET_LT_TOTAL)
  324. {
  325. SC_FengDaiDelay = dwTickCount + SC_PARAM_YaDai_DELAY;
  326. SC_FengDai_Step = 2;
  327. }
  328. }
  329. else
  330. SC_FengDai_Step = 0;
  331. break;
  332. case 2:
  333. if(dwTickCount >= SC_FengDaiDelay)
  334. {
  335. if(!SC_PARAM_Mator_Mode)
  336. SC_YaDai_VAVLE = 1;
  337. SC_FengDai_Step = 0;
  338. }
  339. break;
  340. }
  341. }
  342. void NiLongShangChiJi_Motor(void)
  343. {
  344. if(SC_TUITOU_IN_UP && ((dwRealPos >= (SC_LT_buff + SC_PARAM_SET_LT_LENGTH)) || (SC_PARAM_LT_TOTAL == 0)))
  345. {
  346. SC_LT_buff = dwRealPos;
  347. SC_PARAM_LT_TOTAL++;
  348. }
  349. switch(SC_MotorStep)
  350. {
  351. case 0:
  352. break;
  353. case 1:
  354. SC_MotorStep = 2;
  355. SetPos(X_AXIS,0);
  356. SC_PARAM_LT_TOTAL=0;
  357. break;
  358. case 2:
  359. SC_MotorStep = 3;
  360. SC_FengDai_Step = 1;
  361. if(((SC_ZipCnt<2) && (SC_PARAM_SHUKONG_MODE == 1)) || (SC_PARAM_SHUKONG_MODE == 0))
  362. {
  363. SC_DianGLG_VAVLE=0;
  364. AxisContinueMoveAcc(X_AXIS,SC_PARAM_GYGO_HIGN_SPEED,SC_DIR_P,SC_PARAM_START_SPEED,1000,20,50);
  365. }
  366. else
  367. {
  368. SC_MotorStep = 30;
  369. SC_DianGLG_VAVLE=1;
  370. if(!SC_PARAM_ZIPPER_LENGTH)
  371. SC_length_buff=0;
  372. SC_DCC_TIME_BL=SC_PARAM_GO_HIGN_SPEED/500;
  373. AxisMovePosAccDecNotStop(X_AXIS,SC_PARAM_GO_HIGN_SPEED,SC_length_buff-500, SC_PARAM_START_SPEED,SC_PARAM_START_SPEED,SC_PARAM_ACC_TIME,SC_DCC_TIME_BL,0);
  374. // AxisMovePosAccDec(X_AXIS,SC_PARAM_GO_HIGN_SPEED,SC_length_buff-500,SC_PARAM_START_SPEED,SC_PARAM_START_SPEED,SC_PARAM_ACC_TIME,SC_PARAM_ACC_TIME,00);
  375. }
  376. break;
  377. case 3:
  378. if((dwRealPos >= SC_PARAM_ERROR_LENGTH) && (SC_PARAM_ERROR_LENGTH))
  379. {
  380. SC_SetAlarmCode(SC_NO_ZIPPER_ALARM);
  381. }
  382. if(!SC_PARAM_Mator_Mode)
  383. {
  384. if(SC_GUO_LIAN_IN_UP)
  385. {
  386. AxisChangeSpeedDirect(X_AXIS,SC_PARAM_GO_LOW_SPEED);
  387. SC_MotorStep = 4;
  388. }
  389. }
  390. else
  391. {
  392. if(SC_PARAM_LT_TOTAL >= SC_PARAM_SET_LT_TOTAL)
  393. {
  394. AxisChangeSpeedDirect(X_AXIS,SC_PARAM_GO_LOW_SPEED);
  395. SC_MotorStep = 5;
  396. SC_MotorDelay = dwTickCount + SC_PARAM_GOUZHEN_GANYIN_DELAY;
  397. }
  398. }
  399. break;
  400. case 4:
  401. if(SC_GUO_LIAN_IN_DW)
  402. {
  403. SC_MotorDelay = dwTickCount + SC_PARAM_GOUZHEN_GANYIN_DELAY;
  404. SC_MotorStep =5;
  405. }
  406. break;
  407. case 5:
  408. if(dwTickCount >= SC_MotorDelay)
  409. {
  410. SC_GouZhen_VAVLE = 1;
  411. SC_MotorStep = 6;
  412. SC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  413. }
  414. break;
  415. case 6:
  416. if(SC_GZ_IN)
  417. {
  418. AxisEgmStop(X_AXIS);
  419. if(SC_PARAM_LT_TOTAL >= SC_PARAM_SET_LT_TOTAL)
  420. {
  421. SC_YaDai_VAVLE = 1;
  422. SC_MotorStep = 7;
  423. SC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  424. }
  425. else
  426. {
  427. SC_SetAlarmCode(SC_LATOU_CHECK_ALARM);
  428. }
  429. }
  430. else if(dwTickCount >= SC_MotorDelay)
  431. {
  432. SC_SetAlarmCode(SC_GOUZHEN_IN_ALARM);
  433. }
  434. break;
  435. case 7:
  436. if(!X_DRV && SC_YADAI_IN && (SC_GOUZHEN_ON || SC_PARAM_Mator_Mode))
  437. {
  438. SC_MotorStep = 0;
  439. if(SC_ZipCnt == 1)
  440. {
  441. if(SC_PARAM_SHUKONG_MODE == 1)
  442. {
  443. SC_length_buff = dwRealPos;
  444. SetData32bits(SC_PARAM_ZIPPER_LENGTH_ADDR,SC_length_buff);
  445. }
  446. }
  447. }
  448. else if(dwTickCount >= SC_MotorDelay)
  449. {
  450. if(!SC_GOUZHEN_ON)
  451. SC_SetAlarmCode(SC_GOUZHEN_ON_ALARM);
  452. if(!SC_YADAI_IN)
  453. {
  454. SC_SetAlarmCode(SC_YADAI_IN_ALARM);
  455. }
  456. }
  457. break;
  458. //10~11 电机反转
  459. case 10:
  460. if(SC_GZ_IN && SC_YADAI_IN)
  461. {
  462. if(SC_PARAM_FANZHUAN_LENGTH)
  463. {
  464. // SetDir(X_AXIS, SC_DIR_N);
  465. AxisMovePosAccDec(X_AXIS,SC_PARAM_CYCLE_PULSE *2,-SC_PARAM_FANZHUAN_LENGTH,SC_PARAM_START_SPEED,1000,SC_PARAM_ACC_TIME,SC_PARAM_DEC_TIME,00);
  466. }
  467. SC_MotorStep = 11;
  468. }
  469. break;
  470. case 11:
  471. if(!X_DRV)
  472. {
  473. SC_MotorStep = 0;
  474. }
  475. break;
  476. // 数控模式
  477. case 30:
  478. {
  479. if((dwRealPos + 20) >= (SC_length_buff-500) && SC_length_buff )
  480. {
  481. AxisChangeSpeedDirect(X_AXIS,SC_PARAM_GO_LOW_SPEED); //进入低速
  482. SC_MotorStep =6;
  483. SC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  484. }
  485. if((dwRealPos >= SC_PARAM_ERROR_LENGTH) && (SC_PARAM_ERROR_LENGTH))
  486. {
  487. SC_SetAlarmCode(SC_NO_ZIPPER_ALARM);
  488. }
  489. if((dwRealPos + SC_PARAM_GOUZHEN_LENGTH + 20)>= (SC_length_buff-500))
  490. {
  491. SC_GouZhen_VAVLE = 1;
  492. }
  493. if(SC_GouZhen_VAVLE && SC_GZ_IN)
  494. {
  495. SC_MotorStep = 7;
  496. SC_YaDai_VAVLE = 1;
  497. SC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  498. AxisEgmStop(X_AXIS);
  499. }
  500. }
  501. break;
  502. }
  503. }
  504. void NiLongShangChiJi_StepCheckStart(void)
  505. {
  506. // 启动
  507. if((SC_START_IN_UP) || bStart || SC_bSingleone )
  508. {
  509. #if 1
  510. if(!bRunning && (SC_AutoStep == 0))
  511. {
  512. {
  513. bRunning = 1;
  514. SC_SZ_OUT=0;
  515. SC_AutoStep=1;
  516. if(SC_bSingleone)
  517. SC_Singleone=1;
  518. SC_SUOZHOU=1;
  519. SC_AutoDelay = dwTickCount + 180;
  520. SetAlarmCode(SC_ALARM_ADDR,0);
  521. /* if(SC_PARAM_SET_LT_TOTAL == 0)
  522. SC_PARAM_SET_LT_TOTAL = 1;*/
  523. }
  524. }
  525. SC_bSingleone = 0;
  526. bStart = 0;
  527. #endif
  528. }
  529. #if 1
  530. //停止
  531. if(SC_STOP_IN_UP || bStop )
  532. {
  533. if(bRunning)
  534. {
  535. SC_ZipCnt=0;
  536. SC_AutoStep = 0;
  537. SC_MotorStep = 0;
  538. SC_Singleone=0;
  539. SC_AutoDelay = dwTickCount;
  540. SC_MotorDelay = dwTickCount;
  541. bRunning = 0;
  542. SC_SUOZHOU=1;
  543. AxisEgmStop(X_AXIS);
  544. SC_ChengXing_VAVLE =0;
  545. }
  546. else
  547. {
  548. bRunning = 0;
  549. SC_ZipCnt=0;
  550. SC_AutoDelay = dwTickCount;
  551. SetAlarmCode(100,0);
  552. AxisEgmStop(X_AXIS);
  553. SC_GouZhen_VAVLE =0;
  554. SC_Singleone=0;
  555. SC_XiaYa_VAVLE =0;
  556. SC_DianGLG_VAVLE=0;
  557. SC_XiaChong_VAVLE=0;
  558. SC_SUOZHOU=0;
  559. SC_ChengXing_VAVLE =0;
  560. if(SC_ChengXing_ORIGIN_IN)
  561. SC_YaDai_VAVLE =0;
  562. SC_SZ_OUT=1;
  563. }
  564. bStop = 0;
  565. }
  566. #endif
  567. #if 1
  568. if(bAlarmStop)
  569. {
  570. SC_ZipCnt=0;
  571. bAlarmStop = 0;
  572. bRunning = 0;
  573. SC_AutoStep = 0;
  574. SC_MotorStep = 0;
  575. SC_Singleone=0;
  576. AxisEgmStop(X_AXIS);
  577. }
  578. #endif
  579. }
  580. #endif