TYHongMenDZJ.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. #include "global.h"
  2. #if TONG_YONG_MACHINE
  3. void HMDZ_ManualAction(void);
  4. void HMDZ_AutoAction(void);
  5. void HMDZ_StepCheckStart(void);
  6. void HMDZ_Motor(void);
  7. void HMDZ_ExtiActionX31(void);
  8. static long save_limit_pos,cRealPos;
  9. void HMDZ_ExtiActionX31(void)
  10. {
  11. }
  12. void HMDZ_SetAlarmCode(unsigned alarm_code)
  13. {
  14. SetAlarmCode(HMDZ_ALARM_ADDR,alarm_code);
  15. bAlarmStop = 1;
  16. }
  17. void HMDZ_InitAction(void)
  18. {
  19. HMDZ_SZ_OUT = 1;
  20. }
  21. void HMDZ_Action(void)
  22. {
  23. HMDZ_Motor();
  24. HMDZ_ManualAction();
  25. HMDZ_AutoAction();
  26. HMDZ_StepCheckStart(); // 调用脚踏开关检测程序
  27. }
  28. //手动动作
  29. void HMDZ_ManualAction(void)
  30. {
  31. if(HMDZ_bRunning == 0)
  32. {
  33. if(HMDZ_bClearTotal) //切断计数清零
  34. {
  35. HMDZ_bClearTotal = 0;
  36. ClrcToTal(HMDZ_TOTAL_ADDR);
  37. }
  38. if(HMDZ_bSS)
  39. {
  40. HMDZ_bSS = 0;
  41. HMDZ_SS_VAVLE = ~HMDZ_SS_VAVLE;
  42. }
  43. if(HMDZ_bDL)
  44. {
  45. HMDZ_bDL = 0;
  46. HMDZ_DL_VAVLE = ~HMDZ_DL_VAVLE;
  47. }
  48. if(HMDZ_bQS)
  49. {
  50. HMDZ_bQS = 0;
  51. HMDZ_QS_VAVEL = ~HMDZ_QS_VAVEL;
  52. }
  53. if(HMDZ_bTS)
  54. {
  55. HMDZ_bTS = 0;
  56. HMDZ_TS_VAVLE = ~HMDZ_TS_VAVLE;
  57. }
  58. if(HMDZ_bJL)
  59. {
  60. HMDZ_bJL = 0;
  61. HMDZ_JL_VAVLE = ~HMDZ_JL_VAVLE;
  62. }
  63. if(HMDZ_bYL)
  64. {
  65. HMDZ_bYL = 0;
  66. HMDZ_CL_VAVLE = ~HMDZ_CL_VAVLE;
  67. }
  68. if(HMDZ_bCL)
  69. {
  70. HMDZ_bCL = 0;
  71. HMDZ_SS_VAVLE = ~HMDZ_SS_VAVLE;
  72. }
  73. //电机控制
  74. if(HMDZ_bGoMotor)
  75. {
  76. HMDZ_SZ_OUT = 0;
  77. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,HMDZ_DIR_N,5,1,5,5);
  78. }
  79. if(HMDZ_bBackMotor)
  80. {
  81. HMDZ_SZ_OUT = 0;
  82. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,HMDZ_DIR_P,5,1,5,5);
  83. }
  84. if(!HMDZ_bGoMotor && !HMDZ_bBackMotor && (HMDZ_MotorStep == 0))
  85. {
  86. if(X_DRV)AxisDecStop(X_AXIS);
  87. }
  88. }
  89. }
  90. void HMDZ_AutoAction(void)
  91. {
  92. if(HMDZ_bRunning)
  93. {
  94. switch(HMDZ_AutoStep)
  95. {
  96. case 1:
  97. if(dwTickCount >= HMDZ_AutoDelay)
  98. {
  99. HMDZ_AutoStep = 2;
  100. HMDZ_JL_VAVLE = 1;
  101. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_YL_DELAY;
  102. }
  103. break;
  104. case 2:
  105. if(dwTickCount >= HMDZ_AutoDelay)
  106. {
  107. HMDZ_YL_VAVLE = 1;
  108. HMDZ_JL_VAVLE = 0;
  109. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_DL_DELAY;
  110. HMDZ_AutoStep = 3;
  111. }
  112. break;
  113. case 3:
  114. if(dwTickCount >= HMDZ_AutoDelay)
  115. {
  116. HMDZ_DL_VAVLE = 1;
  117. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  118. HMDZ_AutoStep = 4;
  119. }
  120. break;
  121. case 4:
  122. if(HMDZ_DL_LIMIT_IN && HMDZ_SG_LIMIT_IN)
  123. {
  124. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_SS_DELAY;
  125. HMDZ_AutoStep = 5;
  126. }
  127. else if(dwTickCount >= HMDZ_AutoDelay)
  128. {
  129. if(!HMDZ_DL_LIMIT_IN)HMDZ_SetAlarmCode(HMDZ_DL_LIMIT_ALARM);
  130. else HMDZ_SetAlarmCode(HMDZ_SG_LIMIT_ALARM);
  131. }
  132. break;
  133. case 5:
  134. if(dwTickCount >= HMDZ_AutoDelay)
  135. {
  136. HMDZ_SS_VAVLE = 1;
  137. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  138. HMDZ_AutoStep = 6;
  139. }
  140. break;
  141. case 6:
  142. if(HMDZ_SS_LIMIT_IN)
  143. {
  144. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_SS_BACK_DELAY;
  145. HMDZ_AutoStep = 7;
  146. }
  147. else if(dwTickCount >= HMDZ_AutoDelay)
  148. HMDZ_SetAlarmCode(HMDZ_SS_LIMIT_ALARM);
  149. break;
  150. case 7:
  151. if(dwTickCount >= HMDZ_AutoDelay)
  152. {
  153. HMDZ_SS_VAVLE = 0;
  154. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  155. HMDZ_AutoStep = 8;
  156. }
  157. break;
  158. case 8:
  159. if(HMDZ_SS_ORIGIN_IN && !HMDZ_MOTOR_ORIGIN_IN)
  160. {
  161. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_RS_MOTOR_DELAY+50;
  162. HMDZ_SZ_OUT = 0;
  163. HMDZ_AutoStep = 9;
  164. }
  165. else if(dwTickCount >= HMDZ_AutoDelay)
  166. {
  167. if(!HMDZ_SS_ORIGIN_IN)
  168. HMDZ_SetAlarmCode(HMDZ_SS_ORIGIN_ALARM);
  169. else
  170. HMDZ_SetAlarmCode(HMDZ_MOTOR_ORIGIN_ALARM);
  171. }
  172. break;
  173. case 9:
  174. if(dwTickCount >= HMDZ_AutoDelay)
  175. {
  176. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,HMDZ_DIR_N,HMDZ_PARAM_RS_MOTOR_SPEED,HMDZ_PARAM_RS_MOTOR_START_SPEED,HMDZ_PARAM_RS_MOTOR_ACC,HMDZ_PARAM_RS_MOTOR_DEC);
  177. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  178. HMDZ_AutoStep = 10;
  179. }
  180. break;
  181. case 10:
  182. if(HMDZ_MOTOR_ORIGIN_IN)
  183. {
  184. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  185. HMDZ_AutoStep = 11;
  186. }
  187. else if(dwTickCount >= HMDZ_AutoDelay)
  188. HMDZ_SetAlarmCode(HMDZ_MOTOR_ORIGIN_ALARM);
  189. break;
  190. case 11:
  191. if(HMDZ_RS_LIMIT_IN)
  192. {
  193. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_RS_MOTOR_STOP_DELAY;
  194. HMDZ_AutoStep = 12;
  195. }
  196. else if(dwTickCount >= HMDZ_AutoDelay)
  197. HMDZ_SetAlarmCode(HMDZ_RS_LIMIT_ALARM);
  198. break;
  199. case 12:
  200. if(dwTickCount >= HMDZ_AutoDelay)
  201. {
  202. if(X_DRV)AxisDecStop(X_AXIS);
  203. HMDZ_AutoStep = 13;
  204. }
  205. break;
  206. case 13:
  207. if(!X_DRV)
  208. {
  209. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_TS_DELAY;
  210. HMDZ_AutoStep = 14;
  211. }
  212. break;
  213. case 14:
  214. if(dwTickCount >= HMDZ_AutoDelay)
  215. {
  216. HMDZ_TS_VAVLE = 1;
  217. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  218. HMDZ_AutoStep = 15;
  219. }
  220. break;
  221. case 15:
  222. if(HMDZ_TS_LIMIT_IN)
  223. {
  224. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_QS_DELAY;
  225. HMDZ_AutoStep = 16;
  226. }
  227. else if(dwTickCount >= HMDZ_AutoDelay)
  228. HMDZ_SetAlarmCode(HMDZ_TS_LIMIT_ALARM);
  229. break;
  230. case 16:
  231. if(dwTickCount >= HMDZ_AutoDelay)
  232. {
  233. HMDZ_QS_VAVEL = 1;
  234. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  235. HMDZ_AutoStep = 17;
  236. }
  237. break;
  238. case 17:
  239. if(HMDZ_QS_LIMIT_IN)
  240. {
  241. HMDZ_AutoDelay = dwTickCount;
  242. HMDZ_AutoStep = 18;
  243. }
  244. else if(dwTickCount >= HMDZ_AutoDelay)
  245. HMDZ_SetAlarmCode(HMDZ_QS_LIMIT_ALARM);
  246. break;
  247. case 18:
  248. if(dwTickCount >= HMDZ_AutoDelay)
  249. {
  250. HMDZ_DL_VAVLE = 0;
  251. HMDZ_TS_VAVLE = 0;
  252. HMDZ_YL_VAVLE = 0;
  253. HMDZ_CL_VAVLE = 1;
  254. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_CL_BACK_DELAY;
  255. HMDZ_AutoStep = 19;
  256. }
  257. break;
  258. case 19:
  259. if(dwTickCount >= HMDZ_AutoDelay)
  260. {
  261. HMDZ_CL_VAVLE = 0;
  262. HMDZ_QS_VAVEL = 0;
  263. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  264. HMDZ_AutoStep = 20;
  265. }
  266. break;
  267. case 20:
  268. if(HMDZ_DL_ORIGIN_IN && HMDZ_QS_ORIGIN_IN && HMDZ_TS_ORIGIN_IN && HMDZ_SS_ORIGIN_IN)
  269. {
  270. HMDZ_AutoDelay = dwTickCount;
  271. HMDZ_AutoStep = 21;
  272. }
  273. else if(dwTickCount >= HMDZ_AutoDelay)
  274. {
  275. if(!HMDZ_DL_ORIGIN_IN)
  276. HMDZ_SetAlarmCode(HMDZ_DL_ORIGIN_ALARM);
  277. else if(!HMDZ_QS_ORIGIN_IN)
  278. HMDZ_SetAlarmCode(HMDZ_QS_ORIGIN_ALARM);
  279. else if(!HMDZ_TS_ORIGIN_IN)
  280. HMDZ_SetAlarmCode(HMDZ_TS_ORIGIN_ALARM);
  281. else
  282. HMDZ_SetAlarmCode(HMDZ_SS_ORIGIN_ALARM);
  283. }
  284. break;
  285. case 21:
  286. if(dwTickCount >= HMDZ_AutoDelay)
  287. {
  288. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,HMDZ_DIR_P,HMDZ_PARAM_RS_MOTOR_SPEED,HMDZ_PARAM_RS_MOTOR_START_SPEED,HMDZ_PARAM_RS_MOTOR_ACC,HMDZ_PARAM_RS_MOTOR_DEC);
  289. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  290. HMDZ_AutoStep = 22;
  291. }
  292. break;
  293. case 22:
  294. if(HMDZ_MOTOR_ORIGIN_IN)
  295. {
  296. if(X_DRV)AxisDecStop(X_AXIS);
  297. HMDZ_AutoStep = 23;
  298. }
  299. else if(dwTickCount >= HMDZ_AutoDelay)
  300. HMDZ_SetAlarmCode(HMDZ_MOTOR_ORIGIN_ALARM);
  301. break;
  302. case 23:
  303. if(!X_DRV)
  304. {
  305. HMDZ_SS_VAVLE = 1;
  306. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  307. HMDZ_AutoStep = 24;
  308. }
  309. break;
  310. case 24:
  311. if(HMDZ_SS_LIMIT_IN)
  312. {
  313. HMDZ_SS_VAVLE = 0;
  314. HMDZ_QS_VAVEL = 1;
  315. HMDZ_AutoStep = 25;
  316. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  317. }
  318. else if(dwTickCount >= HMDZ_AutoDelay)
  319. HMDZ_SetAlarmCode(HMDZ_SS_LIMIT_ALARM);
  320. break;
  321. case 25:
  322. if(HMDZ_QS_LIMIT_IN)
  323. {
  324. HMDZ_CL_VAVLE = 1;
  325. HMDZ_AutoStep = 26;
  326. HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_CL_BACK_DELAY;
  327. }
  328. else if(dwTickCount >= HMDZ_AutoDelay)
  329. HMDZ_SetAlarmCode(HMDZ_QS_LIMIT_ALARM);
  330. break;
  331. case 26:
  332. if(dwTickCount >= HMDZ_AutoDelay)
  333. {
  334. HMDZ_CL_VAVLE = 0;
  335. HMDZ_QS_VAVEL = 0;
  336. HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME;
  337. HMDZ_AutoStep = 27;
  338. }
  339. break;
  340. case 27:
  341. if(HMDZ_QS_ORIGIN_IN)
  342. {
  343. HMDZ_AutoStep = 28;
  344. }
  345. else if(dwTickCount >= HMDZ_AutoDelay)
  346. HMDZ_SetAlarmCode(HMDZ_QS_ORIGIN_ALARM);
  347. break;
  348. case 28:
  349. if(HMDZ_MotorStep == 0)
  350. {
  351. AddToTal(HMDZ_TOTAL_ADDR);
  352. CalProSP(HMDZ_PROSPEED_ADDR);
  353. HMDZ_AutoStep = 1;
  354. }
  355. break;
  356. }
  357. }
  358. }
  359. void HMDZ_StepCheckStart(void)
  360. {
  361. // 启动
  362. if((HMDZ_START_IN) || HMDZ_bStart)
  363. {
  364. HMDZ_bStart = 0;
  365. if(!HMDZ_bRunning && (HMDZ_AutoStep == 0))
  366. {
  367. if(!HMDZ_MOTOR_ORIGIN_IN)HMDZ_SetAlarmCode(HMDZ_MOTOR_ORIGIN_ALARM);
  368. else if(!HMDZ_DL_ORIGIN_IN)HMDZ_SetAlarmCode(HMDZ_DL_ORIGIN_ALARM);
  369. else if(!HMDZ_QS_ORIGIN_IN)HMDZ_SetAlarmCode(HMDZ_QS_ORIGIN_ALARM);
  370. else if(!HMDZ_TS_ORIGIN_IN) HMDZ_SetAlarmCode(HMDZ_TS_ORIGIN_ALARM);
  371. else if(!HMDZ_SS_ORIGIN_IN)HMDZ_SetAlarmCode(HMDZ_SS_ORIGIN_ALARM);
  372. else
  373. {
  374. HMDZ_bRunning = 1;
  375. HMDZ_AutoStep = 1;
  376. }
  377. }
  378. }
  379. //停止
  380. if(HMDZ_STOP_IN_UP || HMDZ_bStop)
  381. {
  382. HMDZ_bStop = 0;
  383. HMDZ_bRunning = 0;
  384. HMDZ_AutoStep = 0;
  385. HMDZ_MotorStep = 0;
  386. HMDZ_SS_VAVLE = 0;
  387. HMDZ_DL_VAVLE = 0;
  388. HMDZ_QS_VAVEL = 0;
  389. HMDZ_TS_VAVLE = 0;
  390. HMDZ_JL_VAVLE = 0;
  391. HMDZ_YL_VAVLE = 0;
  392. HMDZ_CL_VAVLE = 0;
  393. HMDZ_SZ_OUT = 1;
  394. AxisDecStop(X_AXIS);
  395. if(GetAlarmCode(HMDZ_ALARM_ADDR) != 0)SetAlarmCode(HMDZ_ALARM_ADDR,0);
  396. }
  397. if(HMDZ_bAlarmStop)
  398. {
  399. HMDZ_bAlarmStop = 0;
  400. HMDZ_bRunning = 0;
  401. HMDZ_AutoStep = 0;
  402. HMDZ_MotorStep = 0;
  403. HMDZ_SS_VAVLE = 0;
  404. HMDZ_DL_VAVLE = 0;
  405. HMDZ_QS_VAVEL = 0;
  406. HMDZ_TS_VAVLE = 0;
  407. HMDZ_JL_VAVLE = 0;
  408. HMDZ_YL_VAVLE = 0;
  409. HMDZ_CL_VAVLE = 0;
  410. }
  411. }
  412. void HMDZ_Motor(void)
  413. {
  414. user_datas[121]= HMDZ_MotorStep;
  415. user_datas[125] = HMDZ_AutoStep;
  416. switch(HMDZ_MotorStep)
  417. {
  418. }
  419. }
  420. #endif