CH.12 | PLC SUBROUTINE FUNCTIONS

INTRODUCTION

  • Subroutines

    • programs that contain additional ladder logic diagram files that work with the main ladder logic diagram.

    • Execution in a PLC program scan depends on the state of an input device or the result of a compare instruction.

    • Placed in Program files 3 through 255 (SBR3 - SBR255)

    • Number and size restricted by PLC memory.

12.3 RETURN FROM SUBROUTINE

  • First rung must have SBR instruction, which indicates this program represents a subroutine

  • SBR must be connected to an OTE like B3:0.

    • Unless stated otherwise, using internal bits is recommended so that the limited # of outputs isn’t wasted.

  • The Return (RET) Instruction causes the instruction pointer to go back and point to the next rung in the main PLC program file.

    • SBR file must have a RET instruction.

12.4 SUBROUTINE APPLICATIONS

  • In most industrial applications

    • Lengthy LLDs are required

    • Usually divided into several SBR files

      • Each SBR is written and tested separately.

      • A shorter Main program used to call SBR for different conditions.

12.5 INTERRUPT ROUTINES

  • Interupt Routine

    • is one that interrupts the scan of the main PLC ladder logic diagram (LAD2) in order to execute an interrupt subroutine.

    • Similar to SBR and must reside in LAD3-LAD255

    • INT instruction replaces SBR at the beginning of SBR, indicating Interrupt Subroutine.

    • Two Types

      • Selectable Timed Interrupt (STI)

        • Used to interrupt the scan of a main program file at specific time intervals in order to scan a specified subroutine file.

        • Time intervals are specified by placing a time interval value in Status file register S:30.

      • I/O Interrupt (ISR)

        • Allows an I/O module to interrupt the processor operation cycle in order to scan a specified interrupt subroutine.

        • CANNOT use a standard discrete I/O module to accomplish I/O interrupt.

        • Module must be designed for ISR features.