CODESYS, TON未复位

huangapple go评论70阅读模式
英文:

CODESYS, TON not resetting

问题

我已经定义了INT和TON

VAR
state : INT := 0;
timer_on : TON;
END_VAR


现在,程序如下

IF (state = 0) THEN
timer_on(IN := TRUE, PT := T#5s);

IF (timer_on.Q = TRUE) THEN
    timer_on.IN := FALSE;
    state := 1;
END_IF

END_IF


当执行后,状态在5秒后变为0。这没问题。但是当我把状态改回0时,它立即变为1。根据文档

> 当IN为TRUE且ET等于PT时,Q为TRUE。否则为FALSE。

在我的情况下,5秒后Q总是为TRUE,即使IN为FALSE。
英文:

I have an INT and TON defined

VAR
	state : INT := 0;
	timer_on : TON;
END_VAR

Now. The program is like this

IF (state = 0) THEN
	timer_on(IN := TRUE, PT := T#5s);

	IF (timer_on.Q = TRUE) THEN
		timer_on.IN := FALSE;
		state := 1;
	END_IF
END_IF

When it is executed state is changed to 0 after 5 seconds. That's ok. But when I change state back to 0 it immediately goes back to 1. According to the documentation

> Q is TRUE when IN is TRUE and ET is equal to PT. Otherwise it is FALSE.

In my case, after 5 seconds Q is always TRUE even when IN is FALSE

答案1

得分: 2

更改函数块的输入变量不会执行函数块。您需要运行它才能看到更改。

当您运行程序时会发生以下情况:

  1. 状态为0,因此首个IF被执行。
  2. timer_on被启动,持续5秒。
  3. 5秒后,状态仍为0且timer_on.Q变为true,因此第二个IF也被执行。
  4. timer_on.IN被设置为false,但timer_on没有被执行,状态也被设置为1。
  5. 状态为1,所以代码被跳过。
  6. 在手动将状态设置为0后,首个IF被执行。timer_on以IN为true运行,但因为这个计时器从未被重置,它会立即完成。

解决方案是将timer_on.IN := FALSE;这行代码更改为timer_on(IN := FALSE);。这将以IN为false运行计时器,正如文档所述,这将为下一次使用重置它本身。

英文:

Changing the input variables of a function block does NOT execute the function block. You need to run it to see the change.

What happens when you run your program:

  1. state is 0, so first IF is entered
  2. timer_on is started for 5 seconds
  3. after 5 seconds, state is still 0 and timer_on.Q becomes true, so second if is also entered.
  4. timer_on.IN is set to false, but timer_on is not executed, state is also set to 1
  5. state is 1 so code is skipped
  6. after state is set to 0 manually, the first if is enered. timer_on is run with IN true, but because this timer was never reset, it immidiately finishes.

The solution is to change the timer_on.IN := FALSE; line to timer_on(IN := FALSE);. This will run the timer with IN false which, as the documentation states, will reset itself for the next use.

huangapple
  • 本文由 发表于 2023年3月1日 14:41:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定