JXDaKong.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. #include "global.h"
  2. #if JU_XING_MACHINE
  3. void DK_InitAction(void);
  4. void DK_Action(void);
  5. void DK_XM_ChuiQi(void);
  6. void DK_FL_ChuiQi(void);
  7. void DK_ChaoSheng(void);
  8. void DK_XiaChong(void);
  9. void DK_SetAlarmCode(unsigned alarm_code);
  10. void DK_StartStopAction(void);
  11. void DK_AutoRunStep(void);
  12. void DK_Motor(void);
  13. void DK_SetAlarmCode(unsigned alarm_code)
  14. {
  15. SetAlarmCode(DK_ALARM_ADDR,alarm_code);
  16. DK_bAlarmStop = 1;
  17. /* switch(alarm_code)
  18. {
  19. case DK_KADAI_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break;
  20. case DK_XIACHONG_ARRIVE_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break;
  21. case DK_XM_LIMIT_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break;
  22. case DK_SM_LIMIT_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break;
  23. case DK_GUOLIAN_ALARM:AlarmMessageSave(DK_ALARM_ADDR);break;
  24. default:;
  25. }*/
  26. }
  27. void DK_InitAction(void)
  28. {
  29. XGearRatio = 1;
  30. }
  31. void DK_XM_ChuiQi(void)
  32. {
  33. if(DK_XMCQ_VAVLE && (dwTickCount >= DK_XMCQ_Delay))
  34. {
  35. DK_XMCQ_VAVLE = 0;
  36. }
  37. }
  38. void DK_FL_ChuiQi(void)
  39. {
  40. if(DK_FLCQ_VAVLE && (dwTickCount >= DK_FLCQ_Delay))
  41. {
  42. DK_FLCQ_VAVLE = 0;
  43. }
  44. }
  45. void DK_ChaoSheng(void)
  46. {
  47. if(DK_CS_OUT && (dwTickCount >= DK_CS_Delay))
  48. {
  49. DK_CS_OUT = 0;
  50. }
  51. }
  52. //手动动作
  53. void DK_ManualAction(void)
  54. {
  55. if(!DK_bRunning)
  56. {
  57. //警告跳出
  58. if(bClearTotal)
  59. {
  60. bClearTotal = 0;
  61. ClrcToTal(DK_TOTAL_ADDR);
  62. }
  63. if(DK_bMotor)
  64. {
  65. if(!X_DRV)AxisContinueMove(X_AXIS,DK_PARAM_HIGH_SPEED,DK_DIR_P);
  66. }
  67. else
  68. {
  69. if(X_DRV)AxisDecStop(X_AXIS);
  70. }
  71. if(DK_bGouZhen)
  72. {
  73. DK_bGouZhen = 0;
  74. DK_GZ_VAVLE = ~DK_GZ_VAVLE;
  75. }
  76. if(DK_bYaDai)
  77. {
  78. DK_bYaDai = 0;
  79. DK_YD_VAVLE = ~DK_YD_VAVLE;
  80. }
  81. if(DK_bSM)
  82. {
  83. DK_bSM = 0;
  84. DK_SM_VAVLE = ~DK_SM_VAVLE;
  85. }
  86. if(DK_bXM)
  87. {
  88. DK_bXM = 0;
  89. DK_XM_VAVLE = ~DK_XM_VAVLE;
  90. }
  91. if(DK_bCS)
  92. {
  93. DK_bCS = 0;
  94. DK_CS_OUT = 1;
  95. DK_CS_Delay = dwTickCount + DK_PARAM_CS_TIME;
  96. }
  97. if(DK_bXMCQ)
  98. {
  99. DK_bXMCQ = 0;
  100. DK_XMCQ_VAVLE = 1;
  101. DK_XMCQ_Delay = dwTickCount + DK_PARAM_XMCQ_TIME;
  102. }
  103. if(DK_bFLCQ)
  104. {
  105. DK_bFLCQ = 0;
  106. DK_FLCQ_VAVLE = 1;
  107. DK_FLCQ_Delay = dwTickCount + DK_PARAM_FLCQ_TIME;
  108. }
  109. if(DK_bChuDai)
  110. {
  111. DK_bChuDai = 0;
  112. DK_CD_MOTOR = ~DK_CD_MOTOR;
  113. }
  114. if(DK_bManXiaChong)
  115. {
  116. DK_bManXiaChong = 0;
  117. if(DK_XiaChongStep == 0)
  118. {
  119. DK_XiaChongStep = 1;
  120. }
  121. }
  122. }
  123. }
  124. //打孔动作
  125. void DK_Action(void)
  126. {
  127. DISPLAY_DATA0 = GetEncodeCount();
  128. DK_ManualAction();
  129. DK_XM_ChuiQi();
  130. DK_FL_ChuiQi();
  131. DK_ChaoSheng();
  132. DK_XiaChong();
  133. DK_StartStopAction();
  134. DK_AutoRunStep();
  135. DK_Motor();
  136. }
  137. //下冲动作
  138. void DK_XiaChong(void)
  139. {
  140. if(DK_XiaChongStep == 1)
  141. {
  142. DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_DELAY;
  143. DK_XiaChongStep = 2;
  144. }
  145. else if((DK_XiaChongStep == 2) && (dwTickCount >= DK_XiaChongDelay))
  146. {
  147. DK_XM_VAVLE = 1;
  148. DK_XiaChongDelay = dwTickCount + VAVLE_ALARM_TIME;
  149. DK_XiaChongStep = 3;
  150. }
  151. else if(DK_XiaChongStep == 3)
  152. {
  153. if(DK_XM_LIMIT_IN)
  154. {
  155. DK_SM_VAVLE = 1;
  156. DK_XiaChongDelay = dwTickCount + VAVLE_ALARM_TIME;
  157. DK_XiaChongStep = 4;
  158. }
  159. else if(dwTickCount >= DK_XiaChongDelay)
  160. {
  161. DK_SetAlarmCode(DK_XM_LIMIT_ALARM);
  162. }
  163. }
  164. else if(DK_XiaChongStep == 4)
  165. {
  166. if(DK_SM_LIMIT_IN)
  167. {
  168. DK_SM_VAVLE = 1;
  169. DK_XiaChongDelay = dwTickCount + DK_PARAM_DELAY_CS;
  170. DK_XiaChongStep = 5;
  171. }
  172. else if(dwTickCount >= DK_XiaChongDelay)
  173. {
  174. DK_SetAlarmCode(DK_SM_LIMIT_ALARM);
  175. }
  176. }
  177. else if((DK_XiaChongStep == 5) && (dwTickCount >= DK_XiaChongDelay))
  178. {
  179. DK_CS_OUT = 1;
  180. DK_CS_Delay = dwTickCount + DK_PARAM_CS_TIME;
  181. DK_XiaChongStep = 6;
  182. }
  183. else if((DK_XiaChongStep == 6) && (DK_CS_OUT == 0))
  184. {
  185. DK_XiaChongDelay = dwTickCount + DK_PARAM_COLD_TIME;
  186. DK_XiaChongStep = 7;
  187. }
  188. else if((DK_XiaChongStep == 7) && (dwTickCount >= DK_XiaChongDelay))
  189. {
  190. DK_SM_VAVLE = 0;
  191. DK_XM_VAVLE = 0;
  192. DK_XiaChongDelay = dwTickCount + VAVLE_ALARM_TIME;
  193. DK_XiaChongStep = 8;
  194. }
  195. else if(DK_XiaChongStep == 8)
  196. {
  197. if(!DK_SM_LIMIT_IN && !DK_XM_LIMIT_IN)
  198. {
  199. DK_XiaChongStep = 0;
  200. }
  201. else if(dwTickCount >= DK_XiaChongDelay)
  202. {
  203. if(DK_SM_LIMIT_IN)DK_SetAlarmCode(DK_SM_LIMIT_ALARM);
  204. else if (DK_XM_LIMIT_IN)DK_SetAlarmCode(DK_XM_LIMIT_ALARM);
  205. }
  206. }
  207. }
  208. //启动停止故障停止动作
  209. void DK_StartStopAction(void)
  210. {
  211. if((START_IN_UP || DK_bStart) && !DK_bRunning && (DK_AutoStep ==0))
  212. {
  213. if(GetTotal(DK_TOTAL_ADDR) >= SET_TOTAL)DK_SetAlarmCode(DK_TOTAL_ALARM);
  214. else
  215. {
  216. DK_AutoStep = 1;
  217. DK_bRunning = 1;
  218. DK_AutoDelay = 0;
  219. }
  220. DK_bStart = 0;
  221. }
  222. if(DK_KaDai_IN && (GetAlarmCode(DK_ALARM_ADDR) == 0))
  223. {
  224. DK_SetAlarmCode(DK_KADAI_ALARM);
  225. }
  226. if(STOP_IN_UP || DK_bStop)
  227. {
  228. DK_bStop = 0;
  229. if(DK_bRunning && (SingOneFlg == 0))
  230. {
  231. SingOneFlg = 1;
  232. }
  233. else
  234. {
  235. DK_GZ_VAVLE = 0;
  236. DK_YD_VAVLE = 0;
  237. DK_XM_VAVLE = 0;
  238. DK_XMCQ_VAVLE = 0;
  239. DK_SM_VAVLE = 0;
  240. DK_FLCQ_VAVLE = 0;
  241. DK_CS_OUT = 0;
  242. DK_CD_MOTOR = 0;
  243. DK_XiaChongStep = 0;
  244. DK_bRunning = 0;
  245. DK_AutoStep = 0;
  246. AxisEgmStop(X_AXIS);
  247. }
  248. }
  249. if(DK_bAlarmStop)
  250. {
  251. DK_bAlarmStop = 0;
  252. AxisEgmStop(X_AXIS);
  253. DK_AutoStep = 0;
  254. DK_XiaChongStep = 0;
  255. DK_bRunning = 0;
  256. SingOneFlg = 0;
  257. }
  258. }
  259. //电机动作
  260. void DK_Motor(void) //
  261. {
  262. static long save_buff,length_buff;
  263. switch(DK_MotorStep)
  264. {
  265. case 0:
  266. break;
  267. case 1:
  268. QD_MotorStep = 2;
  269. break;
  270. case 2:
  271. save_buff = GetPos(X_AXIS);
  272. if(dwZipCnt <= 1)
  273. {
  274. AxisContinueMove(X_AXIS,DK_PARAM_LOW_SPEED,DK_DIR_P); //第一条走低速
  275. }
  276. else
  277. {
  278. AxisMoveTwoPos(X_AXIS,DK_PARAM_HIGH_SPEED,(length_buff - DK_PARAM_LOWSPEED_LENGTH),DK_PARAM_LOW_SPEED,0xFFFFFF,DK_DIR_P);//第二条开始走两段速
  279. }
  280. DK_MotorDelay = dwTickCount + GUO_LIAN_OVER_TIME;
  281. QD_MotorStep = 3;
  282. break;
  283. case 3:
  284. if(DK_GUO_LIAN_IN_UP)
  285. {
  286. QD_MotorStep = 4;
  287. DK_MotorDelay = dwTickCount + DK_PARAM_DELAY_GZ;
  288. }
  289. else if(dwTickCount >= DK_MotorDelay)
  290. {
  291. }
  292. if(DK_GZ_IN)
  293. {
  294. AxisEgmStop(X_AXIS);
  295. QD_MotorStep = 6;
  296. }
  297. break;
  298. case 4:
  299. if(dwTickCount >= DK_MotorDelay)
  300. {
  301. DK_GZ_VAVLE = 1;
  302. QD_MotorStep = 5;
  303. }
  304. if(DK_GZ_IN)
  305. {
  306. AxisEgmStop(X_AXIS);
  307. QD_MotorStep = 6;
  308. }
  309. break;
  310. case 5:
  311. if(DK_GZ_IN)
  312. {
  313. AxisEgmStop(X_AXIS);
  314. QD_MotorStep = 6;
  315. }
  316. break;
  317. case 6:
  318. if(!X_DRV)
  319. {
  320. if(dwZipCnt == 1)length_buff = GetPos(X_AXIS) - save_buff; //以第二条测量出来的长度为准来做减速
  321. QD_MotorStep = 0;
  322. }
  323. break;
  324. }
  325. }
  326. //自动运行动作
  327. void DK_AutoRunStep(void)
  328. {
  329. if(DK_bRunning)
  330. {
  331. if(DK_AutoStep == 1)
  332. {
  333. dwZipCnt = 0;
  334. DK_AutoStep = 2;
  335. }
  336. else if((DK_AutoStep == 2) && (dwTickCount >= DK_AutoDelay))
  337. {
  338. if(QD_MotorStep == 0)QD_MotorStep = 1;
  339. DK_AutoStep = 3;
  340. }
  341. else if(DK_AutoStep == 3)
  342. {
  343. if(QD_MotorStep == 0)
  344. {
  345. DK_AutoStep = 4;
  346. }
  347. }
  348. else if(DK_AutoStep == 4)
  349. {
  350. if(DK_XiaChongStep == 0)DK_XiaChongStep = 1;
  351. DK_AutoStep = 5;
  352. }
  353. else if(DK_AutoStep == 5)
  354. {
  355. if(DK_XiaChongStep == 0)
  356. {
  357. DK_AutoStep = 6;
  358. }
  359. }
  360. else if(DK_AutoStep == 6)
  361. {
  362. AddToTal(DK_TOTAL_ADDR);
  363. dwZipCnt++;
  364. if((GetTotal(DK_TOTAL_ADDR) >= DK_PARAM_SET_TOTAL) || SingOneFlg)
  365. {
  366. if(SingOneFlg)
  367. {
  368. DK_AutoStep = 0;
  369. DK_bRunning = 0;
  370. SingOneFlg = 0;
  371. }
  372. else
  373. {
  374. DK_SetAlarmCode(DK_TOTAL_ALARM);
  375. }
  376. }
  377. else
  378. {
  379. DK_AutoStep = 2;
  380. DK_AutoDelay = DK_PARAM_CYCLE_DELAY + dwTickCount;
  381. CalProSP(DK_PROSPEED_ADDR);
  382. }
  383. }
  384. }
  385. }
  386. #endif