direct logic 405 subroutine question!

darrentpi

Member
Join Date
Jul 2004
Posts
44
Hi I have never used a sub routine instruction, but figured I have a good example where I need one. I was wondering in my program, I have all sorts of messy instructions, for a routine operation, mostly I/o, but I want to use those same instructions in a subrutine for a different operation, can this be done. Kinda like having to competly different programs, but both using the same instructions, but in completly different logic.
When I tried it, and downloaded the program, I had a fatal error message telling me MISSING RET or something.
 
1. Missing RET - the subroutine must have, as its last rung, a non-condition RET instruction. This means that the rung has nothing on it but the RET instruction. This will be just before the box for the next subroutine or DLBL or the END instruction. If you also need to stop processing the subroutine in the middle based on some condition then use the RETC coil.

2. Now - regarding your main question. This is a "parameter passing" subroutine. The AB PLC5 has this but the AD stuff doesn't. But don't give up home. AD has POINTERS!!!

These are V registers which contain the address of the desired information. These can be set by a LDA instruction which contains the address of the target (eg LDA O2000 would load the address of V2000). If you wish to point to a bit you still must load the adress of the entire word which contains the bit. Look in the tables in the manual. You then do an OUT to the register which will hold this addrss. Let's say this would be V3000. So this would be OUT V3000

Various calls to the same subroutine would load different addesses into the pointer variables. Some may point to information for the subroutine to use. Some may point to locations where the subroutine would place the results of its operation.

3. In you subroutine to reference the contents pointed to by the pointer variable you use the 'P' prefix. A LD P3000 would first check V3000, get the address the V300 contains (in this first case V2000) then get the CONTENTS of V2000. Likewise, an OUT P3000 would store the accumulator's contents into V2000.

4. You may wish to operate using a single bit in the 'pointed-to' location. Check your manual on this 'pointer bit of word' construction as some have it incorrect. It's either BP3000.X or PB3000.X I don't have a working program in front of me. The 'X' part unfortunately cant be a variable. So if you are passing or expecting results as bit information, have the same bit be in the same location of a word. In other words, if you are using bit information, devote a seperate whole bit word for information being used or operated on by the subroutine for each call.

We used this whole setup extensively in our machines. I have controlled 10 movement axes using subroutines and pointers. So I know that it works. Warning - turning on an output using OUT 'bit of word' in a subroutine is almost like a SET or RST in that it is only evaluated again if the same pointer is set up and the subroutine is called again. Be very careful. You may wish to only use SET and RST just to remind yourself.
 
Thanks for the advice, if I call up a routine, lets say for example an input to call a routine, goes high, the scan will then skip everything below it, tell the location where the SBR instruction is placed, which acording to the help files I program the routine instruction right after the end instruction. Does the program now scan all the logic after the end instruction, which is the new logic I want it to execute? And as soon as the instruction goes low, will it then scan back to the original program?
 
Your idea of subroutines is wrong. When the subroutine is invoked the execution of the current logic is paused, the logic in the subroutine is done then the scan continues on where it left off immediately after the subroutine call. On the next pass through the logic, if the input is still on (assuming thisis the only condition for executing the subroutine) then it will execute again in the same manner. It will continue on each pass that the input was true (at least according to the way you described the process. Is this what you intend?)
 
Last edited:
I thought the way I may have understood subroutines is how you just explained it. Let me see if I have it right.
plc scans program from left to right, and from top to bottom, so in slow motion will it start scaning from the beginning of the logic, through down to the end instruction, and then repeates 100 m sec at a time I think, and lets say at rung 14 I have a call for subroutine instruction, with a address to call when it needs to be executed. Now will the scan pause everything under that routine call and jump to the routine rung beginning and continue to scan and puse through the section I didnt want executed, untill the routine call address goes low.
I tried downloading my little program last night, on my test bench and again error! missing RET or something, you had mentioned this is a instruction that needs to be placed before or after the end instruction.
Darren
Thanks for your advise, as this is really helping me.
 
There can be two sections of the DL06 program. The main logic section ends with an unconditioned rung with and END instruction. Unless told differently the PLC will scan through all this logic then, on the next scan, start again at the top.

But another section may follow this first END statement. It can have interrupt routines (these are routines triggered when specific events (usually hardware but they can be precise timers) take place. It can have subroutines which are triggered by GTS commands from within the main logic or possibly other subroutines. It can also have data labeled information (DLBL). We won't worry about that right now. This whole section is terminated by its own END statement.

Lets say the PLC is scanning sown the main logic and encounters a GTS K1 statement. The execution in the main area PAUSES at that point, jumps to the logic at the subroutine labeled K1, executes it then (let's assume a simple subroutine) at its end hits the RET statement (which must have no conditions) and returns to the point in the main logic immediately after where it encountered the GTS statement and continues on executing the rest of the logic in the main area. It does not SKIP the logic between the GTS and the end of the main area (assuming no GOTO statements - that's a whole other topic).

If your GTS was conditioned then this little side trip into the subroutine will only happen each pass that the condition is true. Note: if there is an output turned ON in the subroutine it will not be turned OFF just because the subroutine wasn't called on a given scan.
 

Similar Topics

Hi, I have a problem with a analogue output. When I look in the data view on the program the value it 4095 which according to my knowledge is...
Replies
3
Views
2,483
Just curious what is considered a one shot with direct logic software. Help would be great thanks DM
Replies
8
Views
6,233
What instruction, or menu will i find a tof delay? and how do I edit or insert a instruction between or infront of an exsisting, cant figure out...
Replies
6
Views
4,144
I will be interfacing these two units on a up coming project. I have limited knowledge with direct logics plc's and no knowledge on ez touch...
Replies
4
Views
8,051
So this is my attempt at collecting and displaying data on a Cmore panel With a DL06. Each pair in my logic is the "Time total" or the TA15 and...
Replies
4
Views
477
Back
Top Bottom