siemens step 5 function blocks

Hello,

I've only red your privat message today, sorry for that. I also see that Paul has helped you out. There is still one thing that I would like to mention.

I think your program is written in a way I normaly use. I think it's a step program, in one PB or FB your initional program is written.

Something like this:

If condition X is true then set step 1 (FY x1), If step 1 is "1" and the next conditions are true then reset step 1 (FY x1) and set step 2 (FY x2) and so on.

After this you've got one (or several) FB were you handle your outputs.

I'll try to explain in a small program.

FB 50 (in ladder)

I0.0 I0.1 F 0.0
I---II---II----------------(S)---I Step 1

F0.0 I0.2 F 0.1
I---II---II----------------(S)---I Step 2
I
I F 0.0
I----(R)---I


F0.1 I0.3 F 0.2
I---II---II----------------(S)---I Step 2
I
I F 0.1
I----(R)---I




In AWL

: A I 0.0
: A I 0.1
: S F 0.0
: ***

: A F 0.0
: A I 0.2
: S F 0.1
: R F 0.0
: ***

: A F 0.1
: A I 0.2
: S F 0.2
: R F 0.1
: ***

And now in the output FB (let's say FB51)

FB51
: L KF +1
: L FY 0
: >< F
: JC dummy1
: = Q 0.0
dummy1 : ***

Now you see that output Q 0.0 is "1" only in step 1, This is a good way of programming step programs because your outputs are handled in ONLY ONE FB. If your programs stop you only need to look in your FY to see what was the last active step. So you can find quickly which condition is missing.

I hope this has helped you in understanding a little bit of S5 FB's.

Rudi
 
Hi Paul, its me again. :p
The program in question is quite large and thats why i've only been giving you snippets. The system has 4 seperate machines with their own individual PLCs and at certain points they pass finished components over to one another. The particular part of the process which had the fault, tests a tiny gear box for tightness by first rotating it in an anticlockwise rotation and then in a clockwise rotation. If no tightness is found then a pick and place takes it and places it onto a pallet on an adjacent machine. However if the gearbox is found to be tight a sensor is made and the pick and place picks the gearbox up and places it onto a reject conveyor.
All fairly straight forward stuff, except the dam program is written in these FBs.
I think that i'm finally starting to understand the KF values but i'm not 100%.
Rudi (Fritz) has sent me another message explaining things again and it does appear that they are step numbers.
So, this is what i am now thinking, please correct me if i'm wrong. I will try to write a small routine below.
FB10 seg 1
:L KF +20------load accum. 1 with a decimal 20

:L FY 10------Load the value in FY 10 (in HEX) into accum. 1
and push the value that was in accum. 1 (20)
into accum.2

:>< F -------Compare accum.2 with accum.1 and if KY =
14 (in HEX) which equals 20 (DEC)
then JU to the next line. However if the FY
is any other number (not equal to) 20 then
JC to M001

:JC =M001
:JU =M002
M001
:S F 10.1
:S F 10.2
:R F 10.0
M002
:A I 10.0
:S Q 50.0
:***

Well, what do you think am i still barking up the wrong tree? Its still the +KF and FY thats puzzling me :oops:
 
stevelawson said:
Well, what do you think am i still barking up the wrong tree?

Steve

First of all I don't think you are barking up the wrong tree, it seems that you are sorting this out piece by piece, a good knowledge of the process will help you understand what is going on in this FB.

In all the 'snippets' you have posted, you have used absolute addressing everytime and no symbolic addressing, by that I mean you are using I10.0 ect instead of 'TIGHTNESS_SENSOR', does this mean that there is no annotation availiable for your program? If that is the case then shame on the original programmmer. (n)

Good annotation, will certainly aid you in your understanding of what is going on in the program.
stevelawson said:
Its still the +KF and FY thats puzzling me

I am not sure what is confusing you about the KF's and FY's, maybe it because they are using two different number formats, but that's only what we see, not what the PLC sees. All the program is doing is comparing two numbers, one is a constant (+KF), that means it is stated at the time of programming and does not change, and one is a variable stored in a flag word (FY), the number stored in the FY is change by the program as and when required. Maybe if you looked at these in the 'STATUS VARIABLE' screen, and declared them both as KF (INT) or KH (HEX) format, you might understand a bit better.

Hope this helps some more, if you need more help post more questions, there are plenty of people here who can help, besides me! Though you might not believe that if the replies in this thread are anything to go by.

Paul
 
Thanks for being so helpful, but i think i'm going to give it rest now and come back to it in a fresh frame of mind when my brains not scorched.
But just quickly going back to the KF and KY which are tripping me up.

A flagword (FW) is made up of 16 bits and this can also be broken down into 2 flagbytes each consisting of 8 bits. See my analogy below.

----------------FW 10----------------

------FY 10---------------FY 11------

Now if what i have written above is a true statement how do we compare values greater than 8 in a FY?????

I will speak to you again on this subject soon.
I bet thats cheered you up :p

Steve.
 
stevelawson said:
Now if what i have written above is a true statement how do we compare values greater than 8 in a FY?????

Steve,

Don't forget that is 8 bits, and 8 bits can represent up to 255 in decimal.

00000000 = 0
00000001 = 1
00000010 = 2 (see my signature!)
and so on until
11111111 = 255 (FF in hex)

Paul
 
Yes it was a stupid statement, i think i meant flags. Well who knows what i meant?
I'm really loosing the plot now.

Steve
 
Hello Steve,

Its still the +KF and FY thats puzzling me

In HEX


FB51
:L KH 14 Load value in HEX in Accu 1
:L FY 10 Load value in HEX in Accu 1 and move ...accu 2
:= >< F If accu 1 >< accu 2 then jump to M001 else next line
:JC M001
:S F 10.1
:S F 10.2
M001 :***



In BIT format


FB51
:L KM 0000 1110 Load value in bitformat in Accu 1
:L FY 10 Load value in HEX in Accu 1 and move ...accu 2
:= >< F If accu 1 >< accu 2 then jump to M001 else next line
:JC M001
:S F 10.1
:S F 10.2
M001 :***



In DEC


FB51
:L KF 20 Load value in DEC in Accu 1
:L FY 10 Load value in HEX in Accu 1 and move ...accu 2
:= >< F If accu 1 >< accu 2 then jump to M001 else next line
:JC M001
:S F 10.1
:S F 10.2
M001 :***



The above is exactly the same for the CPU as when you should use KF. You even could use KM (bits) see above.

For the first rung

You are asking yourself what should happen in step 20 (14 hex) so,
load the value 14 in HEX (KH) and load the stepvalue which is stored in FY 10. If those values, doesn't matter in which form (KH,KF,KM..) or different then go to the next network else execute what should happen in step 20.

Keep asking questions until you understand, that's what this forum is all about!

Rudi
 
Hi Rudi, i was going to have a night off tonight but curiosity got the better of me.
I think i need to go back to basics with this and assume nothing. Afterall, i have no experience of this style of programming. I,m sure its relatively easy once you've grasped whats going on and this is the problem for me.
Commands that contain basic operands i can grasp. I can see that in the FB below the conditions are true and the processor will jump to label M001. I think.

FB 10 SEG 1

-------:A--I 0.0-----"1"
-------:A--I 0.1-----"1"
-------:AN-I 0.3-----"0"
-------:JC-----M001

Now here comes the problem, when the segment starts with the following, i have a complete mental meltdown.

FB 10 SEG 1

-------:L--KF--+20
-------:L--FY--55
-------:><-F
-------:JC-----M001

From what i can gather the statement is saying (if KF +20 is not equal to FY 55) then jump to label M001
My understanding of this is that you are comparing the value of 2 numbers, 1 in accum.1 and the other in accum.2 and if they are not the same then jump to label M001.
But wheres the logic conditions that you are comparing?
Do you see my problem Rudi, i just don't understand :oops:

Rudi, i will be out for an hour or so. So if you reply i will get back to you later.

Steve.
 
Since the other guys aren't on right now i thought I would toss this out for you to mull over.
The compare instructions compare ACCUM2 relative to ACCUM1. So in your case the math notation version of the code you wrote would be:
+20 >< FY55
In other words, as long as FY55 is not equal to 20, the result of the comparison is true.
The '>< F' is the comparison operator. Just like the two statements:
A I0.0
A I0.1
Will evaluate to either a '1' or a '0' in the RLO, the >< F will evaluate to either a '1' or a '0' in the RLO. The 'JC' immediately following either case will act on the RLO regardless of how the RLO was determined. I think the thing to remember is that the comparison instructions ( <, >, ><, etc) all have an effect on the RLO and, by implication, any instruction that uses the RLO.

I hope this helps.
Keith
 
Ah! Now I understand

Originally posted By stevelawson But wheres the logic conditions that you are comparing?

The penny has finally dropped with me about what confuses you regarding the KF FY comparison.

I think Keith has done a good job of explaining that in his post.

The RLO will show a '1' or '0' as a result of doing the compare, and that will then determine what jump instruction is followed (JC if the RLO is 1, JU if the RLO is 0).

Originally posted By Keith
Since the other guys aren't on right now

Keith, feel free to jump in anytime!

Paul
 
Hi guys, thanks for your help.
The RLO will show a '1' or '0' as a result of doing the compare, and that will then determine what jump instruction is followed (JC if the RLO is 1, JU if the RLO is 0).

This i undertand, honestly. What i don't understand and i'm really struggling to explain it, is whats actually being compared, i know its 2 numbers but whats their significance, where are they in the program?

If say 2 inputs in series I 0.0 AND I 0.1 make up a condition to do a JC then how do you assign a KF or a KY to mirror this condition to do a comparison?

So, could you possibly write a simple set of instructions implementing a jump instruction using the KF FY and ><F commands and then write the same instruction using normal operators like :A :AN etc underneath. Both sets of instructions need to do exactly the same thing so that i can compare the 2 step by step.

Also could you write some comments (in idiot language) after each instruction to explain whats happening. Please be very clear when it comes to the KF KY instruction explaining the relevance of the chosen number and its purpose.

Sorry about this guys but i'm on a mission now.

Steve.
 
I think the easiest way to show this is to break down a binary example and write it in terms equivalent to an integer compare. So here goes.

A simple binary example would be:

AN I0.0
JC M001

You know that this will jump if I0.0 is '0' and not jump if I0.0 is '1'.

This can be thought of as:



binary integer
L KF +1 L KF +20
L I0.0 L FY 55
>< F >< F
JC M001 JC M001




This is not quite correct as the processor will not be happy about the type mismatch but the concept holds. The big different between the binary compares and the integer compares is the digital compares are implied in the instruction (A is =, AN is ><). You can do this since with a binary value limited to '1' or '0' you only have two choices, = or ><. With integers you have many more choices for comparison so you need to explicitly list your desired comparison.


I hope this helps and doesn't just confuse you more.

Keith

P.S. I edited my post as I made a mistake in the original.
The 'KF' reference is to an integer constant enteres as a decimal value. So 'KF +20' jsut means you are loading ACCUM1 with a constant value of 20. 'FY 55' means you are loading ACCUM1 with whatever is in byte 55 of internal memory. This could be any value between 0 and 255 decimal. Its value will be determined by whatever code in your program writes to it ( look to lines with 'T FY 55').
 
Last edited:
stevelawson said:
but whats their significance, where are they in the program?

I think that you will have to tell us where they are in the program, well the KY any rate, as the KF is a constant and does not change.
Somewhere in that program, probably many times you will see something like:-

:L IB 250 // Load input byte 250, this could be from a counter, that's counting parts maybe?
:T FY 10 //Transfer the counter value to FY10



FY 10 would then be used in your FB to compare it to a constant (KF) to determine what the process should do when the count reaches a certain value.

I would think that somewhere in your program, a number in one form or another, is being transfered in the address FY10, what you need to do is find where these transfers occur and then determine what the controlling logic does to put these figures into FY10.

Does that make sense?

You seem to understand about the JU and JC instructions and how they work, so it might be best to forget about them at the moment and concentrate on the KY and KF. The KF is a constant and does not change (sorry for keep repeating that line), so what we are doing is checking to see when the value in the KY is the same as the KF value (or not in your case). I will try and explain it a little better..

In my left hand I have a number of coins that total 55p (the KF value), I put my right hand in my right pocket and pull out some coins and check whether I have 55p in my right hand (the KY value), I don't, so I now do what M002 tells me to do, along comes my brother and he replaces the coins in my right hand (the ones from my pocket) with a number of coins from his pocket, again I check them against my left hand to see if I have 55p, again I don't, so M002 gets the nod. This time my wife comes along and replaces the coins my brother gave me with some more coins, again I check them against my left hand, but this time I have 55p in my right hand, so now I ignore M002 and do what M001 wants me to do, and so on. The value in my left hand stayed the same (the KF value) and the value in my right hand (the KY value) was constantly changing or being changed by others (or other parts of the program).

Hope that helps some more, if not you know where to come!

Don't be sorry for asking questions, because if you don't ask you won't know.

Paul
 
Guys, thankyou so much for your persiverance with me on this topic.
I was part way through a reply to Keiths post explaining that i understood the binary example, when i had to go back to the thread to copy something from it. It was at this point that i saw Pauls latest post and it imediately took me straight back to college.
Apples ,Bannanas and Pears. These were the tools that one of my tutors used to use to get points across to thickies like myself.
You know the old, if i had 5 Apples in a basket routine.
Anyhow, that analogy of 55p in my lefthand etc. made perfect sense to me and i can now see why i've been beating myself up for the last week.
I was thinking that the KF and KY were referring to input, flag, output etc. conditions and not mathematical comparisons.
When i look back at some of the posts it had been mentioned :D
I just need to find some time at work now to practice this new found knowledge.

Once again guys, thankyou :)

Steve.
 
stevelawson said:
Anyhow, that analogy of 55p in my lefthand etc. made perfect sense to me

(y) The penny's dropped or should that be the 55 pennies have dropped!!! :D

Well, I think that if I was any good at explaining things it wouldn't have taken so long! :rolleyes:

Seriously Steve, I am glad that we got there in the end,

stevelawson said:
I just need to find some time at work now to practice this new found knowledge.

You know where to come if you have any more questions! Maybe next time we will be able to answer you in one or two replies instead of the 25 odd it took us this time! banghead

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,210
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,812
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,276
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
253
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
557
Back
Top Bottom