123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947 |
- #include "global.h"
- #if XI_DONG_MACHINE
- /******输入输出说明******
- 输入监控页
- M48 X00 启动开关
- M49 X01 停止开关
- M50 X02 送料开关
- M51 X03 分带开关
- M52 X04 装料开关
- M53 X05 锁带开关
- M54 X06 夹料开关
- M55 X07 迫紧开关
- M56 X10 推料到位感应
- M57 X11 推料退到位感应
- M58 X12 送料到位感应
- M59 X13 送料退到位接近开关
- M60 X14 缺料感应
- M61 X15 过链接近开关
- M62 X16 迫紧接近开关
- M63 X17 卡带故障开关
- M64 X20 分带到位感应
- M65 X21 反推带到位感应
- M66 X22 工字码接近开关
- M67 X23 拨码片8脚
- M68 X24 拨码片4脚
- M69 X25 拨码片2脚
- M70 X26 模式转换 0 老款工作方式 1 新装饰链
- M71 X27 拨码片1脚
- 输出监控页
- M32 Y00 工字码数个位
- M33 Y01 工字码数十位
- M34 Y02 工字码间隙个位
- M35 Y03 振动盘
- M36 Y04 锁带电磁阀
- M37 Y05 送料电磁阀
- M38 Y06 夹料电磁阀
- M39 Y07 分带电磁阀
- M40 Y10 工字码间隙十位
- M41 Y11 工字码位置个位
- M42 Y12 工字码位置十位
- M43 Y13 蜂鸣器/计数表
- M44 Y14 装料电磁阀
- M45 Y15 迫紧电磁阀
- M46 Y16 反锁带电磁阀
- M47 Y017 反推带电磁阀
- ********************/
- extern unsigned long GZM_cCountTime;
- extern unsigned char GZM_cGeiLiaoNum;
- #define AddPuls 55
- //警告
- #define GZM_TuiLiaoDW_W 1 //推料到位(前)磁感开关异常
- #define GZM_TuiLiaoTDW_W 2 //推料退到位磁感开关异常
- #define GZM_SongLiaoDW_W 3 //送料到位磁感开关异常
- #define GZM_SongLiaoTDW_W 4 //送料退到位接近开关异常
- #define GZM_QueLiao_W 5 //缺料磁感开关异常
- #define GZM_NoZip_W 6 //过链接近开关异常
- #define GZM_PoJin_W 7 //迫紧接近开关异常
- #define GZM_KaDai_W 8 //卡带故障开关异常
- #define GZM_FengDaiDW_W 9 //分带到位磁感开关异常
- #define GZM_FanTiuDaiDW_W 10 //反推带到位磁感开关异常
- void GZM_TuiLiao(void);
- void GZM_PoJin(void);
- void GZM_Motor(void);
- unsigned char GZM_cOneTime,GZM_cWorkNum = 0,GZM_cBuMa,GZM_bStop,GZM_bRunning,GZM_cFirst,GZM_cGeiLiaoNum;
- long GZM_cPulseCount,GZM_dwSavePosBuff;
- void GZM_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(GZM_ALARM_ADDR,alarm_code);
- GZM_bStop = 1;
- }
- void GZM_InitAction(void)
- {
- XGearRatio = 1;
- YGearRatio = 1;
- }
- void GZM_Action(void)
- {
- GZM_PoJin();
-
- if(M15)
- {
- M15 = 0;
- SetAlarmCode(GZM_ALARM_ADDR,0);
- }
-
- //下止位减1
- if(M12)
- {
- M12 = 0;
- if(user_datas[41] > 0)user_datas[41] -= 1;
- }
- //下止位加1
- else if(M11)
- {
- M11 = 0;
- if((user_datas[41] < 500) || (X026 && (user_datas[41] < 9999)))user_datas[41]++;
- }
- //间隙位减1
- if(M17)
- {
- M17 = 0;
- if(user_datas[42] > 0)user_datas[42] -= 1;
- }
- //间隙位加1
- else if(M16)
- {
- M16 = 0;
- if(user_datas[42] < 500)user_datas[42]++;
- }
- //振动盘控制
- if(user_datas[71] != 0)
- SETY003();
- else
- CLRY003();
- //停止
- if(X001 || M1 || (GZM_bStop != 0) || X017)
- {
- if(X01_UP)
- {
- if(GZM_bRunning == 0)
- GZM_cWorkNum = 0;
- }
-
- GZM_bStop = 0;
- GZM_bRunning = 0;
- M1 = 0;
- AxisEgmStop(X_AXIS);
- cStepMByte = 0;
- cStepMByte1 = 0;
- cStepMByte2 = 0;
- cStepMByte3 = 0;
- cStepMByte4 = 0;
- cStepMByte5 = 0;
- cStepMByte6 = 0;
- AxisEgmStop(X_AXIS);
- Y00 = 0;
- Y01 = 0;
- Y02 = 0;
- Y04 = 0;
- Y05 = 0;
- Y06 = 0;
- Y07 = 0;
- Y10 = 0;
- Y11 = 0;
- Y12 = 0;
- Y13 = 0;
- Y14 = 0;
- Y15 = 0;
- Y16 = 0;
- if(X17_UP)
- {
- GZM_SetAlarmCode(GZM_KaDai_W) ;
- }
- }
- //手动
- if((GZM_bRunning==0) && (X001 == 0))
- {
- SETDR();
- //下止数量减1
- if(M19)
- {
- M19 = 0;
- if(user_datas[43] > 0)user_datas[43] -= 1;
- }
- //下止数量减1
- else if(M18)
- {
- M18 = 0;
- if(user_datas[43] < 500)user_datas[43]++;
- }
- //清产量
- if(M9)
- {
- M9 = 0;
- ClrcToTal(78);
- }
- //起动
- if((X00_UP|| M0 || M10) && (GZM_bRunning == 0))
- { // 分针 送料 迫紧 不良链
- if((X020 == 0) && (X013 != 0) && (X011 != 0) && (X017==0) && (X010 == 0) && (X016 != 0) //各限位
- //各手动 手动锁带 手动分带 夹码 上升(送料) 推料
- && (X005 == 0) && (X003 == 0) && (X006 == 0) && (X004 == 0) && (X002 == 0))
- {
- cStepMByte = 1; //
- GZM_bRunning = 1;
- CLRDR();
- if(M10)
- GZM_cOneTime = 1;
- else
- GZM_cOneTime = 0;
- if(M8)
- GZM_cBuMa = 1;
- else
- GZM_cBuMa = 0;
- M0 = 0;
- M10 = 0;
- }
- }
- //动作程序 起动
- //推料动作
- if((X02_UP || M4))
- {
- M4 = 0;
- if((Y005 == 0) || X002)
- {
- if((X013 != 0) && (X016 != 0) && (X012 == 0) && (Y014 == 0) && (Y015 == 0))
- {
- SETY005();
- SETY006();
- }
- else //条件不满足警告
- {
-
- }
- }
- else
- {
- CLRY005();
- CLRY006();
- }
- }
- //夹料动作
- if(X06_UP || M3)
- {
- M3 = 0;
- if((Y006 == 0) || (X006))
- SETY006();
- else
- CLRY006();
- }
-
- //分带手动
- if(X03_UP || M5)
- {
- M5 = 0;
- if((Y007 == 0) || X003)
- {
- if(Y015 == 0)SETY007();
- }
- else
- CLRY007();
- }
- //手动送料(装料)
- if(X04_UP || M6)
- {
- M6 = 0;
- if((Y014 == 0) || X004)
- {
- if((X011 != 0) && (X010 == 0) && (Y005 == 0) && (X016 != 0) && (X020 != 0) && (Y015 == 0))SETY014();
- }
- else
- CLRY014();
- }
- //锁带动作
- if(X05_UP || M2)
- {
- M2 = 0;
- if((Y004 == 0) || X005)
- SETY004();
- else
- CLRY004();
- }
- //迫紧动作
- if(X07_UP || M7)
- {
- M7 = 0;
- if((X010 == 0) && (X011 != 0) && (Y005 == 0) && (X012!=0) && (X013 == 0) && (Y014 != 0) && (X020 == 0) && (X016 != 0) && !Y015)cStepMByte2 = 1;
- }
- }
- else if((GZM_bRunning != 0))
- {
- GZM_TuiLiao(); //推料
- GZM_Motor();
- if(!X026)
- {
- switch(cStepMByte)
- {
- case 0:
- break;
- case 1:
- cStepMByte = 2;
- cDelayTime1 = dwTickCount + 220; //先等待电机锁轴
- GZM_cFirst = 0;
- break;
- case 2:
- if(dwTickCount >= cDelayTime1)
- {
- GZM_cGeiLiaoNum = 0; //推料次数清零
- cStepMByte1 = 1; //推料启动
- cStepMByte3 = 1; //拖带电机启动
- cStepMByte = 3;
- }
- break;
- case 3:
- // 一次拖带完成
- if((cStepMByte3 == 0))
- {
- //第一条处理,判断是否为补码
- if(((X022 != 0) || M8) && (GZM_cFirst == 0))
- {
- cStepMByte = 50;
- }
- else
- {
- cStepMByte = 4;
- SETY007(); //分带输出
- cDelayTime1 = dwTickCount + GZM_ERRORTIME; //先等待电机锁轴
- }
- }
- break;
- case 4:
- //分带到位
- if(X020)
- { //保证给料回到原位 推料完成
- if((X011 != 0) && (X010 == 0) && (Y005 == 0) && (cStepMByte1 == 0))
- {
- SETY014(); //装料输出
- cStepMByte = 5;
- cDelayTime1 = dwTickCount + GZM_ERRORTIME;
- }
- }
- else if(dwTickCount >= cDelayTime1)
- {
- GZM_SetAlarmCode(GZM_FengDaiDW_W);
- }
- break;
- case 5: //装到位
- if((X012 != 0) && (X013 == 0))
- {
- cStepMByte = 6;
- cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[10]; //延时退分带
- }
- else if(dwTickCount >= cDelayTime1)
- {
- GZM_SetAlarmCode(GZM_SongLiaoDW_W);
- }
- break;
- case 6:
- if(dwTickCount >= cDelayTime1)
- {
- cStepMByte = 7;
- CLRY007();
- }
- break;
- case 7:
- if(X020 == 0)
- {
- cStepMByte = 8;
- cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[11]; //分带信号离开二次拖带
- }
- break;
- case 8:
- if(dwTickCount >= cDelayTime1)
- {
- cStepMByte = 9;
- cStepMByte3 = 10; //电机二次拖带
- if((GZM_cWorkNum > 0) || (X022 != 0) || M8)//第二次为间隙
- {
- GZM_cPulseCount = user_datas[42] + user_datas[16] + user_datas[1];
- }
- else
- {
- // 第一次长度脉冲 + 修正值
- GZM_cPulseCount = user_datas[41] + user_datas[15];
- }
- }
- break;
- case 9:
- if(cStepMByte3 == 0)
- {
- if(Y004 && (GZM_cWorkNum == 0) && (M8 == 0))
- {
- CLRY004();
- cDelayTime1 = dwTickCount + (unsigned long)10 * 3; //二次拖带停止后延时迫紧
- }
- else if(dwTickCount >= cDelayTime1)
- {
- cStepMByte = 10;
- cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[12]; //二次拖带停止后延时迫紧
-
- if((GZM_cWorkNum == 0) && (M8 == 0)) //第一颗时反转一下
- {
- SETY010();
-
- if(user_datas[22] != 0)
- {
- AxisMovePos(X_AXIS,5,-GZM_cPulseCount);
- cStepMByte3 = 500;
- }
- }
- else
- GZM_cPulseCount = 0;
- }
- }
- break;
- case 10: // 单一自动 迫紧
- if((dwTickCount >= cDelayTime1) && ((GZM_cOneTime == 0) || M7) && (GZM_cPulseCount == 0))
- {
- cStepMByte3 = 0;
- M7 = 0;
- cStepMByte = 11;
- cStepMByte2 = 1; //迫紧开始
- CLRY010();
- if(user_datas[5] == 0)CLRY004();
- }
- break;
- case 11:
- if(cStepMByte2 == 0)
- {
- cStepMByte = 12;
- CLRY014(); //装料下
- M8 = 0;
- GZM_cWorkNum++;
- if(GZM_cWorkNum >= user_datas[43]) //当条打完
- {
- CLRY004(); //夹带松开
- }
- else //打下一颗
- {
- //输出电机反转和反向锁定电磁阀
- SETY010();
- }
- cDelayTime1 = dwTickCount + GZM_ERRORTIME;
- }
- break;
- case 12: //装料下到位
- if((X012 == 0) && (X013 != 0))
- {
- if(GZM_cWorkNum >= user_datas[43]) //当条打完
- {
- if((GZM_cOneTime != 0) || (GZM_cBuMa != 0))
- {
- cStepMByte = 0;
- GZM_bRunning = 0;
- }
- else
- cStepMByte = 2;
- //产量加一保存
- AddToTal(76);
- //计算生产速度
- CalProSP(78);
- cDelayTime1 = dwTickCount;
- GZM_cWorkNum = 0;
- }
- else
- {
- cStepMByte = 30;
- cDelayTime1 = dwTickCount + 15;
- }
- }
- else if(dwTickCount >= cDelayTime1)GZM_SetAlarmCode(GZM_SongLiaoTDW_W);
- break;
- //以下为反转电机
- case 30:
- if(dwTickCount >= cDelayTime1) //后锁带时间到
- {
- cDelayTime1 = dwTickCount + 25; //25
- //松开前锁带
- CLRY004();
- cStepMByte = 31;
- }
- break;
- case 31:
- if(dwTickCount >= cDelayTime1)
- {
- cDelayTime1 = dwTickCount + 30; //25
- //反向电磁阀
- SETY011();
- cStepMByte = 32;
- }
- break;
- case 32:
- if(dwTickCount >= cDelayTime1)
- {
- cStepMByte = 33;
- GZM_cPulseCount = user_datas[41] + AddPuls + user_datas[9];
- //重新推料
- if((GZM_cWorkNum > 0) && (M8 == 0))
- {
- GZM_cGeiLiaoNum = 0; //推料次数清零
- cStepMByte1 = 1; //推料启动
- }
- cStepMByte3 = 15;
- cDelayTime1 = dwTickCount + (unsigned long)350;
- }
- break;
- case 33://退到位
- if(X021 != 0)
- {
- AxisEgmStop(X_AXIS);
- if(X21_UP)
- {
- cDelayTime1 = dwTickCount + (unsigned long)35;
- }
- if(dwTickCount >= cDelayTime1)
- {
- cDelayTime1 = dwTickCount + (unsigned long)user_datas[14]*10; //锁带时间
- SETY004(); //锁带
- cStepMByte = 34;
- }
- }
- else if(((dwRealPos -GZM_dwSavePosBuff)>300) && (dwTickCount >= cDelayTime1))
- {
- GZM_SetAlarmCode(GZM_FanTiuDaiDW_W); //
- }
- break;
- case 34:
- if(dwTickCount >= cDelayTime1)
- {
- //输出电机正转,关反向电磁阀
- CLRY010();
- CLRY011();
- //分带
- cStepMByte = 4;
- SETY007(); //分带输出
- cDelayTime1 = dwTickCount + GZM_ERRORTIME;
- }
- break;
- //50-52步为第一条补带的先往前
- case 50:
- cStepMByte = 51;
- // 第一次长度脉冲 + 修正值
- GZM_cPulseCount = user_datas[41] + user_datas[15] + user_datas[17];
- cStepMByte3 = 10;
- GZM_cFirst = 1;
- break;
- case 51:
- if(cStepMByte3 == 0)
- {
- cStepMByte = 52;
- cDelayTime1 = dwTickCount + (unsigned long)35;
- }
- break;
- case 52: //返向转动
- if(dwTickCount >= cDelayTime1)
- {
- cStepMByte = 30;
- //输出电机反转和反向锁定电磁阀
- SETY010();
- cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[14]; //50
- }
- }
- }
- else //第二种机械,只有打码
- {
- switch(cStepMByte)
- {
- case 0:
- break;
- case 1: //先锁轴
- CLRDR();
- cDelayTime1 = dwTickCount + (unsigned long)10 * 20;
- cStepMByte = 2;
- break;
- case 2:
- if(dwTickCount >= cDelayTime1)
- {
- if(M8 == 0) //不是补码状态下先拖空柆
- {
- cStepMByte = 3;
- cStepMByte3 = 20; //第一条 先走空位长度
- }
- else //走补码程序
- {
-
- }
- cStepMByte1 = 1; //推料开始
- }
- break;
- case 3: //第一次拉带完成
- if((cStepMByte3 == 0))
- {
- cStepMByte = 4;
- SETY007(); //分带输出
- cDelayTime1 = dwTickCount + GZM_ERRORTIME; //判断分带是否到位
- }
- break;
- case 4:
- //分带到位
- if(X020)
- { //保证给料回到原位 推料完成
- if((X011 != 0) && (X010 == 0) && (Y005 == 0) && (cStepMByte1 == 0))
- {
- SETY014(); //装料输出
- cStepMByte = 5;
- cDelayTime1 = dwTickCount + GZM_ERRORTIME;
- //反锁就先输出
- SETY010();
- }
- }
- else if(dwTickCount >= cDelayTime1)GZM_SetAlarmCode(GZM_FengDaiDW_W);
- break;
- case 5: //装到位
- if((X012 != 0) && (X013 == 0))
- {
- cStepMByte = 6;
- cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[10]; //延时退分带
- }
- else if(dwTickCount >= cDelayTime1)GZM_SetAlarmCode(GZM_SongLiaoDW_W);
- break;
- case 6:
- if(dwTickCount >= cDelayTime1)
- {
- cStepMByte = 7;
- //分带关闭
- CLRY007();
- //反推电磁阀输出
- SETY011();
- //前锁带关闭
- CLRY004();
- }
- break;
- case 7:
- if(X020 == 0)
- {
- cStepMByte = 8;
- cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[11]; //分带信号离开二次拖带
- }
- break;
- case 8:
- if(dwTickCount >= cDelayTime1)
- {
- //计算脉冲数 细分*空位长度/周长,第一次的长度+第二次间隙长度+加上补尝
- GZM_cPulseCount = user_datas[42] + user_datas[16] + user_datas[1]; //加上公式
- cStepMByte = 9;
- //电机反转
- cStepMByte3 = 15;
- }
- break;
- case 9:
- if(cStepMByte3 == 0)
- {
- cStepMByte = 10;
- cDelayTime1 = dwTickCount + (unsigned long)10 * user_datas[12]; //二次拖带停止后延时迫紧
- }
- else if(X021 != 0) //退回脉冲没到之前,到达反限位时出错
- {
-
- }
- break;
- case 10: // 单一自动 迫紧
- if((dwTickCount >= cDelayTime1) && ((GZM_cOneTime == 0) || M7))
- {
- M7 = 0;
- cStepMByte = 11;
- cStepMByte2 = 1; //迫紧开始
- }
- break;
- case 11:
- if(cStepMByte2 == 0) //迫紧完成
- {
- cStepMByte = 12;
- CLRY014(); //装料下
- M8 = 0;
- GZM_cWorkNum++;
- if(GZM_cWorkNum >= user_datas[43]) //当条打完
- {
- CLRY010(); //反转锁带松开
- CLRY011(); //反推电磁阀松开
- }
- else //打下一颗
- {
- //前锁带输出
- SETY004();
- }
- cDelayTime1 = dwTickCount + GZM_ERRORTIME;
- }
- break;
- case 12: //装料下到位
- if((X012 == 0) && (X013 != 0))
- {
- if(GZM_cWorkNum >= user_datas[43]) //当条打完
- {
- if(GZM_cOneTime != 0)
- {
- cStepMByte = 0;
- GZM_bRunning = 0;
- }
- else
- cStepMByte = 99;
- //产量加一保存
- AddToTal(76);
- //计算生产速度
- CalProSP(78);
- cDelayTime1 = dwTickCount;
- GZM_cWorkNum = 0;
- }
- }
- else if(dwTickCount >= cDelayTime1)GZM_SetAlarmCode(GZM_SongLiaoTDW_W);
- break;
- }
- }
- }
- }
- //夹码.推码动作
- void GZM_TuiLiao(void)
- {
- switch(cStepMByte1)
- {
- case 0:
- break;
- case 1:
- // 推料后 推料前 主轴 送料前 送料后
- if((X011 != 0) && (X010 == 0) && X016 && !X012 && X013) //推料电磁阀在原点
- {
- cStepMByte1 = 2;
- SETY006();
- cDelayTime2 = dwTickCount + (unsigned long)10 * user_datas[7];
- }
- else //先退推料电磁阀
- {
- CLRY005();
- CLRY006();
- }
- break;
- case 2://等夹料时间
- if(dwTickCount >= cDelayTime2)
- {
- cStepMByte1 = 3;
- SETY005();
- cDelayTime2 = dwTickCount + (unsigned long)10 * user_datas[0];
- }
- break;
- case 3:
- if((X010 != 0) && (X011 == 0)) //送到前面
- {
- cStepMByte1 = 4;
- cDelayTime2 = dwTickCount + (unsigned long)10*user_datas[6]; //延时检测
- }
- else if(dwTickCount >= cDelayTime2)
- {
- CLRY005();
- CLRY006();
- GZM_cGeiLiaoNum++;
- if(GZM_cGeiLiaoNum >= user_datas[3]) //3次就结束警告
- {
- GZM_SetAlarmCode(GZM_TuiLiaoDW_W);
- }
- else
- {
- cStepMByte1 = 10;
- cDelayTime2 = dwTickCount + GZM_ERRORTIME;
- }
- }
- break;
- case 4: //延时检测是否有料
- if(dwTickCount >= cDelayTime2)
- {
- CLRY006(); //松开夹
- if(!X014)
- {
- cDelayTime2 = dwTickCount + (unsigned long)10*user_datas[8]; //150ms
- cStepMByte1 = 5;
- }
- else
- {
- CLRY005(); //退料同时退
- GZM_cGeiLiaoNum++;
- if(GZM_cGeiLiaoNum >= user_datas[3]) //3次就结束
- {
- GZM_SetAlarmCode(GZM_QueLiao_W);
- }
- else
- {
- cStepMByte1 = 10;
- cDelayTime2 = dwTickCount + GZM_ERRORTIME;
- }
- }
- }
- break;
- case 5:
- if(dwTickCount >= cDelayTime2) //松开夹料后退推料
- {
- cStepMByte1 = 6;
- CLRY005();
- cDelayTime2 = dwTickCount + GZM_ERRORTIME;
- }
- break;
- case 6:
- if(!X010 && X011) //退料到位
- {
- cStepMByte1 = 0; //
- }
- else if(dwTickCount >= cDelayTime2) //退推料到位出错
- {
- GZM_SetAlarmCode(GZM_TuiLiaoTDW_W);
- }
- break;
- case 10:
- if(!X010 && X011) //出错后退料到位
- {
- cStepMByte1 = 11;
- cDelayTime2 = dwTickCount + (unsigned long)100*user_datas[4]; //延时重新推料
- }
- else if(dwTickCount >= cDelayTime2) //退推料到位出错
- {
- GZM_SetAlarmCode(GZM_TuiLiaoTDW_W);
- }
- break;
- case 11:
- if(dwTickCount >= cDelayTime2)
- {
- cStepMByte1 = 1;
- }
- break;
- }
- }
- //迫紧动作
- void GZM_PoJin(void)
- {
- switch(cStepMByte2)
- {
- case 0:
- break;
- case 1:
- cStepMByte2 = 2;
- SETY012(); //迫紧输出
- cDelayTime3 = dwTickCount + GZM_ERRORTIME;
- break;
- case 2:
- if(!X016)
- {
- cStepMByte2 = 3;
- CLRY012();
- cDelayTime3 = dwTickCount + (unsigned long)75;
- }
- else if(dwTickCount >= cDelayTime3) //主轴没法转动
- {
- GZM_SetAlarmCode(GZM_PoJin_W);
- }
- break;
- case 3:
- if(dwTickCount >= cDelayTime3)
- {
- cStepMByte2 = 4;
- cDelayTime3 = dwTickCount + GZM_ERRORTIME;
- }
- break;
- case 4:
- if(X016)
- {
- cStepMByte2 = 0;
- }
- else if(dwTickCount >= cDelayTime3) //主轴没法转动一周
- {
- GZM_SetAlarmCode(GZM_PoJin_W);
- }
- break;
- }
- }
- //拖带电机
- void GZM_Motor(void)
- {
- static long save_pos;
- switch(cStepMByte3)
- {
- case 1:
- if(X015 == 0)
- {
- cStepMByte3 = 2;
- cDelayTime4 = dwTickCount + 5;
- MoveAction_Const_AccDec(X_AXIS, GZM_DIR_P,user_datas[2],user_datas[19],5,1);
- }
- else //在空位慢速
- {
- cStepMByte3 = 3;
- cDelayTime4 = dwTickCount + (unsigned long)1000 * user_datas[13];
- MoveAction_Const_AccDec(X_AXIS, GZM_DIR_P,user_datas[19],user_datas[19],5,1);
- }
- break;
- case 2:
- if((dwTickCount >= cDelayTime4) && X15_UP)
- {
- MoveChangSpeed(X_AXIS,user_datas[19]);
- cStepMByte3 = 3;
- cDelayTime4 = dwTickCount + (unsigned long)1000 * user_datas[13];
- }
- break;
- case 3:
- if(X15_DW)
- {
- AxisEgmStop(X_AXIS);
- cStepMByte3 = 0;
- }
- else if(dwTickCount >= cDelayTime4)//没链停机
- {
- GZM_SetAlarmCode(GZM_NoZip_W);
- }
- break;
- //以上为前检测拖带
- //下面是二次拖带
- case 10:
- cStepMByte3 = 11;
- MoveAction_Const_AccDec(X_AXIS, GZM_DIR_P,user_datas[20],1,5,1);
- break;
- case 11:
- if(X15_DW)
- {
- AxisEgmStop(X_AXIS);
- cStepMByte3 = 0;
- }
- break;
- //反推时快速返回
- case 15:
- cStepMByte3 = 11;
- GZM_dwSavePosBuff = dwRealPos;
- MoveAction_Const_AccDec(X_AXIS, GZM_DIR_P,user_datas[20],1,5,1);
- break;
- //走拖带轮的拉链长度
- case 20:
- cStepMByte3 = 21;
- //计算脉冲数 细分*空位长度/周长,第一次的长度+第二次间隙长度
- GZM_cPulseCount = 1600 * user_datas[41]/user_datas[21] + user_datas[42] + user_datas[16] + user_datas[1]; //加上公式
- save_pos = dwRealPos;
- AxisMovePos(X_AXIS,user_datas[19],GZM_cPulseCount);
- break;
- //等待走拉链长度走完
- case 21:
- if((dwRealPos - save_pos) < 200) //前锁带先锁
- {
- SETY004(); //前锁带输出
- }
- if(!X_DRV)
- {
- cStepMByte3 = 0;
- }
- break;
- }
- }
-
- #endif
|