PWCDaKong.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. #include "global.h"
  2. #if PENG_WEI_CHANG_MACHINE
  3. void DK_InitAction(void);
  4. void DK_ChuiQi(void);
  5. void DK_Action(void);
  6. void DK_XiaChong(void);
  7. void DK_SetAlarmCode(unsigned alarm_code);
  8. void DK_StartStopAction(void);
  9. void DK_AutoRunStep(void);
  10. void DK_Motor(void);
  11. void DK_SetAlarmCode(unsigned alarm_code)
  12. {
  13. SetAlarmCode(DK_ALARM_ADDR,alarm_code);
  14. DK_bAlarmStop = 1;
  15. }
  16. void DK_InitAction(void)
  17. {
  18. float buff_pulse,buff_dist;
  19. buff_pulse = DK_PARAM_CYCLE_PULSE;
  20. buff_dist = DK_PARAM_CYCLE_LENGTH;
  21. XGearRatio = buff_pulse/buff_dist;
  22. }
  23. void DK_ChuiQi(void)
  24. {
  25. if(DK_CQ_VAVLE && (dwTickCount>=DK_CQ_Delay)) DK_CQ_VAVLE = 0;
  26. }
  27. //手动动作
  28. void DK_ManualAction(void)
  29. {
  30. if(!DK_bRunning)
  31. {
  32. //警告跳出
  33. if(bClearTotal)
  34. {
  35. bClearTotal = 0;
  36. ClrcToTal(DK_TOTAL_ADDR);
  37. }
  38. if(DK_bMotor)
  39. {
  40. if(!X_DRV)AxisContinueMove(X_AXIS,10,DK_DIR_N);
  41. }
  42. if(DK_bBackMotor)
  43. {
  44. if(!X_DRV)AxisContinueMove(X_AXIS,10,DK_DIR_P);
  45. }
  46. if(!DK_bMotor && !DK_bBackMotor)
  47. {
  48. if(X_DRV)AxisDecStop(X_AXIS);
  49. }
  50. if(DK_bGZ)
  51. {
  52. DK_bGZ = 0;
  53. DK_GZ_VAVLE = ~DK_GZ_VAVLE;
  54. }
  55. if(DK_GZSwitch_IN_UP)DK_GZ_VAVLE = 1;
  56. if(DK_GZSwitch_IN_DW)DK_GZ_VAVLE = 0;
  57. if(DK_bCQ)
  58. {
  59. DK_bCQ = 0;
  60. DK_CQ_Delay = dwTickCount + DK_PARAM_CQ_TIME;
  61. DK_CQ_VAVLE = 1;
  62. }
  63. if(DK_bXM)
  64. {
  65. DK_bXM = 0;
  66. DK_XM_VAVLE = ~DK_XM_VAVLE;
  67. }
  68. if(DK_bSM)
  69. {
  70. DK_bSM = 0;
  71. DK_SM_VAVLE = ~DK_SM_VAVLE;
  72. }
  73. if(DK_bRJ || DK_RJSwitch_IN_UP)
  74. {
  75. DK_bRJ = 0;
  76. if(DK_XiaChongStep==0)DK_XiaChongStep=1;
  77. }
  78. }
  79. }
  80. //打孔动作
  81. void DK_Action(void)
  82. {
  83. DK_ManualAction();
  84. DK_ChuiQi();
  85. DK_XiaChong();
  86. DK_StartStopAction();
  87. DK_AutoRunStep();
  88. DK_Motor();
  89. }
  90. //下冲动作
  91. void DK_XiaChong(void)
  92. {
  93. if(DK_XiaChongStep == 1)
  94. {
  95. DK_XiaChongDelay = dwTickCount + DK_PARAM_SM_DELAY;
  96. DK_XiaChongStep = 2;
  97. }
  98. else if((DK_XiaChongStep == 2)&& (dwTickCount >= DK_XiaChongDelay))
  99. {
  100. DK_SM_VAVLE = 1;
  101. DK_XiaChongStep = 3;
  102. DK_XiaChongDelay = dwTickCount + DK_VAVLE_ALARM_TIME;
  103. }
  104. else if(DK_XiaChongStep == 3)
  105. {
  106. if(DK_SM_LIMIT_IN)
  107. {
  108. DK_XiaChongStep = 4;
  109. }
  110. else if(dwTickCount >= DK_XiaChongDelay)
  111. DK_SetAlarmCode(DK_SM_LIMIT_ALARM);
  112. }
  113. else if(DK_XiaChongStep == 4)
  114. {
  115. if(DK_PARAM_XM_ENABLE)
  116. {
  117. DK_XiaChongDelay = dwTickCount + DK_PARAM_XM_DELAY;
  118. DK_XiaChongStep = 5;
  119. }
  120. else
  121. DK_XiaChongStep = 7;
  122. }
  123. else if((DK_XiaChongStep == 5) && (dwTickCount >= DK_XiaChongDelay))
  124. {
  125. DK_XM_VAVLE = 1;
  126. DK_XiaChongDelay = dwTickCount + DK_VAVLE_ALARM_TIME;
  127. DK_XiaChongStep = 6;
  128. }
  129. else if(DK_XiaChongStep == 6)
  130. {
  131. if(DK_XM_LIMIT_IN)
  132. {
  133. DK_XiaChongStep = 7;
  134. }
  135. else if(dwTickCount >= DK_XiaChongDelay)
  136. DK_SetAlarmCode(DK_XM_LIMIT_ALARM);
  137. }
  138. else if(DK_XiaChongStep == 7)
  139. {
  140. DK_XiaChongDelay = dwTickCount + DK_PARAM_CS_DELAY;
  141. DK_XiaChongStep = 8;
  142. }
  143. else if((DK_XiaChongStep == 8) && (dwTickCount >= DK_XiaChongDelay))
  144. {
  145. if(!DK_PARAM_CS_ENABLE)DK_CS_OUT = 1;
  146. DK_XiaChongDelay = dwTickCount + DK_PARAM_CS_TIME;
  147. DK_XiaChongStep = 9;
  148. }
  149. else if((DK_XiaChongStep == 9) && (dwTickCount >= DK_XiaChongDelay))
  150. {
  151. if(!DK_PARAM_CS_ENABLE)DK_CS_OUT = 0;
  152. DK_XiaChongDelay = dwTickCount + DK_PARAM_CS_COLD_TIME;
  153. DK_XiaChongStep = 10;
  154. }
  155. else if((DK_XiaChongStep == 10) && (dwTickCount >= DK_XiaChongDelay))
  156. {
  157. DK_SM_VAVLE = 0;
  158. if(DK_PARAM_XM_ENABLE)DK_XM_VAVLE = 0;
  159. DK_GZ_VAVLE = 0;
  160. DK_XiaChongStep = 11;
  161. DK_XiaChongDelay = dwTickCount + DK_VAVLE_ALARM_TIME;
  162. }
  163. else if((DK_XiaChongStep == 11))
  164. {
  165. if(!DK_SM_LIMIT_IN && !DK_XM_LIMIT_IN)
  166. {
  167. DK_XiaChongStep = 0;
  168. DK_XiaChongDelay = dwTickCount;
  169. }
  170. else if(dwTickCount >= DK_XiaChongDelay)
  171. {
  172. if(DK_SM_LIMIT_IN)
  173. DK_SetAlarmCode(DK_SM_LIMIT_ALARM);
  174. else
  175. DK_SetAlarmCode(DK_XM_LIMIT_ALARM);
  176. }
  177. }
  178. }
  179. //启动停止故障停止动作
  180. void DK_StartStopAction(void)
  181. {
  182. if(DK_bRunning)
  183. DK_PARAM_RUN_STATE = 1;
  184. else
  185. DK_PARAM_RUN_STATE = 0;
  186. if((START_IN_UP || DK_bStart || DK_bSingle) && !DK_bRunning && (DK_AutoStep ==0))
  187. {
  188. if(DK_GZ_VAVLE || DK_GZ_IN)DK_SetAlarmCode(DK_START_GZ_ALARM);
  189. else if(DK_SM_VAVLE || DK_SM_LIMIT_IN)DK_SetAlarmCode(DK_START_SM_ALARM);
  190. else if(DK_XM_VAVLE || DK_XM_LIMIT_IN)DK_SetAlarmCode(DK_START_XM_ALARM);
  191. else
  192. {
  193. if(DK_bSingle)
  194. {
  195. SingOneFlg = 1;
  196. DK_bSingle = 0;
  197. }
  198. DK_AutoStep = 1;
  199. DK_bRunning = 1;
  200. DK_AutoDelay = 0;
  201. }
  202. DK_bStart = 0;
  203. }
  204. /* if(DK_KaDai_IN && (GetAlarmCode(DK_ALARM_ADDR) == 0))
  205. {
  206. DK_SetAlarmCode(DK_KADAI_ALARM);
  207. }
  208. */
  209. if(STOP_IN_UP || DK_bStop)
  210. {
  211. DK_bStop = 0;
  212. if(DK_bRunning)
  213. {
  214. DK_bRunning = 0;
  215. DK_AutoStep = 0;
  216. DK_MotorStep = 0;
  217. DK_PROSPEED = 0;
  218. AxisEgmStop(X_AXIS);
  219. }
  220. else
  221. {
  222. DK_bRunning = 0;
  223. DK_AutoStep = 0;
  224. DK_MotorStep = 0;
  225. DK_XiaChongStep = 0;
  226. DK_GZ_VAVLE = 0;
  227. DK_CQ_VAVLE = 0;
  228. DK_SM_VAVLE = 0;
  229. DK_XM_VAVLE = 0;
  230. DK_SZ_OUT = 1;
  231. DK_CS_OUT = 0;
  232. DK_PROSPEED = 0;
  233. SingOneFlg = 0;
  234. AxisEgmStop(X_AXIS);
  235. }
  236. }
  237. if(DK_bAlarmStop)
  238. {
  239. DK_bAlarmStop = 0;
  240. DK_bRunning = 0;
  241. DK_AutoStep = 0;
  242. DK_MotorStep = 0;
  243. DK_XiaChongStep = 0;
  244. DK_GZ_VAVLE = 0;
  245. DK_CQ_VAVLE = 0;
  246. DK_SM_VAVLE = 0;
  247. DK_XM_VAVLE = 0;
  248. DK_SZ_OUT = 1;
  249. DK_CS_OUT = 0;
  250. SingOneFlg = 0;
  251. DK_PROSPEED = 0;
  252. AxisEgmStop(X_AXIS);
  253. }
  254. }
  255. //电机动作
  256. void DK_Motor(void) //
  257. {
  258. static long save_buff,length_buff;
  259. DISPLAY_DATA0 = dwTickCount;
  260. if(DK_bRunning)dwRealPos = GetPos(X_AXIS);
  261. switch(DK_MotorStep)
  262. {
  263. case 0:
  264. break;
  265. case 1:
  266. if(DK_SZ_OUT)
  267. {
  268. DK_SZ_OUT = 0;
  269. DK_MotorDelay = dwTickCount + 100;
  270. }
  271. DK_MotorStep = 2;
  272. break;
  273. case 2:
  274. if(dwTickCount >= DK_MotorDelay)
  275. {
  276. if(!X_DRV)AxisContinueMove(X_AXIS,DK_PARAM_HIGH_SPEED,DK_DIR_N);
  277. DK_MotorDelay = dwTickCount + DK_PARAM_NO_ZIPPER_TIME;
  278. DK_MotorStep = 3;
  279. }
  280. break;
  281. case 3:
  282. if(DK_GuoLian_IN_UP)
  283. {
  284. if(X_DRV)AxisChangeSpeed(X_AXIS,DK_PARAM_LOW_SPEED);
  285. DK_MotorStep = 4;
  286. DK_MotorDelay = dwTickCount + DK_PARAM_GZ_DELAY;
  287. }
  288. else if(dwTickCount >= DK_MotorDelay)
  289. DK_SetAlarmCode(DK_GUOLIAN_ALARM);
  290. break;
  291. case 4:
  292. if(dwTickCount >= DK_MotorDelay)
  293. {
  294. DK_GZ_VAVLE = 1;
  295. DK_CQ_Delay = dwTickCount + DK_PARAM_CQ_TIME;
  296. DK_CQ_VAVLE = 1;
  297. DK_MotorDelay = dwTickCount + DK_VAVLE_ALARM_TIME;
  298. DK_MotorStep = 5;
  299. }
  300. break;
  301. case 5:
  302. if(DK_GZ_IN)
  303. {
  304. save_buff = dwRealPos;
  305. DK_MotorStep = 6;
  306. }
  307. else if(dwTickCount >= DK_MotorDelay)
  308. DK_SetAlarmCode(DK_GZ_ALARM);
  309. break;
  310. case 6:
  311. if(dwRealPos >= (DK_PARAM_DELAY_STOP_MOTOR + save_buff))
  312. {
  313. AxisEgmStop(X_AXIS);
  314. DK_MotorStep = 7;
  315. }
  316. break;
  317. case 7:
  318. if(!X_DRV)
  319. {
  320. DK_MotorStep = 8;
  321. }
  322. break;
  323. case 8:
  324. {
  325. DK_MotorDelay = dwTickCount;
  326. DK_MotorStep = 0;
  327. }
  328. break;
  329. }
  330. }
  331. //自动运行动作
  332. void DK_AutoRunStep(void)
  333. {
  334. DISPLAY_DATA0 = DK_XiaChongStep;
  335. DISPLAY_DATA1 = DK_ManualStep;
  336. DISPLAY_DATA2 = DK_MotorStep;
  337. DISPLAY_DATA3 = DK_AutoStep;
  338. if(DK_bRunning)
  339. {
  340. if(DK_AutoStep == 1)
  341. {
  342. DK_AutoStep = 2;
  343. }
  344. else if((DK_AutoStep == 2) && (dwTickCount >= DK_AutoDelay))
  345. {
  346. if(DK_MotorStep == 0)
  347. {
  348. DK_MotorStep = 1;
  349. DK_AutoStep = 3;
  350. }
  351. }
  352. else if(DK_AutoStep == 3)
  353. {
  354. if(DK_MotorStep == 0)
  355. {
  356. DK_AutoStep = 4;
  357. }
  358. }
  359. else if(DK_AutoStep == 4)
  360. {
  361. DK_AutoStep = 5;
  362. }
  363. else if(DK_AutoStep == 5)
  364. {
  365. if(DK_MotorStep == 0)
  366. {
  367. if(SingOneFlg)
  368. {
  369. DK_AutoStep = 0;
  370. DK_bRunning = 0;
  371. SingOneFlg = 0;
  372. }
  373. else
  374. DK_AutoStep = 6;
  375. }
  376. }
  377. else if(DK_AutoStep == 6)
  378. {
  379. if(DK_XiaChongStep == 0)
  380. {
  381. DK_XiaChongStep = 1;
  382. DK_AutoStep = 7;
  383. }
  384. }
  385. else if(DK_AutoStep == 7)
  386. {
  387. if(DK_XiaChongStep == 0)
  388. {
  389. DK_AutoStep = 8;
  390. }
  391. }
  392. else if(DK_AutoStep == 8)
  393. {
  394. AddToTal(DK_TOTAL_ADDR);
  395. AddToTal(DK_ALLTOTAL_ADDR);
  396. {
  397. DK_AutoStep = 2;
  398. DK_AutoDelay = DK_PARAM_CYCLE_DELAY + dwTickCount;
  399. CalProSP(DK_PROSPEED_ADDR);
  400. }
  401. }
  402. }
  403. }
  404. #endif