siemens step 5 function blocks

stevelawson

Member
Join Date
Feb 2004
Posts
115
Siemens Step 5 Function Blocks Post #1

Hi everyone, this is my first time on this forum and i thought i would just test the water.
So here goes, can anybody explain to me how to fault find on programs written in function blocks.
My basic problem is understanding the purpose of the =m001 =m002 etc. statements that follow a set of conditions and end in either conditional or unconditional jumps.
What do they mean and how do i status where the FB has stopped when experiencing a fault.
i hope this makes sense.
Many thanks steve.
 
Hello Steve;
The jump to label (conditional or unconditionnal) are used in STL programming to control program execution. most instructions (math, comare...) are not conditionnal in Step 5 STL, so if they are loaded in the processor they are executed. To make sure they are not read into the processor, you jump over them if conditions are not right.

For example:

AN F100.0 // flag F100.0 is not set
JNC M001 // check if the earlier statement is true
L FW102 //execute the add function if satement is true
L FW103
+F
T FW220
...

M001: L FW101 // if original logic is not true, execute this logic
L FW103
+F
T FW220

//at the end of this block, FW220 will contain the
//result of one sum or the other,
//on the state of flag F100.0

Now if your processor has gone to Stop, check the B-stack and the I-stack through the Test functions of step 5. These will tell you what block and what instruction were being processed when the stop arrived, and the probable cause of the fault.

Hope this helps,
Daniel Chartier
 
When you see M001,M002,etc. they are where the jump from, if in the logic area. If they are in the left gutter, that is where the jump is to. If the command is JC =M001 and the RLO (Result Of Logic) in the step before the JC (Jump Conditional) command is TRUE (1) then it will jump to the M001 in the left gutter and continue executing from there. If not true, the logic below the JC command is executed. If you see a JU, that is Jump Unconditional, true or false. When you are in the STATUS mode, you will see the power flow under the RLO tab at the top and should light up green 1's or 0's. If you get between when the logic is being jumped over, it won't trun green and in the lower right corner you should see "not executed" or something like that.

If this is your first time here, WELCOME. You will find guys here that know just about everything, about everything and are very open to sharing their information and their opinions, whether you want them or NOT. Enjoy!
 
Thanks for the info guys.
I think iv'e got half an idea of what your talking about. So to put it to the test i will try and write a little routine to see if it works.
If I0.0 and I0.2 are made and I 0.1 is not made the PLC does a conditional jump to M001. If inputs I 0.3 and I 0.4 within M001 are made then output Q 1.0 will be set.

However, if any of the above inputs are in a different condition then the PLC goes into an unconditional jump M002 and if the logic conditions in M002 are true then Q 1.1 would be set.

If i'm talking nonsence could someone please write a small routine that i could try out on a simulator. Please put every written command in the routine so its completely idiot proof.
Thanks in anticipation,
Steve.

FB 100 SEG 1


:A I 0.0
:AN I 0.I
:A I 0.2
:JC =M001
M001:
:A I 0.3
:A I 0.4
:S Q 1.0
:***

FB 100 SEG 2

:A I 0.0
:AN I 0.1
:A I 0.2
:JU =M002
M002:
:A I 0.5
:A I 0.6
:S Q 1.1
:***
 
Last edited:
stevelawson said:
FB 100 SEG 1

:A I 0.0
:AN I 0.I
:A I 0.2
:JC =M001
M001:
:A I 0.3
:A I 0.4
:S Q 1.0
:***

FB 100 SEG 2

:A I 0.0
:AN I 0.1
:A I 0.2
:JU =M002
M002:
:A I 0.5
:A I 0.6
:S Q 1.1
:***

Steve

Something I have just picked up on is that segment is the same as segment 1 apart from the JU.

You could have written something like:-


A I 0.0
AN I 0.1
A I 0.2
JC M001
JU M002

M001: A I0.3
A I0.4
= Q1.0

M002: A I0.4
A I0.5
= Q1.1
BE





My disclaimer here is that I havn't tested it, I wrote it going on what you put in your post. Try it out and see what happens.

Paul
 
