Search code examples
plc

What is differential instructions in PLC?


I'm using Omron CP1L PLC and program with CX-programmer. I have hard time understanding what exactly is "Differential Instructions", from the documentation:

With differentiated instructions, execution results for instructions are reflected in Condition Flags only when execution condition is met, and results for a pre- vious rung (rather than execution results for the differentiated instruction) will be reflected in Condition Flags in the next cycle. You must therefore be aware of what Condition Flags will do in the next cycle if execution results for differ- entiated instructions to be used.

My understanding is: instruction always execute when condition is met, and of course if Condition Flags exist to get its state of ON or OFF from previous rung's instruction, instructions on the next rung would get executed. So I completely do not grasp the point of the explanation in the documentation. And see no difference between the two:

(A) Without using differential

Without differential

(B) Using differential
enter image description here


Solution

  • What the manual is warning you about is that, in the incorrect case, Instruction A will be executed only once after C becomes true (differentiated instruction) but the execution of Instruction B depends on the state of the condition flag from the instruction executed in A. If A is executed only once then the condition flag is only valid for the current PLC scan. Subsequent PLC scans with C satisfied will NOT execute differential instruction A but MAY execute differential instruction B -- IF a previous rung performs a comparison operation and sets the global condition flag TRUE.

    If you understand the danger of global variables, this is basically the same thing. Some flags in PLC logic are global flags used by certain instructions. They remain valid only immediately after the instruction is executed and will change each time it is executed on different data. In the incorrect case an unguarded rung is dangling with a global condition flag for an operation which is NOT guaranteed to execute.

    In the Correct case the execution condition is differentiated instead of the instruction. When C becomes true it goes to a [DIFU D]. This makes D true for the next PLC scan ONLY - D will only EVER be true for one PLC scan each time C goes from FALSE to TRUE. This guarantees that Instruction A (which generates the Condition Flag value) is executed only once and, further, that it is guaranteed to execute every time that the condition flag exposing Instruction B is encountered.

    Edit : Problematic execution flow - state of CF is RANDOM (more precisely : uncontrolled!) unless we have just performed a comparison operation. All other comparison operations in the entire program will alter its value every time a comparison instruction executes anywhere in the program!

    STATE          C          Instruction A       CF(=)    InstructionB
    
    Scan #1  :    OFF             N/E            RANDOM       N/E
    Scan #2  :    ON         EXECUTES > TRUE      TRUE       EXECUTES  //desired
    Scan #3  :    ON              N/E            RANDOM(T)    N/E
    Scan #4  :    ON              N/E            RANDOM(F)    N/E
    Scan #5  :    ON              N/E            RANDOM(T)  *EXECUTES*!! //UNDESIRED
    

    Here, so long as C remains ON, Instruction B will execute every time the CF switches from FALSE To TRUE due to other comparison operations in other areas of the program. This is not desired - we only want InstructionB to execute if InstructionA has executed and has returned CF= as TRUE.