s7 function

Amr Hassan

Member
Join Date
May 2005
Posts
340
Hi

i am using s7 siamtic manager software . I want to create a function to set for example the first bit of a byte under certain condition


so in the declaration i define a byte (for example #byte1)

How can i write the statement in the fc or do i have to define another variable in the declaration with bool type



i tried to type:

s #byte.1 but did not work

thanks in advance
 
Check in the "Object Properties" of byte1 declration the initial address of local memory (L), i.e. 2.0

Then the instruction S L 2.0 wil set the first bit of #byte1
 
setting the bit

I assume the variable you have defined is an Input Output. You can use the "Word OR Function" (this instruction is part of the included instructions 'built-in') and that would allow you to OR the variable with a constant to turn on the appropriate bit.EG:
11110011 OR 00000100 = 11110111
The advantage to this method is that you can use the local variable with it's symbolic name.
 
Hello!

The problem with the mentioned solutions is that they rely on the absolute address of the variable. So if you change something in the instance DB then the addresses may shift thereby making address point to a different place.

It's better to actually find the address of the variable first and then set the corresponding bit using the OW (OrWord) function.

To get the address of the variable use a code like this:

LAR1 #Word1 // Loads the address of Word1
L W#16#1 // Load bit pattern for bit to set
L LW [AR1,P#0.0] // Load the byte of Word1
OW
T LW [AR1,P#0.0] // Transfer result of OR to Word1

PS! I changed the data type from Byte to Word. If you want to use byte you have to make sure that you use the correct part of the word in your byte.

Cheers
Borte
 
Indirect Addressing?

I agree with Borte on that; however, if this is not going to be a dynamic project (changing constantly) then I mihgt not get into all the indirect addressing. If there is a possibility that you might have to go through several iterations of changes, then go for the indirect addressing route. I merely suggested the symbolic route because it is clearer to the less experienced S7 user.
 
Thanks for your help, it gave me very good ideas

Let me explain more what i want to do


i want to make a sequencer



a i0.0
s m0.0
r m0.7



a i0.1
sm0.1
r m0.0


a i0.2
s m0.2
r m0.1

......



a i0.7
s m0.0
r m0.1



a m0.0
o m0.2
=q0.0


a m0.1
o m0.3
=q0.1



now i want to call this function serveral times , every time with a different byte (i.e. o ,1,2,..)

so what i want is that in the declaration i use the the byte and not all the bits

in suggested solution i have to use comparator so set the output , any other ideas?
 
Not usre where you are going with that

Amr,

where are you going with the code you listed, that uses discrete addresses that are not reusable. I assume you are going to recode that into local addresses in FC?
 
Local data vs. permanent Data

In a FC or FB block, there is a header. That header is the definition of the local data available to the FC or FB during that instance. Hence the description of instance data. We previously discussed the indirect addressing topic because when you reconfigure the block header then you change the address of the local data. As long as you use symbolic addressing, this will never be an issue in a FC and is mangageble in a FB (This can be an issue in FB's because the data in the instance DB is retentive in an FB and there can be a big synchronization issue between downloading a FB and the instance DB.) The Address m0.0 is a permanent address that is accessible by all blocks and by external devices as well. The address #SequenceBit1 is a local address accessible on by the block in which it is defined. If the same name local tag is defined in two seperate blocks, then they are still seperate and distinct. The local data concept is useful because you can write a block and not have to worry about what the value of that data was external to that block and whether you have changed a value need elsewhere. The only local data that is retentive, remembered and used from scan to scan is "Static" data type used only in FB's, hence the need for and Instace DB for FB calls. This a longwinded answer, but I hope it is helpful. Because Data is temporary, then you can call a FC that you write 100 times and each time will be a "unique" call, if done using only local data internal to the FC.
 
Last edited:
yes of course m0.0 ,... m0.7 shell be defined in the declaration
what i was asking is that instead of having 8 bits in the declartion , only have one byte

Thanks
 
"in the declartion , only have one byte" too easy. I suggest you use the type "struct" in order to pass from the byte to bit and viceversa.

Create a new function block, FB1, declare:
as IN BINPUT Byte
as OUT BOUT Byte
as STAT STEPS Struct (then open the STEPS object and declare STEP0 bool, STEP1 bool, ..., STEP7 bool

as TEMP TINPUT Struct (then open the TINPUT object and declare I0 bool, I1 bool, ..., I7 bool
as TEMP TOUT Struct (then open the TOUT object and declare O0 bool, O1 bool, ..., O7 bool


and the code:

L #BINPUT // transfer from input byte
T LB 0 // TINPUT byte, verify L0.0 start address

A #TINPUT.I0
S #STEPS.STEP0 // Step 0 control
R #STEPS.STEP7

A #TINPUT.I1
S #STEPS.STEP1 // Step 1 control
R #STEPS.STEP0

A #STEPS.STEP0
O #STEPS.STEP2
= #TOUT.O0 // temporary output

L LB 2 // TOUT byte, verify L2.0 its start address
T #BOUT // transfer to output byte



And the multiple calls, the external parametrs are bytes only
CALL FB 1 , DB101
BINPUT:=IB0
BOUT :=QB4

CALL FB 1 , DB102
BINPUT:=IB1
BOUT :=QB5
.........

You'll have the steps into the static DBs
 
Thanks for u all , that was very helpful
i have never used the struct before and now i learned something new
thanks
 
Last edited:

Similar Topics

Hi, I have attached herewith one image which our programmer has been used in S7 1500 PLC. Now we need to use the same instructions in S7 1200 PLC...
Replies
4
Views
114
Im trying to create a level indicator for water Tank i have used the ADD function while the pump is on and level increasing everything works...
Replies
33
Views
986
Good morning crew! Ok my logic works but I am missing something. When the start button is pushed it should like the red light for 4sec then shut...
Replies
13
Views
410
Please see attached file. I need this program in Function Block form but I am totally lost on this. Any help would be appreciated. Thanks!
Replies
8
Views
291
The idea here is to provide for a brief rapid influx of message codes while preventing sequentially repeating the same message. i.e. if two...
Replies
23
Views
669
Back
Top Bottom