Hi Paul thanks for your input no pun intended.
I think i see where your coming from, by writing JC and JU at the end of the segment, if the logic conditions above are true the processor will jump to M001 and if untrue the processor will process M002 is this what you mean?
 
stevelawson said:
if the logic conditions above are true the processor will jump to M001 and if untrue the processor will process M002 is this what you mean?

Yep,

that's what I meant Steve,

I noticed that you are using a S5 plc, you might have to change my statement to suit the S5, what I have written is for an S7, I think the syntax is slightly different.

Paul
 
Right then Paul, what if the segment starts with logic commands like below.
FB100 SEG1
L KF +20
L FY 59
>< F
JC =M001

I know that the FY 59 is a flagbyte but i am not sure about the KF +20
or the >< F.
Each segment of the program i am looking at starts in the above way with a different :L KF +XX value for each segment.
Could you please explain this?
Steve.
 
Steve

L KF +20 means load the constant 20 into accu 1

The ><F function is a compare function, I thought it should be <>F which is compare for inequality, without going through my Step 5 manuals (which are at work and I am at home at the moment) I can't check this. Perhaps someone else will comfirm that.

Hope this helps for now

Paul
 
I had a feeling thats what it might mean, but whats confusing me is that every segment starts in this way and the numbers are not relevant to anything in the program. There are sub-routines of the program that will detect when a number of consecutive rejects have been made and this will flag up a fault. However, the numbers involved don't coincide with the KF +XX at the start of the segments.
These values are totally random ie seg 11 = KF +22 SEG 16 = KF +9
totally confusing.
 
Steve

Referencing to your previous thread that was answered by fritz fredrick, I take it that this question has evolved from that FB you wrote out there?

You state that it is for the number of consecutive rejected parts, which make sense, as the constants being loaded vary, thus when the number of rejected parts is, say 10, certain flags are set and if the rejected parts is then 15, then the previous flags are reset and different flags are set. I am guessing here as I haven't fully studied the FB you posted.

However, the numbers involved don't coincide with the KF +XX at the start of the segments.

This might be because the FY is being loaded into accu 1 as a HEX value not INT. In seg 11, you said that KF +22 is loaded, is the value being loaded from the FY 16?

If the compare instruction is a 'compare for inequality', then the RLO will be 1, unless the value in the FY is 16H or 22 INT.

Paul
 
Hi Paul, thanks for sticking with me on this one. I didn't even realise that i had a reply from Fritz, i must acknowledge him with a thankyou.
Anyhow, it would appear that i have completely thrown you with my mention of the rejects, so i will try to explain again armed with the info Fritz's has left me.
If we examine the segment below i will attempt to fill in the commands for each line.
I am still really confued by :L KF +XX because, has i badly tried to explain in my last post, there is no relevance to these numbers that i can see. I had come to assume that they may be step numbers. However, if this was the case why would we be comparing the FY with the KF?
So, once again can you explain the KF value? and by the way the FY values are loaded in hexidecimal.
So, what do i know?
Each step in the routine is controlled by the relevant FY.
Step 1 is FY = 0 up to step 10 is FY =A
Normally when the program gets in a loop i can force it on to the next step using CONTROL VARIABLE. (change 9 to A etc). However on this particular occasion, forcing the FY only caused the machine to single cycle and stop in the same place. The reason for this was that a flag was constantly set and i could only reset it by using CONTROL VARIABLE again to reset the flag. The machine is running fine now without really doing anything other than resetting the flag.
I just want to understand the structure better.

Here goes with my explanation then.

FB55 SEG11

:L KF +22 Load the value of 22 into accumulator 1
:L FY 59 Load the value of FY 59 and place it accum. 1 and put
the value what was in accum. 1 (22) into accumulator 2

:>< F Compare accum. 2 with accum. 1 and if the condition is
true ie. (not equal to) then jump to M001 if untrue ie
(equal to) then processor goes to next line. If untrue
i think the next line would be :A I 48.2 ???

:JC =M001
:S F 154.2
:S F 154.6
:R F 154.1
:A I 48.2 If "1" then jump to M002 if "0" jump unconditional M001
:JC =M002
:JU =M001
M002:
:L KF +23 Load the value of 23 into accumulator 1

