Sub-routine

rblopena

Member
Join Date
May 2003
Posts
4
how to used subroutine in cqm1?, because i want to make my program short so that plc will lessen the time of scanning my program. THANKS!!!
 
Subroutine itself don't do program more fast.
Subroutine call itself need stackin etc. for the processor so program will came more slowly, if there still have same functions.

What kind of program-developer you have ?
 
OMRON JUMPS

In OMRON, its best to use JMP & JME this will allow you to jump to certain parts of a program or skip others alltogether.

Although if its a CQM1H you have, I have written some huge programs and never needed to use JUMPS, if you use 'DIFU' & 'DIFD' as much as possible, you will have a program which will run quickly anyway.

Chris
 
Huh?...

CMF said:
I have written some huge programs and never needed to use JUMPS, if you use 'DIFU' & 'DIFD' as much as possible, you will have a program which will run quickly anyway.

Please explain how using DIFU and DIFD "as much as possible" has ANY effect on how 'fast' the program will run... :confused:

beerchug

-Eric
 
Re: Huh?...

Eric Nelson said:
Please explain how using DIFU and DIFD "as much as possible" has ANY effect on how 'fast' the program will run... :confused:
They are one shot evaluations as OSR (DIFU) and OSL (DIFD) what I never need.
 
Last edited:
Yeah Seppo, I know what they are, I use 'em all the time... :D

I just want to know how using them 'as much as possible' will magically decrease scan time... :unsure:

Chris, using them where not needed will actually INCREASE scan time. Check the execution time of a DIFU/D vs. a regular OUT, the DIFU/D is considerably longer. They also require more memory!... (n)

Or, did I misunderstand something?... :confused:

beerchug

-Eric
 
The question was how can subroutines make programs run faster.

rblopena, you are right, you can save CPU time by using subroutines as long as they are not called contuinously. When subroutines are not called then subroutines use no CPU time. The main scan of a well organinzed program may consist mainly of conditional calls to subroutines.

I routinely put the inintialization code in a subroutine that gets called only when the first scan is active. The rest of the time this initialization subroutine has no affect on the program or the scan time. This is much better than putting the initialization code in the main loop where is get scanned and consumes CPU time.

Seppo is correct that there is extra overhead in calling a subroutine. The program will execute more slowly if the subroutine is called every scan. I would be faster to put the code in-line in theis case. However, it may make the main program to long a look disorgranized.

CMF, is correct that jumps over sections of code will save time, but I like the concept of conditionally call subroutines better.

Eric, the DIFU/D is just a way to keep from continously call a subroutine. This is one way to make sure a subroutine gets called only when it required. Another trick I have used to to have the subroutine clear the bit that activated it. Seppo must use this trick if he doesn't use one shots.
 
Re: The question was how can subroutines make programs run faster.

Peter Nachtwey said:
Eric, the DIFU/D is just a way to keep from continously call a subroutine. This is one way to make sure a subroutine gets called only when it required. Another trick I have used to to have the subroutine clear the bit that activated it. Seppo must use this trick if he doesn't use one shots.

Aha! Maybe THAT'S what CMF meant to say?

That idea could come in handy Peter. I've never needed to call a subroutine for only one scan, but that's definately a great way to speed up a program when necessary. Wait a minute... As you mentioned, I call my 'initialization' subroutine(s) for 1 scan, so I guess I HAVE done that... :D

For the most part, my 'main' program is usually just a bunch of calls. I do that primarily for organizational purposes, so I don't see where I could benefit with one-shotting a call. Most of my calls are conditional, so there's usually just a handful of subroutine running. Rarely do I run into scan time issues, as today's processors are plenty quick. "Back in the day", you had to get pretty clever sometimes in order to get the scan down to a 'usable' speed... ;)

beerchug

-Eric
 
Peter Nachtwey said:
Seppo must use this trick if he doesn't use one shots.
In the following circuit 7215Step5 is one shot step and it allmost 'free' without separate evolution. 7215Step5 is there needlessly 2 times, 1 is enough (as well as 7215Step8). This is not Step5 advertise !!

s7-i7215.jpg
 
Last edited:

Similar Topics

We have a project that has all the routines viewable but not editable. I just want to force a bit high but cant do it. The only way to do so is...
Replies
2
Views
2,838
Good Morning , I'm merging another RS Logix 5000 PLC program ( CompactLogix ) into another . Everything is working great except this one...
Replies
9
Views
3,712
Hello everyone, I am new to ladder logic and am currently working on a small project where I might need some help. So I am modifying the sequence...
Replies
9
Views
2,411
Currently I am using a bunch of TON's and TOF's to start up and turn off a motor sequence. I created a sub routine for the manual sequence and I...
Replies
15
Views
4,704
Hi all, In the past I have use Sub Routines more as a organizational tool for my programs than anything else. I would just put things into nice...
Replies
6
Views
2,536
Back
Top Bottom