Step7 - Read some bit from Word in Interface area

Join Date
Jul 2006
Location
mimon
Posts
32
Hello everyone, I have a question.
I created FB, I defining word in input and word in temp interface area.
I need read some bit from this InputWord(TempWord).

e.g.
L #InputWord
T #TempWord

A TempWord.bit0
A TempWord.bit3
= M10.2

Where is problem ?
 
Look in the definition table at the address of TempWord, let's say it shows 8.0. That means your TempWord is located in bytes 8 and 9 of the local memory area. Therefor the bit you're describing as TempWord.bit0 can be addressed as L9.0 and TempWord.bit3 as L9.3. This should work without any problem.

Kind regards,
 
To reference bits of a variable declared as a word use indirect addressing as follows. If you use the hardcoded L address, this may change if you add another variable in the future.

Code:
	 LAR1 P##TempWord
	 A	 [AR1,P#0.0]
	 A	 [AR1,P#0.3]
	 =	 M	 10.2
 
You can do as Simon tells. But it isn't easy for beginner to use indirect addressing. I reccomend to define some set of pseudotemporary variables in M area. Temporary means using of it in different places in your program. You can define, for example MW10 as TempWord in Symbol Table, M10.0 - as TempBit0, M10.3 - as TempBit3. Use it like TEMP variables. Only one restriction - you cann't use same pseudotemporary variable in OB1 and in interrupts OBs.
 
Another method for checking bits 0 and 3 in InputWord:

L W#16#9 // load word with bits 0 and 3 set to 1
L #InputWord
AW // clear unused bits in ACCU1
==I // check if ACCU1=16#9 (bits 0 and 3 are set)
= M10.2
 
How about

tempbits.JPG

[EDIT: That could then be followed by
A #t_TEMP_BIT_3
etc]

They maybe new, but have to learn sometime.
 
Last edited:
gregoryg said:
Simon - bits in WORD! Input is an word, and I'm checking bits in word.

I ran your code in the simulator and passed MW2 as the parameter. I set M2.0 and M2.3 and M10.2 does not become true. How did you test your code ?
 
Discrepancy between you is caused by bit numbering. Gregory means bits in word. It's correct because programmer hasn't need to think about byte order. Simon means bits in byte. However, programmer can give name for bits (as in my example) as he wants. But in this case he must to take in accordance memory structure: in MW2 high-order byte is MB2, low-order - MB3. Bytes aren't swapped in accumulator when loading take place.
 
Gambrinus said:
You can do as Simon tells. But it isn't easy for beginner to use indirect addressing. I reccomend to define some set of pseudotemporary variables in M area. Temporary means using of it in different places in your program. You can define, for example MW10 as TempWord in Symbol Table, M10.0 - as TempBit0, M10.3 - as TempBit3. Use it like TEMP variables. Only one restriction - you cann't use same pseudotemporary variable in OB1 and in interrupts OBs.

I wouldn't be happy with that, temp marker bytes went out with S5.

It does not matter that the user is new, he should be taught the correct way, this forum would help anyone who does not understand indirect addressing.
 
SimonGoldsworthy said:
bar.pavel needs to clarify which bits he realy wants to reference - I assumed one thing and gregoryg assumed another.

L #InputWord
T #TempWord

A TempWord.bit0
A TempWord.bit3
= M10.2

I agree that does not make sense and could not be programmed anyway.
 
But if someone comes to "S7 world" from for ex. CodeSys or TwinCAT or other system programmed in ST... It may have sense for him.
 

Similar Topics

Hi all. I use kepware opc to read data from Matlab, it works fine. Now i want to move these data to step 7, how can i read data from OPC to step 7...
Replies
2
Views
3,252
I am using SFC 59 to read data using DPV1 from a PROFIBUS slave to a PLC. My problem is the length, I know the RET_VAL holds error code or read...
Replies
0
Views
1,933
I'm trying to read out a Meinberg GPS-clock to sync the time on my plc. Now I have following problem: I have no physical room to place a...
Replies
3
Views
2,954
Hi.I'm quite new in this field and I allready have a problem. I'm working with an Simatic S7-300(CPU 313C-2DP)and a 3UF5 SIMOCODE-DP.The simocode...
Replies
5
Views
7,176
This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
158
Back
Top Bottom