Repeating Timer

ce_ht

Member
Join Date
Nov 2017
Location
Derby
Posts
12
Hi all,I'm still learning the ropes using ST in Codesys; I am trying to use two timers that repeat until a condition becomes false. I have declared each Timer as a TON variable. Here is my code:

IF TestFlag = TRUE THEN


TimerOne (IN:= TimerOneTrigger,PT:= TIME#1000MS);

IF TimerOne.Q THEN
TimerOneTrigger:= FALSE;
TimerTwoTrigger:= TRUE;
END_IF

TimerTwo (IN:= TimerTwoTrigger,PT:= TIME#2000MS);

IF TimerTwo.Q THEN
TimerOneTrigger:= TRUE;
TimerTwoTrigger:= FALSE;
END_IF
END_IF

TimerOneTrigger is mapped to a button in my visulization. Running this code only runs each timer once. What am I missing to allow this to keep runing until my TestFlag variable becomes false?

Thanks
 
I've run this in an S7 environment and the two timers repeat - however for testing all I did was set TimerOneTrigger. If you have TimerOneTrigger mapped to a button, will the button make it true whilst pressed or what? If the button is capable of resetting TimerOneTrigger then depending on when this happens it may stop the timers toggling.
 
I've run this in an S7 environment and the two timers repeat - however for testing all I did was set TimerOneTrigger. If you have TimerOneTrigger mapped to a button, will the button make it true whilst pressed or what? If the button is capable of resetting TimerOneTrigger then depending on when this happens it may stop the timers toggling.

Yes the trigger goes true when the button is pressed. Interesting that it worked for you in S7. I'll do some more fault finding in the rest of the code. Thanks.
 
If you turn off your test flag once you have started the timers repeating, then the timers will carry on repeating when you put your test flag back on.
 
Last edited:
Check if your button is holding TimerOneTrigger true. I think the code is right and working. The problem might be that the TimerOne does not reset becouse the input stays true. Or use r_trig to trigger the timer one if you want that button keeps true bit.
 
Last edited:
Thank you both. If that section of code looks ok it must be the button or another section of my programme causing the issue I'll have a look.
 

Similar Topics

How would I make a timer that would repeat on an interval as long as a certain value is true. IF EVENT THEN EVENTXBIT := TRUE ENDIF IF...
Replies
4
Views
6,596
ControlLogix 5575 (L75): Sudden/Repeating "Unconnected Message Timeout" (0204) This ControlLogix PLC (L75/5575) has been in operation for at...
Replies
24
Views
10,517
Hello, I am returning for some guidance on how to get my program to repeat itself infinitely until a stop button is pressed. I need a particular...
Replies
7
Views
4,015
Lately one of our production lines has been randomly going down. It is all Siemens (S7-300), and about twelve years old, mostly original. The...
Replies
35
Views
11,037
Hi All, I am involved in a project where around 300 I/O points (analog and discrete inputs and outputs) are connected to a local panel and we...
Replies
7
Views
6,603
Back
Top Bottom