12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- #include "global.h"
- #if CHANG_SHENG_GEI_LI_MACHINE==1
- unsigned char cSeBiaoStep = 0;
- unsigned long dwSeBiaoDelayCnt = 0;
- unsigned long JY_cycletime,JY_TDtime,JY_XiaCongtime;
- //
- typedef struct
- {
- unsigned short runstep;
- unsigned short count_mode;
- unsigned long up_time;
- unsigned long Down_time;
- unsigned long up_cycle_time;
- unsigned long down_cycle_time;
- unsigned long cycle_time;
- unsigned long prv_cycle_time;
- unsigned long up_pulse_time;
- unsigned long down_pulse_time;
- unsigned short prv_up_pulse_time;
- unsigned short prv_down_pulse_time;
- unsigned short countnum;
- unsigned short counterronum;
- } Exti_Count_t;
- Exti_Count_t Exti_Count;
- unsigned long GetToothNum(unsigned long zipper_length);
- unsigned long JYDC_ToothGetLength(unsigned long tooth_num);
- unsigned char cJHJYStopNum;
- unsigned char MotorRunLengthFlag=0;
- unsigned char kadaibegin = 0;
- #define CHUDAI_MAX_LENGTH 12000
- #define CHUDAI_MIN_LENGTH 100
- unsigned long Cur_chudai_length,Cur_DC_length,Cur_CC_length;
- unsigned long Cur_DC_Num=0;
- unsigned short JYDC_LinkStep,JYDC_STARTFLAG;
- unsigned short CCJ_STARTFLAG;
- unsigned long Cur_CC_Num=0;
- unsigned char Link_TB_FLG=0,Link_TB_Set=0;
- unsigned char link_DC_OVER_FLG;
- void JYDC_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(JYDC_ALARM_ADDR,alarm_code);
- JYDC_bAlarmStop = 1;
- }
- void JYDC_DelayAction(void)
- {
- }
- void JYDC_LinkAction(void)
- {
- unsigned long length_tmp;
- if((JYDC_bRunning&&CCJ_bRunning))//联机
- {
- length_tmp=JYDC_ToothGetLength(JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY);
- Cur_DC_length=length_tmp*Cur_DC_Num+dwXRealPos;
- Cur_CC_length=length_tmp*Cur_CC_Num+dwYRealPos;
- Cur_chudai_length=CHUDAI_MAX_LENGTH+Cur_DC_length-Cur_CC_length;
- if(JYDC_STARTFLAG==0)link_DC_OVER_FLG=1;
- if(CCJ_STARTFLAG==0)Link_TB_Set=1;
- switch(JYDC_LinkStep)
- {
- case 1:
- if(JYDC_Wait_IN)//定寸到位,定寸停,启动下止,
- {
- JYDC_STARTFLAG=0;
- CCJ_STARTFLAG=1;
- JYDC_LinkStep=2;
- }
- else//否则启动定寸
- {
- JYDC_STARTFLAG=1;
- CCJ_STARTFLAG=0;
- JYDC_LinkStep=20;
- }
- Link_TB_FLG=0;
- //Link_TB_Set=0;
- break;
- case 2://离开定寸位置,
- if(!JYDC_Wait_IN)
- {
- Cur_DC_Num=0;
- Cur_CC_Num=0;
- JYDC_LinkStep=3;
- }
- break;
- case 3: //离开一定位置后,启动定寸
- if(Cur_CC_length>=4000)
- {
- JYDC_STARTFLAG=1; //启动定寸
- //Link_TB_Set=1;
- JYDC_LinkStep=4;
- //link_DC_OVER_FLG=1;
- Link_TB_Set=1;
- }
- break;
- case 4://同步
- Link_TB_FLG=1;
- //安全保护
- if(CCJ_Wait_IN)
- {
- if(CCJ_MotorStep == 2)
- {
- CCJ_AutoStep=2;
- CCJ_MotorStep=0;
- AxisEgmStop(Y_AXIS);
- }
- CCJ_STARTFLAG=0;
- JYDC_STARTFLAG=1;
- Cur_DC_Num=0;
- Link_TB_FLG=0;
- JYDC_LinkStep=20;
- }
- if(JYDC_Wait_IN)
- {
- if(JYDC_cMotorStep == 62)
- {
- JYDC_cMotorStep=65;
- }
- CCJ_STARTFLAG=1;
- JYDC_STARTFLAG=0;
-
- Cur_CC_Num=0;
- Link_TB_FLG=0;
- JYDC_LinkStep=2;
- }
- break;
- case 20:
- if(JYDC_Wait_IN)//||Cur_DC_length>=8000
- {
- Cur_DC_Num=0;
- Cur_CC_Num=0;
- if(JYDC_Wait_IN)
- {
- JYDC_LinkStep=21;
- JYDC_STARTFLAG=0;
- CCJ_STARTFLAG=1;
- }
- else
- {
- JYDC_LinkStep=3;
- CCJ_STARTFLAG=1;
- }
- }
- break;
- case 21:
- JYDC_LinkStep=2;
- break;
-
- }
- }
- else
- {
- JYDC_STARTFLAG=1;
- CCJ_STARTFLAG=1;
- link_DC_OVER_FLG=1;
- Link_TB_Set=1;
- //Link_TB_Set=1;
- Link_TB_FLG=1;
-
- if( CCJ_Wait_IN && CCJ_bRunning)
- {
- if(CCJ_MotorStep == 2)
- {
- CCJ_AutoStep = 0;
- CCJ_MotorStep = 0;
- AxisEgmStop(Y_AXIS);
- CCJ_bRunning = 0;
- }
- else
- CCJ_SingOneFlg = 1;
- }
- }
-
- }
- //模具选择
- void ModeSelect(void)
- {
- switch(MODE_SELECT) //模具选择
- {
- case 0: //3#模具
- JY_JIZHUN_CISHU = JY_JIZHUN_CISHU1;//基准长度对应齿数
- JY_JIZHUN_LEN = JY_JIZHUN_LEN1;//基准长度
- SET_DAOKOU_JY = SET_DAOKOU_JY1; //机械模具刀口
- break;
- case 1: //5#模具
- JY_JIZHUN_CISHU = JY_JIZHUN_CISHU2;//基准长度对应齿数
- JY_JIZHUN_LEN = JY_JIZHUN_LEN2;//基准长度
- SET_DAOKOU_JY = SET_DAOKOU_JY2; //机械模具刀口
- break;
- case 2: //8#模具
- JY_JIZHUN_CISHU = JY_JIZHUN_CISHU3;//基准长度对应齿数
- JY_JIZHUN_LEN = JY_JIZHUN_LEN3;//基准长度
- SET_DAOKOU_JY = SET_DAOKOU_JY3; //机械模具刀口
- break;
- default: //特殊模具
- JY_JIZHUN_CISHU = JY_JIZHUN_CISHU4;//基准长度对应齿数
- JY_JIZHUN_LEN = JY_JIZHUN_LEN4;//基准长度
- SET_DAOKOU_JY = SET_DAOKOU_JY4; //机械模具刀口
-
- break;
- }
- //基准齿数或长度为0时
- if((JY_JIZHUN_CISHU == 0) || (JY_JIZHUN_LEN == 0))
- {
- JY_JIZHUN_CISHU = 49;
- JY_JIZHUN_LEN = 1250;
- SET_DAOKOU_JY = 10;
- }
- }
- //手动动作
- void JYDC_ManualAction(void)
- {
- unsigned long ch;
- //产量清零
- if(bClearTotal)
- {
- bClearTotal = 0;
- ClrcToTal(JYDC_TOTAL_ADDR);
- }
- if(!JYDC_bRunning)
- {
- //齿数加
- if(JYDC_bAddTooth)
- {
- JYDC_bAddTooth = 0;
- //JYDC_PARAM_REVICHISHU++;
- ch = GetData32bits(SET_LEN_ADDR_JY);
- ch++;
- SetData32bits(SET_LEN_ADDR_JY,ch);
- }
- //齿数减
- if(JYDC_bDecTooth)
- {
- JYDC_bDecTooth = 0;
- //if(JYDC_PARAM_REVICHISHU)JYDC_PARAM_REVICHISHU--;
- ch = GetData32bits(SET_LEN_ADDR_JY);
- if(ch)
- ch--;
- SetData32bits(SET_LEN_ADDR_JY,ch);
- }
- //手动下冲
- if(JYDC_bManXiaChong || JYDC_ManXiaChong_UP)
- {
- JYDC_bManXiaChong = 0;
- if(JYDC_cXiaChongStep == 0)
- {
- JYDC_cXiaChongStep = 1;
- }
- }
- //手动锁齿
- if(JYDC_bManSuoChi)
- {
- JYDC_bManSuoChi = 0;
- JYDC_SuoChi_VAVLE = ~JYDC_SuoChi_VAVLE;
- }
- //手动吹气
- if(JYDC_bManChuiQi)
- {
- JYDC_bManChuiQi = 0;
- JYDC_ChuiQi_VAVLE = 1;
- JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
- }
- //改变尺寸重新算
- if(JYDC_bChangeLength)
- {
- JYDC_bChangeLength = 0;
- ModeSelect();
- SetData32bits(31,CalInch(SET_ZIPPER_LENGTH));
- SetData32bits(SET_LEN_ADDR_JY, GetToothNum(SET_ZIPPER_LENGTH)); //对就齿数
-
- }
- //输入英寸
- if(JYDC_bSetInch)
- {
- JYDC_bSetInch = 0;
- SetData32bits(SET_LEN_ADDR,CalLengthCM(SET_ZIPPER_LENGTH_INCH));
- JYDC_bChangeLength = 1;
- }
- //设定齿数算长度
- if(JYDC_bSetTooth)
- {
- JYDC_bSetTooth = 0;
- SetData32bits(SET_LEN_ADDR,JYDC_ToothGetLength(JYDC_PARAM_REVICHISHU));
- JYDC_bChangeLength = 1;
- }
- //铣齿电机
- if(JYDC_bManXiChiMotor)
- {
- JYDC_bManXiChiMotor = 0;
- JYDC_XiChi_MOTOR = ~JYDC_XiChi_MOTOR;
- }
- if(JYDC_bManMotor)
- {
- if(!X_DRV)
- {
- JYDC_SuoChi_VAVLE = 0;
- AxisContinueMove(X_AXIS,10,JHJY_DIR_P);
- }
- }
- else if(!JYDC_bManGuaChiMotor && !JYDC_cCSStopStep)
- {
- if(X_DRV)
- {
- AxisEgmStop(X_AXIS);
- }
- }
- }
- }
- //高速输入X30/X16定时器中断
- void JYDC_ExtiActionX30(unsigned char up_down)
- {
- static unsigned char jy_num=0;
- sw_timer_t now;
- sw_timer_now(&now);
-
- if(JYDC_bRunning)
- {
- //下降沿检测
- if((Exti_Count.runstep==1)&&(up_down&&Exti_Count.count_mode||!up_down&&!Exti_Count.count_mode))//第一次上升沿
- {
- Exti_Count.up_time=hw_read_us();
- Exti_Count.up_pulse_time=0;
- Exti_Count.up_cycle_time=0;
- Exti_Count.down_pulse_time=0;
- //Exti_Count.countnum++;
- Exti_Count.runstep=2;
- }
- else if((Exti_Count.runstep==2)&&(!up_down&&Exti_Count.count_mode||up_down&&!Exti_Count.count_mode))
- {
- Exti_Count.prv_up_pulse_time=Exti_Count.up_pulse_time;
- Exti_Count.up_pulse_time=hw_read_us()-Exti_Count.up_time;
- Exti_Count.Down_time=hw_read_us();
-
- if(Exti_Count.up_pulse_time>=JYDC_HLEVEL_TIME)//&&Exti_Count.up_pulse_time>=Exti_Count.prv_up_pulse_time/3)//高电平脉冲大于400us
- {
-
- Exti_Count.runstep=3;
- Exti_Count.countnum++;
- if(Exti_Count.countnum>=JYDC_CURJY_SET)
- {
- //AxisEgmStop(X_AXIS);
- DISPLAY_DATA2=jy_num;
- Exti_Count.runstep=0;
- jy_num=0;
- if(SET_STOP_PLUS)
- axis_plus_stop(axis_x,SET_STOP_PLUS);//多走几个脉冲停机
- else
- AxisEgmStop(X_AXIS);
- }
- }
- else
- {
- Exti_Count.counterronum++;
- //SingOneFlg=1;
- JYDC_Check_HERRO=1;
- DISPLAY_DATA1=Exti_Count.countnum;
- //DISPLAY_DATA3=Exti_Count.up_pulse_time;
- }
- if(jy_num>=80)jy_num=0;
- {
- if(!JYDC_Check_HL)
- user_datas[130+jy_num]=Exti_Count.up_pulse_time;
- else
- user_datas[130+jy_num]=Exti_Count.down_pulse_time;
- }
- jy_num++;
- }
- else if((Exti_Count.runstep==3)&&(up_down&&Exti_Count.count_mode||!up_down&&!Exti_Count.count_mode))
- {
- //周期,低电平脉宽
- Exti_Count.prv_down_pulse_time=Exti_Count.down_pulse_time;
- Exti_Count.down_pulse_time=hw_read_us()-Exti_Count.Down_time;
- //记录上升沿发生时间
- Exti_Count.up_time=hw_read_us();
- Exti_Count.runstep=2;
- //判断
- if(Exti_Count.down_pulse_time>=JYDC_LLEVEL_TIME)//&&Exti_Count.down_pulse_time>=Exti_Count.prv_down_pulse_time/3)//高电平脉冲大于400us
- {
- Exti_Count.runstep=2;
- }
- else
- {
- Exti_Count.counterronum++;
- JYDC_Check_LERRO=1;
- DISPLAY_DATA1=Exti_Count.countnum;
- }
- }
- }
- else
- {
- if(up_down)//上升沿
- {
- //记录当前值周期,下降沿计数是,才有的上次的下降沿-本次的下降沿
- Exti_Count.up_cycle_time=hw_read_us()-Exti_Count.up_time;
- if(Exti_Count.up_cycle_time>10000)Exti_Count.up_cycle_time=10000;
- Exti_Count.up_time=hw_read_us();
- }
- else //下降沿
- {
- //记录当前值周期,下降沿计数是,才有的上次的下降沿-本次的下降沿
- Exti_Count.down_cycle_time=hw_read_us()-Exti_Count.Down_time;
- if(Exti_Count.down_cycle_time>10000)Exti_Count.down_cycle_time=10000;
- Exti_Count.Down_time=hw_read_us();
- }
- if(Exti_Count.count_mode)Exti_Count.cycle_time=Exti_Count.up_cycle_time;
- else Exti_Count.cycle_time=Exti_Count.down_cycle_time;
- if((Exti_Count.count_mode==0&&up_down||Exti_Count.count_mode&&up_down==0)){
- if((Exti_Count.cycle_time>=10000))Exti_Count.countnum++;
-
- }
- }
- }
- int GetJYChishu(void)
- {
- return Exti_Count.countnum;
- }
- void SetJYChishu(int num)
- {
- Exti_Count.countnum=num;
- }
- //高速输入X31/X17外部色标信号中断
- void JYDC_ExtiActionX31(void)
- {
-
- }
- //输入拉链长度返回所输入拉链长度所对应的齿数
- unsigned long GetToothNum(unsigned long zipper_length)
- {
- float length_buff1,tooth_buff,length_buff2;
- length_buff1 = zipper_length;
- tooth_buff = JY_JIZHUN_CISHU;
- length_buff2 = JY_JIZHUN_LEN;
- return (unsigned long)round(length_buff1 * tooth_buff / length_buff2);
- }
- //输入齿数返回拉链长度
- unsigned long JYDC_ToothGetLength(unsigned long tooth_num)
- {
- float toothbuff1,tooth_buff,length_buff2;
- toothbuff1 = tooth_num;
- tooth_buff = JY_JIZHUN_CISHU;
- length_buff2 = JY_JIZHUN_LEN*10;
- return (unsigned long)round((toothbuff1 * length_buff2 / tooth_buff));
- }
- //吹气动作
- void JYDC_ChuiQi(void)
- {
- if(JYDC_XiaChong_IN_DW)
- {
- JYDC_ChuiQi_VAVLE = 1;
- JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
- }
-
- if(JYDC_ChuiQi_VAVLE)
- {
- if(JYDC_ChuiQiDelay < dwTickCount)JYDC_ChuiQi_VAVLE = 0;
- }
-
- if(JYDC_XiChiChuiQi_VAVLE)
- {
- if(JYDC_XiChiChuiQiDelay < dwTickCount)JYDC_XiChiChuiQi_VAVLE = 0;
- }
- }
- //下冲动作
- void JYDC_XiaChong(void)
- {
- switch(JYDC_cXiaChongStep)
- {
- case 1:
- cJHJYStopNum = 0;
- JYDC_ShaChe_VAVLE = 0;
- JYDC_SuoChi_VAVLE = 1; //手动下冲锁齿输出
- if(JYDC_bRunning)
- JYDC_XiaChongDelay = dwTickCount + XIACONG_DELAY_TIME + 5;
- else
- JYDC_XiaChongDelay = dwTickCount + 15;
- JYDC_cXiaChongStep = 2;
- break;
- case 2:
- if(dwTickCount >= JYDC_XiaChongDelay)
- {
- JYDC_XiaChong_MOTOR = 1;
-
- if(JYDC_XiaChong_IN) //如是在感应上就先走下降延
- {
- JYDC_cXiaChongStep = 3;
- JYDC_XiaChongDelay = dwTickCount + 3000;
- }
- else
- {
- JYDC_cXiaChongStep = 4;
- JYDC_XiaChongDelay = dwTickCount + 35;
- }
- }
- break;
- case 3:
- if(JYDC_XiaChong_IN_DW)
- {
- JYDC_cXiaChongStep = 4;
- JYDC_XiaChongDelay = dwTickCount + 35;
- }
- else if(dwTickCount >= JYDC_XiaChongDelay)//下冲警告
- {
- JYDC_SetAlarmCode(JYDC_XIACHONG_ARRIVE_ALARM);
- JYDC_XiaChong_MOTOR = 0;
- JYDC_cXiaChongStep = 6;
- }
- break;
- case 4:
- if(dwTickCount >= JYDC_XiaChongDelay)
- {
- JYDC_cXiaChongStep = 5;
- JYDC_XiaChongDelay = dwTickCount + 3000;//JYDC_PARAM_XC_ALARM_TIME;
- }
- break;
- case 5:
- if(JYDC_XiaChong_IN_UP)
- {
- JYDC_XiaChong_MOTOR = 0;
- JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_SHACHE_DELAY_TIME;//延时刹车
- JYDC_cXiaChongStep = 6;
- }
- else if(dwTickCount >= JYDC_XiaChongDelay)//下冲警告
- {
- JYDC_SetAlarmCode(JYDC_XIACHONG_ARRIVE_ALARM);
- JYDC_XiaChong_MOTOR = 0;
- JYDC_cXiaChongStep = 6;
- }
- break;
- case 6:
- if(dwTickCount >= JYDC_XiaChongDelay) //延时刹车
- {
- JYDC_ShaChe_VAVLE = 1;
- JYDC_cXiaChongStep = 0;
- //齿数清零
- axispostion=0;
- SetPos(X_AXIS,0);
- SetJYChishu(0);
- if(!JYDC_bRunning)
- {
- SetPos(X_AXIS, 0);
- }
- JYDC_XiaChongDelay = dwTickCount + JYDC_PARAM_SHACHE_TIME;
- }
- break;
- }
- if(JYDC_ShaChe_VAVLE && (dwTickCount >= JYDC_XiaChongDelay))
- {
- JYDC_ShaChe_VAVLE = 0;
- }
- }
- //启动停止故障停止动作
- void JYDC_StartStopAction(void)
- {
- static unsigned long long_time_delay,Dw_StopInTime;
- if((JYDC_START_IN_UP || JYDC_bStart||JYDC_bSingleONE) && !JYDC_bRunning && (JYDC_cAutoStep ==0))
- {
- //产量对比
- if(JYDC_bSingleONE)SingOneFlg=1;
- JYDC_bSingleONE=0;
- if(GetTotal(JYDC_TOTAL_ADDR) >= JYDC_SET_TOTAL)
- JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
- else
- {
-
- JYDC_cAutoStep = 1;
- JYDC_bRunning = 1;
- JYDC_SuoChi_VAVLE = 0;
- JYDC_cAutoDelay = dwTickCount + 300;
- cJHJYStopNum = 0;
- MotorRunLengthFlag=0;
- kadaibegin=0;
- JYDC_cCSStopStep = 0;
- Exti_Count.counterronum=0;
- JYDC_LinkStep=1;
- link_DC_OVER_FLG=1;
- SingOneFlg=0;
- }
- JYDC_bStart = 0;
- }
- //卡带
- if(JYDC_KaDai_IN)
- {
- if(!X_DRV)
- {
- JYDC_SuoChi_VAVLE = 1;
- JYDC_bRunning = 0;
- JYDC_cAutoStep = 0;
- SetAlarmCode(JYDC_ALARM_ADDR,JYDC_KADAI_ALARM);
- }
- else
- {
- if(!JYDC_cCSStopStep)//在运行过程中,卡带的动作?
- {
- JYDC_cCSStopStep = 1;
- }
- }
- }
-
- if(JYDC_STOP_IN_UP || JYDC_bStop)
- {
- JYDC_bStop = 0;
- Dw_StopInTime = dwTickCount + 70;
- cJHJYStopNum++;
- //吹气
- JYDC_ChuiQi_VAVLE = 1;
- JYDC_ChuiQiDelay = dwTickCount + JYDC_PARAM_CHUIQI_TIME * 10;
- JYDC_cAutoDelay = dwTickCount;
- //停机
- //JYDC_bRunning = 0;
- JYDC_cAutoStep = 0;
- if(X_DRV)//在运行过程中
- {
- if(cJHJYStopNum >= 2)
- {
- JYDC_cCSStopStep = 0;
- JYDC_bRunning = 0;
- AxisEgmStop(X_AXIS);
- JYDC_cAutoStep = 0;
- JYDC_cMotorStep=0;
- }
- else
- {
- JYDC_cCSStopStep = 1;
- }
- }
- else
- {
- SingOneFlg = 1;
- if(cJHJYStopNum >= 2)
- {
- JYDC_SuoChi_VAVLE = 0;
- JYDC_bRunning = 0;
- AxisEgmStop(X_AXIS);
- JYDC_cAutoStep = 0;
- JYDC_cMotorStep=0;
- JYDC_cCSStopStep = 0;
- }
- }
- JYDC_bManGuaChiMotor = 0;
- JYDC_XiChi_MOTOR=0;
-
- }
- if(JYDC_STOP_IN_DW)Dw_StopInTime = dwTickCount + 70;
- //长时间按停止时锁带关
- if(JYDC_STOP_IN)
- {
- if(dwTickCount>=long_time_delay)
- {
- JYDC_SuoChi_VAVLE = 0;
- AxisEgmStop(X_AXIS);
- JYDC_cCSStopStep = 0;
- }
- }
- else
- {
- long_time_delay = dwTickCount+1300;
- }
- if(JYDC_bAlarmStop)
- {
- JYDC_bAlarmStop = 0;
- JYDC_cAutoStep= 0;
- if(X_DRV)//在运行过程中
- {
- JYDC_cCSStopStep = 1;
- }
- else
- {
- JYDC_bRunning=0;
- JYDC_SuoChi_VAVLE = 1;
- }
- JYDC_cAutoDelay = dwTickCount;
- SingOneFlg = 0;
- JYDC_bManGuaChiMotor = 0;
- JYDC_XiChi_MOTOR=0;
- }
- }
- unsigned char CheckMaxLowSpeed(unsigned char cspeed)
- {
- if(cspeed > JYDC_PARAM_SET_SPEED)
- return JYDC_PARAM_SET_SPEED;
- else
- return cspeed;
- }
- //自动运行动作
- void JYDC_AutoAction(void)
- {
- DISPLAY_DATA0 = Link_TB_Set;//Exti_Count.counterronum;
- //DISPLAY_DATA1 = JYDC_cMotorStep;
- //DISPLAY_DATA2 = JYDC_cAutoStep;
- //DISPLAY_DATA3 = JYDC_cXiaChongStep;
- //DISPLAY_DATA4 = JY_TDtime;//JYDC_cCheckLengthOk;
- DISPLAY_DATA5 = JYDC_cMotorStep;//JYDC_cValveStep;
- DISPLAY_DATA6 = dwXRealPos;
- //DISPLAY_DATA6 = JYDC_LinkStep;
- //DISPLAY_DATA7= link_DC_OVER_FLG;//JY_XiaCongtime;
- //铣齿电机开关
- if(JYDC_bRunning)
- {
- switch(JYDC_cAutoStep)
- {
- case 0:
- break;
- case 1:
- if(dwTickCount >= JYDC_cAutoDelay)
- {
- JY_cycletime=dwTickCount;
- JYDC_CRUKONGWEILENGTH=0;
- JYDC_cAutoStep = 2;
- }
- break;
- case 2://拖带
- if(dwTickCount >= JYDC_cAutoDelay)//左右分针要退到位,过链到位要离开
- {
- if(JYDC_XICHI_MOTOR_MODE)
- JYDC_XiChi_MOTOR = 1;
- else
- JYDC_XiChi_MOTOR = 0;
- JYDC_cAutoStep = 3;
- JY_TDtime=dwTickCount;
- switch(JYDC_DC_MODE)
- {
- case JYDC_DC_GD_MODE:JYDC_cMotorStep = 60; break; //光电
- case JYDC_DC_SB_MODE:JYDC_cMotorStep = 20; break; //色标
- case JYDC_DC_GZ_MODE:JYDC_cMotorStep = 1; break; //钩针
- }
- }
- break;
- case 3://拖带完成,延时锁齿
- if(JYDC_cMotorStep == 0)
- {
- JY_TDtime=dwTickCount-JY_TDtime;
- JYDC_cAutoDelay = dwTickCount + 0;
- JYDC_cAutoStep = 4;
- }
- break;
- case 4://锁齿
- if(dwTickCount >= JYDC_cAutoDelay)
- {
- JYDC_SuoChi_VAVLE=1;
- Exti_Count.runstep=0;
- JYDC_cAutoStep = 5;
- }
- break;
- case 5://下冲
- if((dwTickCount >= JYDC_cAutoDelay))
- {
- JY_TDtime=dwTickCount-JY_TDtime;
- if(JYDC_cXiaChongStep == 0)
- {
- if(!JYDC_bTest)JYDC_cXiaChongStep = 1;
- else
- {
- JYDC_cXiaChongStep = 0;
- axispostion=0;
- SetPos(X_AXIS,0);
- SetJYChishu(0);
- }
- JYDC_cAutoStep = 6;
- }
- }
- break;
- case 6: //下冲已完成,判断除齿长度,是否多刀
- if((JYDC_cXiaChongStep == 0))
- {
- JY_XiaCongtime=dwTickCount-JY_XiaCongtime;
- //除齿判断
- if(JYDC_CRUKONGWEILENGTH>=JYDC_PARAM_KONG_WEI_LENGTH)
- {
- JYDC_CRUKONGWEILENGTH=0;
- if(JYDC_cGZDW_CNT < 3)JYDC_cGZDW_CNT++;
- AddToTal(JYDC_TOTAL_ADDR); //计数增加和保存
- CalProSP(JYDC_PROSPEED_ADDR);
- JYDC_cAutoStep = 7;
- }
- else
- {
- JYDC_cAutoStep = 2;
- }
- }
- break;
- case 7:
- if(GetTotal(JYDC_TOTAL_ADDR) >= JYDC_SET_TOTAL)
- {
- JYDC_SetAlarmCode(JYDC_TOTAL_ALARM);
- CCJ_SingOneFlg=1;
- }
- JYDC_cAutoStep = 8;
- break;
- case 8:
- JYDC_cAutoDelay = dwTickCount + 0;//JYDC_PARAM_CYCLE_DELAY;
- JYDC_cAutoStep = 1;
- link_DC_OVER_FLG=1;
- JY_cycletime=dwTickCount-JY_cycletime;
- if(SingOneFlg||JYDC_bTest)
- {
- JYDC_cGZDW_CNT=0;
- dwZipCnt = 0;
- SingOneFlg = 0;
- JYDC_cAutoStep = 0;
- JYDC_bRunning = 0;
- JYDC_XiChi_MOTOR=0;
- }
- break;
- }
- }
- }
- void JYDC_Motor(void)
- {
- static unsigned long zipper_length,low_length;
- //实时显示行程总长
- //JYDC_All_LENTH = JYDC_SET_ZIPPER_LENGTH + JYDC_SET_REVISE_ZIPPER_LENGTH + JYDC_PARAM_KONG_WEI_LENGTH;
- dwXRealPos = GetPos(X_AXIS);
- JYDC_dwEncPos = GetJYChishu();//获取胶牙齿数
- axis_position_encode=(long)(JYDC_ToothGetLength(JYDC_dwEncPos)*XGearRatio);//(long)(JYDC_dwEncPos*XGearRatio); //由齿数获取长度
- switch(JYDC_cMotorStep)
- {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- case 8:
- break;
- case 9:
- break;
- case 10:
- break;
- case 11:
- break;
- case 20:
- break;
- case 21:
- break;
- case 22:
- break;
- case 60:
- if(JYDC_STARTFLAG&&(Link_TB_Set||!CCJ_bRunning)&& (!JYDC_Wait_IN||!CCJ_bRunning))
- {
- Link_TB_Set=0;
- if(JYDC_dwEncPos>=JYDC_PARAM_REVICHISHU+SET_DAOKOU_JY&&JYDC_CRUKONGWEILENGTH==0)
- {
- JYDC_cMotorStep = 64;
- JYDC_CRUKONGWEILENGTH=SET_DAOKOU_JY;
- JYDC_cMotorDelay = dwTickCount + NO_TOOTHCOUT_TIME;
- }
- else
- {
- JYDC_cMotorStep = 61;
- JYDC_SuoChi_VAVLE = 0; //锁齿阀关
- JYDC_cAutoDelay = dwTickCount + 40;
- //if(jydc_use_x30)
- // EXTI30Enable();
- //if(jydc_use_x20)
- // EXTI20Enable();
- }
- }
- break;
- case 61:
- if((dwTickCount >= JYDC_cMotorDelay))
- {
- if(JYDC_CRUKONGWEILENGTH==0)
- {
-
- zipper_length =JYDC_ToothGetLength(JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY-JYDC_dwEncPos);
- JYDC_CURJY_SET=JYDC_PARAM_REVICHISHU + SET_DAOKOU_JY-JYDC_dwEncPos;
- //DISPLAY_DATA0=zipper_length;
- //DISPLAY_DATA1=JYDC_PARAM_REVICHISHU;
- //DISPLAY_DATA2=SET_DAOKOU_JY;
-
- JYDC_CRUKONGWEILENGTH=SET_DAOKOU_JY;
- }
- else if(JYDC_PARAM_KONG_WEI_LENGTH-JYDC_CRUKONGWEILENGTH>=SET_DAOKOU_JY)
- {
- zipper_length=JYDC_ToothGetLength(SET_DAOKOU_JY);
- JYDC_CURJY_SET=SET_DAOKOU_JY;
- JYDC_CRUKONGWEILENGTH+=SET_DAOKOU_JY;
- }
- else
- {
- zipper_length=JYDC_ToothGetLength(JYDC_PARAM_KONG_WEI_LENGTH-JYDC_CRUKONGWEILENGTH);
- JYDC_CURJY_SET=JYDC_PARAM_KONG_WEI_LENGTH-JYDC_CRUKONGWEILENGTH;
- JYDC_CRUKONGWEILENGTH+=JYDC_PARAM_KONG_WEI_LENGTH-JYDC_CRUKONGWEILENGTH;
- }
- low_length=JYDC_ToothGetLength(JYDC_PARAM_LOW_LENGTH);
- if(zipper_length<1400)
- {
- AxisMovePosAccDecNotStop(X_AXIS,JYDC_PARAM_SET_SPEED*3/4+600,zipper_length,1200,JYDC_PARAM_LOW_SPEED,150,150,low_length);
- }
- else if(zipper_length<2400)
- {
- AxisMovePosAccDecNotStop(X_AXIS,JYDC_PARAM_SET_SPEED*7/8,zipper_length,1200,JYDC_PARAM_LOW_SPEED,150,150,low_length);
- }
- else
- {
- AxisMovePosAccDecNotStop(X_AXIS,JYDC_PARAM_SET_SPEED,zipper_length,1200,JYDC_PARAM_LOW_SPEED,150,150,low_length);
- }
- DISPLAY_DATA7=low_length;
- JYDC_cMotorDelay = dwTickCount + NO_TOOTHCOUT_TIME;
- //吹气
- JYDC_XiChiChuiQi_VAVLE = 1;
- JYDC_XiChiChuiQiDelay = dwTickCount + 200;
- JYDC_cMotorStep = 64;
- Exti_Count.runstep=1;
- Exti_Count.countnum=0;
- }
- break;
- case 64:
- if(!X_DRV)
- {
- JYDC_cMotorStep = 0;
- Cur_DC_Num++;
- Exti_Count.runstep=0;
- JYDC_cMotorDelay = dwTickCount;
- }
- else if(dwTickCount >= JYDC_cMotorDelay)
- {
- JYDC_SetAlarmCode(JYDC_COUNT_ALARM);
- AxisEgmStop(X_AXIS);
- }
- break;
- case 65:
- if(dwXRealPos<=zipper_length-500)//剩余长度小于5CM
- {
- AxisMovePosAccDec(X_AXIS,1000,300,600,600,20,20,0);
- JYDC_cMotorStep = 66;
- }
- else
- {
- JYDC_cMotorStep = 62;
- }
- break;
- case 66:
- if(!X_DRV)
- {
- JYDC_cAutoStep=2;
- JYDC_cMotorStep=0;
- JYDC_CRUKONGWEILENGTH=0;
- }
- break;
- }
- }
- //按齿数暂停
- void JYDC_ChiShuStop(void)
- {
- switch(JYDC_cCSStopStep)
- {
- case 1:
- JYDC_cCSStopStep = 2;
- AxisContinueMoveChangeSpeed(X_AXIS,JYDC_PARAM_LOW_SPEED,JYDC_PARAM_LOW_SPEED/2,20,40);
- break;
- case 2:
- if(GetCurSpeed(X_AXIS) <= (JYDC_PARAM_LOW_SPEED*3/2))
- {
- JYDC_cCSStopStep = 3;
- if(GetJYChishu() + 3 < JYDC_CURJY_SET)JYDC_CURJY_SET = GetJYChishu() + 3;
- JYDC_ShuChiStopDelay = dwTickCount + NO_TOOTHCOUT_TIME;
-
- }
- break;
- case 3:
- if(!X_DRV)//(GetCurSpeed(X_AXIS)<= (JYDC_PARAM_LOW_SPEED + 50)) &&
- {
- JYDC_cMotorDelay = dwTickCount + 100;
- JYDC_cCSStopStep = 4;
- }
- else if(dwTickCount >= JYDC_ShuChiStopDelay)
- {
- JYDC_bRunning = 0;
- JYDC_cCSStopStep = 0;
- AxisEgmStop(X_AXIS);
- }
- break;
- case 4:
- if(dwTickCount>=JYDC_cMotorDelay)
- {
- JYDC_cCSStopStep = 0;
- JYDC_bRunning = 0;
- JYDC_SuoChi_VAVLE = 1;
- }
- break;
- }
- }
- void JYDC_InitAction(void)
- {
- float length_buff,pulse_buff;
- length_buff = JYDC_CYCLE_LENGTH;
- pulse_buff = JYDC_CYCLE_PULSE;
- XGearRatio = pulse_buff/length_buff;
- if(MODE_SELECT > 3)
- MODE_SELECT = 0;
- ModeSelect();
- //当前齿数
- SetData32bits(CUR_LEN_ADDR_JY,0);
- cJHJYStopNum = 0;
- SetDirReverse(X_AXIS, 0);
- //EXTI30Enable();
- EXTI20Enable();
-
- //光电方式传感器采用类似编码器方式进行数齿
- // if(JYDC_DC_MODE == JYDC_DC_GD_MODE)
- // axis_set_parameter(axis_x,AXIS_USE_ENCODE,1);
- // else
- axis_set_parameter(axis_x,AXIS_USE_ENCODE,0);
-
- }
- //胶牙定寸动作
- void JYDC_Action(void)
- {
- Exti_Count.count_mode=user_datas[34];
- JYDC_ManualAction();
- JYDC_ChuiQi();
- JYDC_XiaChong();
- JYDC_StartStopAction();
- JYDC_AutoAction();
- JYDC_Motor();
- JYDC_ChiShuStop();
- JYDC_LinkAction();
- SetData32bits(CUR_LEN_ADDR_JY,JYDC_dwEncPos); //当前齿数给值
- }
- #endif
|