Comm-Tronix (Customer) asked a question.

I am trying to make a programmable delay using a while loop inside a subroutine but the watchdog timer is tripping.

 I thought the decrement statement inside the loop would keep that from happening. Any ideas on how to slow the program scan times?


  • OkiePC (Customer)

    A PLC, by design, is a fast operating infinite loop. If the loop fails to repeat, you get a watchdog fault. This is intentional. Don't write code that works against this design.

     

    Use the "done" bit from your timer to condition the operation that must be delayed.

     

    https://www.youtube.com/watch?v=T3tnXu-Eywc

     

    Expand Post
    Selected as Best
  • OkiePC (Customer)

    A PLC, by design, is a fast operating infinite loop. If the loop fails to repeat, you get a watchdog fault. This is intentional. Don't write code that works against this design.

     

    Use the "done" bit from your timer to condition the operation that must be delayed.

     

    https://www.youtube.com/watch?v=T3tnXu-Eywc

     

    Expand Post
    Selected as Best
  • PouchesInc (Customer)

    You do not use timers in a while loop when doing PLC coding. Loops already inflate scan time and need to be used carefully, adding timers in to a loop would inflate the time so much you get a timeout error for the PLC, which is what you are seeing.

  • Comm-Tronix (Customer)

    I would like to 'reuse' the timer multiple times. A subroutine does not work.

    • OkiePC (Customer)

      "I would like to 'reuse' the timer multiple times. A subroutine does not work."

      For what purpose?

      If you want the same timed condition, you can use the values from one timer as many times as you like. If you want different timed conditions, use a different timer tag with different conditions.

  • HOST_franji1 (HOST Engineering)

    Ladder Logic is not embedded C programming. You should almost never use looping inside a PLC code block or subroutine (exceptions like doing data array initialization or calculations).

     

    Start at the highest level. What are you trying to do (not programmatically, but your actual machine you are controlling). Describe it like you are talking to an OPERATOR of the device, not a programmer with implementation questions.