XDDaKong.c 11 KB

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