Announcement

Collapse
No announcement yet.

Looping in a subroutine?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts


  • Looping in a subroutine?

    Hello All,

    I am trying to write a program that loops a subroutine. I've attached a file which successfully loops in the main program but does not loop inside a subroutine. All I am doing is activating a timer, and then energizing a solenoid connected to Y002 relay output. My end application is to turn the solenoid on and off several times over the course of a minute. My main code will have several subroutines and I am trying to break up the code for debugging purposes. The PLC is a Click c0-02dr-d.

    Is there anyway to loop inside of a subroutine? I see the For..Next instructions but I wasn't able to get that to work.

    Thank you,

    Sam
    Attached Files


  • #2
    Have you looked at a timed drum instruction?
    Attached Files
    If you've done the very best you can, worrying won't make it any better - Walt Disney

    Comment



    • #3
      If you hold up the Program in the Subroutine only looking at a timer, then the rest of the program will hang while the Sub Routine is doing it job..

      I write Subroutines In Legacy stuff.. '06/205.. The program is generally broken up in to Subroutines for simplistic Troubleshooting.. I ( Mostly ) always call ALL the subroutines from the Main Ladder all the time .. then the Called Subroutine looks to see what it needs to do this scan .. If nothing, then it just exists.. If it needs to do an action ( On/Off, Count, Calculate ETC ) then it will do that and then exit.. Sometimes the Main program will only call a Subroutine every second.. Or every Minute.. but the Subroutine does not hold up the Main program for very long.. as other things need to run..

      If I have problems with a routine, I will Deactivate the Call to it in the Main Program.. till I get it all sorted out.. this way I can make it 'Live' for a few scans by what ever logic I want and check the results..

      Cap

      Comment



      • #4
        Thanks for the reply Ridgeline Mach! Evidently it was working, I just wasn't resetting the counter like you're supposed to. I hadn't considered the drum instruction which will be useful for another subroutine. Thanks again!

        Comment

        Working...
        X