GLJiaoYaDinCun.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. #include "global.h"
  2. #if CHANG_SHENG_GEI_LI_MACHINE==1
  3. unsigned char cSeBiaoStep = 0;
  4. unsigned long dwSeBiaoDelayCnt = 0;
  5. unsigned long JY_cycletime,JY_TDtime,JY_XiaCongtime;
  6. //
  7. typedef struct
  8. {
  9. unsigned short runstep;
  10. unsigned short count_mode;
  11. unsigned long up_time;
  12. unsigned long Down_time;
  13. unsigned long up_cycle_time;
  14. unsigned long down_cycle_time;
  15. unsigned long cycle_time;
  16. unsigned long prv_cycle_time;
  17. unsigned long up_pulse_time;
  18. unsigned long down_pulse_time;
  19. unsigned short prv_up_pulse_time;
  20. unsigned short prv_down_pulse_time;
  21. unsigned short countnum;
  22. unsigned short counterronum;
  23. } Exti_Count_t;
  24. Exti_Count_t Exti_Count;
  25. unsigned long GetToothNum(unsigned long zipper_length);
  26. unsigned long JYDC_ToothGetLength(unsigned long tooth_num);
  27. unsigned char cJHJYStopNum;
  28. unsigned char MotorRunLengthFlag=0;
  29. unsigned char kadaibegin = 0;
  30. #define CHUDAI_MAX_LENGTH 12000
  31. #define CHUDAI_MIN_LENGTH 100
  32. unsigned long Cur_chudai_length,Cur_DC_length,Cur_CC_length;
  33. unsigned long Cur_DC_Num=0;
  34. unsigned short JYDC_LinkStep,JYDC_STARTFLAG;
  35. unsigned short CCJ_STARTFLAG;
  36. unsigned long Cur_CC_Num=0;
  37. unsigned char Link_TB_FLG=0,Link_TB_Set=0;
  38. unsigned char link_DC_OVER_FLG;
  39. void JYDC_SetAlarmCode(unsigned alarm_code)
  40. {
  41. SetAlarmCode(JYDC_ALARM_ADDR,alarm_code);
  42. JYDC_bAlarmStop = 1;
  43. }
  44. void JYDC_DelayAction(void)
  45. {
  46. }
  47. void JYDC_LinkAction(void)
  48. {
  49. unsigned long length_tmp;
  50. if((JYDC_bRunning&&CCJ_bRunning))//联机
  51. {
  52. length_tmp=JYDC_ToothGetLength(JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY);
  53. Cur_DC_length=length_tmp*Cur_DC_Num+dwXRealPos;
  54. Cur_CC_length=length_tmp*Cur_CC_Num+dwYRealPos;
  55. Cur_chudai_length=CHUDAI_MAX_LENGTH+Cur_DC_length-Cur_CC_length;
  56. if(JYDC_STARTFLAG==0)link_DC_OVER_FLG=1;
  57. if(CCJ_STARTFLAG==0)Link_TB_Set=1;
  58. switch(JYDC_LinkStep)
  59. {
  60. case 1:
  61. if(JYDC_Wait_IN)//定寸到位,定寸停,启动下止,
  62. {
  63. JYDC_STARTFLAG=0;
  64. CCJ_STARTFLAG=1;
  65. JYDC_LinkStep=2;
  66. }
  67. else//否则启动定寸
  68. {
  69. JYDC_STARTFLAG=1;
  70. CCJ_STARTFLAG=0;
  71. JYDC_LinkStep=20;
  72. }
  73. Link_TB_FLG=0;
  74. //Link_TB_Set=0;
  75. break;
  76. case 2://离开定寸位置,
  77. if(!JYDC_Wait_IN)
  78. {
  79. Cur_DC_Num=0;
  80. Cur_CC_Num=0;
  81. JYDC_LinkStep=3;
  82. }
  83. break;
  84. case 3: //离开一定位置后,启动定寸
  85. if(Cur_CC_length>=4000)
  86. {
  87. JYDC_STARTFLAG=1; //启动定寸
  88. //Link_TB_Set=1;
  89. JYDC_LinkStep=4;
  90. //link_DC_OVER_FLG=1;
  91. Link_TB_Set=1;
  92. }
  93. break;
  94. case 4://同步
  95. Link_TB_FLG=1;
  96. //安全保护
  97. if(CCJ_Wait_IN)
  98. {
  99. if(CCJ_MotorStep == 2)
  100. {
  101. CCJ_AutoStep=2;
  102. CCJ_MotorStep=0;
  103. AxisEgmStop(Y_AXIS);
  104. }
  105. CCJ_STARTFLAG=0;
  106. JYDC_STARTFLAG=1;
  107. Cur_DC_Num=0;
  108. Link_TB_FLG=0;
  109. JYDC_LinkStep=20;
  110. }
  111. if(JYDC_Wait_IN)
  112. {
  113. if(JYDC_cMotorStep == 62)
  114. {
  115. JYDC_cMotorStep=65;
  116. }
  117. CCJ_STARTFLAG=1;
  118. JYDC_STARTFLAG=0;
  119. Cur_CC_Num=0;
  120. Link_TB_FLG=0;
  121. JYDC_LinkStep=2;
  122. }
  123. break;
  124. case 20:
  125. if(JYDC_Wait_IN)//||Cur_DC_length>=8000
  126. {
  127. Cur_DC_Num=0;
  128. Cur_CC_Num=0;
  129. if(JYDC_Wait_IN)
  130. {
  131. JYDC_LinkStep=21;
  132. JYDC_STARTFLAG=0;
  133. CCJ_STARTFLAG=1;
  134. }
  135. else
  136. {
  137. JYDC_LinkStep=3;
  138. CCJ_STARTFLAG=1;
  139. }
  140. }
  141. break;
  142. case 21:
  143. JYDC_LinkStep=2;
  144. break;
  145. }
  146. }
  147. else
  148. {
  149. JYDC_STARTFLAG=1;
  150. CCJ_STARTFLAG=1;
  151. link_DC_OVER_FLG=1;
  152. Link_TB_Set=1;
  153. //Link_TB_Set=1;
  154. Link_TB_FLG=1;
  155. if( CCJ_Wait_IN && CCJ_bRunning)
  156. {
  157. if(CCJ_MotorStep == 2)
  158. {
  159. CCJ_AutoStep = 0;
  160. CCJ_MotorStep = 0;
  161. AxisEgmStop(Y_AXIS);
  162. CCJ_bRunning = 0;
  163. }
  164. else
  165. CCJ_SingOneFlg = 1;
  166. }
  167. }
  168. }
  169. //模具选择
  170. void ModeSelect(void)
  171. {
  172. switch(MODE_SELECT) //模具选择
  173. {
  174. case 0: //3#模具
  175. JY_JIZHUN_CISHU = JY_JIZHUN_CISHU1;//基准长度对应齿数
  176. JY_JIZHUN_LEN = JY_JIZHUN_LEN1;//基准长度
  177. SET_DAOKOU_JY = SET_DAOKOU_JY1; //机械模具刀口
  178. break;
  179. case 1: //5#模具
  180. JY_JIZHUN_CISHU = JY_JIZHUN_CISHU2;//基准长度对应齿数
  181. JY_JIZHUN_LEN = JY_JIZHUN_LEN2;//基准长度
  182. SET_DAOKOU_JY = SET_DAOKOU_JY2; //机械模具刀口
  183. break;
  184. case 2: //8#模具
  185. JY_JIZHUN_CISHU = JY_JIZHUN_CISHU3;//基准长度对应齿数
  186. JY_JIZHUN_LEN = JY_JIZHUN_LEN3;//基准长度
  187. SET_DAOKOU_JY = SET_DAOKOU_JY3; //机械模具刀口
  188. break;
  189. default: //特殊模具
  190. JY_JIZHUN_CISHU = JY_JIZHUN_CISHU4;//基准长度对应齿数
  191. JY_JIZHUN_LEN = JY_JIZHUN_LEN4;//基准长度
  192. SET_DAOKOU_JY = SET_DAOKOU_JY4; //机械模具刀口
  193. break;
  194. }
  195. //基准齿数或长度为0时
  196. if((JY_JIZHUN_CISHU == 0) || (JY_JIZHUN_LEN == 0))
  197. {
  198. JY_JIZHUN_CISHU = 49;
  199. JY_JIZHUN_LEN = 1250;
  200. SET_DAOKOU_JY = 10;
  201. }
  202. }
  203. //手动动作
  204. void JYDC_ManualAction(void)
  205. {
  206. unsigned long ch;
  207. //产量清零
  208. if(bClearTotal)
  209. {
  210. bClearTotal = 0;
  211. ClrcToTal(JYDC_TOTAL_ADDR);
  212. }
  213. if(!JYDC_bRunning)
  214. {
  215. //齿数加
  216. if(JYDC_bAddTooth)
  217. {
  218. JYDC_bAddTooth = 0;
  219. //JYDC_PARAM_REVICHISHU++;
  220. ch = GetData32bits(SET_LEN_ADDR_JY);
  221. ch++;
  222. SetData32bits(SET_LEN_ADDR_JY,ch);
  223. }
  224. //齿数减
  225. if(JYDC_bDecTooth)
  226. {
  227. JYDC_bDecTooth = 0;
  228. //if(JYDC_PARAM_REVICHISHU)JYDC_PARAM_REVICHISHU--;
  229. ch = GetData32bits(SET_LEN_ADDR_JY);
  230. if(ch)
  231. ch--;
  232. SetData32bits(SET_LEN_ADDR_JY,ch);
  233. }
  234. //手动下冲
  235. if(JYDC_bManXiaChong || JYDC_ManXiaChong_UP)
  236. {
  237. JYDC_bManXiaChong = 0;
  238. if(JYDC_cXiaChongStep == 0)
  239. {
  240. JYDC_cXiaChongStep = 1;
  241. }
  242. }
  243. //手动锁齿
  244. if(JYDC_bManSuoChi)
  245. {
  246. JYDC_bManSuoChi = 0;
  247. JYDC_SuoChi_VAVLE = ~JYDC_SuoChi_VAVLE;
  248. }
  249. //手动吹气
  250. if(JYDC_bManChuiQi)
  251. {
  252. JYDC_bManChuiQi = 0;
  253. JYDC_ChuiQi_VAVLE = 1;
  254. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  255. }
  256. //改变尺寸重新算
  257. if(JYDC_bChangeLength)
  258. {
  259. JYDC_bChangeLength = 0;
  260. ModeSelect();
  261. SetData32bits(31,CalInch(SET_ZIPPER_LENGTH));
  262. SetData32bits(SET_LEN_ADDR_JY, GetToothNum(SET_ZIPPER_LENGTH)); //对就齿数
  263. }
  264. //输入英寸
  265. if(JYDC_bSetInch)
  266. {
  267. JYDC_bSetInch = 0;
  268. SetData32bits(SET_LEN_ADDR,CalLengthCM(SET_ZIPPER_LENGTH_INCH));
  269. JYDC_bChangeLength = 1;
  270. }
  271. //设定齿数算长度
  272. if(JYDC_bSetTooth)
  273. {
  274. JYDC_bSetTooth = 0;
  275. SetData32bits(SET_LEN_ADDR,JYDC_ToothGetLength(JYDC_PARAM_REVICHISHU));
  276. JYDC_bChangeLength = 1;
  277. }
  278. //铣齿电机
  279. if(JYDC_bManXiChiMotor)
  280. {
  281. JYDC_bManXiChiMotor = 0;
  282. JYDC_XiChi_MOTOR = ~JYDC_XiChi_MOTOR;
  283. }
  284. if(JYDC_bManMotor)
  285. {
  286. if(!X_DRV)
  287. {
  288. JYDC_SuoChi_VAVLE = 0;
  289. AxisContinueMove(X_AXIS,10,JHJY_DIR_P);
  290. }
  291. }
  292. else if(!JYDC_bManGuaChiMotor && !JYDC_cCSStopStep)
  293. {
  294. if(X_DRV)
  295. {
  296. AxisEgmStop(X_AXIS);
  297. }
  298. }
  299. }
  300. }
  301. //高速输入X30/X16定时器中断
  302. void JYDC_ExtiActionX30(unsigned char up_down)
  303. {
  304. static unsigned char jy_num=0;
  305. sw_timer_t now;
  306. sw_timer_now(&now);
  307. if(JYDC_bRunning)
  308. {
  309. //下降沿检测
  310. if((Exti_Count.runstep==1)&&(up_down&&Exti_Count.count_mode||!up_down&&!Exti_Count.count_mode))//第一次上升沿
  311. {
  312. Exti_Count.up_time=hw_read_us();
  313. Exti_Count.up_pulse_time=0;
  314. Exti_Count.up_cycle_time=0;
  315. Exti_Count.down_pulse_time=0;
  316. //Exti_Count.countnum++;
  317. Exti_Count.runstep=2;
  318. }
  319. else if((Exti_Count.runstep==2)&&(!up_down&&Exti_Count.count_mode||up_down&&!Exti_Count.count_mode))
  320. {
  321. Exti_Count.prv_up_pulse_time=Exti_Count.up_pulse_time;
  322. Exti_Count.up_pulse_time=hw_read_us()-Exti_Count.up_time;
  323. Exti_Count.Down_time=hw_read_us();
  324. if(Exti_Count.up_pulse_time>=JYDC_HLEVEL_TIME)//&&Exti_Count.up_pulse_time>=Exti_Count.prv_up_pulse_time/3)//高电平脉冲大于400us
  325. {
  326. Exti_Count.runstep=3;
  327. Exti_Count.countnum++;
  328. if(Exti_Count.countnum>=JYDC_CURJY_SET)
  329. {
  330. //AxisEgmStop(X_AXIS);
  331. DISPLAY_DATA2=jy_num;
  332. Exti_Count.runstep=0;
  333. jy_num=0;
  334. if(SET_STOP_PLUS)
  335. axis_plus_stop(axis_x,SET_STOP_PLUS);//多走几个脉冲停机
  336. else
  337. AxisEgmStop(X_AXIS);
  338. }
  339. }
  340. else
  341. {
  342. Exti_Count.counterronum++;
  343. //SingOneFlg=1;
  344. JYDC_Check_HERRO=1;
  345. DISPLAY_DATA1=Exti_Count.countnum;
  346. //DISPLAY_DATA3=Exti_Count.up_pulse_time;
  347. }
  348. if(jy_num>=80)jy_num=0;
  349. {
  350. if(!JYDC_Check_HL)
  351. user_datas[130+jy_num]=Exti_Count.up_pulse_time;
  352. else
  353. user_datas[130+jy_num]=Exti_Count.down_pulse_time;
  354. }
  355. jy_num++;
  356. }
  357. else if((Exti_Count.runstep==3)&&(up_down&&Exti_Count.count_mode||!up_down&&!Exti_Count.count_mode))
  358. {
  359. //周期,低电平脉宽
  360. Exti_Count.prv_down_pulse_time=Exti_Count.down_pulse_time;
  361. Exti_Count.down_pulse_time=hw_read_us()-Exti_Count.Down_time;
  362. //记录上升沿发生时间
  363. Exti_Count.up_time=hw_read_us();
  364. Exti_Count.runstep=2;
  365. //判断
  366. if(Exti_Count.down_pulse_time>=JYDC_LLEVEL_TIME)//&&Exti_Count.down_pulse_time>=Exti_Count.prv_down_pulse_time/3)//高电平脉冲大于400us
  367. {
  368. Exti_Count.runstep=2;
  369. }
  370. else
  371. {
  372. Exti_Count.counterronum++;
  373. JYDC_Check_LERRO=1;
  374. DISPLAY_DATA1=Exti_Count.countnum;
  375. }
  376. }
  377. }
  378. else
  379. {
  380. if(up_down)//上升沿
  381. {
  382. //记录当前值周期,下降沿计数是,才有的上次的下降沿-本次的下降沿
  383. Exti_Count.up_cycle_time=hw_read_us()-Exti_Count.up_time;
  384. if(Exti_Count.up_cycle_time>10000)Exti_Count.up_cycle_time=10000;
  385. Exti_Count.up_time=hw_read_us();
  386. }
  387. else //下降沿
  388. {
  389. //记录当前值周期,下降沿计数是,才有的上次的下降沿-本次的下降沿
  390. Exti_Count.down_cycle_time=hw_read_us()-Exti_Count.Down_time;
  391. if(Exti_Count.down_cycle_time>10000)Exti_Count.down_cycle_time=10000;
  392. Exti_Count.Down_time=hw_read_us();
  393. }
  394. if(Exti_Count.count_mode)Exti_Count.cycle_time=Exti_Count.up_cycle_time;
  395. else Exti_Count.cycle_time=Exti_Count.down_cycle_time;
  396. if((Exti_Count.count_mode==0&&up_down||Exti_Count.count_mode&&up_down==0)){
  397. if((Exti_Count.cycle_time>=10000))Exti_Count.countnum++;
  398. }
  399. }
  400. }
  401. int GetJYChishu(void)
  402. {
  403. return Exti_Count.countnum;
  404. }
  405. void SetJYChishu(int num)
  406. {
  407. Exti_Count.countnum=num;
  408. }
  409. //高速输入X31/X17外部色标信号中断
  410. void JYDC_ExtiActionX31(void)
  411. {
  412. }
  413. //输入拉链长度返回所输入拉链长度所对应的齿数
  414. unsigned long GetToothNum(unsigned long zipper_length)
  415. {
  416. float length_buff1,tooth_buff,length_buff2;
  417. length_buff1 = zipper_length;
  418. tooth_buff = JY_JIZHUN_CISHU;
  419. length_buff2 = JY_JIZHUN_LEN;
  420. return (unsigned long)round(length_buff1 * tooth_buff / length_buff2);
  421. }
  422. //输入齿数返回拉链长度
  423. unsigned long JYDC_ToothGetLength(unsigned long tooth_num)
  424. {
  425. float toothbuff1,tooth_buff,length_buff2;
  426. toothbuff1 = tooth_num;
  427. tooth_buff = JY_JIZHUN_CISHU;
  428. length_buff2 = JY_JIZHUN_LEN*10;
  429. return (unsigned long)round((toothbuff1 * length_buff2 / tooth_buff));
  430. }
  431. //吹气动作
  432. void JYDC_ChuiQi(void)
  433. {
  434. if(JYDC_XiaChong_IN_DW)
  435. {
  436. JYDC_ChuiQi_VAVLE = 1;
  437. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  438. }
  439. if(JYDC_ChuiQi_VAVLE)
  440. {
  441. if(JYDC_ChuiQiDelay < dwTickCount)JYDC_ChuiQi_VAVLE = 0;
  442. }
  443. if(JYDC_XiChiChuiQi_VAVLE)
  444. {
  445. if(JYDC_XiChiChuiQiDelay < dwTickCount)JYDC_XiChiChuiQi_VAVLE = 0;
  446. }
  447. }
  448. //下冲动作
  449. void JYDC_XiaChong(void)
  450. {
  451. switch(JYDC_cXiaChongStep)
  452. {
  453. case 1:
  454. cJHJYStopNum = 0;
  455. JYDC_ShaChe_VAVLE = 0;
  456. JYDC_SuoChi_VAVLE = 1; //手动下冲锁齿输出
  457. if(JYDC_bRunning)
  458. JYDC_XiaChongDelay = dwTickCount + XIACONG_DELAY_TIME + 5;
  459. else
  460. JYDC_XiaChongDelay = dwTickCount + 15;
  461. JYDC_cXiaChongStep = 2;
  462. break;
  463. case 2:
  464. if(dwTickCount >= JYDC_XiaChongDelay)
  465. {
  466. JYDC_XiaChong_MOTOR = 1;
  467. if(JYDC_XiaChong_IN) //如是在感应上就先走下降延
  468. {
  469. JYDC_cXiaChongStep = 3;
  470. JYDC_XiaChongDelay = dwTickCount + 3000;
  471. }
  472. else
  473. {
  474. JYDC_cXiaChongStep = 4;
  475. JYDC_XiaChongDelay = dwTickCount + 35;
  476. }
  477. }
  478. break;
  479. case 3:
  480. if(JYDC_XiaChong_IN_DW)
  481. {
  482. JYDC_cXiaChongStep = 4;
  483. JYDC_XiaChongDelay = dwTickCount + 35;
  484. }
  485. else if(dwTickCount >= JYDC_XiaChongDelay)//下冲警告
  486. {
  487. JYDC_SetAlarmCode(JYDC_XIACHONG_ARRIVE_ALARM);
  488. JYDC_XiaChong_MOTOR = 0;
  489. JYDC_cXiaChongStep = 6;
  490. }
  491. break;
  492. case 4:
  493. if(dwTickCount >= JYDC_XiaChongDelay)
  494. {
  495. JYDC_cXiaChongStep = 5;
  496. JYDC_XiaChongDelay = dwTickCount + 3000;//JYDC_PARAM_XC_ALARM_TIME;
  497. }
  498. break;
  499. case 5:
  500. if(JYDC_XiaChong_IN_UP)
  501. {
  502. JYDC_XiaChong_MOTOR = 0;
  503. JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_SHACHE_DELAY_TIME;//延时刹车
  504. JYDC_cXiaChongStep = 6;
  505. }
  506. else if(dwTickCount >= JYDC_XiaChongDelay)//下冲警告
  507. {
  508. JYDC_SetAlarmCode(JYDC_XIACHONG_ARRIVE_ALARM);
  509. JYDC_XiaChong_MOTOR = 0;
  510. JYDC_cXiaChongStep = 6;
  511. }
  512. break;
  513. case 6:
  514. if(dwTickCount >= JYDC_XiaChongDelay) //延时刹车
  515. {
  516. JYDC_ShaChe_VAVLE = 1;
  517. JYDC_cXiaChongStep = 0;
  518. //齿数清零
  519. axispostion=0;
  520. SetPos(X_AXIS,0);
  521. SetJYChishu(0);
  522. if(!JYDC_bRunning)
  523. {
  524. SetPos(X_AXIS, 0);
  525. }
  526. JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_SHACHE_TIME;
  527. }
  528. break;
  529. }
  530. if(JYDC_ShaChe_VAVLE && (dwTickCount >= JYDC_XiaChongDelay))
  531. {
  532. JYDC_ShaChe_VAVLE = 0;
  533. }
  534. }
  535. //启动停止故障停止动作
  536. void JYDC_StartStopAction(void)
  537. {
  538. static unsigned long long_time_delay,Dw_StopInTime;
  539. if((JYDC_START_IN_UP || JYDC_bStart||JYDC_bSingleONE) && !JYDC_bRunning && (JYDC_cAutoStep ==0))
  540. {
  541. //产量对比
  542. if(JYDC_bSingleONE)SingOneFlg=1;
  543. JYDC_bSingleONE=0;
  544. if(GetTotal(JYDC_TOTAL_ADDR) >= JYDC_SET_TOTAL)
  545. JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  546. else
  547. {
  548. JYDC_cAutoStep = 1;
  549. JYDC_bRunning = 1;
  550. JYDC_SuoChi_VAVLE = 0;
  551. JYDC_cAutoDelay = dwTickCount + 300;
  552. cJHJYStopNum = 0;
  553. MotorRunLengthFlag=0;
  554. kadaibegin=0;
  555. JYDC_cCSStopStep = 0;
  556. Exti_Count.counterronum=0;
  557. JYDC_LinkStep=1;
  558. link_DC_OVER_FLG=1;
  559. SingOneFlg=0;
  560. }
  561. JYDC_bStart = 0;
  562. }
  563. //卡带
  564. if(JYDC_KaDai_IN)
  565. {
  566. if(!X_DRV)
  567. {
  568. JYDC_SuoChi_VAVLE = 1;
  569. JYDC_bRunning = 0;
  570. JYDC_cAutoStep = 0;
  571. SetAlarmCode(JYDC_ALARM_ADDR,JYDC_KADAI_ALARM);
  572. }
  573. else
  574. {
  575. if(!JYDC_cCSStopStep)//在运行过程中,卡带的动作?
  576. {
  577. JYDC_cCSStopStep = 1;
  578. }
  579. }
  580. }
  581. if(JYDC_STOP_IN_UP || JYDC_bStop)
  582. {
  583. JYDC_bStop = 0;
  584. Dw_StopInTime = dwTickCount + 70;
  585. cJHJYStopNum++;
  586. //吹气
  587. JYDC_ChuiQi_VAVLE = 1;
  588. JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
  589. JYDC_cAutoDelay = dwTickCount;
  590. //停机
  591. //JYDC_bRunning = 0;
  592. JYDC_cAutoStep = 0;
  593. if(X_DRV)//在运行过程中
  594. {
  595. if(cJHJYStopNum >= 2)
  596. {
  597. JYDC_cCSStopStep = 0;
  598. JYDC_bRunning = 0;
  599. AxisEgmStop(X_AXIS);
  600. JYDC_cAutoStep = 0;
  601. JYDC_cMotorStep=0;
  602. }
  603. else
  604. {
  605. JYDC_cCSStopStep = 1;
  606. }
  607. }
  608. else
  609. {
  610. SingOneFlg = 1;
  611. if(cJHJYStopNum >= 2)
  612. {
  613. JYDC_SuoChi_VAVLE = 0;
  614. JYDC_bRunning = 0;
  615. AxisEgmStop(X_AXIS);
  616. JYDC_cAutoStep = 0;
  617. JYDC_cMotorStep=0;
  618. JYDC_cCSStopStep = 0;
  619. }
  620. }
  621. JYDC_bManGuaChiMotor = 0;
  622. JYDC_XiChi_MOTOR=0;
  623. }
  624. if(JYDC_STOP_IN_DW)Dw_StopInTime = dwTickCount + 70;
  625. //长时间按停止时锁带关
  626. if(JYDC_STOP_IN)
  627. {
  628. if(dwTickCount>=long_time_delay)
  629. {
  630. JYDC_SuoChi_VAVLE = 0;
  631. AxisEgmStop(X_AXIS);
  632. JYDC_cCSStopStep = 0;
  633. }
  634. }
  635. else
  636. {
  637. long_time_delay = dwTickCount+1300;
  638. }
  639. if(JYDC_bAlarmStop)
  640. {
  641. JYDC_bAlarmStop = 0;
  642. JYDC_cAutoStep= 0;
  643. if(X_DRV)//在运行过程中
  644. {
  645. JYDC_cCSStopStep = 1;
  646. }
  647. else
  648. {
  649. JYDC_bRunning=0;
  650. JYDC_SuoChi_VAVLE = 1;
  651. }
  652. JYDC_cAutoDelay = dwTickCount;
  653. SingOneFlg = 0;
  654. JYDC_bManGuaChiMotor = 0;
  655. JYDC_XiChi_MOTOR=0;
  656. }
  657. }
  658. unsigned char CheckMaxLowSpeed(unsigned char cspeed)
  659. {
  660. if(cspeed > JYDC_PARAM_SET_SPEED)
  661. return JYDC_PARAM_SET_SPEED;
  662. else
  663. return cspeed;
  664. }
  665. //自动运行动作
  666. void JYDC_AutoAction(void)
  667. {
  668. DISPLAY_DATA0 = Link_TB_Set;//Exti_Count.counterronum;
  669. //DISPLAY_DATA1 = JYDC_cMotorStep;
  670. //DISPLAY_DATA2 = JYDC_cAutoStep;
  671. //DISPLAY_DATA3 = JYDC_cXiaChongStep;
  672. //DISPLAY_DATA4 = JY_TDtime;//JYDC_cCheckLengthOk;
  673. DISPLAY_DATA5 = JYDC_cMotorStep;//JYDC_cValveStep;
  674. DISPLAY_DATA6 = dwXRealPos;
  675. //DISPLAY_DATA6 = JYDC_LinkStep;
  676. //DISPLAY_DATA7= link_DC_OVER_FLG;//JY_XiaCongtime;
  677. //铣齿电机开关
  678. if(JYDC_bRunning)
  679. {
  680. switch(JYDC_cAutoStep)
  681. {
  682. case 0:
  683. break;
  684. case 1:
  685. if(dwTickCount >= JYDC_cAutoDelay)
  686. {
  687. JY_cycletime=dwTickCount;
  688. JYDC_CRUKONGWEILENGTH=0;
  689. JYDC_cAutoStep = 2;
  690. }
  691. break;
  692. case 2://拖带
  693. if(dwTickCount >= JYDC_cAutoDelay)//左右分针要退到位,过链到位要离开
  694. {
  695. if(JYDC_XICHI_MOTOR_MODE)
  696. JYDC_XiChi_MOTOR = 1;
  697. else
  698. JYDC_XiChi_MOTOR = 0;
  699. JYDC_cAutoStep = 3;
  700. JY_TDtime=dwTickCount;
  701. switch(JYDC_DC_MODE)
  702. {
  703. case JYDC_DC_GD_MODE:JYDC_cMotorStep = 60; break; //光电
  704. case JYDC_DC_SB_MODE:JYDC_cMotorStep = 20; break; //色标
  705. case JYDC_DC_GZ_MODE:JYDC_cMotorStep = 1; break; //钩针
  706. }
  707. }
  708. break;
  709. case 3://拖带完成,延时锁齿
  710. if(JYDC_cMotorStep == 0)
  711. {
  712. JY_TDtime=dwTickCount-JY_TDtime;
  713. JYDC_cAutoDelay = dwTickCount + 0;
  714. JYDC_cAutoStep = 4;
  715. }
  716. break;
  717. case 4://锁齿
  718. if(dwTickCount >= JYDC_cAutoDelay)
  719. {
  720. JYDC_SuoChi_VAVLE=1;
  721. Exti_Count.runstep=0;
  722. JYDC_cAutoStep = 5;
  723. }
  724. break;
  725. case 5://下冲
  726. if((dwTickCount >= JYDC_cAutoDelay))
  727. {
  728. JY_TDtime=dwTickCount-JY_TDtime;
  729. if(JYDC_cXiaChongStep == 0)
  730. {
  731. if(!JYDC_bTest)JYDC_cXiaChongStep = 1;
  732. else
  733. {
  734. JYDC_cXiaChongStep = 0;
  735. axispostion=0;
  736. SetPos(X_AXIS,0);
  737. SetJYChishu(0);
  738. }
  739. JYDC_cAutoStep = 6;
  740. }
  741. }
  742. break;
  743. case 6: //下冲已完成,判断除齿长度,是否多刀
  744. if((JYDC_cXiaChongStep == 0))
  745. {
  746. JY_XiaCongtime=dwTickCount-JY_XiaCongtime;
  747. //除齿判断
  748. if(JYDC_CRUKONGWEILENGTH>=JYDC_PARAM_KONG_WEI_LENGTH)
  749. {
  750. JYDC_CRUKONGWEILENGTH=0;
  751. if(JYDC_cGZDW_CNT < 3)JYDC_cGZDW_CNT++;
  752. AddToTal(JYDC_TOTAL_ADDR); //计数增加和保存
  753. CalProSP(JYDC_PROSPEED_ADDR);
  754. JYDC_cAutoStep = 7;
  755. }
  756. else
  757. {
  758. JYDC_cAutoStep = 2;
  759. }
  760. }
  761. break;
  762. case 7:
  763. if(GetTotal(JYDC_TOTAL_ADDR) >= JYDC_SET_TOTAL)
  764. {
  765. JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
  766. CCJ_SingOneFlg=1;
  767. }
  768. JYDC_cAutoStep = 8;
  769. break;
  770. case 8:
  771. JYDC_cAutoDelay = dwTickCount + 0;//JYDC_PARAM_CYCLE_DELAY;
  772. JYDC_cAutoStep = 1;
  773. link_DC_OVER_FLG=1;
  774. JY_cycletime=dwTickCount-JY_cycletime;
  775. if(SingOneFlg||JYDC_bTest)
  776. {
  777. JYDC_cGZDW_CNT=0;
  778. dwZipCnt = 0;
  779. SingOneFlg = 0;
  780. JYDC_cAutoStep = 0;
  781. JYDC_bRunning = 0;
  782. JYDC_XiChi_MOTOR=0;
  783. }
  784. break;
  785. }
  786. }
  787. }
  788. void JYDC_Motor(void)
  789. {
  790. static unsigned long zipper_length,low_length;
  791. //实时显示行程总长
  792. //JYDC_All_LENTH = JYDC_SET_ZIPPER_LENGTH + JYDC_SET_REVISE_ZIPPER_LENGTH + JYDC_PARAM_KONG_WEI_LENGTH;
  793. dwXRealPos = GetPos(X_AXIS);
  794. JYDC_dwEncPos = GetJYChishu();//获取胶牙齿数
  795. axis_position_encode=(long)(JYDC_ToothGetLength(JYDC_dwEncPos)*XGearRatio);//(long)(JYDC_dwEncPos*XGearRatio); //由齿数获取长度
  796. switch(JYDC_cMotorStep)
  797. {
  798. case 0:
  799. break;
  800. case 1:
  801. break;
  802. case 2:
  803. break;
  804. case 3:
  805. break;
  806. case 4:
  807. break;
  808. case 5:
  809. break;
  810. case 8:
  811. break;
  812. case 9:
  813. break;
  814. case 10:
  815. break;
  816. case 11:
  817. break;
  818. case 20:
  819. break;
  820. case 21:
  821. break;
  822. case 22:
  823. break;
  824. case 60:
  825. if(JYDC_STARTFLAG&&(Link_TB_Set||!CCJ_bRunning)&& (!JYDC_Wait_IN||!CCJ_bRunning))
  826. {
  827. Link_TB_Set=0;
  828. if(JYDC_dwEncPos>=JYDC_PARAM_REVICHISHU+SET_DAOKOU_JY&&JYDC_CRUKONGWEILENGTH==0)
  829. {
  830. JYDC_cMotorStep = 64;
  831. JYDC_CRUKONGWEILENGTH=SET_DAOKOU_JY;
  832. JYDC_cMotorDelay = dwTickCount + NO_TOOTHCOUT_TIME;
  833. }
  834. else
  835. {
  836. JYDC_cMotorStep = 61;
  837. JYDC_SuoChi_VAVLE = 0; //锁齿阀关
  838. JYDC_cAutoDelay = dwTickCount + 40;
  839. //if(jydc_use_x30)
  840. // EXTI30Enable();
  841. //if(jydc_use_x20)
  842. // EXTI20Enable();
  843. }
  844. }
  845. break;
  846. case 61:
  847. if((dwTickCount >= JYDC_cMotorDelay))
  848. {
  849. if(JYDC_CRUKONGWEILENGTH==0)
  850. {
  851. zipper_length =JYDC_ToothGetLength(JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY-JYDC_dwEncPos);
  852. JYDC_CURJY_SET=JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY-JYDC_dwEncPos;
  853. //DISPLAY_DATA0=zipper_length;
  854. //DISPLAY_DATA1=JYDC_PARAM_REVICHISHU;
  855. //DISPLAY_DATA2=SET_DAOKOU_JY;
  856. JYDC_CRUKONGWEILENGTH=SET_DAOKOU_JY;
  857. }
  858. else if(JYDC_PARAM_KONG_WEI_LENGTH-JYDC_CRUKONGWEILENGTH>=SET_DAOKOU_JY)
  859. {
  860. zipper_length=JYDC_ToothGetLength(SET_DAOKOU_JY);
  861. JYDC_CURJY_SET=SET_DAOKOU_JY;
  862. JYDC_CRUKONGWEILENGTH+=SET_DAOKOU_JY;
  863. }
  864. else
  865. {
  866. zipper_length=JYDC_ToothGetLength(JYDC_PARAM_KONG_WEI_LENGTH-JYDC_CRUKONGWEILENGTH);
  867. JYDC_CURJY_SET=JYDC_PARAM_KONG_WEI_LENGTH-JYDC_CRUKONGWEILENGTH;
  868. JYDC_CRUKONGWEILENGTH+=JYDC_PARAM_KONG_WEI_LENGTH-JYDC_CRUKONGWEILENGTH;
  869. }
  870. low_length=JYDC_ToothGetLength(JYDC_PARAM_LOW_LENGTH);
  871. if(zipper_length<1400)
  872. {
  873. AxisMovePosAccDecNotStop(X_AXIS,JYDC_PARAM_SET_SPEED*3/4+600,zipper_length,1200,JYDC_PARAM_LOW_SPEED,150,150,low_length);
  874. }
  875. else if(zipper_length<2400)
  876. {
  877. AxisMovePosAccDecNotStop(X_AXIS,JYDC_PARAM_SET_SPEED*7/8,zipper_length,1200,JYDC_PARAM_LOW_SPEED,150,150,low_length);
  878. }
  879. else
  880. {
  881. AxisMovePosAccDecNotStop(X_AXIS,JYDC_PARAM_SET_SPEED,zipper_length,1200,JYDC_PARAM_LOW_SPEED,150,150,low_length);
  882. }
  883. DISPLAY_DATA7=low_length;
  884. JYDC_cMotorDelay = dwTickCount + NO_TOOTHCOUT_TIME;
  885. //吹气
  886. JYDC_XiChiChuiQi_VAVLE = 1;
  887. JYDC_XiChiChuiQiDelay = dwTickCount + 200;
  888. JYDC_cMotorStep = 64;
  889. Exti_Count.runstep=1;
  890. Exti_Count.countnum=0;
  891. }
  892. break;
  893. case 64:
  894. if(!X_DRV)
  895. {
  896. JYDC_cMotorStep = 0;
  897. Cur_DC_Num++;
  898. Exti_Count.runstep=0;
  899. JYDC_cMotorDelay = dwTickCount;
  900. }
  901. else if(dwTickCount >= JYDC_cMotorDelay)
  902. {
  903. JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
  904. AxisEgmStop(X_AXIS);
  905. }
  906. break;
  907. case 65:
  908. if(dwXRealPos<=zipper_length-500)//剩余长度小于5CM
  909. {
  910. AxisMovePosAccDec(X_AXIS,1000,300,600,600,20,20,0);
  911. JYDC_cMotorStep = 66;
  912. }
  913. else
  914. {
  915. JYDC_cMotorStep = 62;
  916. }
  917. break;
  918. case 66:
  919. if(!X_DRV)
  920. {
  921. JYDC_cAutoStep=2;
  922. JYDC_cMotorStep=0;
  923. JYDC_CRUKONGWEILENGTH=0;
  924. }
  925. break;
  926. }
  927. }
  928. //按齿数暂停
  929. void JYDC_ChiShuStop(void)
  930. {
  931. switch(JYDC_cCSStopStep)
  932. {
  933. case 1:
  934. JYDC_cCSStopStep = 2;
  935. AxisContinueMoveChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED,JYDC_PARAM_LOW_SPEED/2,20,40);
  936. break;
  937. case 2:
  938. if(GetCurSpeed(X_AXIS) <= (JYDC_PARAM_LOW_SPEED*3/2))
  939. {
  940. JYDC_cCSStopStep = 3;
  941. if(GetJYChishu() + 3 < JYDC_CURJY_SET)JYDC_CURJY_SET = GetJYChishu() + 3;
  942. JYDC_ShuChiStopDelay = dwTickCount + NO_TOOTHCOUT_TIME;
  943. }
  944. break;
  945. case 3:
  946. if(!X_DRV)//(GetCurSpeed(X_AXIS)<= (JYDC_PARAM_LOW_SPEED + 50)) &&
  947. {
  948. JYDC_cMotorDelay = dwTickCount + 100;
  949. JYDC_cCSStopStep = 4;
  950. }
  951. else if(dwTickCount >= JYDC_ShuChiStopDelay)
  952. {
  953. JYDC_bRunning = 0;
  954. JYDC_cCSStopStep = 0;
  955. AxisEgmStop(X_AXIS);
  956. }
  957. break;
  958. case 4:
  959. if(dwTickCount>=JYDC_cMotorDelay)
  960. {
  961. JYDC_cCSStopStep = 0;
  962. JYDC_bRunning = 0;
  963. JYDC_SuoChi_VAVLE = 1;
  964. }
  965. break;
  966. }
  967. }
  968. void JYDC_InitAction(void)
  969. {
  970. float length_buff,pulse_buff;
  971. length_buff = JYDC_CYCLE_LENGTH;
  972. pulse_buff = JYDC_CYCLE_PULSE;
  973. XGearRatio = pulse_buff/length_buff;
  974. if(MODE_SELECT > 3)
  975. MODE_SELECT = 0;
  976. ModeSelect();
  977. //当前齿数
  978. SetData32bits(CUR_LEN_ADDR_JY,0);
  979. cJHJYStopNum = 0;
  980. SetDirReverse(X_AXIS, 0);
  981. //EXTI30Enable();
  982. EXTI20Enable();
  983. //光电方式传感器采用类似编码器方式进行数齿
  984. // if(JYDC_DC_MODE == JYDC_DC_GD_MODE)
  985. // axis_set_parameter(axis_x,AXIS_USE_ENCODE,1);
  986. // else
  987. axis_set_parameter(axis_x,AXIS_USE_ENCODE,0);
  988. }
  989. //胶牙定寸动作
  990. void JYDC_Action(void)
  991. {
  992. Exti_Count.count_mode=user_datas[34];
  993. JYDC_ManualAction();
  994. JYDC_ChuiQi();
  995. JYDC_XiaChong();
  996. JYDC_StartStopAction();
  997. JYDC_AutoAction();
  998. JYDC_Motor();
  999. JYDC_ChiShuStop();
  1000. JYDC_LinkAction();
  1001. SetData32bits(CUR_LEN_ADDR_JY,JYDC_dwEncPos); //当前齿数给值
  1002. }
  1003. #endif