S7-400 -- the behaviour of Set and Reset instructions inside of a Function

Serg_Rus

Member
Join Date
Nov 2009
Location
Rus
Posts
7
Hello!
I recently encountered interesting case with Siemens S-7 400 hardware, STEP7 and Siemens PLC-Simulator.
I use a pair of Set and Reset instructions inside of Function subroutine (let's say FC1). They write the result to output variable of a function. When i call the function its output variable is connected to the variable inside of a some data block (DB).

For example code inside of the FC1:

A #in1
S #out1

A #in2
R #out1


That's all.
According to Siemens manual this should work fine. In my case the whole programm has following structure. I call one function (let's say FC2) from main organization block (OB1). And this function calls the FC1 described above (with Set and Reset instructions). Then i tested this programm with Siemens PLC-Simulator. And it didn't work! Set instruction didn't hold it's state like it should! I made some experiments. If I call FC1 directly from OB1 it works. If i use Set and Reset directly from OB1 (without any functions) it also works. But i need the programm structure to be exactly like i said. I thought the problem was in the FC subroutines (because they do not store temporary variables). So i created function block subroutine with S and R instructions (FB1) and the instance DB for it. And yes, it works correctly. But then i tried another thing -- I moved #out1 variable from Out section of the FC1's interface to the In/Out section. It started to work fine :) Strange, isn't it? But that's not all. I tried the programm with real S7-400 hardware and ALL variants work fine! FC or FB, Out or In/Out -- it doesn't matter!
So the questions are:
-- is it a bug ot the PLC-Simulator?
-- does it have to do something with internal mechanics behind S and R instructions?
-- can i use my programm as i first planned it with nested FC calls?
All opinions are welcome. Thank you in advance :)
 
Last edited:
In your first attempt, where #out1 and #out2 were assigned to OUTPUTs, your code did not take into account when the INPUTs #in1 and #in2 are not on. In that case the outputs are undefined. That it seemed to work partially was because all the rest of your program is so simple.

When you changed from FC to FB, the #out1 and #out2 becomes a memory of its last state and it will work.
Same with changing #out1 and #out2 from OUTPUTs to IN_OUTs. The #out1 and #out2 in this case also get memory of the last state.

This is a typical beginners programming error.
With FCs, OUTPUTs must not be conditionally defined.
 

Similar Topics

Hi All, I was testing the effects today of my processor losing power while running, and it appears that when power is restored the outputs resume...
Replies
23
Views
10,233
Hey all, first time poster here. I am wondering if anyone has tried using a Keyence SR-X300 barcode scanner to a Micrologix 1400. Keyence sent...
Replies
0
Views
12
I have a micro1400 processor running two routines (transfer compression/compression molding press). Recipe parameters are stored from job to job...
Replies
0
Views
28
Is there anyone who can help me regarding this HMI is missing the choices when I make a new Device in TIA. Only 7" Display above are the choices...
Replies
3
Views
77
I'm using a SLC typed write from the ControlLogix5572 to the MicroLogix 1400, with path: 2, (MicroLogix IP). The ControlLogix equipment has a...
Replies
0
Views
87
Back
Top Bottom