Sub Routines

juddge

Lifetime Supporting Member
Join Date
Oct 2021
Location
Penrith NSW
Posts
21
Hi guys,

I am creating a sub routine and was wondering how i can trigger Bit when the sub routine first runs
is it just a Open Line ?
or is the 1STScan Bit usable inside a Subroutine for the firs time it opens ?
or does a sub routine delete all settings once finished ?


example

Main program calls the Sub routine
Sub routine runs a drum for count of 3
then routine ends

how can i tell the routine to Reset all counters and drums inside when the sub routine before it returns to the main program ?
 
The information you have supplied is lacking important information.
Firstly, you have not said which PLC you are using.
Other information, it appears from your explanation that you expect the function block to keep processing until the count is reached, this is not how it works, for example if the code inside the FB was to increment the counter every say 1 second & stay in that routine without processing the rest of the scan program the watchdog timer would elapse & shut the PLC down.
I expect you want the first scan bit to only set a bit when it first calls the FB does this mean it only runs once on PLC going from stop to run ?
So Yes the first scan bit can be used within a subroutine or FB as many call them but it has to be a global tag.
Yes you could compare the counters & reset them when the count value is reached.
You cannot keep a routine running without processing the rest of the scan program.
The only way to do it is in the scan program make all other logic into subroutines or FB's as they are known, so the other routines are only called once the routine you are talking about has finished.
 
To add on to what Parky said, a subroutine does not run instead of the Main Routine. It runs in addition to the Main Routine.

For Allen-Bradley controllers, when I want to track if the subroutine has been called, I make the first rung an OTL (or an OTE) with a memory BOOL tag. No inputs ahead of it. If that tag is on, I know the sub has run. I can then use that BOOL tag as a way to seal in the JSR that called the sub. So as long as that BOOL tag is ON the sub gets called.

Then in the sub, when I am done with whatever function I am performing and I want to stop calling the sub, I have a rung at the end that unlatches the BOOL tag. I have a condition ahead of it that defines when to unlatch. I can also reset any counters, timers, or other values at that time.

Hope that makes sense

OG
 
Hi , sorry it is for a Click PLC
I now realise sun routines are for doing something else - like a side quest whilst the main program still runs

What I have for my situation is water jets that need to run in a sequence, so I have setup drums to operate them , but I have 24 Jets
So I need 2 drums

What I am endeavouring to do is have 3 ways to run the drums
1. Drum 1 then as soon as drum 1 finishes - run drum 2 then finish
2 . Drum 1 and 2 run at the same time , but cycle twice for runtime similar to 1
3 . Drum 1 starts then 15 seconds later - drum 2 starts and they both cycle 2 times befor finishing

I was hoping to only have the 2 drums setup and based on input selection run the selected sequence of drums 1,2,3

Could the drums be sun routines for this - or is it better to leave them in the main routine
 
I think you have the right approach. Create a subroutine for Drum 1 and another for Drum 2, but you need to signal that one sequence ended within the each drum.



In your main routine you can then write the logic that calls the subroutines depending on the selection from the operator. The sequencing of them is achieved by the feedback from each.
 
Not really used drum sequencers much & prefer to do my own sequence control, however, they do have their uses.
It will depend on the functionallity of the particular drum sequence per platform.
As far as I can remember, the drum sequencers are triggered on a false to true transition (it will depend on the particular plc), so yes it should be reasonably easy to set up. As drum functions are effectively sub routines there should be no need to run them in your own FB's (Subroutines), just call them or enable them when required.
DRBitboy has recently had a play with a drum function on the click so I bet he will be munching at the bit to give you some ideas.
Me personally, would probably use a sequence variable then each value of the seq. variable would turn on x bits then transition to the next step, for example lets assume 3 different combinations of x number of solenoids & 5 steps per combination for example
SEQ. = 0 //No operation
10 - 50 Sequence 1 // Note: doing it in steps of 10 allows spares if extra steps required.
60-100 Sequence 2
110-150 sequence 3
Use the step numbers & compares to drive the solenoids.
Which ever way you go, just remember what you need to do should you need to abort a sequence i.e. switch off all active solenoids i.e. reset the drums back to idle or not called.
another way is to use an array of masks, i.e. bits set in a word or double word for more than 16 solenoids each element in the array will either be true or false depending on the solenoids to be energised, if there is a need to have different times the solenoids operate for each step then a two dimensional array containing the solenoid bit pattern & the times for their operation, ideal if you have say an HMI so patterns/times could be altered.
 

Similar Topics

Good Morning , I'm working on a project along with a manufacturer. We are both working on a project , and I'm integrating an existing portion...
Replies
8
Views
2,258
Hello: I am new to PLC's as far as writing the programs and have never written a sub routine. I know in a regular ladder you are limited to...
Replies
4
Views
2,511
Anyone help me please to add subroutines to a program that runs a baler.I want to delay the return stroke after a ram has extended.I've been doing...
Replies
1
Views
1,563
  • Poll
On another thread, the subject of subroutines came up. I do not use them myself. I spoke with everal others that do not either. Perhaps it...
Replies
26
Views
5,176
Reading another thread recently, someone advised upon not making subroutine jumps conditional, i.e. call them every scan, due to the fact that you...
Replies
25
Views
11,489
Back
Top Bottom