Structured Text repeating timer based on true/false bit

spatricks

Member
Join Date
Jan 2013
Location
oklahoma city
Posts
9
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 EVENTXBIT = TRUE THEN
DO THIS
WAIT X MINUTES
END_IF


IF ANOTHER EVENT THEN
EVENTXBIT := FALSE
ENDIF



This is what I have so far. It counts up to 3 min and then stops, instead of resetting. I figured since I change the variable to false it should retrigger.

Code:
TEST_VAR := TRUE;
TIMER_RETRIGGER_ALM0(TEST_VAR,T#3m);

IF TIMER_RETRIGGER_ALM0.Q THEN
	TEST_VAR  := FALSE;
END_IF;
 
Last edited:
TEST_VAR := TRUE;
TIMER_RETRIGGER_ALM0(TEST_VAR,T#3m);
IF TIMER_RETRIGGER_ALM0.Q THEN TEST_VAR := FALSE;
TIMER_RETRIGGER_ALM0(TEST_VAR,T#3m);
END_IF;



The timer is always called with a TRUE signal and does not 'know' the signal shift.
Try to add the cursive line and see if that works.
The output (.Q) will likely reset also, so you will not be able to catch it outside this code without copying it to another variable.

Kalle
 
This is how I would do it. Note that this is CoDeSys and it looks like the timer call is a little different than what you are using.

To have something to do each time the timer times out, I just incremented a variable. The thing you want to happen at each timeout should go in the IF/THEN block where I'm incrementing the i variable.

I don't like calling the timer in multiple places as if they get spread out, it can be very difficult to troubleshoot.

Code:
PROGRAM PLC_PRG
VAR
    I: INT;
    FirstPassDone: BOOL;
    Timer_Retrigger_ALM0: TON;
    TEST_VAR: BOOL;
    ALM0_Trigger: BOOL;
END_VAR

(* Run Code on First Pass through Program *)
IF NOT(FirstPassDone) THEN
    I:=0;
    FirstPassDone := TRUE;
END_IF

(* Call the Timer *)
Timer_Retrigger_ALM0(IN:= ALM0_Trigger , PT:= T#5s);

(* Set the Timer Trigger *)
ALM0_Trigger := (TEST_VAR AND NOT(Timer_Retrigger_ALM0.Q));

(* Do Something each time the timer finishes *)    
IF Timer_Retrigger_ALM0.Q THEN
    i := i + 1;
END_IF
 
This is what I figured out before seeing your responses. Let me know what you think. Basically if the ACK bit is the conditional variable.


Code:
TIMER_RETRIGGER_ALM0(NOT TIMER_RETRIGGER_ALM0.Q AND ALM0_ACK,T#2m);


IF TIMER_RETRIGGER_ALM0.Q = TRUE THEN
	 DATA_inputONOFFSMSText := '';
   	 DATA_inputONOFFSMSText := 'Alarm detected: Input 1 is ON';	
  	 UTIL_SEND_SMS_2( TRUE, CONFIG_slotID, CONFIG_receiverList, DATA_inputONOFFSMSText);
	 
END_IF;
 
TEST_VAR := TRUE; TIMER_RETRIGGER_ALM0(TEST_VAR,T#3m); (* after 3m Q will be high always. IF TIMER_RETRIGGER_ALM0.Q THEN TEST_VAR := FALSE; END_IF;
In codesys you can not wait (all plc cant)
but you can use an AND if timer not expired and input true then do your thing.
 

Similar Topics

I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
363
Good evening. I display the step number of a SFC on a display. Sometimes, on a trip, it goes quickly through many steps and I need to prove to...
Replies
1
Views
105
I am trying to set up a piece of equipment with a Horner HE-X4R. I'd like to use structured text and so far I'm just trying to get a basic On/off...
Replies
0
Views
61
Good morning. I'm doing a rehab and I need to recycle some part of the old code that won't change and that I need. This is a calculation that...
Replies
22
Views
1,332
I'm writing some structured text that's handling a data structure that comes from a PC. The PC structure is in the "new" LREAL 64-bit floating...
Replies
3
Views
478
Back
Top Bottom