View Full Version : s5-s7 conversion 'ASM' command and Special FB's

April 25th, 2007, 02:51 PM

I am working on a project of converting an S5 plc to S7-300.
I used the converter tool provided with Simatic Manager and it converted most of the program quite succesfully. I have some problems , and i thougt i could get some help here.

Problem 1 : 'ASM' command in S5 STL.

Here is a list of special function blocks in which the 'asm' command is used.

FB240 COD:B4
FB241 COD:16
FB242 MUL:16
FB243 DIV:16

And here is an example of how it is used. The usage is the same in every block.
Page 1
Segment 1

:ASM KH 0000

I could not find anywhere, what this command does. A stanger thing is that none of those special FB's are called in the rest of the program. They are defined, and in all of them only two commands are used just the same way in the example i gave above.
I could not understand the reason of defining the blocks. Why did the programmer defined them if they aren't called in any line of the code?
I mean, wouldn't the system work without those unused blocks? If they aren't called anywhere, does that mean that it is ok if i avoid them while programming the s7-300? If so , i don't need to deal with 'asm' code , too.

Problem 2: Special OB's. OB21,OB22 and OB31.

OB21 and OB22 are special OB's for hot and warm restart. I have converted them into OB101 and OB100 in s7. is this correct?
OB31 is used for set cycle monitoring time.

the only code written in ob 31 is :
Page 1
Segment 1
:NOP 1

I could not understand its use and so i could not decide if i should use anything to stand for OB31 in the s7 program.

Problem 3: FB167 and FB168, counter module IP240.

There is an encoder in the system and it is read with ip240 counter module. In the program, FB168 and FB167 are called several times. there are some variables like KANR,BGAD etc. I found explanations for all those parameters. But i could not find out from which address the counted value is going to taken. Here is an example of FB168's use:
Page 1
Segment 1

:C DB 140
:JU FB 168
DBNR : KF +140
FKT : KY 1,0
PAFE : FY 200
:L FY 200
:L KH 0000
:S F 145.7
:L DR 28
:T FY 146
:L DR 29
:T FY 143

PAFE parameter is addressed at FY200 and it represents the error byte. So, in the block above, an error check is processed. But where is the counted value?
Here is an example of FB167's use:
Segment 4
:JU FB 167
BGAD : KF +128
KANR : KF +1
DBNR : KF +140
AFL : KF +1
IMP : KF +0
BCD : KY 0,0
PRA1 : KM 00000000 00000000
PRA2 : KM 00000000 00011101
RUND : KF +0
LOSE : KF +0
DAV : KF +0
PAFE : FY 200
:L FY 200
:L KF +0
:S F 145.7
:C DB 140
:L DW 10
:C DB 142
:T DW 0

Same problem, i could not understand where is the value written or read from the counter card? How should i convert the parts related with counter card to s7?

I am desperately looking forward to get some help. Please help me if you can.
Thank you for your attention,

L D[AR2,P#0.0]
April 25th, 2007, 05:18 PM
A quick search for ASM gave the following example:


There is more to read if you do a search.

L D[AR2,P#0.0]
April 25th, 2007, 05:21 PM
I think the counter value gets written into the DB number passed as DBNR (DB140 in one of your examples)

April 26th, 2007, 02:13 AM
I'd searched this forum about the 'asm' command. Yes,there are some topics about it, but none of them made me understand the issue.

The parts about the Counter card are seem to be relatively easier but i have no clue about the 'asm' command. Anybody to help?

April 26th, 2007, 06:27 AM
Some standard function blocks include the instruction ASM which is 'switch to ASSEMBLER operation'.

Although the programming unit may interpret and display subsequent data as STEP5 instructions, they should be disregarded since the raw data is assembler data and not MC5.

Standard function blocks are identified by a Library number starting with 'P71200..' and are best regarded as 'black boxes'.

In S5-S7 conversions you should duplicate the functionality of non-converting standard functions rather than try to 're-create' them in STEP7.

April 26th, 2007, 12:38 PM
hi krk,
so , in my situation , since none of the special function blocks is called anywhere in the program , i dont need to do anything about them while converting to s7. is it correct?

April 26th, 2007, 01:48 PM
hi krk,
so , in my situation , since none of the special function blocks is called anywhere in the program , i dont need to do anything about them while converting to s7. is it correct?

Yup...that's right

April 27th, 2007, 09:06 AM
thank you all for your helpful answers.

April 28th, 2007, 05:46 AM
The asm instruction is followed by ju=m001 then be
if you use a hex editor (if you can find the block) & change the be to nop1 then the code becomes readable as mc5 however it probably does not make much sense.
a lot of blocks you mentioned are for communications 525,535 & others for special function cards.
The others are maths routines for 115.
If none of these are called then it should "almost" convert.
The OB's if not programmed usually stop the plc if errors unless programmed with a be, the idea is that on an error the relevant OB is called, you can then process say errors & then you should stop the plc using STP command in the OB, however on some systems it may be you do not wish to stop the processor but beware, an error could cause a major catastrophe & be very dangerous.

April 28th, 2007, 02:41 PM
I have investigated another system in the factory in which an S5 115u is used. This is relatively simpler system. I saw that same special FB's are seen in the program.
I learned that those FB's are not kept in PLC's memory. They are stored in an EEPROM in the CPU card! They say that Siemens did this because CPU memory was small nd it was a smart and practical way to use that small memory more efficient. Those blocks are kept in EEPROM and programmer can not write anything to them. You don't need to add them in your program but you can use them whenever you need by simply calling them in your program.
So,since they are not called in the program i am converting ,I have decided to disregard special FB's which are not called.
I am not going to do anything about them.

I will use OB100 and OB101 in S7 for OB21 and OB22 in S5. OB1 is easy to convert and i don't think OB31 will cause any trouble. I will make the first try without OB31 and i will work over it in case of a problem.

Now , my only problem is the use of counter card. There are weird codes in STL language for using the counter card in S5.
I could not find out how to adapt them in S7 but i am working on it.

Thank you all once more for your helpful replies.
And again , please let me know if something i mentioned about what i will do is wrong .


April 29th, 2007, 04:52 AM
The chances are that the S7 version of the counter card will have it's own different way of controlling the data, in general the code used in the 115 version is probably only how to read & set the data/functions, once you know how they use the data & reset functions it should not be too difficult to reproduce this in S7.

May 1st, 2007, 07:40 AM
Thank you all.
One last thing is to understand how the counter card programmed in S5. if i could understand the way they used the card, i can write the s7 program. So, please have a look at this post:

May 1st, 2007, 08:42 AM
Hello emokar;

if i could understand the way they used the card [in S5], i can write the s7 program

Are you planning to use the same counter cards on the S7 backplane? If not, I am not sure your assumption is correct. High-speed counter cards and integrated counters (in S7-31xC CPUs) all come with dedicated FBs/SFBs that are pre-built to use the S7 interrupt codes; they will not work the same way that their S5 counterparts did.
I followed your other thread, but I thought it was only as an exercice, not to implement a real counter card.

Daniel Chartier

May 1st, 2007, 02:50 PM
I think i could not be clear enough. In the program of the S5 115U , some operations are made to the value which is taken from the ip240 counter card. I must first understand why those operations are done. After completely understanding what is going on , i will write s7 codes which will do the same job using fm350-1. that value of encoder is used in many places in the program. So i must get exactly the same value not to change the whole program.