10BaseT. said:
If you do want to roll you own - try this , I posted it before , but I can't find where :-
You need to sub M10.0 for your first cycle flag , and MD58 is your last scan time - you may find it gives you what you want .
FUNCTION "TON" : VOID
TITLE =TON - Timer On Delay
//If the enable condition go true, timer TON starts incrementing according with
//the last CPU cycle time. When the accumulated value is greater than or equal to
//the preset value, the timer stops and sets the timer done bit.
NAME : TON
VERSION : 0.1
VAR_INPUT
EN : BOOL ; //Timer Enabled
Pre : TIME ; //Timer Preset
END_VAR
VAR_OUTPUT
TT : BOOL ; //Timer Timing
DN : BOOL ; //Timer Done
END_VAR
VAR_IN_OUT
Acc : TIME ; //Timer Accumulator
END_VAR
BEGIN
NETWORK
TITLE =Reset Accumulator Value If Timer Not Enabled Or First CPU Cycle
A( ;
ON #EN;
O M 10.0;
) ;
JNB _001;
L 0;
T #Acc;
_001: NOP 0;
NETWORK
TITLE =Accumulator Value Increasing
A #EN;
A( ;
L #Acc;
L #Pre;
<=D ;
) ;
JNB _002;
L MD 58;
L #Acc;
+D ;
T #Acc;
_002: NOP 0;
NETWORK
TITLE =Timer Done
A( ;
L #Acc;
L #Pre;
>D ;
) ;
A #EN;
= #DN;
NETWORK
TITLE =Timer Timing
A #EN;
AN #DN;
= #TT;
NETWORK
TITLE =ENO Setting
SET ;
SAVE ;
END_FUNCTION