回复:急问,定时器不够用怎么办?

天枰

  • 帖子

    315
  • 精华

    10
  • 被关注

    15

论坛等级:侠士

注册时间:2007-08-09

普通 普通 如何晋级?

发布于 2011-01-11 16:08:21

15楼

学写SCL
TYPE "TypeTimer"
VERSION : 1.0
STRUCT
In : BOOL ;
InSave : BOOL ;
OutPlusUp : BOOL ; //上升沿脉冲输出
OutPlusDown : BOOL ; //下降沿脉冲输出
OutUpDelay : BOOL ; //上升沿延时接通
OutDownDelay : BOOL ; //下降沿延时接通
TimeSeting : INT ; //定时器设定值
TimeCurrentUp : INT ; //计时当前值
TimeCurrentDown : INT ; //计时当前值
END_STRUCT;
END_TYPE

FUNCTION_BLOCK FB101

VAR_INPUT
TimeElapse: INT;
END_VAR

VAR
T : ARRAY [1 .. 1000 ] OF "TypeTimer";
index : INT ;
TimeSave:INT;
END_VAR


BEGIN
//边沿检测及脉冲生成
FOR index:= 1 TO 1000 BY 1 DO
t[index].OutPlusUp:= 0;
t[index].OutPlusDown:=0;
IF t[index].in <> t[index].insave THEN
t[index].insave:=t[index].in;
IF t[index].in THEN
t[index].OutPlusUp:=1;
T[index].TimeCurrentUp:=T[index].TimeSeting;
ELSE
t[index].OutPlusDown:=0;
T[index].TimeCurrentDown:=T[index].TimeSeting;
END_IF;
END_IF;
END_FOR;

//定时器,每100ms计算一次
Timesave := TimeElapse+Timesave;
IF Timesave >=100 THEN
Timesave := Timesave-100;
FOR index:= 1 TO 1000 BY 1 DO
IF t[index].in THEN
T[index].TimeCurrentDown:=T[index].TimeSeting;
IF T[index].TimeCurrentUp = 0 THEN
t[index].OutUpDelay:=1;
ELSE
T[index].TimeCurrentUp:=T[index].TimeCurrentUp-1;
t[index].OutUpDelay:=0;
END_IF;
ELSE
T[index].TimeCurrentDown:=T[index].TimeSeting;
IF T[index].TimeCurrentUp = 0 THEN
t[index].OutDownDelay:=1;
ELSE
T[index].TimeCurrentDown:=T[index].TimeCurrentDown-1;
t[index].OutDownDelay:=0;
END_IF;
END_IF;
END_FOR;
END_IF;

END_FUNCTION_BLOCK
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC S7-300/400

共有54710条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。