JCWYHuaXianJi.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. #include "global.h"
  2. #if JIA_CHENG_WEI_YE_MACHINE
  3. void HuaXian_AlarmProtect(void);
  4. void HuaXian_ManualAction(void);
  5. void HuaXian_AutoAction(void);
  6. void HuaXian_StepCheckStart(void);
  7. void HuaXian_Motor(void);
  8. void HuaXian_ActionStep(void);
  9. static unsigned long cZipCnt = 0;
  10. static unsigned short cHuaXianTimesCnt = 0;
  11. void HX_SetAlarmCode(unsigned alarm_code)
  12. {
  13. SetAlarmCode(HX_ALARM_ADDR,alarm_code);
  14. bAlarmStop = 1;
  15. }
  16. void HuaXian_InitAction(void)
  17. {
  18. float length_buff,pulse_buff;
  19. length_buff = HX_PARAM_CYCLE_LENGTH;
  20. pulse_buff = HX_PARAM_CYCLE_PULSE;
  21. XGearRatio = pulse_buff/length_buff;
  22. CalFreqTab_X_Free(15);
  23. HX_SZ_OUT = 1;
  24. }
  25. void HuaXian_Action(void)
  26. {
  27. HuaXian_AlarmProtect();
  28. HuaXian_Motor();
  29. HuaXian_ManualAction();
  30. HuaXian_ActionStep();
  31. HuaXian_AutoAction();
  32. HuaXian_StepCheckStart(); // 调用脚踏开关检测程序
  33. }
  34. //手动动作
  35. void HuaXian_ManualAction(void)
  36. {
  37. if(bRunning == 0)
  38. {
  39. if(HX_bClearTotal) //切断计数清零
  40. {
  41. HX_bClearTotal = 0;
  42. ClrcToTal(HX_TOTAL_ADDR);
  43. }
  44. if(HX_bDown)
  45. {
  46. HX_bDown = 0;
  47. HX_DOWN_VAVLE = ~HX_DOWN_VAVLE;
  48. }
  49. if(HX_bHX)
  50. {
  51. HX_bHX = 0;
  52. HX_HX_VAVLE = ~HX_HX_VAVLE;
  53. }
  54. if(HX_bGZ)
  55. {
  56. HX_bGZ = 0;
  57. HX_GZ_VAVLE = ~HX_GZ_VAVLE;
  58. }
  59. if(HX_bHXRun)
  60. {
  61. HX_bHXRun = 0;
  62. if(HX_HuaXianStep==0)HX_HuaXianStep=1;
  63. }
  64. //电机控制
  65. if(HX_bGoMotor)
  66. {
  67. HX_SZ_OUT = 0;
  68. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, HX_DIR_N, 5,1,5,30);
  69. }
  70. if(HX_bBackMotor)
  71. {
  72. HX_SZ_OUT = 0;
  73. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, HX_DIR_P, 5,1,5,30);
  74. }
  75. if(!HX_bGoMotor && !HX_bBackMotor && (HX_MotorStep == 0))
  76. {
  77. if(X_DRV)AxisDecStop(X_AXIS);
  78. }
  79. }
  80. }
  81. void HuaXian_AlarmProtect(void)
  82. {
  83. dwRealPos = GetPos(X_AXIS);
  84. }
  85. void HuaXian_ActionStep(void)
  86. {
  87. switch(HX_HuaXianStep)
  88. {
  89. case 0:break;
  90. case 1:
  91. HX_HuaXianStep = 2;
  92. HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
  93. break;
  94. case 2:
  95. if(HX_DOWN_UP_IN)
  96. {
  97. HX_HuaXianStep = 3;
  98. HX_HXDelay = dwTickCount+HX_PARAM_DELAY_DOWN;
  99. }
  100. else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_UP_ALARM);
  101. break;
  102. case 3:
  103. if(dwTickCount >= HX_HXDelay)
  104. {
  105. HX_DOWN_VAVLE = 1;
  106. HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
  107. HX_HuaXianStep = 4;
  108. }
  109. break;
  110. case 4:
  111. if(HX_DOWN_DOWN_IN)
  112. {
  113. HX_HuaXianStep = 5;
  114. HX_HXDelay = dwTickCount+HX_PARAM_DELAY_HX;
  115. }
  116. else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_DOWN_ALARM);
  117. break;
  118. case 5:
  119. if(dwTickCount >= HX_HXDelay)
  120. {
  121. HX_HX_VAVLE = 1;
  122. HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
  123. HX_HuaXianStep = 6;
  124. }
  125. break;
  126. case 6:
  127. if(HX_HX_LIMIT_IN)
  128. {
  129. HX_HuaXianStep = 7;
  130. HX_HXDelay = dwTickCount+HX_PARAM_DELAY_DOWNBACK;
  131. }
  132. else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_HX_LIMIT);
  133. break;
  134. case 7:
  135. if(dwTickCount >= HX_HXDelay)
  136. {
  137. HX_DOWN_VAVLE = 0;
  138. HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
  139. HX_HuaXianStep = 8;
  140. }
  141. break;
  142. case 8:
  143. if(!HX_DOWN_DOWN_IN)
  144. {
  145. HX_HuaXianStep = 9;
  146. HX_HXDelay = dwTickCount+HX_PARAM_DELAY_HXBACK;
  147. }
  148. else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_DOWN_ALARM);
  149. break;
  150. case 9:
  151. if(dwTickCount >= HX_HXDelay)
  152. {
  153. HX_HX_VAVLE = 0;
  154. cHuaXianTimesCnt++;
  155. if((cHuaXianTimesCnt >= HX_PARAM_HX_TIMES) || !bRunning)HX_GZ_VAVLE = 0;
  156. HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME;
  157. HX_HuaXianStep = 10;
  158. }
  159. else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_HX_LIMIT);
  160. break;
  161. case 10:
  162. if(HX_DOWN_UP_IN && HX_HX_ORIGIN_IN)
  163. {
  164. if((cHuaXianTimesCnt >= HX_PARAM_HX_TIMES) || !bRunning)
  165. {
  166. HX_HuaXianStep = 0;
  167. HX_HXDelay = dwTickCount;
  168. }
  169. else
  170. {
  171. HX_HuaXianStep = 1;
  172. HX_HXDelay = dwTickCount;
  173. }
  174. }
  175. else if(dwTickCount >= HX_HXDelay)
  176. {
  177. if(!HX_DOWN_UP_IN)
  178. HX_SetAlarmCode(HX_DW_UP_ALARM);
  179. else
  180. HX_SetAlarmCode(HX_HX_ORIGIN);
  181. }
  182. break;
  183. default:;
  184. }
  185. }
  186. void HuaXian_AutoAction(void)
  187. {
  188. if(bRunning)
  189. {
  190. switch(HX_AutoStep)
  191. {
  192. case 1:
  193. if(dwTickCount >= HX_AutoDelay)
  194. {
  195. if(HX_MotorStep == 0)
  196. {
  197. HX_MotorStep = 30;
  198. HX_AutoStep = 2;
  199. }
  200. }
  201. break;
  202. case 2:
  203. if(HX_MotorStep == 0)
  204. {
  205. HX_AutoStep = 3;
  206. }
  207. break;
  208. case 3:
  209. if(HX_HuaXianStep == 0)
  210. {
  211. cHuaXianTimesCnt = 0;
  212. HX_HuaXianStep = 1;
  213. HX_AutoStep = 4;
  214. }
  215. break;
  216. case 4:
  217. if(HX_HuaXianStep == 0)
  218. {
  219. HX_AutoStep = 5;
  220. }
  221. break;
  222. case 5:
  223. cZipCnt++;
  224. AddToTal(HX_TOTAL_ADDR);
  225. CalProSP(HX_PROSPEED_ADDR);
  226. if((GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) || SingOneFlg)
  227. {
  228. bRunning = 0;
  229. HX_AutoStep = 0;
  230. SingOneFlg = 0;
  231. if(GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) HX_SetAlarmCode(HX_TOTAL_ALARM);
  232. }
  233. else
  234. {
  235. HX_AutoStep = 1;
  236. HX_AutoDelay = dwTickCount + HX_PARAM_DELAY_DELAY_START;
  237. }
  238. break;
  239. }
  240. }
  241. }
  242. void HuaXian_StepCheckStart(void)
  243. {
  244. // 启动
  245. if((START_IN_UP) || bStart || HX_bSingle)
  246. {
  247. bStart = 0;
  248. if(!bRunning && (HX_AutoStep == 0))
  249. {
  250. if(!HX_DOWN_UP_IN)HX_SetAlarmCode(HX_DW_UP_ALARM);
  251. else if(!HX_HX_ORIGIN_IN)HX_SetAlarmCode(HX_HX_ORIGIN);
  252. else if(HX_GOUZHEN_IN)HX_SetAlarmCode(HX_GZ_ALARM);
  253. else if(HX_GZ_VAVLE)HX_SetAlarmCode(HX_GZ_OUT_ALARM);
  254. else if(GetAlarmCode(HX_ALARM_ADDR) != 0);
  255. else if(GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) HX_SetAlarmCode(HX_TOTAL_ALARM);
  256. else
  257. {
  258. bRunning = 1;
  259. HX_AutoStep = 1;
  260. if(HX_bSingle) SingOneFlg= 1;
  261. cZipCnt = 0;
  262. }
  263. }
  264. HX_bSingle = 0;
  265. }
  266. //停止
  267. if(STOP_IN_UP || bStop)
  268. {
  269. bStop = 0;
  270. if(bRunning)
  271. {
  272. bRunning = 0;
  273. HX_AutoStep = 0;
  274. HX_MotorStep = 0;
  275. HX_HuaXianStep=0;
  276. HX_AutoDelay = dwTickCount;
  277. HX_MotorDelay = dwTickCount;
  278. HX_HXDelay = dwTickCount;
  279. SingOneFlg = 0;
  280. AxisDecStop(X_AXIS);
  281. }
  282. else
  283. {
  284. bRunning = 0;
  285. HX_AutoStep = 0;
  286. HX_MotorStep = 0;
  287. HX_HuaXianStep=0;
  288. HX_AutoDelay = dwTickCount;
  289. HX_MotorDelay = dwTickCount;
  290. HX_HXDelay = dwTickCount;
  291. SingOneFlg = 0;
  292. HX_GZ_VAVLE = 0;
  293. HX_DOWN_VAVLE = 0;
  294. HX_HX_VAVLE = 0;
  295. HX_SZ_OUT = 1;
  296. AxisDecStop(X_AXIS);
  297. if(GetAlarmCode(HX_ALARM_ADDR) != 0)SetAlarmCode(HX_ALARM_ADDR,0);
  298. }
  299. }
  300. if(bAlarmStop)
  301. {
  302. bAlarmStop = 0;
  303. bRunning = 0;
  304. HX_AutoStep = 0;
  305. HX_MotorStep = 0;
  306. HX_HuaXianStep=0;
  307. HX_AutoDelay = dwTickCount;
  308. HX_MotorDelay = dwTickCount;
  309. HX_HXDelay = dwTickCount;
  310. SingOneFlg = 0;
  311. AxisDecStop(X_AXIS);
  312. }
  313. }
  314. //电机动作
  315. void HuaXian_Motor(void) //
  316. {
  317. switch(HX_MotorStep)
  318. {
  319. case 30:
  320. if(HX_SZ_OUT)
  321. {
  322. HX_SZ_OUT = 0;
  323. HX_MotorDelay = dwTickCount + 50;
  324. }
  325. HX_MotorStep = 31;
  326. break;
  327. case 31:
  328. if(dwTickCount>=HX_MotorDelay)
  329. {
  330. MoveAction_Const_AccDec(X_AXIS, HX_DIR_P,HX_PARAM_HIGH_SPEED,1,5,30);
  331. HX_MotorDelay = dwTickCount + HX_PARAM_MOTOR_ALARM_TIME;
  332. HX_MotorStep = 32;
  333. }
  334. break;
  335. case 32:
  336. if(HX_GOUZHEN_IN)
  337. {
  338. AxisEgmStop(X_AXIS);
  339. HX_MotorStep = 35;
  340. }
  341. if(HX_GUO_LIAN_IN_UP)
  342. {
  343. if(X_DRV)MoveChangSpeed(X_AXIS,HX_PARAM_LOW_SPEED);
  344. HX_MotorDelay = dwTickCount + HX_PARAM_DELAY_GZ;
  345. HX_MotorStep = 33;
  346. }
  347. else if(dwTickCount>=HX_MotorDelay)HX_SetAlarmCode(HX_NO_ZIPPER_ALARM);
  348. break;
  349. case 33:
  350. if(dwTickCount>=HX_MotorDelay)
  351. {
  352. HX_GZ_VAVLE = 1;
  353. HX_MotorDelay = dwTickCount + HX_PARAM_MOTOR_ALARM_TIME;
  354. HX_MotorStep = 34;
  355. }
  356. break;
  357. case 34:
  358. if(HX_GOUZHEN_IN)
  359. {
  360. AxisEgmStop(X_AXIS);
  361. HX_MotorStep = 35;
  362. }
  363. else if(dwTickCount>=HX_MotorDelay)HX_SetAlarmCode(HX_GZ_ALARM);
  364. break;
  365. case 35:
  366. if(!X_DRV)
  367. {
  368. AxisMovePos(X_AXIS,HX_PARAM_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  369. HX_MotorStep = 36;
  370. }
  371. break;
  372. case 36:
  373. if(!X_DRV)
  374. {
  375. HX_MotorDelay = dwTickCount;
  376. HX_MotorStep = 0;
  377. }
  378. break;
  379. }
  380. }
  381. #endif