:T FY 59 Transfer the value in accumulator 1 into FY 59
M001:
:***

Anymore thoughts Paul.

Steve.
 
Last edited:
Ok Steve,

We will try again, I am confusing myself as well now.

this is what you block says:-


FB55 SEG11
:L KF +22
:L FY 59
:>< F
:JC M001
:S F154.2
:S F154.6
:R F154.1
:A I48.2
:JC M002
:JU M001

M002:
L KF +23
T FY 59
M001:
***



One line at a time, this will also help me to understand a bit better.

L KF +22 //load constant (INT) 22
L FY 59 //Load the value in FY 59, although this value is in HEX that doesn't matter.
>< F //Compare both values with each other
JC M001 //jump if the above is true to label M001.
S F154.2 //Set flag 154.2
S F154.6 //Set flag 154.6
R F154.1 //Reset flag 154.1
A I48.2 //Check wether input 48.2 is made
JC M002 //If I48.2 is made then jump to label M002
JU M001 //If I48.2 is not made then jump to label M001

M002: //Label M002
L KF +23 //load constant (INT) 23
T FY 59 //Transfer the value 23 into FY 59 (in hex that would be 17)
M001 //Label M001, which is the segment end, go to next segment.

Now, I am not convince that the compare function should be a compare for inequality, I would have thought it would be a == (compare for equality), because as you say, this seems to be logic to 'step' the process on, what I call an 'Auto state register', in otherwords when the process is in 'auto state' 22 do such and such, then when 'auto state' 22 has finished (I48.2 is made) load 23 into the 'auto state' register and do whats required to complete that 'auto state' and so on.

Each step in the routine is controlled by the relevant FY.
Would that be FY 59?

The reason for this was that a flag was constantly set and i could only reset it by using CONTROL VARIABLE again to reset the flag.
What flag did you reset?

If you are having to force the machine into the next 'auto state' by inserting the next state number into the FY (59 or ?) and the machine is only cycling once and then stopping at the same place again, then the conditions that allow the next step (auto state) to load are not being satisfied, perhaps I48.2 is not being made?

I am not sure if this has helped you any, or maybe totally confused you. Perhaps you could email me the relevant block, or even the whole project, that might give me a better understanding of what is actually happening.

Paul
 
Ureka, i think i can finally see it. I have been beating myself up with these KF +xx values and the answer has been staring me in the face all the time.
I'm now sure that the KF value is the number of steps in each of the FYs i.e.
KF +10 has 10 steps and KF +23 has 23 steps. The reason why they are in no order is because a step further down the program could have more or less steps depending on the amount of instructions to be processed.
Now if i have got it right in my head, the reason why iv'e been getting so confused is because i'm just looking at the constant number and not the changing state of that number has it steps through its routine?

Tomorrow i will do a STATUS VARIABLE and watch for a mirroring of the variables has the program steps along.
I'm sure i'm getting somewhere now and its all down to you Paul ;) You must have been cursing me after all this time.
I will keep you posted on my progress.
Once again many thanks for getting me this far.

Steve.
 
Last edited:
stevelawson said:
its all down to you Paul ;) You must have been cursing me after all this time.

Glad I could help, though I am not sure how! :confused:

I haven't been cursing you, I got curious as to what this program is for, especially as you only showed a 'snippet' of the program.

I see that this 'problem' has been keeping you up at night, judging by the early hours reply! :D

Paul
 

Similar Topics

Hi, is it possible to read the name of the steps in an S7 Graph sequencer? In the parameterinterface there is, for example the parameter #S_NO...
Replies
21
Views
7,091
I have recently encountered a problem with a Function Call being know how protected. I cannot not open the Function Call to edit the ladder logic...
Replies
5
Views
7,801
I am having problems understanding a program i am trying to troubleshoot. The reason why i am having difficulty is because its written in function...
Replies
1
Views
9,244
Good Morning, Hoping someone with some Siemens experience can give me a hand with this one. Customer has a S7-200 cpu, which has a 6GK7...
Replies
0
Views
214
I'm just trying to figure out the right method of adding a DO card to an existing rack. It's not the *next* open slot, but I have to move the AO...
Replies
5
Views
528
Back
Top Bottom