Siemens programming question

muusic_man

Member
Join Date
Nov 2008
Location
Delaware
Posts
148
I have the following code in My S7-300 function block:

AN #Dig_IN_GLYCOL_LVL_OK
S #ALM_LO_GLYCOL_LVL
AN #FLAG_CHILLER_ENABLE
AN #TMP_UNIT_LOCAL_ENABLED
R #ALM_LO_GLYCOL_LVL

I want to add a time delay of 3 seconds before the set of the alarm. Can someone show me what the code would look like. I am an AB guy by trade and was asked to make this minor change to one of our Siemens PLCs. Thanks in advance.
 
Since this is a Function Block (FB) I assume that this is an FB used for several instances.

Add the SFB4 to the STAT declaration part of the FB. Give it the name T_LO_GLYCOL

Then change the code to this:

Code:
Network 1:
      AN    #Dig_IN_GLYCOL_LVL_OK
      =     L      1.0
      BLD   103
      CALL  #T_LO_GLYCOL
       IN:=L1.0
       PT:=T#3S
       Q :=
       ET:=
      NOP   0

Network 2:
      A     #T_LO_GLYCOL.Q
      S     #ALM_LO_GLYCOL_LVL

Network 3:
      AN    #FLAG_CHILLER_ENABLE
      AN    #TMP_UNIT_LOCAL_ENABLED
      R     #ALM_LO_GLYCOL_LVL
By splitting into the 3 networks and formatting the code like this you can switch to LAD which probably you will be more comfortable with as an AB programmer.

Notice that you have to change the IDB of all the instances that uses the FB, and you have to download the FB and IDBs to the CPU.
 
Thanks so much Jesper. This worked well.

Now if I could be bold enough to ask another question.

I have an FC76 that has a piece of code that reads as follows:

AN #DIG_IN_SUCTION_OK
A #ENABLE_LO_SUCTION
= #ALARM_LO_SUCTION

This function is called from my FB56.

What is the easiest way to delay the alarm delay the alarm for 5 seconds. In other words, if the first statement is true for 3 seconds then goes false, nothing happens. I will only ge the alarm when the suction is low and stays low for 5 seconds.

You Siemens guys are amazing to me. I can make an AB product do all sorts of tricks and then I enter the Siemens realm I can't even build a simple timer. I feel so stupid. LOL

BTW, I told my boss who helped me make the first edit you helped me with. He said to thank you as well.
 
The problem with FCs is that they do not contain any "memory", so you cannot put a Timer in an FC, since a Timer has to "remember" the expired time.

You can change the FC76 to an FB, so that it becomes embedded into the calling FB. Just like SFB4 in the previous example. And then add an SFB4 to the called FB. That would be the most "correct" solution.

Or, you can delay the state of the variable #DIG_IN_SUCTION_OK (probably the one that has to be delayed, yes ?) that is passed to FC76 in the calling FB. So you would have to add another SFB4 to the calling FB. That would be the "quick-and-dirty" solution.
 
STL code:
Code:
      AN    #DIG_IN_SUCTION_OK
      A     #ENABLE_LO_SUCTION
      L     S5T#5S      //5s delay  
      SD    T      1    //TON

      A     T      1
      =         #ALARM_LO_SUCTION
or copy this to your program to see it in lad or fbd:
Code:
      AN     #DIG_IN_SUCTION_OK
      A    #ENABLE_LO_SUCTION
      L     S5T#5S
      SD    T      1
      NOP   0
      NOP   0
      NOP   0
      A     T      1
      =         #ALARM_LO_SUCTION
 
marcius, that wont work.

The calling block is an FB, so it must be reusable code.
You cannot use S5Timers with reusable code (*).

*: For the anal-retentive, then there are ways to use S5Timers with reusable code, but it is very inflexible and cumbersome, and it does not work the way marcius posted.
 
The S5timer siemens can be used very well as an input.

Code:
      AN    #DIG_IN_GLYCOL_LVL_OK
      L     S5T#3S
      FR    #TIMER_ON_DELAY
      SD    #TIMER_ON_DELAY             //T [DIW 2]

      A     #TIMER_ON_DELAY             //T [DIW 2]
      S     #ALM_LO_GLYCOL_LVL

      AN    #FLAG_CHILLER_ENABLE
      AN    #TMP_UNIT_LOCAL_ENABLED
      R     #ALM_LO_GLYCOL_LVL

Pic.jpg
 

Similar Topics

Could anyone tell me how to reset a counter in a particular time in a day , say 8 a.m. and 8 p.m. in Simatic S7 system. If anyone provide me an...
Replies
3
Views
2,187
Hi, I'm wondering how to program a function that has an integer(or word) input but return the value contains in the address of the input. for...
Replies
8
Views
4,024
I'm new to the Siemens plc and Step7 software. I have a S7-200 and I like to combine a bunch of alarm bits (%m10.0-%m10.7 & %m11.0-%m11.7) into...
Replies
1
Views
3,011
Hi all my expert friends...I'm still new with Siemens PLC and I am using the Siemens PLC model S7-300 (CPU315-2 DP). I am facing some programming...
Replies
9
Views
11,673
S
Hi all my expert friends...I'm still new with Siemens PLC and I am using the Siemens PLC model S7-300 (CPU315-2 DP). I am facing some programming...
Replies
0
Views
9,137
stevenPLC
S
Back
Top Bottom