Please Help

Discussion in 'Programmer's Corner' started by Nirvana, Jun 1, 2005.

  1. Nirvana

    Thread Starter Well-Known Member

    Jan 18, 2005
    [attachmentid=684]How to make a loop


    Hi here is a simple program which turns on a lamp after 10 seconds then turns it back of again 10 seconds later. I am using a normally closed switch LDI X402 so that when power is on no button needs to be pressed as it is normally closed, so its automatic if you like.
    But I have included a push button LD X406, once this is pressed the automatic system is over- riden and the lamp comes on and stays on until the off button ANI X411 is pressed which turns off the lamp.
    Please have a look at the ladder diagram then could you answer the question below it.

    The Ladder Diagram has been attatched as a file ppt, the question is how do I make the program go in a loop, meaning lamp on for 10 then off for 10, I want it to keep repeating this, IE on10 off 10 on10 off 10 etc etc.

    Please Help
  2. davespringer


    Jul 27, 2005
    I have never seen this kind of program before, but if you were to write this in C, you would need an outer loop that goes forever:

    for (;;) {
    /* 10 sec-on, then 10 sec-off code goes here */

    What is the programming language you are using? Does it have flow control constructs like for and if/then/else? Unconditional branches?
  3. DanBrunermer

    New Member

    Aug 5, 2005
    In PLC ladder, there really is no such thing as a 'loop', per se. When dealing with ladder logic, you must remember that the controller will continuously execute each rung over and over as fast as it can.

    To do timed loops, check your manual for Timers. Usually a timer includes a rung for enabling/disabling, and NO/NC outputs. You will probably need two timers, one for on and one for off. You could get away with using one, if you have retriggerable timers and you don't mind adding extra logic to remember whether the ON or OFF state is current/next.

    You have two other states, if I understood it. You have 'Light On' mode and 'Light Blinking' mode, right? To track those:
    OnPB OffPB Light
    ----| |--------------|\|------------------( )--
    | Light Blink |
    ---| |--|\|----|
    | Blink OnT |
    ---| |--| |----

    OffPB OnPB Blink
    ----| |-------------|\|------------------( )--
    | Blink |
    ---| |---

    Note that 'Blink' is a memory bit, not an actual output.

    With Blink thus defined, now you just need to set up two timers that will each count for ten seconds, first the off timer and then the on. When both sequences have completed, retrigger the timers.

    Hope this helps,
    Dan B.