

Process tree and process types

When I wrote the first program all the code was place in the main PLC_PRG task.  As the program was growing the need for splitting the code into sub-programs and task became evident.  Here are the rules that I have followed: 

In the main PLC_PRG program all the 'regular' commands are placed: for controlling the lights, sockets, blinds and heaters.  I have placed in separate programs the following tasks:

  • all that can hang up the controller - like functions related to web communication,
  • things that should be run at given periods of time (like updating the current time),
  • distinctive, less important items, which for the sake of order can be kept separately and run with lower priority - like code updating visualization elements. 

Finally my list of programs and the tree of processes looks as follows:

ProgramList TaskTree


Function blocks, functions and program RS232 are described in a separate article

The program SQL_DataStorage is also described in a dedicated article, the  GardenRecorder function block collects tha information about opening/closing of sprinklers. 

DataSaveToFile makes it possible to write data to csv files.  Since the communication with a SQL database is working flawlessly, this proces is no longer used.

EmailSender sends emails when something important happens - it informs me about alarms, triggered movement sensor and all the movements in the house within a few minutes after the alarm was launched.

ReadClock is responsible for updating the global variable CURRENT_TIME as well as CALENDAR_CALC and CALENDAR from the OSCAT library.  I read some time ago that reading the real-time clock consumes significant portion of the processing power and should not be done in the main program.  The task Update_Clock calling the RadClock() program is executed every second.

SensorReader reads all analog inputs every second and correct the values by a value fond empirically.

Timers manages all the schedulers  (FbScheduleweekly z Building_common.lib) and is run every second.,

VIS_Management updated some visualization.


In order to add a new program, function block or a function, one needs to right-click on the window with programs (POUs) and choose Add Object.

In order to add a task on the task list in the Resources tab, one needs to choose Task configuration, right-click on the task list and click Append Task.  The new task needs to have a name, a priority and a Type where:

  • cyclic means a task run at a given interval (for example every second - t#1s),
  • freewheeling means a task run repeatedly time after time. In my program only MainTask and RS232 are set as freewheeling,
  • triggered by event is run when certain global variables reach some preconfigured values. 

When a new task is ready, it needs to receive a program call.  Right-click on the task and choose Append Program Call.  For example, my MainTask calls the PLC_PROG().