News:

  • October 16, 2026, 07:22:19 AM

Login with username, password and session length

Author Topic: Scans & Programs, Tasks & Subroutines  (Read 6503 times)

etElMadr

  • Full Member
  • ***
  • Posts: 37
Scans & Programs, Tasks & Subroutines
« on: September 20, 2021, 09:45:05 AM »
As I understand it, PLCs in concept: 1) scan inputs 2) process logic 3) update outputs

With logic in just a simple $Main program, that Scan Sequence is simple to understand. But, I am not clear what is happening when you introduce Programs. My understandings is Programs run asynchronously. Are Programs running in parallel? If they are not running in parallel, and I configure the Programs to Never Yield, what is the scan order?



franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Scans & Programs, Tasks & Subroutines
« Reply #1 on: September 20, 2021, 10:48:21 AM »
PLCs still execute one instruction at a time, just like in other languages.  They appear parallel from an I/O standpoint (your description of PLC's I/O scan is accurate).

But PROGRAM and TASK code blocks are run in sequence, but not all codeblocks run every scan.  The System Tasks run at various times.
$tFirstScan runs on first scan

$tLastScan runs when PLC transitions from RUN->PROGRAM mode (NOT power-down)

These system tasks will run on the PLC scan after $tFirstScan finishes.
$tTopOfScan runs before all other PROGRAM and TASK code-blocks
$Main
$tBottomOfScan runs after all other PROGRAM and TASK code-blocks

Any other User PROGRAMs or TASKs are run somewhere between $tTopOfScan and $tBottomOfScan, similar to $Main.  You can tweak the order of execution within a scan for $Main and User PROGRAMs and TASKs from the Project Browser.  Make sure you are in Edit Mode (Ctrl+E), then right-click on a code-block in the Project Browser and select "Change Execution Order" to bring up that dialog.

We have some Power Point training slides available on our website (www.hosteng.com) and look in the left frame for Training Slides/All Do-more PLCs.  Look at presentation #7, Programs vs. Tasks.  That goes into much more detail.

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 702
  • Hmmm...
    • Host Engineering, Inc.
Re: Scans & Programs, Tasks & Subroutines
« Reply #2 on: September 20, 2021, 04:41:36 PM »
As I understand it, PLCs in concept: 1) scan inputs 2) process logic 3) update outputs

With logic in just a simple $Main program, that Scan Sequence is simple to understand. But, I am not clear what is happening when you introduce Programs. My understandings is Programs run asynchronously. Are Programs running in parallel? If they are not running in parallel, and I configure the Programs to Never Yield, what is the scan order?

You may want to check out my tech training slides on our website. Goto hosteng.com, in the left pane down under "Training Slides," for example, click on "All Do-more PLCs, and then download the PowerPoint called "Programs VS Tasks."
There are two types of people in the world; those that can extrapolate from incomplete data sets.