1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161 |
- #include "global.h"
- #if FJ_YING_XING_MACHINE == 1
- void MXC_NiLongXiuCiJiCheckStart(void);
- void MXC_ShaChe_Output(void);
- void MXC_NiLongXiuCiJi_Motor(void);//电机
- void MXC_NiLongXiuCiJi_XiaC(void);
- void MXC_Start_FenZ(void);
- void MXC_NiLongXiuCiJi_FenZhengProc(void);
- void MXC_ChuiQiProc(void);
- void MXC_JiaoDao(void);
- void MXC_ManualAction(void);
- void MXC_AutoAction(void);
- void MXC_NiLongXiuCiJi_GouZhenProc(void);
- void DianDanLenghtCheck(void);
- long MultLengthOffset(unsigned long zip_length);
- unsigned short DingDanCheckOk(void);
- unsigned char cLFengTimer, cRFengTimer, cGuZhangStop = 0;
- unsigned long cShaCheTime, cLaLianLine, cGouZhenTime;
- unsigned char cChuiQiStep = 0, cGouZhenResetOK;
- unsigned short cBudaiCheckDelay = 0;
- unsigned char bHandWork, bPulseTatol_EN, bFirst, cInt1_OK, cStopFlag, cOneTimes, cKey_Time;
- long cSetEncode, cTotal, cDinWeiTime, cAddSetPulseNum, cEncodePulse, cWorkPulseNum;
- unsigned long cZipperLength[2];
- unsigned char cCheckLengthOk = 0, cDaoJu_Flag = 0;
- unsigned char STOP_IN_FLAG, STOP_IN_FLAG_OLD, STOP_FILTER;
- unsigned char MXC_SingOneFlag = 0;
- unsigned char MXC_KD_Flag = 0, KD_GO_ON_FLAG = 0;
- long MXC_KD_pos = 0, save_pos_buff = 0;
- long zipper_length_buff;
- short *len_buf;
- short *offset_len;
- //故障报警
- void MXC_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(MXC_ALARM_ADDR, alarm_code);
- MXC_bAlarmStop = 1;
- }
- //高速输入X31/X17外部色标信号中断
- void MXC_ExtiActionX31(void)
- {
- if (cSeBiaoEn && !cSeBiaoOk)
- {
- cSeBiaoOk = 1;
- cSeBiaoEn = 0;
- if (X_DRV)
- //SetRemainLength(X_AXIS, MXC_PARAM_SEBIAO_DW_LENGTH,MXC_PARAM_SB_OFFSET_SPEED);
- AxisMovePosAccDec(X_AXIS, MXC_PARAM_SB_OFFSET_SPEED, MXC_PARAM_SEBIAO_DW_LENGTH,
- MXC_PARAM_START_SPEED, MXC_PARAM_START_SPEED,
- 10, 10, 80);
- }
- // DISPLAY_DATA2++;
- }
- //检测订单数据内是否还有可以加工的数据,返回订单序号
- unsigned short DingDanCheckOk(void)
- {
- unsigned short ch, i;
-
- for (ch = 0; ch < (MXC_DingDanNum); ch++)
- {
-
- i = MXC_DingDan_NowNum;//当前订单号
- // 订单完成数量 //订单量 // 拉链长度
- if ((GetData32bits(MXC_DingDanAddr + i * 6 + 2) < GetData32bits(MXC_DingDanAddr + i * 6 + 4)) && (GetData32bits(MXC_DingDanAddr + i * 6) != 0))
- {
-
- //设置拉链长度
- SetData32bits(15, GetData32bits(MXC_DingDanAddr + i * 6));
- //累计条数
- SetData32bits(76, GetData32bits(MXC_DingDanAddr + i * 6 + 2)); //当前一般为0
- //设置加工条数
- SetData32bits(22, GetData32bits(MXC_DingDanAddr + i * 6 + 4));
-
- MXC_SET_REVISE_ZIPPER_LENGTH = user_datas[i + MXC_DingDanOffsetAddr];
- return ch;//进入设置则退出该函数
- }
- MXC_DingDan_NowNum++;
- if (MXC_DingDan_NowNum >= MXC_DingDanNum)
- MXC_DingDan_NowNum = 0;
- }
- return ch; //如ch = MXC_DingDanNum)无订单加工
- }
- //num订单序号设置订单数据植物入生产表
- void SetDingDanData(void)
- {
- unsigned short ch, i;
- i = MXC_DingDan_NowNum; //当前
- for (ch = 0; ch < MXC_DingDanNum; ch++)
- {
- // 订单完成数量 //订单量
- if ((GetData32bits(MXC_DingDanAddr + i * 6 + 2) >= GetData32bits(MXC_DingDanAddr + i * 6 + 4)) || (GetData32bits(MXC_DingDanAddr + i * 6) == 0))
- { //勾针并且长度小于勾针最小长度
- if ((MXC_DC_MODE != 0) || (MXC_ScanMa_LENGTH >= MXC_GouzhenMin_Length)) //伺服或色标可以直接输入
- {
- //设置拉链长度
- SetData32bits((MXC_DingDanAddr + i * 6), MXC_ScanMa_LENGTH);
- //设置累计条数
- SetData32bits(MXC_DingDanAddr + i * 6 + 2, 0);
- //设置加工条数
- SetData32bits(MXC_DingDanAddr + i * 6 + 4, MXC_ScanMa_Production);
- }
- break;
- }
- else
- {
- i++;
- if (i >= MXC_DingDanNum)
- i = 0;
- }
- }
- }
- long MultLengthOffset(unsigned long zip_length)
- {
- if (zip_length <= user_datas[MXC_MultLengthOffsetAddr])
- len_buf = &user_datas[MXC_MultOffsetAddr];
- else if (zip_length <= user_datas[MXC_MultLengthOffsetAddr + 1])
- len_buf = &user_datas[MXC_MultOffsetAddr + 1];
- else if (zip_length <= user_datas[MXC_MultLengthOffsetAddr + 2])
- len_buf = &user_datas[MXC_MultOffsetAddr + 2];
- else if (zip_length <= user_datas[MXC_MultLengthOffsetAddr + 3])
- len_buf = &user_datas[MXC_MultOffsetAddr + 3];
- else
- len_buf = &user_datas[MXC_MultOffsetAddr + 4];
- return (*len_buf);
- }
- //订单完成条数增加
- void DingDanTotalAdd(void)
- {
- //把当前产量赋值到当前订单组
- SetData32bits(MXC_DingDanAddr + MXC_DingDan_NowNum * 6 + 2, GetData32bits(76));
- }
- void DianDanLenghtCheck(void)
- {
-
- unsigned int i = 0, ch = 0;
- //长度不能小于勾针长度
- ch = 0;
- if (MXC_DingDanSet130)
- {
- MXC_DingDanSet130 = 0;
- i = 0;
- ch = 1;
- }
- //长度不能小于勾针长度
- if (MXC_DingDanSet136)
- {
- MXC_DingDanSet136 = 0;
- i = 1;
- ch = 1;
- }
- //长度不能小于勾针长度
- if (MXC_DingDanSet142)
- {
- MXC_DingDanSet142 = 0;
- i = 2;
- ch = 1;
- }
- //长度不能小于勾针长度
- if (MXC_DingDanSet148)
- {
- MXC_DingDanSet148 = 0;
- i = 3;
- ch = 1;
- }
- if (MXC_DingDanSet154)
- {
- MXC_DingDanSet154 = 0;
- i = 4;
- ch = 1;
- }
-
- if ((MXC_DC_MODE == 0) && ch) //在勾针定寸模式下不能勾针最小尺寸
- {
-
- if (GetData32bits(MXC_DingDanAddr + i * 6) < MXC_GouzhenMin_Length)
- {
-
- SetData32bits(MXC_DingDanAddr + i * 6, MXC_GouzhenMin_Length);
- }
- }
- }
- //上电订单检测
- void IntitDingDan(void)
- {
- if (MXC_DingDan_NowNum >= MXC_DingDanNum)
- MXC_DingDan_NowNum = 0;
- }
- void MXC_ExtiActionX20(void)
- {
- }
- void MXC_InitAction(void)
- {
- float length_buff, pulse_buff;
-
- //CalFreqTab_X_Free(25);
- length_buff = MXC_PARAM_DAILUN_LENGTH;
- pulse_buff = 2000;
- XGearRatio = pulse_buff / length_buff;
-
- if (MXC_USE_GZ_SERVO)
- MXC_StartFirst = 1; //上电第一次要重新定位
- MXC_Gouzhencurrent_L = 0; //上电当前位置要清零
- length_buff = MXC_PARAM_GouZhenLun_LENGTH; // 勾针电机一圈周长;
- pulse_buff = 2000; // 勾针电机细分
- YGearRatio = pulse_buff / length_buff;
-
- MXC_ProSpeed = 0; //生产速度
-
- MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
- MXC_TuoDaiSongZhou = MXC_SERVER_DISEN;
- //
- if (MXC_PARAM_XIAZHI_EN == 0)
- MXC_XIA_ZHI_ENABLE = 0; //0不带下止,带下止时强关掉
-
- if (MXC_XIA_ZHI_ENABLE)
- MXC_XiaZhi_MOTOR = 1;
- else
- MXC_XiaZhi_MOTOR = 0;
-
- SetAlarmCode(MXC_ALARM_ADDR, 0); //警告清零
-
- //Y轴方向实际输出电平设置
- SetDirReverse(Y_AXIS, 1); //方向输出的实际电平取反
- //订单初始华
- //IntitDingDan();
-
- STOP_IN_FLAG = MXC_STOP_IN;
- STOP_IN_FLAG_OLD = STOP_IN_FLAG;
- }
- void MXC_NiLongXiuCiJiAction(void)
- {
-
- MXC_NiLongXiuCiJiCheckStart(); //启动
- MXC_NiLongXiuCiJi_FenZhengProc(); //左右分针
- MXC_NiLongXiuCiJi_XiaC(); //下冲
- MXC_ChuiQiProc();
- MXC_NiLongXiuCiJi_Motor(); //拖带控制
- MXC_JiaoDao();
- MXC_ManualAction();
- MXC_AutoAction();
- MXC_NiLongXiuCiJi_GouZhenProc(); //勾针数控动作
- //订单植入
- /* if(MXC_Scan_Ma)
- {
- MXC_Scan_Ma = 0;
- SetDingDanData();
- }
- */
-
- }
- void MXC_ManualAction(void)
- {
- long i;
- static unsigned char save_flg = 0;
- //清总产量
- if (MXC_bClear) //清总产量
- {
- MXC_bClear = 0;
- ClrcToTal(MXC_TOTAL_ADDR);
- // MXC_bSaveWorkData = 1;
- save_flg = 1;
- }
-
- if (save_flg)
- {
- if (!MXC_bSaveWorkData)
- {
- ClrcToTal(MXC_TOTAL_ADDR);
- if (MXC_DingDanWorkMode)
- {
- DingDanTotalAdd();
- }
- save_flg = 0;
- }
- }
-
- // //当长度改变时,生产总量自动清零
- // if (MXC_bChangeLength)
- // {
- // MXC_bChangeLength = 0;
- // MXC_bClear = 1;
- // }
-
- //加5
- if (MXC_bAddLength)
- {
- MXC_bAddLength = 0;
- i = MXC_SET_REVISE_ZIPPER_LENGTH;
- i += 5;
- SetData32bits(MXC_ZIPPER_LENGTH_ADDR, i);
- }
- //减5
- if (MXC_bDecLength)
- {
- MXC_bDecLength = 0;
- i = MXC_SET_REVISE_ZIPPER_LENGTH;
- i -= 5;
- SetData32bits(MXC_ZIPPER_LENGTH_ADDR, i);
- }
- //工作方式选择(数控定寸和勾针定寸)
- if (MXC_bSetDCMode)
- {
- MXC_bSetDCMode = 0;
- if (!MXC_bRunning)
- {
- MXC_DC_MODE++;
- if (MXC_DC_MODE > 2)
- MXC_DC_MODE = 0;
-
- if (MXC_DC_MODE != 0)
- {
- MXC_GouZhen_VAVLE = 1;
- MXC_XIA_ZHI_ENABLE = 0;
- MXC_XiaZhi_MOTOR = 0;
- }
- }
- }
- //订单组拉链长度改变
- if((MXC_DingDanWorkMode == 1) && MXC_Length_Change_flag && (MXC_cMotorStep == 0))
- {
- MXC_Length_Change_flag = 0;
- DingDanCheckOk();
- }
-
- //勾针方式选择(活动勾针和固定勾针)
- if (MXC_bChangeGouZhenMode)
- {
- MXC_bChangeGouZhenMode = 0;
- if (!MXC_bRunning)
- {
- // MXC_GOU_ZHEN_MODE++;
- // if(MXC_GOU_ZHEN_MODE > 1)MXC_GOU_ZHEN_MODE = 0;
- }
- }
- //下止工作选择)
- if (MXC_bChangeXiaZhiMode)
- {
- MXC_bChangeXiaZhiMode = 0;
- if (!MXC_bRunning)
- {
- MXC_XIA_ZHI_ENABLE++;
- if (MXC_XIA_ZHI_ENABLE > 2)
- MXC_XIA_ZHI_ENABLE = 0;
-
- if (MXC_XIA_ZHI_ENABLE)
- MXC_XiaZhi_MOTOR = 1;
- else
- MXC_XiaZhi_MOTOR = 0;
- }
- }
- //顶刀保护
- if(MXC_bDingDao_Baohu)
- {
- MXC_bDingDao_Baohu = 0;
- MXC_DingDao_BaoHu_VAVLE = 1;
- MXC_cDDBHDelay = dwTickCount + MXC_DDBH_Time;
- }
-
- if (MXC_bJiaoDao)
- {
- MXC_cJiaoDaoStep = 1;
- MXC_bJiaoDao = 0;
- }
-
- if (MXC_bChuiQi)
- {
- MXC_bChuiQi = 0;
-
- if (MXC_cChuiQiStep == 0)
- MXC_cChuiQiStep = 1;
- }
-
- if ((MXC_bRunning) == 0) ////手动
- {
- if(MXC_bDJTD_P)//电机拖带
- {
- if(!X_DRV)
- {
- MXC_TuoDaiSongZhou= MXC_SERVER_EN;
- AxisContinueMoveAcc(X_AXIS, MXC_PARAM_LOW_SPEED, MXC_DIR_P, MXC_PARAM_START_SPEED,
- MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED);
- }
- }
- if(MXC_bDJTD_N)//电机拖带
- {
- if(!X_DRV)
- {
- MXC_TuoDaiSongZhou= MXC_SERVER_EN;
- AxisContinueMoveAcc(X_AXIS, MXC_PARAM_LOW_SPEED, MXC_DIR_N, MXC_PARAM_START_SPEED,
- MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED);
- }
- }
- if(X_DRV && !MXC_bDJTD_P && !MXC_bDJTD_N && !MXC_bRunning && (MXC_cMotorStep == 0))
- {
- AxisEgmStop(X_AXIS);
- }
- if (MXC_ManXiaChong_UP || MXC_bXiaChong)
- {
- MXC_bXiaChong = 0;
- if (MXC_cXiaChongStep == 0)
- {
- MXC_cXiaChongStep = 1;
- MXC_DingDanJianGe_State = 0;
- }
- }
-
- if (MXC_cXiaChongStep == 0)
- {
- if (MXC_bLeftFenZhen)
- {
- MXC_bLeftFenZhen = 0;
- MXC_LeftFenZhen_VAVLE = ~MXC_LeftFenZhen_VAVLE;
- }
-
- if (MXC_bRightFenZhen)
- {
- MXC_bRightFenZhen = 0;
- MXC_RightFenZhen_VAVLE = ~MXC_RightFenZhen_VAVLE;
- }
-
- //点动下冲
- if ((MXC_bDotXiaChong))
- {
- MXC_bDotXiaChong = 0;
-
- if (MXC_LeftFenZhen_IN && MXC_RighttFenZhen_IN)
- {
- if (MXC_XiaChongMotorMode == 0)//交流电机,直接下冲
- {
- if (MXC_cXiaChongStep == 0)
- MXC_cXiaChongStep = 20;
- }
- else
- {
- if (MXC_cXiaChongStep == 0)
- MXC_cXiaChongStep = 40;
- }
- }
- else
- {
- MXC_SetAlarmCode(MXC_XIA_CHONG_ALARM); //下冲条件不满足
- }
- }
-
- if (MXC_bGouZhen)
- {
- MXC_bGouZhen = 0;
- if ((MXC_GOU_ZHEN_MODE == 0)) //普通勾针(活动)过链
- {
- //MXC_cGouZhenTime = dwTickCount + 300;
- MXC_GouZhen_VAVLE = ~MXC_GouZhen_VAVLE;
- }
- }
- }
-
- if (MXC_bXiaZhi)
- {
- MXC_bXiaZhi = 0;
- if (MXC_XiaZhi_VAVLE)
- {
- MXC_XiaZhi_VAVLE = 0;
- MXC_ChaoSheng = 0;
- }
- else
- {
- if (MXC_XIA_ZHI_ENABLE) //下止选择
- {
- //下止输出
- MXC_cXiaZhiDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
- MXC_XiaZhi_VAVLE = 1;
- }
- }
- }
-
- if (MXC_DC_MODE != 0) //伺服定寸,目前没有钩针 暂时不用
- {
- // MXC_GuDingGouZhen = 1;
- // MXC_GouZhen_VAVLE = 1;
- }
- // else if ((MXC_GOU_ZHEN_MODE == 0) && !Y_DRV && (MXC_cGouZhenDWStep == 0)) //普通勾针(活动)过链在勾针定电机动作情况下不能关
- // {
- // if (dwTickCount >= MXC_cGouZhenTime)
- // MXC_GouZhen_VAVLE = 0;
- // }
-
- if (MXC_bChuDai)
- {
- MXC_ChuDai_VAVLE = 1;
- }
- else
- {
- MXC_ChuDai_VAVLE = 0;
- }
-
- // if (MXC_bTestMotor)
- // {
- // MXC_GouZhen_VAVLE = 1;
- // MXC_cGouZhenTime = dwTickCount + 300;
- // if (!X_DRV)
- // {
- // MXC_TuoDaiSongZhou = MXC_SERVER_EN;
- // //AxisContinueMoveAcc(X_AXIS,10,MXC_DIR_P,MXC_PARAM_START_SPEED,MXC_PARAM_START_SPEED,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
- // }
- // }
- // else if (MXC_cMotorStep == 0)
- // {
- // //if(X_DRV)AxisDecStop(X_AXIS);
- // }
- }
-
- //下止下冲电磁铁
- if ((MXC_XiaZhi_VAVLE != 0) && (dwTickCount >= MXC_cXiaZhiDelay))
- {
- MXC_XiaZhi_VAVLE = 0;
- }
- }
- void MXC_AutoAction(void)
- {
- unsigned char DingDan_Flag;
- unsigned short ch;
- DISPLAY_DATA0 = MXC_cAutoStep;
- DISPLAY_DATA1 = MXC_cMotorStep;
- DISPLAY_DATA2 = KD_GO_ON_FLAG;
- if((DISPLAY_DATA3 <= GetCurSpeed(X_AXIS)) && MXC_bRunning == 1)
- DISPLAY_DATA3 = GetCurSpeed(X_AXIS);
- DISPLAY_DATA4 = MXC_cXiaChongStep;//MXC_cXiaChongStep;
-
- DISPLAY_DATA6 = dwRealPos;
- if (MXC_bRunning)
- {
- if ((!MXC_Zipper_IN))
- MXC_ChuDai_VAVLE = 0;
- else
- MXC_ChuDai_VAVLE = 1;
-
- if ((MXC_DC_MODE == 0) && (MXC_GOU_ZHEN_MODE == 0))
- {
- if (MXC_GouZhen_IN_UP)
- MXC_cGouZhenTime = 1;
- }
- else
- MXC_cGouZhenTime = 1;
-
- switch (MXC_cAutoStep)
- {
- case 0:
- break;
- case 1:
- if (dwTickCount >= MXC_cAutoDelay)
- {
- if (MXC_TuoDaiSongZhou == MXC_SERVER_DISEN)
- {
- MXC_TuoDaiSongZhou = MXC_SERVER_EN;
- MXC_cAutoDelay = dwTickCount + 700; //先锁轴
- }
- else
- MXC_cAutoDelay = dwTickCount;
- //要判断勾针是否已定位好
- if (MXC_cGouZhenDWStep == 0 || MXC_DC_MODE != 0)
- {
- MXC_cAutoStep = 2;
- }
- }
- break;
- case 2:
- //左右分针要退到位,过链到位要离开
- if (!MXC_GouZhen_IN && MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN && (dwTickCount >= MXC_cAutoDelay))// && MXC_DDBH_Origin_IN
- {
- //要判断勾针是否已定位好
- if (MXC_cGouZhenDWStep == 0 || MXC_DC_MODE != 0)
- {
- MXC_cAutoStep = 3;
- MXC_cMotorStep = 1; //启动拖带
- }
- }
- break;
- case 3:
- //拖带已经完成
- if (MXC_cMotorStep == 0)
- {
- if (SingOneFlg)
- {
- dwZipCnt = 0;
- SingOneFlg = 0;
- MXC_cAutoStep = 0;
- MXC_bRunning = 0;
- }
- else
- {
- MXC_cAutoStep = 4;
- }
- }
- break;
- case 4:
- MXC_cAutoStep = 5;
- break;
- case 5:
- //左右分针都已完成
- if ((MXC_cLeftFenZhenStep == 0) && (MXC_cRightFenZhenStep == 0) && (MXC_cXiaChongStep == 0) && (!MXC_TIAOSHI_MODE || MXC_START_IN_UP))
- {
- if (MXC_SET_XIACHONG_DISEN == 0)
- {
- MXC_cXiaChongStep = 1; //下冲电机启动
- MXC_cAutoStep = 6;
-
- }
- else
- {
- MXC_cAutoDelay = dwTickCount + MXC_PARAM_DELAY_XC;
- MXC_cAutoStep = 106;
- }
- }
- break;
- case 106:
- if (dwTickCount >= MXC_cAutoDelay)
- {
- MXC_GouZhen_VAVLE = 1;
- MXC_cAutoStep = 6;
- }
- break;
- case 6: //下冲已完成
-
- if (((MXC_cXiaChongStep == 0) || (MXC_cXiaChongStep >= 5)) )//&& !MXC_XiaZhi_VAVLE
- {
- dwZipCnt++;
- AddToTal(MXC_TOTAL_ADDR); //计数增加和保存
- //条件满足的情况下对应产量也加1
- if(MXC_DingDanWorkMode)
- DingDanTotalAdd();
- // MXC_DingDanJianGe = 0; //回到原来工作模式
-
- CalProSP(MXC_PROSPEED_ADDR);
-
- MXC_cAutoStep = 7;
- }
- break;
- case 7:
- if (MXC_LeftFenZhen_Origin_IN && MXC_RightFenZhen_Origin_IN && !MXC_LeftFenZhen_IN && !MXC_RighttFenZhen_IN)
- {
- if (GetTotal(MXC_TOTAL_ADDR) >= MXC_SET_TOTAL)
- {
- if (MXC_DingDanWorkMode && MXC_USE_GZ_SERVO)//连续订单模式
- {
- MXC_bSaveWorkData = 1;//存盘数据到屏幕
- MXC_cAutoStep = 20;
- }
- else
- {
- MXC_cAutoStep = 0;
- MXC_bRunning = 0;
- MXC_SingOneFlag = 1;
- MXC_SetAlarmCode(MXC_TOTAL_ALARM);
- }
- }
- else
- MXC_cAutoStep = 8;
- }
- break;
- case 8:
- MXC_cAutoDelay = dwTickCount + MXC_PARAM_MOTOR_DELAY;
-
- if (MXC_SingOneFlag)
- {
- dwZipCnt = 0;
- MXC_SingOneFlag = 0;
- MXC_cAutoStep = 0;
- MXC_bRunning = 0;
- }
- else
- MXC_cAutoStep = 1;
- break;
- case 20:
- if (!MXC_bSaveWorkData)//未进行存盘
- {
- //订单组自动赋值
- DingDan_Flag = DingDanCheckOk();
- //订单接收标志位为0,表示当前订单的数量设定做了修改,需要继续加工
- if(DingDan_Flag == 0)
- MXC_cAutoStep = 1;
- //订单接收标志位不为0且不等于5,则有其他订单待做,打上公分节
- else if (DingDan_Flag != (MXC_DingDanNum))
- {
- MXC_cAutoStep = 21;
- MXC_cAutoDelay = dwTickCount + 20;
- if (MXC_DC_MODE == 0) //勾针定寸情况下才要重新的定位勾针
- {
- //长度不一样先定位勾针
- if (MXC_SET_ZIPPER_LENGTH > MXC_Gouzhencurrent_L)
- ch = MXC_SET_ZIPPER_LENGTH - MXC_Gouzhencurrent_L;
- else
- ch = MXC_Gouzhencurrent_L - MXC_SET_ZIPPER_LENGTH;
- if (ch > 2)
- MXC_cGouZhenDWStep = 1;
- }
- }
- else
- MXC_SetAlarmCode(MXC_TOTAL_ALARM);
- DingDan_Flag = 0;
- }
- break;
- case 21:
- if (dwTickCount >= MXC_cAutoDelay)
- {
- if (MXC_DingDanJianGe_Length) //间隔距离为0时直接返回
- {
- MXC_DingDanJianGe_State = 1;
- MXC_cMotorStep = 100;
- MXC_cAutoStep = 22;
- }
- else
- MXC_cAutoStep = 8;
- }
- break;
- case 22:
- if (MXC_cMotorStep == 0)
- {
- MXC_cXiaChongStep = 1;
- MXC_cAutoStep = 23;
- }
- break;
- case 23:
- if (MXC_cXiaChongStep == 0)
- {
- if (MXC_DC_MODE != 0)
- MXC_cAutoStep = 1;
- else
- MXC_cAutoStep = 30;
- }
- break;
- case 30:
- if (MXC_PARAM_GZ_RESET_MODE == 0)//勾针复位方式 0为延时1为数控
- MXC_cMotorStep = 200;
- MXC_cAutoStep = 31;
- break;
- case 31:
- if (MXC_cMotorStep == 0)
- {
- MXC_cAutoStep = 1;
- }
- break;
- }
- }
- }
- // 检测是否踏了脚踏开关
- void MXC_NiLongXiuCiJiCheckStart(void)
- {
- unsigned short ch;
- // 停止键 不能在工作,手动,停止过程中
- if ((MXC_bRunning == 0) && (MXC_START_IN_UP || MXC_bStart || MXC_bNext))
- {
- MXC_bStart = 0;
- if (!MXC_LeftFenZhen_Origin_IN)
- MXC_SetAlarmCode(MXC_START_LFZ_ORIGIN_ALARM); //没拉链
- else if (!MXC_RightFenZhen_Origin_IN)
- MXC_SetAlarmCode(MXC_START_RFZ_ORIGIN_ALARM);
- else if (!MXC_Zipper_IN)
- MXC_SetAlarmCode(MXC_START_NO_ZIPPER_ALARM);
- else if ((MXC_PARAM_SEBIAO_DW_LENGTH > MXC_SET_ZIPPER_LENGTH) && (MXC_DC_MODE == 2))
- MXC_SetAlarmCode(MXC_SEBIAO_ZIPPER_LENGTH_ALARM);
- else if (MXC_KaDai_IN)
- MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
- else
- {
- /* if(GetTotal(MXC_TOTAL_ADDR) >= MXC_SET_TOTAL)
- {
- //调入下一组数据,全部都没有的话警告停止
- if(DingDanCheckOk() >= (MXC_DingDanNum))
- {
- MXC_SetAlarmCode(MXC_TOTAL_ALARM);
- return;
- }
- }*/
-
- if (MXC_bNext)
- {
- SingOneFlg = 1;
- MXC_bNext = 0;
- }
- MXC_bRunning = 1;
-
- cGouZhenTime = 1;
- cCheckLengthOk = 0;
- cZipperLength[0] = 0;
- cZipperLength[1] = 0;
- zipper_length_buff = 0;
- dwZipCnt = 0;
- //DISPLAY_DATA4=0;
- /*
- if((MXC_DingDanJianGe_State == 1) && MXC_DingDanWorkMode && MXC_USE_GZ_SERVO) //间隔链还没有打完情况下先打间隔链
- MXC_cAutoStep = 20;
- else
- */
- MXC_cAutoStep = 1;
- //第一次上电或长度不一样时启动必须先定位勾针
- //长度不一样先定位勾针
- //MXC_StartFirst = 1;
- offset_len = &MXC_SET_REVISE_ZIPPER_LENGTH;
- if ((MXC_SET_ZIPPER_LENGTH + (*offset_len)) > MXC_Gouzhencurrent_L)
- ch = MXC_SET_ZIPPER_LENGTH + MXC_SET_REVISE_ZIPPER_LENGTH - MXC_Gouzhencurrent_L;
- else
- ch = MXC_Gouzhencurrent_L - (MXC_SET_ZIPPER_LENGTH + (*offset_len));
- // 数控模式下不用走动勾针
- if ((MXC_StartFirst || (ch > 1)) && (MXC_DC_MODE == 0) && MXC_USE_GZ_SERVO)
- {
- MXC_cGouZhenDWStep = 1;
- //MXC_StartFirst = 1;
- }
- }
- }
-
- //卡带感应
- if (MXC_KaDai_IN && (dwTickCount >= MXC_cKaDaiDelay))
- {
- if (MXC_DC_MODE == 1)
- {
- if (X_DRV && MXC_bRunning && (MXC_cMotorStep == 20))
- {
- MXC_KD_Flag = 1;
- KD_GO_ON_FLAG = 1;
- }
- }
- MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
-
- MXC_cKaDaiDelay = dwTickCount + 2200;
- }
-
- if (MXC_KD_Flag)
- {
- if (!X_DRV)
- {
- MXC_KD_pos = dwRealPos;
- MXC_KD_Flag = 0;
- }
- }
-
- if (MXC_KaDai_IN_UP)
- {
- if (MXC_cChuiQiStep == 0)
- MXC_cChuiQiStep = 1;
- }
- //停止
- STOP_IN_FLAG_OLD = STOP_IN_FLAG;
-
- if (MXC_STOP_IN)
- {
- if (STOP_FILTER < 50)
- {
- STOP_FILTER++;
- }
- else
- STOP_IN_FLAG = 1;
- }
- else if (STOP_FILTER > 25)
- {
- STOP_FILTER--;
- }
- else
- STOP_IN_FLAG = 0;
-
- if (MXC_bStop)
- {
- MXC_bStop = 0;
- if (MXC_bRunning)
- MXC_SingOneFlag = 1;
- }
-
- if (((STOP_IN_FLAG && !STOP_IN_FLAG_OLD)))
- {
- MXC_bStop = 0;
- if (MXC_cGouZhenDWStep && STOP_IN_FLAG && (MXC_cXiaChongStep == 0))
- {
- AxisDecStop(Y_AXIS);
- MXC_cGouZhenDWStep = 0;
- }
- if (MXC_bRunning)
- {
- if (MXC_cXiaChongStep == 0)
- {
- if (MXC_cChuiQiStep == 0)
- MXC_cChuiQiStep = 1;
-
- if (!MXC_XiaChong_MOTOR)
- MXC_XC_SongZhou = MXC_XC_SERVER_EN;
- }
- MXC_bRunning = 0;
- cStopFlag = 0;
- MXC_cAutoStep = 0;
- MXC_cMotorStep = 0;
- MXC_cDCPStep = 0;
- AxisDecStop(X_AXIS);
- //DISPLAY_DATA4++;
- MXC_cJiaoDaoStep = 0;
- SingOneFlg = 0;
- MXC_SingOneFlag = 0;
- MXC_KD_Flag = 0;
- KD_GO_ON_FLAG = 0;
- }
- else
- {
- DISPLAY_DATA3 = 0;
- MXC_bRunning = 0;
- SetPos(X_AXIS, 0);
- MXC_TuoDaiSongZhou = MXC_SERVER_DISEN;
- cDW_data_Num = 0;
- cStopFlag = 0;
- MXC_cAutoStep = 0;
- MXC_cMotorStep = 0;
- MXC_cXiaChongStep = 0;
- MXC_cLeftFenZhenStep = 0;
- MXC_cRightFenZhenStep = 0;
- MXC_cJiaoDaoStep = 0;
- MXC_cDCPStep = 0;
- MXC_DingDao_BaoHu_VAVLE = 0;
- MXC_XiaZhi_VAVLE = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_XiaChong_MOTOR = 0;
- MXC_ChaoSheng = 0;
- MXC_JiaoDao_OUT = 0;
- MXC_ChuDai_VAVLE = 0;
- MXC_GuDingGouZhen = 0;
- SingOneFlg = 0;
- MXC_SingOneFlag = 0;
- MXC_KD_Flag = 0;
- KD_GO_ON_FLAG = 0;
- if (MXC_XiaChongMotorMode)
- MXC_XC_SongZhou = MXC_XC_SERVER_EN;
- else
- MXC_XC_ShaChe = MXC_SC_DISEN;
-
- if ((MXC_cChuiQiStep == 0) && (MXC_cXiaChongStep == 0))
- MXC_cChuiQiStep = 1;
- AxisDecStop(X_AXIS);
- //DISPLAY_DATA7++;
- SetAlarmCode(MXC_ALARM_ADDR, MXC_NO_ALARM);
- }
- }
-
- // if (!MXC_bRunning && (MXC_cMotorStep == 0) && (MXC_cXiaChongStep == 0))
- // {
- // if (!X_DRV)
- // MXC_TuoDaiSongZhou = MXC_SERVER_DISEN;
- // }
- if (MXC_bAlarmStop)
- {
- MXC_bAlarmStop = 0;
- MXC_bRunning = 0;
- MXC_cAutoStep = 0;
- MXC_cMotorStep = 0;
- MXC_cDCPStep = 0;
- MXC_SingOneFlag = 0;
- AxisDecStop(X_AXIS);
- if ((GetAlarmCode(MXC_ALARM_ADDR) == MXC_XIA_CHONG_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_XC_ALARM) || (GetAlarmCode(MXC_ALARM_ADDR) == MXC_FEN_ZHEN_ALARM))
- {
- MXC_cXiaChongStep = 0;
- MXC_XiaChong_MOTOR = 0;
- }
- }
- }
- void MXC_JiaoDao(void)
- {
- if (MXC_cJiaoDaoStep == 1)
- {
- MXC_cChuiQiDelay = dwTickCount + 500;
- MXC_JiaoDao_OUT = 1;
- MXC_cJiaoDaoStep = 2;
- }
- else if ((MXC_cJiaoDaoStep == 2) && (dwTickCount >= MXC_cChuiQiDelay))
- {
- MXC_JiaoDao_OUT = 0;
- MXC_cJiaoDaoStep = 0;
- }
- }
- void MXC_ChuiQiProc(void)
- {
- //吹气
- if (MXC_XiaChong_IN_UP)
- {
- if (MXC_cChuiQiStep == 0)
- MXC_cChuiQiStep = 1;
- if(!MXC_DingDao_BaoHu_VAVLE && MXC_DDBH_Origin_IN )//
- {
- MXC_DingDao_BaoHu_VAVLE = 1;
- MXC_cDDBHDelay = dwTickCount + MXC_DDBH_Time;
- }
-
- }
- if(MXC_DingDao_BaoHu_VAVLE && dwTickCount > MXC_cDDBHDelay)
- {
- MXC_DingDao_BaoHu_VAVLE = 0;
- }
- #if 0
- switch (MXC_cDCPStep)
- {
- case 0:
- break;
- case 1:
- MXC_cDCPStep = 2;
- MXC_cDaoJuCheckDelay = dwTickCount + 3500;
- break;
- case 2:
- if (MXC_DingChuPian_IN_DW)
- {
- MXC_cDCPStep = 0;
- }
- else if ((dwTickCount >= MXC_cDaoJuCheckDelay) && (MXC_DAO_JU_ALARM_EN == 0))
- MXC_SetAlarmCode(MXC_DAO_JU_ALARM);
- break;
- }
- #endif
- switch (MXC_cChuiQiStep)
- {
- case 1:
- MXC_cChuiQiStep = 2;
- if (MXC_bRunning)
- MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_DELAY_CHUIQI_TIME;
- break;
- case 2:
- if (dwTickCount >= MXC_cChuiQiDelay)
- {
- MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_CHUIQI_TIME;
- MXC_ChuiQi_VAVLE = 1; //
- MXC_cChuiQiStep = 3;
- }
- break;
- case 3:
- if (dwTickCount >= MXC_cChuiQiDelay)
- {
- MXC_ChuiQi_VAVLE = 0; //
- MXC_cChuiQiStep = 0;
- }
- break;
- }
- }
- void MXC_ShaChe_Output(void)
- {
- //启动吹气
- cShaCheTime = dwTickCount + (unsigned long)120;
- if (MXC_XiaChongMotorMode == 0)
- MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
- }
- void MXC_Output_XiaCi(void) //下止输出
- {
- if (MXC_XIA_ZHI_ENABLE) //下止选择
- {
- //下止输出
- MXC_cXiaZhiDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
- MXC_XiaZhi_VAVLE = 1;
- }
- }
- unsigned char ComPareLength(void)//前后拉链对比
- {
- if ((cZipperLength[0] != 0) && (cZipperLength[1] != 0))
- {
- if (cZipperLength[0] > cZipperLength[1])
- {
- if ((cZipperLength[0] - cZipperLength[1]) > 50)
- {
- return 0;
- }
- else
- return 1;
- }
- else
- {
- if ((cZipperLength[1] - cZipperLength[0]) > 50)
- {
- return 0;
- }
- else
- return 1;
- }
- }
- else
- return 0;
- }
- void MXC_NiLongXiuCiJi_Motor(void)
- {
- static long save_buff, gou_zhen_buff;
- static unsigned long zipper_length;
- short *revise_buff;
-
- if (MXC_bRunning)//检测拉链,由于拉链有间隙,故需要延迟检测
- {
- if (MXC_Zipper_IN)
- {
- MXC_cBudaiCheckDelay = dwTickCount + MXC_PARAM_MOTOR_ALARM_TIME;
- }
- else if (dwTickCount >= MXC_cBudaiCheckDelay) //没布带了
- {
- MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM); //没拉链
- }
- }
-
- dwRealPos = GetPos(X_AXIS);
- //当前位置脉冲
- dwRealPosY = GetPos(Y_AXIS);
- DISPLAY_DATA6 = zipper_length;
- // DISPLAY_DATA7 = zipper_length_buff;
- switch (MXC_cMotorStep)
- {
- case 0:
- break;
- //
- case 1:
- //
- if (MXC_LeftFenZhen_Origin_IN && (!MXC_LeftFenZhen_IN) && MXC_RightFenZhen_Origin_IN && (!MXC_RighttFenZhen_IN))
- {
- SetPos(X_AXIS, 0);
- //save_buff = dwRealPos;
- //DISPLAY_DATA2= save_buff;
- revise_buff = &user_datas[17];
- //save_pos_buff = dwRealPos;
-
- if (MXC_DC_MODE == 0) //钩针定寸(暂时无钩针)
- {
- if (MXC_DEC_MODE) //减速方式:1数控模式 0感应方式
- {
- if (MXC_PARAM_AUTO_CHECK_MODE) //1为自动测长0为手动输入长度
- {
- if (cCheckLengthOk)
- {
- AxisMovePosAccDecNotStop(X_AXIS, MXC_PARAM_SET_SPEED, zipper_length - MXC_PARAM_LOWSPEED_LENGTH,
- MXC_PARAM_START_SPEED, MXC_PARAM_LOW_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED, 0);
- }
- else
- {
- if (cCheckLengthOk == 0)
- {
- cZipperLength[0] = cZipperLength[1];
- cZipperLength[1] = zipper_length_buff;
- if (ComPareLength())//返回1,前后拉链没有明显变化
- {
- cCheckLengthOk = 1;
- }
- }
-
- if (cCheckLengthOk)
- {
- zipper_length = cZipperLength[1];
- AxisMovePosAccDecNotStop(X_AXIS, MXC_PARAM_SET_SPEED, zipper_length - MXC_PARAM_LOWSPEED_LENGTH,
- MXC_PARAM_START_SPEED, MXC_PARAM_LOW_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED, 0);
- }
- else
- {
- AxisContinueMoveAcc(X_AXIS, MXC_PARAM_FIRST_SPEED, MXC_DIR_P, MXC_PARAM_START_SPEED,
- MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED);
- }
- }
- }
- else
- {
- if (dwZipCnt == 0)
- AxisContinueMoveAcc(X_AXIS, MXC_PARAM_FIRST_SPEED, MXC_DIR_P, MXC_PARAM_START_SPEED, MXC_PARAM_START_SPEED,
- MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED);
- else
- {
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
- //输入长度过大
- if (zipper_length > zipper_length_buff && dwZipCnt > 1)
- zipper_length = zipper_length_buff;
- AxisMovePosAccDecNotStop(X_AXIS, MXC_PARAM_SET_SPEED, zipper_length - MXC_PARAM_LOWSPEED_LENGTH,
- MXC_PARAM_START_SPEED, MXC_PARAM_LOW_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED, 0);
- }
- }
- MXC_cMotorStep = 3;
- }
- else // 感应方式
- {
- AxisContinueMove(X_AXIS, MXC_PARAM_SET_SPEED, MXC_DIR_P);
- MXC_cMotorStep = 2;
- }
- }
- else if (MXC_DC_MODE == 1 && (!MXC_TIAOSHI_MODE || MXC_START_IN_UP)) //电机定寸
- {
- // if (KD_GO_ON_FLAG)
- // {
- // if(bGongFen_Stop == 1)
- // {
- // if (MXC_KD_pos > (MXC_DingDanJianGe_Length + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH))//警告停止时走链已超过,按正常重新走链
- // zipper_length = MXC_DingDanJianGe_Length + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
- // else//警告停止时还未超出,走剩下的拉链
- // zipper_length = MXC_DingDanJianGe_Length + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - MXC_KD_pos;
- // MXC_cAutoStep = 22;
- // }
- // else
- // {
- // if (MXC_KD_pos > (MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH))//警告停止时走链已超过,按正常重新走链
- // zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
- // else//警告停止时还未超出,走剩下的拉链
- // zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - MXC_KD_pos;
- // }
- // KD_GO_ON_FLAG = 0;
- // }
- // else
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
-
- MXC_cMotorStep = 20;
- MXC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
- MXC_GuDingGouZhen = 1; //定位(固定勾针)电磁阀
-
- AxisMovePosAccDec(X_AXIS, MXC_PARAM_SET_SPEED, zipper_length, MXC_PARAM_START_SPEED,
- MXC_PARAM_SHIFU_LOW_SPEED, MXC_PARAM_ACC_SPEED,( MXC_PARAM_DEC_SPEED + MXC_PARAM_SET_SPEED/200) ,
- MXC_PARAM_SHIFU_LOWSPEED_LENGTH);
- }
- else if(MXC_DC_MODE == 2)//色标定寸
- {
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff);
-
- if ((dwZipCnt == 0) || SingOneFlg)
- AxisContinueMoveAcc(X_AXIS, MXC_PARAM_SB_LOW_SPEED, MXC_DIR_P, MXC_PARAM_START_SPEED,
- MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED);
- else
- AxisContinueMoveAcc(X_AXIS, MXC_PARAM_SB_HIGH_SPEED, MXC_DIR_P, MXC_PARAM_START_SPEED,
- MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED);
- cSeBiaoOk = 0;
- cSeBiaoEn = 0;
- MXC_cMotorStep = 50;
- }
- MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
- MXC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- }
- break;
- // step2-5 活动勾针定寸
- case 2:
- if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0))
- MXC_GouZhen_VAVLE = 0;
- if (MXC_DEC_MODE == 0) // 感应模式
- {
- if (MXC_Dec_IN_DW)
- {
- AxisChangeSpeed(X_AXIS, MXC_PARAM_LOW_SPEED);
- MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
- MXC_cMotorStep = 3;
- }
- if (MXC_GouZhen_IN)
- {
- MXC_cMotorStep = 5;
- AxisEgmStop(X_AXIS);
- }
- }
- if (dwTickCount >= MXC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 3:
- if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0))
- MXC_GouZhen_VAVLE = 0;
- if (MXC_DEC_MODE) // 数控方式
- {
- if (MXC_PARAM_AUTO_CHECK_MODE)
- {
- if (cCheckLengthOk)
- {
- if ((dwRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH)) && MXC_PARAM_GZ_RESET_MODE)
- MXC_GouZhen_VAVLE = 0;
- }
- else
- {
- if (dwTickCount >= MXC_cGouZhenTime)
- MXC_GouZhen_VAVLE = 0;
- }
- }
- else
- {
- if ((dwRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH)) && MXC_PARAM_GZ_RESET_MODE)
- MXC_GouZhen_VAVLE = 0;
- if ((dwZipCnt == 0) && (dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 1))
- MXC_GouZhen_VAVLE = 0;
- }
-
- if (MXC_GouZhen_IN)
- {
- MXC_GouZhen_VAVLE = 0;
- MXC_cMotorStep = 4;
- //AxisEgmStop(X_AXIS);
- //再走一点拉紧
- AxisMovePosAccDec(X_AXIS, MXC_PARAM_LOW_SPEED, 6, MXC_PARAM_LOW_SPEED, MXC_PARAM_LOW_SPEED,
- MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED, 0);
- }
- }
- else // 感应方式
- {
- MXC_cMotorStep = 4;
- }
-
- if (dwTickCount >= MXC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 4:
- if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0))
- MXC_GouZhen_VAVLE = 0;
- if (MXC_DEC_MODE) // 数控方式
- {
- if (!X_DRV)
- {
- MXC_cMotorStep = 0;
- zipper_length_buff = dwRealPos;
- }
- }
- else // 感应方式
- {
- if (MXC_GouZhen_IN)
- {
- MXC_cMotorStep = 5;
- AxisEgmStop(X_AXIS);
- }
- }
- if (dwTickCount >= MXC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 5:
- if (MXC_DEC_MODE) // 数控方式
- {
- }
- else // 感应方式
- {
- if (!X_DRV)
- {
- MXC_cMotorStep = 0;
- }
- }
- if (dwTickCount >= MXC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
-
- /*
- case 11://以下为固定勾针方式
- if(MXC_XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
- {
- if(dwTickCount >= MXC_cAutoDelay)MXC_GuDingGouZhen = 0;
- if(!MXC_GuoLian_IN)
- {
- AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
- MXC_cMotorStep = 12;
- MXC_cAutoDelay = dwTickCount + (unsigned long)1500; //延时检测
- }
- }
- else
- {
- if(MXC_GuoLianCheckMode)
- {
- if(!MXC_GuoLian_IN)
- {
- AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
- MXC_cMotorStep = 12;
- MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[12]; //延时检测
- }
- }
- else
- {
- if(MXC_GuoLian_IN)
- {
- AxisChangeSpeed(X_AXIS,MXC_PARAM_LOW_SPEED);
- MXC_cMotorStep = 12;
- MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[12]; //延时检测
- }
- }
- }
- break;
- case 12:
- if(dwTickCount >= MXC_cAutoDelay)
- {
- if(MXC_GuDingGouZhen)
- {
- MXC_GuDingGouZhen = 0;
- MXC_cAutoDelay = dwTickCount + (unsigned long)1500; //延时检测
- }
- else if(!MXC_GuDingGouZhen)
- {
- // MXC_SetAlarmCode(MXC_GU_DING_GOUZHEN_ALARM);
- }
- }
-
- if(MXC_XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
- {
- if(MXC_GuoLian_IN)
- {
- MXC_GuDingGouZhen = 0;
- MXC_cMotorStep = 13;
- MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机
- }
- }
- else
- {
- if(MXC_GuoLianCheckMode)
- {
- if(MXC_GuoLian_IN_UP)
- {
- MXC_GuDingGouZhen = 0;
- MXC_cMotorStep = 13;
- MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机
- }
- }
- else
- {
- if(MXC_GuoLian_IN_DW)
- {
- MXC_GuDingGouZhen = 0;
- MXC_cMotorStep = 13;
- MXC_cAutoDelay = dwTickCount + (unsigned long)user_datas[10]; //延时停电机
- }
- }
- }
- break;
- case 13:
- if((dwTickCount >= MXC_cAutoDelay))
- {
- if(MXC_XiaMode == 0) //0 普通下止 1 超声下止 当超声下时勾针
- {
- AxisEgmStop(X_AXIS);
- if(MXC_GuoLian_IN)
- {
- MXC_cMotorStep = 0;
- MXC_LIHE_VAVLE = 0;
- }
- }
- else
- {
- if(MXC_GuoLianCheckMode)
- {
- if(MXC_GuoLian_IN)
- {
- MXC_cMotorStep = 0;
- AxisEgmStop(X_AXIS);
- MXC_LIHE_VAVLE = 0;
- }
- }
- else
- {
- if(!MXC_GuoLian_IN)
- {
- MXC_cMotorStep = 0;
- AxisEgmStop(X_AXIS);
- MXC_LIHE_VAVLE = 0;
- }
- }
- }
- }
- break;
- */
- //伺服定寸
- case 20:
- if (!X_DRV)
- {
- user_datas[270+cDW_data_Num] = dwRealPos;
- cDW_data_Num++;
- if(cDW_data_Num >= 30)cDW_data_Num = 0;
- MXC_cMotorStep = 0;
- }
- else if (dwTickCount >= MXC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 50:
- if (dwZipCnt == 0)
- {
- cSeBiaoOk = 0;
- cSeBiaoEn = 1;
- MXC_cMotorStep = 51;
- }
- else
- {
- if ((dwRealPos + MXC_PARAM_SEBIAO_LOWSPEED_LENGTH) >= (zipper_length - MXC_PARAM_SEBIAO_DW_LENGTH))//抵达色标慢速长度
- // AxisChangeSpeed(X_AXIS, MXC_PARAM_LOW_SPEED);//修改减速方式
- AxisContinueMoveChangeSpeed(X_AXIS, MXC_PARAM_LOW_SPEED, MXC_PARAM_LOW_SPEED,
- MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED);
- if ((dwRealPos + MXC_PARAM_SEBIAO_TQ_LENGTH) >= (zipper_length - MXC_PARAM_SEBIAO_DW_LENGTH))
- {
- cSeBiaoOk = 0;//开启色标中断
- cSeBiaoEn = 1;//色标中断使能
- MXC_cMotorStep = 51;
- }
- else if (dwRealPos > (zipper_length + MXC_ERROR_LENGTH))//
- MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
- }
- break;
- case 51:
- if (dwZipCnt != 0)
- {
- if (dwRealPos >= (zipper_length - MXC_PARAM_SEBIAO_LOWSPEED_LENGTH))
- AxisChangeSpeed(X_AXIS, MXC_PARAM_LOW_SPEED);
- if (dwRealPos > (zipper_length + MXC_ERROR_LENGTH))//电机所跑距离超出容错范围
- MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
- }
- if (!X_DRV)
- {
- if (dwZipCnt != 0)
- {
- if (dwRealPos < (zipper_length - MXC_ERROR_LENGTH))//电机停止位置小于容错范围
- MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
- }
- MXC_cMotorStep = 0;
- }
- else if (dwTickCount >= MXC_cMotorDelay)
- MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
- break;
- case 100:
- bGongFen_Stop = 1;
- SetPos(X_AXIS, 0);
- //算出间隔脉冲
- zipper_length = MXC_DingDanJianGe_Length + MXC_PARAM_DAOKOU_LENGTH;
- DISPLAY_DATA5 = zipper_length;
- AxisMovePosAccDec(X_AXIS,MXC_PARAM_SET_SPEED/2,
- zipper_length,
- MXC_PARAM_START_SPEED,
- MXC_PARAM_START_SPEED,
- MXC_PARAM_ACC_SPEED,
- MXC_PARAM_DEC_SPEED,
- 0);
-
- MXC_cMotorStep = 101;
- break;
- case 101:
- if(!X_DRV)
- {
- bGongFen_Stop = 0;
- MXC_cMotorStep = 0;
- }
- break;
- /*
- case 200:
- //先把拉链
- zipper_length = MXC_SET_ZIPPER_LENGTH;
- //把速度降下来
- AxisMovePosAccDec(X_AXIS,MXC_PARAM_SET_SPEED/2,zipper_length,MXC_PARAM_START_SPEED/2,MXC_PARAM_ACC_SPEED,MXC_PARAM_DEC_SPEED);
-
- MXC_cMotorStep = 201;
- break;
- case 201:
- if(!X_DRV)
- {
- MXC_cMotorStep = 0;
-
- }
- break; */
- }
- }
- //下冲
- void MXC_NiLongXiuCiJi_XiaC(void)
- {
- static unsigned char xia_zhi_flg = 0;
- static unsigned long delay_gz_back;
- static unsigned char gz_back_flg = 0;
-
- //屏幕选择带不带下止功能
- if (MXC_PARAM_XIAZHI_EN == 0)
- MXC_XIA_ZHI_ENABLE = 0;
-
- if ((MXC_XIA_ZHI_ENABLE == 2) && MXC_bRunning)
- {
- if ((dwTickCount >= delay_gz_back) && gz_back_flg)
- {
- MXC_GouZhen_VAVLE = 1;
- gz_back_flg = 0;
- MXC_cGouZhenTime = dwTickCount + 300;
- }
- }
-
- switch (MXC_cXiaChongStep)
- {
- case 0:
- return;
- break;
- case 1:
- {
- MXC_DingDanJianGe_State = 0;//走间隔
- if ((MXC_XIA_ZHI_ENABLE == 2) && MXC_bRunning)
- {
- MXC_cXiaChongStep = 7;
- delay_gz_back = dwTickCount + MXC_PARAM_DELAY_GOUZHEN_BACK;
- gz_back_flg = 1;
- xia_zhi_flg = 0;
- MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_DELAY_XC;
- }
- else
- {
- gz_back_flg = 0;
- MXC_cRightFenZhenStep = 1;//右分针动作
- if (MXC_cDCPStep == 0)//做顶出片检测
- MXC_cDCPStep = 1;
- MXC_cLeftFenZhenStep = 0;
- cRFengTimer = 0;
- cLFengTimer = 0;
- MXC_cXiaChongStep = 2;
- }
- }
- break;
- case 2:
- if ((MXC_cRightFenZhenStep == 0) && (MXC_cLeftFenZhenStep == 0))
- {
- if (MXC_XiaChongMotorMode)//0为交流1为步进/伺服
- MXC_XC_SongZhou = MXC_XC_SERVER_EN;
- else
- MXC_XC_ShaChe = MXC_SC_DISEN;
- MXC_XC_SongZhou = MXC_XC_SERVER_DISEN; //刹车打开
- if (MXC_bRunning)
- {
- MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_DELAY_XC;
- }
- MXC_cXiaChongStep = 3;
- }
- break;
- case 3:
- if (dwTickCount >= MXC_cXiaChongDelay)
- {
- MXC_cXiaChongStep = 4;
- MXC_XiaChong_MOTOR = 1; //下冲电机
- if (MXC_bRunning)
- {
- MXC_Output_XiaCi(); //下止输出
- xia_zhi_flg = 1;
- }
- MXC_cXiaChongDelay = dwTickCount + (unsigned long)ERRORTIME; //下冲最长时间
-
- // if(MXC_XiaChongMotorMode == 1)
- // {
- // AxisMoveTwoPos(Y_AXIS,MXC_XiaChongSpeed,2000,MXC_XiaChongLowSpeed,9999999,0);
- // }
- }
- break;
- case 4: //碰到右大微动,延时停
- if (MXC_XiaChong_IN_UP)//下冲回原位
- {
- MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_XC_DELAY;
- MXC_cXiaChongStep = 5;
- MXC_LeftFenZhen_VAVLE = 0; //退左分针
- MXC_RightFenZhen_VAVLE = 0; //退右分针
- MXC_GouZhen_VAVLE = 1;
- MXC_cGouZhenTime = dwTickCount + 300;
- }
- else if (dwTickCount >= MXC_cXiaChongDelay) //自动停机
- {
- MXC_cXiaChongStep = 0;
- // MXC_ShaChe_Output();////刹车
- MXC_XiaChong_MOTOR = 0; // //下冲电机
- MXC_SetAlarmCode(MXC_XC_ALARM);
- MXC_LeftFenZhen_VAVLE = 0; //退左分针
- MXC_RightFenZhen_VAVLE = 0; //退右分针
- // AxisEgmStop(Y_AXIS);
- }
-
- break;
- case 5:
- if (dwTickCount >= MXC_cXiaChongDelay)
- {
-
- // AxisEgmStop(Y_AXIS);
- MXC_XiaChong_MOTOR = 0; //延时刹车
- if (MXC_PARAM_SC_MODE)//1为长时间刹车
- {
- MXC_cXiaChongStep = 0;
- }
- else
- {
- MXC_cXiaChongStep = 6;
- }
-
- // MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_SC_DELAY;
- }
- break;
- case 6:
- // if((dwTickCount >= MXC_cXiaChongDelay))
- {
- MXC_cXiaChongStep = 7;
- MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_SC_DELAY;
- // MXC_ShaChe_Output();
- }
- break;
- case 7:
- if ((dwTickCount >= MXC_cXiaChongDelay) && !MXC_XiaZhi_VAVLE)
- {
- if (MXC_XIA_ZHI_ENABLE == 2)
- {
- MXC_cXiaChongStep = 8;
- MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_XIAZHI_TIME;
- }
- else
- {
- MXC_cXiaChongStep = 0;
- MXC_cXiaChongDelay = dwTickCount;
- }
- if (MXC_bRunning && !xia_zhi_flg)
- {
- MXC_Output_XiaCi(); //下止输出
- }
- MXC_XC_SongZhou = MXC_XC_SERVER_EN;
- }
- break;
- case 8:
- if (dwTickCount >= MXC_cXiaChongDelay)
- {
- MXC_cXiaChongStep = 0;
- }
- break;
- case 20: // 点动普通下冲动作
- MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
- MXC_cXiaChongDelay = dwTickCount + 50;
- MXC_cXiaChongStep = 21;
- break;
- case 21:
- if ((dwTickCount >= MXC_cXiaChongDelay))
- {
- MXC_XiaChong_MOTOR = 1;
- // MXC_cXiaChongDelay = dwTickCount + 50;
- MXC_cXiaChongStep = 22;
- }
- break;
- case 22:
- if (MXC_XiaChong_IN_UP)
- {
- MXC_XiaChong_MOTOR = 0;
- MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
- if (MXC_XiaChongMotorMode)
- MXC_cXiaChongStep = 0;
- else
- {
- MXC_cXiaChongDelay = dwTickCount + 150;
- MXC_cXiaChongStep = 23;
- }
- }
- break;
- case 23:
- if ((dwTickCount >= MXC_cXiaChongDelay))
- {
- MXC_XC_SongZhou = MXC_XC_SERVER_EN;
- MXC_cXiaChongStep = 0;
- }
- break;
- case 40: // 点动电机下冲动作
- MXC_XC_SongZhou = MXC_XC_SERVER_DISEN;
- MXC_cXiaChongDelay = dwTickCount + 50;
- MXC_cXiaChongStep = 41;
- break;
- case 41:
- if (!Y_DRV)
- AxisMovePos(Y_AXIS, 20, 10);
- MXC_cXiaChongStep = 42;
- break;
- case 42:
- if (!Y_DRV)
- {
- MXC_cXiaChongStep = 0;
- }
- break;
- }
- }
- //分针
- void MXC_NiLongXiuCiJi_FenZhengProc(void)
- {
- if (MXC_FenZSelect == 0)
- {
- MXC_cLeftFenZhenStep = 0;
- MXC_cRightFenZhenStep = 0;
- }
- //右分针
- switch (MXC_cRightFenZhenStep)
- {
- case 0:
- break;
- case 1:
- MXC_cFenZhenRightDelay = MXC_PARAM_R_FZ_DELAY + dwTickCount;
- MXC_cRightFenZhenStep = 2;
- break;
- case 2:
- if (dwTickCount >= MXC_cFenZhenRightDelay)
- {
- MXC_cRightFenZhenStep = 3;
- MXC_RightFenZhen_VAVLE = 1; //右分针电磁阀
- MXC_cFenZhenRightDelay = dwTickCount + FenZhengErrorTime;
- }
- break;
- case 3: //碰到右大微动,延时停
- if (!MXC_RightFenZhen_Origin_IN) //右分针原点离开
- {
- MXC_cFenZhenRightDelay = dwTickCount + FenZhengErrorTime;
- MXC_cRightFenZhenStep = 4;
- } //右分针不下去
- else if (dwTickCount >= MXC_cFenZhenRightDelay)
- {
- MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
- MXC_cRightFenZhenStep = 0;
- MXC_RightFenZhen_VAVLE = 0;
- }
- break;
- case 4:
- if (MXC_RighttFenZhen_IN) //插针到位
- {
- MXC_cRightFenZhenStep = 0;
- MXC_cLeftFenZhenStep = 1; //左分针延时启动
- }
- else if (dwTickCount >= MXC_cFenZhenRightDelay)
- {
- MXC_RightFenZhen_VAVLE = 0; //右分针
- cRFengTimer++;
- //当右分针分不到位时,左分针也要重新分针
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_cRightFenZhenStep = 0;
- if (cRFengTimer < 4)//times 次数
- {
- MXC_cRightFenZhenStep = 5;
- MXC_cFenZhenRightDelay = dwTickCount + FenZhengErrorTime;
- }
- else
- {
- MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
- MXC_cRightFenZhenStep = 0;
- MXC_RightFenZhen_VAVLE = 0;
- }
- }
- break;
- //5-6重新下右分针
- case 5:
- if (MXC_RightFenZhen_Origin_IN) //退到位
- {
- MXC_cRightFenZhenStep = 6;
- }
- else if (dwTickCount >= MXC_cFenZhenRightDelay)
- {
- MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
- MXC_RightFenZhen_VAVLE = 0;
- MXC_cRightFenZhenStep = 0;
- }
- break;
- case 6:
- {
- MXC_cRightFenZhenStep = 1;
- }
- break;
- }
- //左分针
- switch (MXC_cLeftFenZhenStep)
- {
- case 0:
- break;
- case 1:
- MXC_cFenZhenLeftDelay = MXC_PARAM_L_FZ_DELAY + dwTickCount;
- MXC_cLeftFenZhenStep = 2;
- break;
- case 2:
- if (dwTickCount >= MXC_cFenZhenLeftDelay)
- {
- MXC_cLeftFenZhenStep = 3;
- MXC_LeftFenZhen_VAVLE = 1; //左分针电磁阀
- MXC_cFenZhenLeftDelay = dwTickCount + FenZhengErrorTime;
- }
- break;
- case 3: //离开左分针原点
- if (!MXC_LeftFenZhen_Origin_IN) //左分针原点离开
- {
- MXC_cFenZhenLeftDelay = dwTickCount + FenZhengErrorTime;
- MXC_cLeftFenZhenStep = 4;
- } //左分针不下去
- else if (dwTickCount >= MXC_cFenZhenLeftDelay)
- {
- MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
- MXC_cLeftFenZhenStep = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- }
- break;
- case 4:
- if (MXC_LeftFenZhen_IN) //插针到位
- MXC_cLeftFenZhenStep = 0;
- else if (dwTickCount >= MXC_cFenZhenLeftDelay)
- {
- MXC_LeftFenZhen_VAVLE = 0; //左分针
- cLFengTimer++;
- if (cLFengTimer < 6)
- {
- MXC_cLeftFenZhenStep = 5;
- MXC_cFenZhenLeftDelay = dwTickCount + FenZhengErrorTime;
- if ((cLFengTimer % 2) == 0)
- {
- MXC_RightFenZhen_VAVLE = 0;
- MXC_cRightFenZhenStep = 0;
- }
- }
- else
- {
- MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
- MXC_cLeftFenZhenStep = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- }
- }
- break;
- //5-6重新下左分针
- case 5:
- if (MXC_LeftFenZhen_Origin_IN) //退到位
- {
- MXC_cLeftFenZhenStep = 6;
- }
- else if (dwTickCount >= MXC_cFenZhenLeftDelay)
- {
- MXC_SetAlarmCode(MXC_FEN_ZHEN_ALARM);
- MXC_cLeftFenZhenStep = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- }
- break;
- case 6:
- if ((cLFengTimer % 2) == 0) //左边插两次都插不到,就退右边再同时插
- {
- MXC_cRightFenZhenStep = 1;
- cRFengTimer = 0;
- MXC_cLeftFenZhenStep = 0;
- }
- else
- {
- MXC_cLeftFenZhenStep = 1;
- }
- break;
- }
- }
- //勾针复位定位动作
- void MXC_NiLongXiuCiJi_GouZhenProc(void)
- {
- static unsigned char kk;
- static unsigned long last_set_length;
- long ch;
-
- //当前勾针位置为脉冲位置加偏移量
- MXC_Gouzhencurrent_L = dwRealPosY;
- //DISPLAY_DATA7 = dwRealPosY;
-
- if (!MXC_bRunning) //在手动状态下才点动勾针
- {
- if ((MXC_cXiaChongStep == 0) && (MXC_cGouZhenDWStep == 0))
- {
-
- //输入变化自动定位
- if (last_set_length != MXC_SET_ZIPPER_LENGTH)
- {
- last_set_length = MXC_SET_ZIPPER_LENGTH;
- if (MXC_USE_GZ_SERVO)
- MXC_cGouZhenDWStep = 1;
- //MXC_StartFirst=1;
- kk = 0;
- }
-
- //勾针定位
- if (MXC_GouZhenlocation)
- {
- MXC_GouZhenlocation = 0;
- MXC_cGouZhenDWStep = 1;
- MXC_StartFirst = 1;
- kk = 0;
- }
- if (MXC_ShaChe)
- {
- MXC_ShaChe = 0;
- if (!Y_DRV)
- {
- MXC_GouzhenShaChe = !MXC_GouzhenShaChe; //刹车取反
- }
- }
- if (MXC_GouZhenforward && !MXC_GouZhenforward_IN && !Y_DRV) //勾针前移 限位开关不能输入
- {
- if (!MXC_GouzhenShaChe || !MXC_GouZhen_VAVLE)
- MXC_cGouZhenMotorDelay = dwTickCount + 150;
- MXC_GouzhenShaChe = 1; //刹车松开
- //MXC_GouzhenMotor_DR = MXC_GZ_DIR_P;
- MXC_GouZhen_VAVLE = 1;
- MXC_cGouZhenTime = dwTickCount + 400;
- kk = 0;
- //先松开刹车延时动电机
- if (dwTickCount >= MXC_cGouZhenMotorDelay)
- {
- if (!Y_DRV)
- {
- AxisContinueMoveAcc(Y_AXIS, MXC_GouzhenSpeed_Hand_SPEED, MXC_GZ_DIR_N, MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED, 0);
- }
- }
- }
-
- if (MXC_GouZhenforward_IN)
- {
- MXC_GouZhenforward = 0;
- }
-
- if (MXC_GouZhenback && !MXC_GouZhenback_IN && !Y_DRV) //勾针后移 限位开关不能输入
- {
- if (!MXC_GouzhenShaChe || !MXC_GouZhen_VAVLE)
- MXC_cGouZhenMotorDelay = dwTickCount + 150;
- MXC_GouzhenShaChe = 1; //刹车松开
- //MXC_GouzhenMotor_DR = MXC_GZ_DIR_N;
- MXC_GouZhen_VAVLE = 1;
- MXC_cGouZhenTime = dwTickCount + 400;
- kk = 0;
- //先松开刹车延时动电机
- if (dwTickCount >= MXC_cGouZhenMotorDelay)
- {
- if (!Y_DRV)
- {
- AxisContinueMoveAcc(Y_AXIS, MXC_GouzhenSpeed_Hand_SPEED, MXC_GZ_DIR_P, MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED, 0);
- }
- }
- }
- if (MXC_GouZhenback_IN || ((dwRealPosY >= GetData32bits(MXC_N_LIMIT_LENGTH_ADDR)) && !MXC_StartFirst))
- {
- MXC_GouZhenback = 0;
- }
- if ((!MXC_GouZhenforward && !MXC_GouZhenback) && (kk == 0))
- {
- if (Y_DRV)
- {
- if (MXC_GouzhenShaChe)
- {
- kk = 1;
- MXC_cGouZhenMotorDelay = dwTickCount + 450;
- }
- }
- AxisEgmStop(Y_AXIS); //立即停
- MXC_GouZhenback = 0;
- MXC_GouZhenforward = 0;
- }
- //电机停止后延时刹车
- if (kk && (dwTickCount >= MXC_cGouZhenMotorDelay))
- {
- kk = 0;
- MXC_GouzhenShaChe = 0; //刹车
- }
- }
- }
- switch (MXC_cGouZhenDWStep)
- {
- case 1:
- MXC_cGouZhenMotorDelay = dwTickCount + 160;
- MXC_GouZhen_VAVLE = 1;
- MXC_GouzhenShaChe = 1; //刹车松开
- MXC_cGouZhenDWStep = 2;
- break;
- case 2: //先回前点
- if (dwTickCount >= MXC_cGouZhenMotorDelay)
- {
- if (!MXC_GouZhenforward_IN)
- {
- if ((!MXC_StartFirst))
- {
- offset_len = &MXC_SET_REVISE_ZIPPER_LENGTH;
- ch = (MXC_SET_ZIPPER_LENGTH + MultLengthOffset(MXC_SET_ZIPPER_LENGTH) + (*offset_len) - MXC_GouzhenMin_Length); //算出脉冲
-
- if (ch < 0)
- {
- MXC_SetAlarmCode(MXC_GOUZHEN_MIN_LENGTH_ALARM);
- MXC_cGouZhenDWStep = 0;
- }
- else
- {
- ch = ch - MXC_Gouzhencurrent_L;
- //DISPLAY_DATA1=ch;
- //DISPLAY_DATA2=MXC_Gouzhencurrent_L;
- // if(ch < 0)
- // MXC_GouzhenMotor_DR = MXC_GZ_DIR_P;
- // else
- // MXC_GouzhenMotor_DR = MXC_GZ_DIR_N;
- //
- // SetDir(Y_AXIS,MXC_GouzhenMotor_DR);
- AxisMovePos(Y_AXIS, MXC_GouzhenSpeed_Auto_SPEED, ch);
- MXC_cGouZhenDWStep = 7;
- }
- }
- else //等于0时就是第一次, 走手动速度
- {
- //MXC_GouzhenMotor_DR = MXC_GZ_DIR_P;
- if (!Y_DRV)
- AxisContinueMoveAcc(Y_AXIS, MXC_GouzhenSpeed_Hand_SPEED, MXC_GZ_DIR_N, MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED, 0);
- MXC_cGouZhenDWStep = 3;
- }
- }
- else //已在原点直接后移
- {
- MXC_cGouZhenDWStep = 4;
- MXC_GouzhenMotor_DR = MXC_GZ_DIR_N; //变为后移方向
- }
- }
- break;
- case 3:
- if (MXC_GouZhenforward_IN) //感应前点 延时后移
- {
- MXC_cGouZhenDWStep = 4;
- AxisEgmStop(Y_AXIS);
- MXC_cGouZhenMotorDelay = dwTickCount + 50;
- }
- break;
- case 4:
- if (dwTickCount >= MXC_cGouZhenMotorDelay)
- {
- //MXC_GouzhenMotor_DR = MXC_GZ_DIR_N; //变为后移方向
- ch = 5;
- AxisContinueMoveAcc(Y_AXIS, ch, MXC_GZ_DIR_P, MXC_PARAM_START_SPEED, MXC_PARAM_ACC_SPEED, MXC_PARAM_DEC_SPEED, 0); //匀速离开零点位置
- MXC_cGouZhenDWStep = 5;
- }
- break;
- case 5:
- if (!MXC_GouZhenforward_IN)
- {
- MXC_cGouZhenDWStep = 6;
- AxisDecStop(Y_AXIS);
- }
- break;
- case 6:
- if (!Y_DRV)
- {
- SetPos(Y_AXIS, 0); //回到原点位置清零
- //MXC_GouzhenMotor_DR = MXC_GZ_DIR_N; //变为后移方向
- offset_len = &MXC_SET_REVISE_ZIPPER_LENGTH;
-
- if ((MXC_SET_ZIPPER_LENGTH + (*offset_len) + MultLengthOffset(MXC_SET_ZIPPER_LENGTH)) >= MXC_GouzhenMin_Length)
- {
- ch = (MXC_SET_ZIPPER_LENGTH + (*offset_len) + MultLengthOffset(MXC_SET_ZIPPER_LENGTH) - MXC_GouzhenMin_Length); //算出脉冲
- //SetDir(Y_AXIS,MXC_GouzhenMotor_DR);
- AxisMovePos(Y_AXIS, MXC_GouzhenSpeed_Auto_SPEED, ch);
- MXC_cGouZhenDWStep = 7;
- }
- else
- {
- MXC_SetAlarmCode(MXC_GOUZHEN_MIN_LENGTH_ALARM);
- MXC_cGouZhenDWStep = 0;
- }
- }
-
- break;
- case 7:
-
- if (!Y_DRV)
- {
- MXC_cGouZhenDWStep = 8;
- MXC_cGouZhenMotorDelay = dwTickCount + 420;
- }
- else if ((MXC_GouzhenMotor_DR == MXC_GZ_DIR_N) && (MXC_GouZhenback_IN || ((dwRealPosY >= GetData32bits(MXC_N_LIMIT_LENGTH_ADDR)) && !MXC_StartFirst)))
- {
- AxisEgmStop(Y_AXIS); //立即停
- MXC_cGouZhenDWStep = 8;
- MXC_SetAlarmCode(MXC_GOUZHEN_MORE_ALARM);
- MXC_cGouZhenMotorDelay = dwTickCount + 420;
- }
- break;
- case 8:
- if (dwTickCount >= MXC_cGouZhenMotorDelay)
- {
- MXC_GouzhenShaChe = 0; //刹车
- MXC_cGouZhenDWStep = 0;
- MXC_StartFirst = 0;
- }
- break;
- }
- }
- #endif
|