No announcement yet.

Need some programming help

  • Filter
  • Time
  • Show
Clear All
new posts

  • Need some programming help

    Hi, I'm fairly new with ladder logic and I'm trying to write a small program but it's not working and I'm wondering if someone can help.

    I'm using a DL05.

    What I'm trying to do is with a single click of an external switch (X0), send a 6 second output to a valve (Y0) and do it 30 times every 5 minutes.

    Seemed simple when I started but I'm hopelessly confused.

    Any help will really be appreciated.


  • #2
    This is currently what I have.
    Attached Files


    • #3
      I think I didn't explain my task correctly. Here's the correct logic.

      What I'm trying to do is with a single click of an external switch (X0), send a 6 second output to a valve (Y0) and do it every 5 minutes, for 30 times (repeats)


      • #4
        1. Wait for X0 to go from OFF to ON
        2. Turn on Y0 for 6 seconds then turn it off
        3. Wait 5 minutes (or 4 minutes and 54 seconds?)
        4. Do steps 2 and 3 30 times regardless of the state of X0 (since you implied that X0 a push button by using the term "single click", or is it a latch, and if they release the latch, should it cancel the whole thing, i.e. turn OFF Y0 and abort the looping, or do you want to PAUSE the looping?)
        There are 10 kinds of people in this world, those who know binary, and those who do not.


        • #5
          Your logic looks sound to me. Is it run mode? (dumb question, but I have to ask)

          You can simplify the part where it looks for TA0 to be less than K60, by just saying NOT T0.


          • #6
            Thanks for the replies.

            FranjiL You're correct about the steps but I couldn't figure out how to do the last two steps.

            3. Wait for 5 minutes.
            4. Do steps 2 and 3 thirty times regardless of the state of X0. Yes X0 is a push button and there is no conditional abort - it is to do the 30 repeats regardless of anything

            Orion, yes it's the run mode. You're correct about the simplification part but I'm more stuck with the waiting and repeating parts.


            • #7
              Oops, I didn't understand the intended operation at first. How about this? It can definitely be improved upon, but maybe it gives you an idea. You can directly set and reset the valve output. The timers in mine are crudely operated, but maybe they inspire you. Refine away!


              • #8
                Hi Orion, Thanks so much for the help. I just tested it briefly and it works great. I do have some questions though about one part of the program and I'll ask you about those later. I just haven't had any time today, still at work.


                • #9
                  Thanks once again Orion for your help, I really like the simplicity of your code, I was thinking about it in a much more complicated - stages and so on - and probably wrong fashion.

                  Can you please explain the logic of the 2nd and the 3rd rung for me? Since I was trying to do the timer differently, I'm still a little confused the way you've put it together.


                  • #10
                    Glad it's getting closer to what you want. Stage programming is awesome and definitely not a bad direction. "Simpler is better" is not always true. More understandable is better, so whatever you do, make sure it's easy for you (and preferably, someone else) to understand when you look at it again down the road.

                    The second rung (first timer) runs until the second timer (Timer2) is done. While it's running (NOT done), the valve is energized. I was whipping through it when I made it and put the NOT Timer2 in the valve rung for good measure, but it's not needed.

                    Timer2 is set to 5 minutes and 6 seconds because, I'm a math idiot... It should be K2940 so that when added with the ValveRunTime it equals 3000 tenths of a second (5 minutes). So Timer2 acts as a valve "off" time. Again, I was burning through it pretty quick. I love logic, but math is one of my weaker subjects (despite being logic :/).

                    If that helps at all, you can take it and run with it. You can make the ValveRunTime preset a variable and the valve "off" time a variable. You could have one timer SET the valve and another RESET it. There are many correct ways to do it and, as long as it works, no wrong ways. (pretty much)

                    Feel free to ask again if I went off the rails in my explanation.


                    • #11
                      Oh and, T0 stays "running" until T1 gets done. These timers are cascading, but also the first is dependent on the state of the second in order to restart its cycle. I forgot to explain that part.


                      • #12
                        Thanks for clearing that up, I think I get it now. The Timer 2 in the second rung threw me off. I got the thing about the different ways to count the 5 minute pause and I'm still not sure how I want to count it, but that's a different issue. Your math was fine, no worries. It's funny how people have different aptitudes. While you think your math is your weak point and logic your strong point, somewhat similarly I can write computer programs quite well but struggle a lot even with simple PLC stuff. When I first got into PLCs, I thought my computer programming skills would translate well, but it never did. Maybe I don't do it enough.


                        • #13
                          I have never gotten past some intermediate scripting, but I believe knowing PLCs has helped me to write scripts, and vice-versa. Especially with PLCs like Do-More that begin to resemble some OOP qualities. String values that have "lengths" and structures that have "properties". You can even write your own protocols, which is beyond me. I'd love to know how to do that someday, but it's not part of my necessary skillset at this time.


                          • #14
                            For any timer I need that is in the minutes or hours range, if I dont have a TMR block that allows me to select a longer period directly then I use counters instead. There is always a 1 second and 1 minute system bit. So use a 1 minute bit and when the counter reaches 5 you know 5 minutes have passed. Leaving timers running and having them count into the thousands and sometimes tens of thousands just feels messy to me. It also saves me from having to convert minutes down to seconds and then going out to tenths of seconds, but the drawback is that you have to use a whole minute interval. When counting minutes you cant add a few seconds to do in the same counter, so if you need 5 minutes and 6 seconds you either have to start a 6 second delay timer, or run two counters one for minutes and one for seconds.
                            Last edited by MikeN; 05-18-2018, 08:38 AM.


                            • #15
                              Originally posted by MikeN View Post
                              There is always a 1 second and 1 minute system bit. So use a 1 minute bit and when the counter reaches 5 you know 5 minutes have passed.
                              One issue with using the 1 minute system bit is that your counter could be off by up to 59 seconds because it all depends upon when your 5 minute "counter" was enabled relative to the system bit cycle. If you want to use a counter, just use the seconds system bit, and use 300 for the counter preset. At most you would be off by 1 second (not 1 minute).

                              There are 10 kinds of people in this world, those who know binary, and those who do not.