Nested Subroutines at free version.

KirillIvanov

Member
Join Date
Jul 2019
Location
Eilat
Posts
11
Hi all.
Please see attached.

Tried to google the error with absolutely no results.


I did the same at payed version and real PLC so I'm almost sure it's some free version or Emulator causing the problem. Just curious if someone knows about this limitation.


The subroutine suppose to call itself again and again with every True condition during 8 checks. 1,2,3 JSR called with no issues. When it's equal or more than 4 I have this error which apparently comes from RSLogix 500 Emulate.

VirtualBox_Windows 7_07_09_2019_18_03_17.png
 
Yes. Same subroutine.

It checks eight conditions with one shots if TRUE and fills FFL with values.



Perhaps there is a better way to make a FOR cycle at Ladder Logic?


Here is the code.

VirtualBox_Windows 7_07_09_2019_18_31_38.png
 
Although you can call subroutines from within other subroutines, you shouldn't be calling the same one within itself.
 
Two issues.

1. There is a limit to how many nested subroutines the SLC supports. It varies by controller and is either 4 or 8.

2. If you are having the subroutine call itself it will potentially fail the watchdog timer. Too much detail to go into here.

Use a JMP instruction at the location you want to jump from (current JSR) and put a LBL at the beginning where you want it to land.

Using the JSR method it is actually suspending the subroutine scan and starting a whole new scan. Then it suspends that and starts another scan.

Using the JMP/LBL method you are within that one scan only and just jumping back to the top to rescan the code there. Much less overhead and no "nested" limits.

OG
 
Two issues.

1. There is a limit to how many nested subroutines the SLC supports. It varies by controller and is either 4 or 8.

2. If you are having the subroutine call itself it will potentially fail the watchdog timer. Too much detail to go into here.

Use a JMP instruction at the location you want to jump from (current JSR) and put a LBL at the beginning where you want it to land.

Using the JSR method it is actually suspending the subroutine scan and starting a whole new scan. Then it suspends that and starts another scan.

Using the JMP/LBL method you are within that one scan only and just jumping back to the top to rescan the code there. Much less overhead and no "nested" limits.

OG


Thanks for your answer.



That exactly what I did at the beginning but it didn't work after a first jump. Probably my code was wrong. Is it possible to use a same jump address for few different rows pointing same label or every jump-label should be unique?


UPD Nevermind... Already found at JMP help that few jumps may point to the same label. Thank you.
 
Last edited:
Give consideration that your logic could take place over multiple scans. I have written applications with lengthy string searches. Working through an array of target strings I broke it up to searching only 10 strings each scan. Even with 150 targets the search took almost no noticable time. I used the Jmp/Lbl pairs within each scan code for the 10 searches.
 

Similar Topics

I have an S7 "best practice" question (although maybe this topic is not as cut and dry). I'm programming in an S7-1500. I'm not programming a...
Replies
3
Views
1,496
Hi all, Digging deep here and need your helping hand. I'm trying to figure out how to assemble a path by hand to reach nested CIP objects. I...
Replies
23
Views
7,741
Hi All, I am a regular visitor to the forum, but not often get involved. I am using Citect 7.5 (2015) and I am having trouble nesting 2...
Replies
2
Views
2,773
Normally when I add a controller scoped UDT the tag is entered in the item as is... Tank_A.Level_Sp Since I’m programming 15 or so tanks with...
Replies
4
Views
2,104
I am working on building a global object for a notification banner. The banner has 10 different notifications that can be displayed and...
Replies
1
Views
2,560
Back
Top Bottom