S7 STL - Wait for reply in loop (interrupts?!)

Supreame

Member
Join Date
Jul 2008
Location
Brasov
Posts
33
Hello,

I am using a FB in witch I want to wait for a reply. For example: a bit is set (e.g. M0.0 - request) and after 10 seconds (or sooner) if another bit is set (M0.1 - reply) then do an action, otherwise generate an error.

The problem: if I wait in a loop (made with a Timer) the execution of the program is frozen there, and inputs are not read (and for that reason I can't exit the loop). I think that an interrupt should be used but I don't know how.

Thanks!

PS: this sould be done in STL
 
Programmable Logic Controllers automatically run loops. These loops are called Scans.

Inputs are read, program is scanned, Outputs are written. Repeat.

You do not have to do anything special to make a PLC program "loop" while it waits for an input.
 
I know that the program loops automatically. What I mean is that I loop in only one network of the FB and the inputs are not read in this loop.
 
Why are you trying to keep it inside this single FB? Let it scan the whole program, updating the I/O as it runs.

It will run the FB each scan (assuming the call is true), so as soon as the Input is true, the FB will do it's stuff correctly.

Assuming it's something like:

Call FC 1

and in FC1, theres:

A M0.0
= M0.1


So you just let it run. Each scan, and it will not do anything with M0.1 until M0.0 is true.

If you want to stop other things from happening while it's waiting for this request/handshake, you need to put M0.1 into the logic of the other things. You cannot try and hold the program at that Network.
 
Tharon said:
Why are you trying to keep it inside this single FB? Let it scan the whole program, updating the I/O as it runs.

It will run the FB each scan (assuming the call is true), so as soon as the Input is true, the FB will do it's stuff correctly.
I just did that and it seems ok for now, but the FB has many networks and many conditions and it's harder and harder to direct the program execution to the correct way (using JC, JCN, JU and so on). That's the reason I tried to remain in only one network.

If you want to stop other things from happening while it's waiting for this request/handshake, you need to put M0.1 into the logic of the other things. You cannot try and hold the program at that Network.
I didn't understand that part...
 
Well. You have your bit M0.1. M0.1 = 0 if the request was made.

So, if you have stuff that you don't want to have happen until the request, you just do:

A M0.1
A I1.0
= O1.0

If I1.0 was a Push Button, and O1.0 was a Light, even if the operator pressed the button, the light would not turn on until M0.1 was true (in this case, the request/handshake of the message).

Rather than trying to Jump around this piece of the program, just let it run, but make it have to have seen the message before the statement is true.

Apply that to everything you want to do.

I try to keep jumps to an absolute minimum in a PLC program. They just complicate things.
 
Sometimes you need to keep track of the 'state'.

Many handshaking or communications protocols are best implemented using state machines to organize the code.

Use the jl instruction and a state variable to jump to different states. Inside the states you should have 4 sections. The first section is for when a state is entered. You need to check if state<>laststate.
The second section is executed each scan. In this section you have code that does the real work and that checks if the state is changing. In this case you change state to the nextstate
The third section is executed when the state is changed and state<>laststate.

This will take a little more code to implement but it will run much faster because only the code in a state get executed. It will also be much easier to debug and document.

The JL instruction is one of the better features of the S7. Make use of it.
 
Peter Nachtwey said:
Many handshaking or communications protocols are best implemented using state machines to organize the code.

Use the jl instruction and a state variable to jump to different states. Inside the states you should have 4 sections. The first section is for when a state is entered. You need to check if state<>laststate.
The second section is executed each scan. In this section you have code that does the real work and that checks if the state is changing. In this case you change state to the nextstate
The third section is executed when the state is changed and state<>laststate.

This will take a little more code to implement but it will run much faster because only the code in a state get executed. It will also be much easier to debug and document.

The JL instruction is one of the better features of the S7. Make use of it.

... and ...?
Don't leave us in suspense! :)
What's in the fourth section?

Ken
 
If you loop in one fb the watchdog would stop the plc, ....Unless you disable it "Bad move".
If you need to check states of a bit then jump round to next state, eventualy to the end of the block.
 

Similar Topics

i am new to simatic manager and i am trying to figure what this part do in the code : A I 5.6 = DB50.DBX 4.6...
Replies
3
Views
133
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
208
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
317
First off thank you in advance. Second I am very new to STL. I am trying to build a counter that has one count up and 23 count down options. Am...
Replies
6
Views
377
Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
676
Back
Top Bottom