Timer program example

The following program example uses a day timer to illustrate how the function blocks should be parameterized, particularly with regard to the inputs eStartEnd, stStartEnd and stSystemTime.

We recommend using the function block NT_GetTime, which is available in the library Tc2_Utilities, for reading the system time in PC- and CX-based systems. A program for reading might look as follows:

Timer program example 1:

It provides a timebase for parameterizing the scheduler function blocks with regard to the time input stSystemTime. The enumerator matching the required behavior is created at input eStartEnd:

eSTARTTIME_ENDTIME

Start criterion: Time - End criterion: Time

eSTARTTIME_DURATION

Start criterion: Time - End criterion: Duration

eSTARTTIME_ENDEVENT

Start criterion: Time - End criterion: Event (boolean input)

eSTARTEVENT_ENDTIME

Start criterion: Event (boolean input) - End criterion: Time

eSTARTEVENT_DURATION

Start criterion: Event (boolean input) - End criterion: Duration

eSTARTEVENT_ENDEVENT

Start criterion: Event (boolean input) - End criterion: Event (boolean input)


For the input stStartEnd a structure variable of the same type has to be declared that is referred to in the example as stStartEnd. The program then describes the subvariables of this structure, which are important for the function type. For the example shown, these are todStartTime and tDuration. All other variables are not read and therefore do not have to be described.

Timer program example 2:


Both programs have to be called in the MAIN function block. The program part P_SchedulerExample may only be called once the program part P_SystemTime supplies valid data, i.e. once P_SystemTimeValid is TRUE. The reason for this protective logic is that reading the time takes several cycles which means that the time when the program starts is invalid and must not be used.

Timer program example 3:

If the program starts on 1 January, the sequences is as follows:

Timer program example 4:

The days on which actions are triggered start with the 2nd of the year (uiBegin:=2). The process is repeated every three days (uiPeriodicity:=3). The switch-on time is 15:00 (stStartEnd.todStartTime:=tod#15:00:00) and the switching duration is 6 hours (stStartEnd.tDuration:=t#6h).