Basic Question about Subroutines

Preeya

Member
Join Date
Nov 2003
Posts
112
Hi everyone, I am fairly new to programming subroutines and interrupts. I am used to dumping evrything on the main program. But with the Siemens S7 200 I am currently using now, I wish to use subroutines and interrupts. My question is -

When a subroutine/interrupt is called (on say instruction 1 of the main program) and executed, does it come back to the next instruction on the main program (instruction 2)?

Or Does both the subroutine and the main program run simultaneously?When the subroutine is being executed, what is the status of the main program?

May be this is a very basic question, but please help me understand the sequence. Thanks for your time!
 
hi preeya,
this is regarding the interrupts & subroutines in s7-200.....
the basic difference in subroutines & interrupts is interrupts as name indicates interrupts the main program scan...executes itself depending on the priority assigned & then returns back to parent coe starting from the next instructions from its occurance as u asked...
whearas subroutines just coexecute.....infact in siemens the microwin takes care of everything....u don't even meed to write the simple RET or END instructions as u do in Allen Bradley & other PLCs...
if u read the help of step 7 microwin u'll find everything u need.....i guess u r using CPU 22x.......i hope this is useful to u

i remain,
Mandar Joshi.
 
Thanks Mandar. Your reply was really useful.
If I understand the coexecution right, while the sub is being executed, the main program also runs parallely..?

And yes I am using CPU 222.
thanks again.
 
Last edited:
preeya,

I have to admit, I don't have any experience on the Siemens S7-200 series. However, I also have to say that I am doubtful about lucifer's answer. I would be surprised to learn that the S7-200 can simultaneously execute a subroutine and the routine that called it. I expect that when a subroutine is called, program execution shifts from the calling routine to the subroutine, proceeds to the end of the subroutine, and returns to the statement following the Call.

If I'm incorrect, my apologies to lucifer.
 
Steve is correct. The difference in subroutine/interrupt calls, the subroutine is called from somewhere in your program scan at the same place everytime. The interrupt is called from a hardware input, or a timed event that is defined as an "Immediate Interrupt", which is called whenever needed without predetermining in the program scan. Yes, both return to the point in the scan, where it happened, to execute the next command.
 
Thanks for all your reply. I might use a subroutine and a timed interrupt for my program. I now understand the flow better.
 
steve is correct
a subroutine is a program called from a higher program.
wife is knitting on bench
when she has to take a new bale she uses a subroutine, and she stops knitting until she has the new bale.
when you ask for coffee she is interupted and will make coffee (if you ask nice) and after she will continue knitting again

so she stops here main program and she will continue.
the danger of interuupts is that when you interrupt her a lot she will never finish knitting.

as knitting is slowed down it is not realtime anymore.
and you will get cold as your sweater is not ready yet.
 

Similar Topics

Hi all, I have a noob question regarding data handling from sensors. I understand configurations and I/O mapping sensor input/output variables...
Replies
2
Views
218
GE 90-30 using ME 6.0 - Newbie question... Let's say on rung 10 I set a coil (S) with a one-shot. Input to coil drops out, but coil stays...
Replies
30
Views
11,076
Dear experts, i have pretty basic/ dump question, can someone help me to figure out how to read/ what is this? i assume it is solenoid vavle...
Replies
4
Views
1,057
Create ladder logic program to count 4 on pulses (not using a counter) and then turn the output on if the on pulse input signal can look like the...
Replies
105
Views
36,345
Im looking to hook up a 3 wire PNP photocell to an Allen Bradley 1746IV 16 module. Ive watched videos about hooking up DC sensors, but they show...
Replies
3
Views
2,940
Back
Top Bottom