Topic: DMD0231

Programs and Tasks Overview


Modular Programming

In an effort to make the programming of Do-more controllers as easy and efficient as possible, all of them support modular programming in the form of code-blocks that can be executed when the programmer wants, and as often as the programmer wants. The two types of Code-blocks are Tasks and Programs. Deciding on whether to put the ladder logic in a Task or in a Program can sometimes be a confusing choice.

 

There is really only one rule that must be followed, and that is Program code-blocks are required for ladder logic that will using any of the Stage Programming. This includes Stage Programming instructions (JMP - Jump To Stage, JMPI - Indexed Jump, SG - Stage, SGRST - Disable Stage, SGRSTR - Disable Range of Stages, SGSET - Enable Stage, SGDIVRG - Jump to Multiple Stages, SGCONVRG - Converge Multiple Stages to SG) and all of the Fully Asynchronous instructions that can be configured to Jump to a Stage when the instruction is done.

 

Aside from this one rule, the function of the ladder logic within the code-block is the best way to decide between a Program and a Task. It's analogous to a high-level programmer deciding to use a function or a subroutine, both can accomplish the same thing, but one will typically be a better way to get the job done. Here are some guidelines that can help make the choice:

 

Programs - are the proper choice for typical ladder logic operations that involve timing, processing asynchronous instructions, handling ladder logic that takes multiple scans to complete, etc..

 

The programmer controls when Programs are executed by using the Run Program (RUN) instruction. Once a Program has been started, it will run every controller scan until one of the following happens:

 

  1. An Exit This Program (EXIT) instruction within the Program itself is executed.
     

  2. Another Program or Task executes a Halt Program or Task (HALT) instruction that targets the Program.
     

  3. A Restart Program or Task (RESTART) instruction is executed that targets the Program.

 


Tasks - are the proper choice for these two types of behavior:
 

  1. A single pass through ladder logic that executes exactly one time.
     

  2. Ladder logic that needs to execute at a specific, recurring interval, like once a second or once every 50ms.

 

The programmer controls when Tasks are executed by using the Enable Task (ENTASK) instruction, which is configured to execute its Task either one time on the leading edge of the input logic, or to execute its Task continuously on power-flow at a specified, millisecond-level interval.

 


Pre-defined Programs and Tasks

Every Do-more Designer project contains a predefined Program code-block named $Main. The controller will automatically execute $Main on the transition from STOP to RUN, and will continue to execute $Main as long as the controller stays in RUN mode. Programmers that don't need (or want) to use multiple code-blocks in their project can put all of the ladder logic in this one code-block, and the project will operate similarly to a traditional, monolithic PLC program.

 

For programmers wanting to 'ease' into the modular programming approach, Do-more Designer provides some pre-built system Tasks that are part of each project. Using these built-in system Tasks provides a way to easily segment a monolithic ladder logic program into logically manageable sections and can make a big difference in the readability and maintainability of a project.

 

The following system Tasks are automatically created with each new project, and are initially located in the Unused System Tasks group in the Project Browser. To begin using one of these system Tasks, simply double-click on that Task name in the Project Browser and it will be moved from the Unused group to the System Tasks group and the code-block will be opened in a Ladder View where it can be edited.

 

The following describes the function of each of these system Tasks:

 

$tFirstScan - this Task will execute one time on the scan when the controller transitions from STOP to RUN mode, it will be the ONLY code block that is executing on that scan

 

$tLastScan - this Task will execute one time on the scan when the controller transitions from RUN to STOP mode, it will be the ONLY code block that is executing on that scan

 


$tTopOfScan - this Task will be the first code-block to execute in each controller scan (except for the first and last scan). This is the proper code-block to place ladder logic that handles input operations like scaling analog input values, mapping real-world inputs to internal variables (Map Inputs and Outputs - MAPIO), and processing external protocol values (Translate to Do-more - SUBSCRIB)

 

$tBottomOfScan - this Task will be the last code-block to execute in each controller scan (except for the first and last scan). This is the proper code-block to place ladder logic that handles output operations like scaling analog output values, mapping internal variables to real-world outputs (Map Inputs and Outputs - MAPIO), and processing external protocol values (Translate from Do-more - PUBLISH).


$t1Second - after all of the ladder logic in this code block has executed it will automatically be scheduled to run again in 1 second

 

$t100ms - after all of the ladder logic in this code block has executed, it will automatically be scheduled to run again in 100 milliseconds

 

$t50ms - after all of the ladder logic in this code block has executed, it will automatically be scheduled to run again in 50 milliseconds

 

Note: these system tasks do not start their execution at the specified interval, instead they will be automatically restarted at the specified interval AFTER the completion of all the ladder logic in the code-block.

 


See Also:

 


Related Topics:

Related Instruction Topics:

 


Copyright © Host Engineering, Inc. ALL RIGHTS RESERVED