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,191
Hi, I'm having an issue with a mircologix not transmitting out. The current setup is a mircologix 1400 connected to a Guardian 100 Radio...
Replies
1
Views
70
Hello, I have a running project on Citect v5.42 and simatic net v6.4 I have created a new spare PC and loaded all software like Citect, station...
Replies
0
Views
57
Hi, I am working with a Micrologix 1400 model 1766-L32BXB. With no input wires connected to the “in12” thru “in19”, I am getting 24 volts while...
Replies
4
Views
172
Hi everyone, I hope I don't butcher this up, please feel free to critique me wherever if I do, I have an issue I would equate to "chasing...
Replies
4
Views
241
Back
Top Bottom