Multiple Programs

Sometimes, multiple programs are needed to perform different functions at different intervals within a project. Here's a simple demonstration:

  1. Similar to the ladder diagram program in section Single Program, create a program Part_trig to get an input signal and trigger another program:
    Figure 1. Part_trig Program
    Note:

    trig is a variable that triggers another program and needs to be defined as External in this program and declared as Global in Res0:

    Figure 2. trig Settings
  2. Then, create another program that is triggered by program ‘Part_trig’. Programs in different languages can be in the same project, so a new POU using FBD(Function block diagram) can be created in this project:
    Figure 3. Create a New POU
  3. To run this program, an instance should be declared for it in the Res.0:
    Figure 4. Declare an Instance
  4. Moreover, if programs need to run at different intervals, a new task should be created and bound to corresponding instance:
    Figure 5. Create and Bound a New Task to an Instance

As shown above, program ‘part_trig’ will run at 20ms intervals while program ‘part_triggered’ on 10ms. It should be mentioned that the program may not be able to run on this interval. The minimum interval of the program depends on the real-time performance of the system.