Jump to content

How to delay a output in a sub-routine


Recommended Posts

Hi, I'm working on a program for hydraulic controls, there are 6 valves with manual control (12 states). Whenever a switch is operated it set the control valve and start the pump (common for all valves).

I have  one ladder net for each valve and call a subroutine to start the pump, open main valve etc. This seems to work and using the subroutine code it is easy to fix and read. However I don't find a good solution to delay the pump stop when the manual switch is released. Haven't worked with PLC in many years, so I need a few tips.

The pseudo code is something like:

Push and hold Button1->Open valveA, open Valve1 and start pump

Release Button1  -> Close valveA, close Valve1 and delay 10sec stop pump

 

Link to comment
Share on other sites

  • MVP 2023

This seems fine for one valve Gabriel, but I thought it had to allow for any or all  of the 6 valves being in use, and only doing pump shutdown on all of them  being off.  6 "master" call MBs inverted in series could start the timer, which is then linked to the pump control..... however that is done.  But that's why I thought it might get a bit iffy if each  valve works via a conditionally run sub.

cheers, Aus

  • Like 1
Link to comment
Share on other sites

You are right Ausman, if any (or all ) of the 6 valves are in use the same main pump are running and the pump shutdown are delayed when the last of them  are turned off. 

I've looked into the sub-routine advice, and also the examples from Unitronics, maybe I'm to OOP minded when I want the same net/routine to be re-used and only 1 timer to be used for the same task.

The switches (S1, S2 etc)  in thise case are also latched while beeing operated with spring return, so no self holding or set/reset for the valves A, B etc.

Link to comment
Share on other sites

Here is the valve program, the subroutine runs the pump as long as the input is high and works perfect (without the off-delay), and I need 1 net for each input/output.

I assume a lot of you prefer using input buffer bits with subroutines, and maybe I'll rewrite for that,  my code is based on the examples provided in the help section.

image.thumb.png.545792b00b1e51efe35dd951d7f9833d.png

  • Like 1
Link to comment
Share on other sites

  • MVP 2023

Use a TE (Extended Pulse) Timer. Activate the timer with a negative transition of the run bit or positive transition of the stop bit (depending on how you have your logic set up - looking above you would need the negative transition). Use the TE Timer output bit in parallel with whatever is activating the output. This will allow the output to continue to run for the preset time after stop signal occurs.

  • Like 1
Link to comment
Share on other sites

Thanks for all suggestions, it looks like I have reconsider how I approach problems like these in the PLC coding.

Instead of calling the delay function for each tasks it's need (in this case it looks like the delay is only needed for 6 valves) I probably need the have a complete sub routine for each of these main tasks. It kind of contradicts how I'd like to get "high coupling and low cohesion" programs to work, but I guess it's also depends on POV.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...