Converting S5 to S7 question?

uptown47

Lifetime Supporting Member
Join Date
Feb 2008
Location
Over there, next to those boxes
Posts
1,146
Hi all

I'm currently converting an S5 program to S7. I've come across the following code and I have a few questions that I thought you may be able to help me out with.

The code is:

A F 20.3
L KT 010.1
SD T 16

DO FW 32
A F 0.0
= F 20.3

AN F 20.3
JC=M001
L FY 34
T FY 30




Questions...
1) Does the "DO" function get executed regardless because there isn't an A T 16 after the timer which I would have expected? In other words, is the timer (T 16) nothing to do with the "DO" instruction.

2) The 'DO' instruction is accessing F [FW 32] as I understand it. How can that work? If FW 32 is equal to 50. Does that mean that the code reads..
A F 50.0
= F 20.3
??

If FW 32 was equal to 52 would the code read:
A F 50.2
= F 20.3
??

Can anyone shed any light on this?

Many thanks

:)
 
1. Yes, the DO instruction does not rely on the RLO.

2. Don't think so (not 100% sure my memory is holding up here), I think FW32 would require both bytes to be set up, cannot remember the order, in KY format, so KY = 0,50 = 50.0, KY = 1,50 = 50.1. (it maybe KY = 50,1 though).

3. No, see above.
 
DO FW 32
A F0.0

Actually is a 'word or' in the way it works, i.e. the op code for A F0.0 is ored with the contents of FW32.

So FW32 bits 8 9 and 10 are the bit dimension, bits 0 - 7 are the byte dimension, and bits 11 - 15 must be left at 0

The resulting instruction is then executed

In S7 you will have to use a pointer.
 
This was what I've come up with to sort out the problem of the addressing being different. Its a function (FC 98) that I can call everytime I need to pass in an word that contains an address to a 'DO' bit.


FUNCTION "'DO' FNC FOR MARKER ADDR" : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
MARKER_WORD : WORD ;
END_VAR
VAR_OUTPUT
ADDRESS_REPRESENTATION : BOOL ;
END_VAR
VAR_TEMP
MY_POINTER : DWORD ;
MY_BYTE : BYTE ;
MY_BIT : BYTE ;
END_VAR
BEGIN
NETWORK
TITLE =

L #MARKER_WORD;
T #MY_BYTE;
L #MARKER_WORD;
SRW 8;
T #MY_BIT;
L #MY_BYTE;
T #MY_POINTER;
SLD 3;
T #MY_POINTER;
L #MY_BIT;
L #MY_POINTER;
+D ;
T #MY_POINTER;
A M [#MY_POINTER];
= #ADDRESS_REPRESENTATION;
END_FUNCTION



Thanks again for your help

:)
 
Here's another implementation that just uses the accumulators and address register 1:

Code:
	  L	 #MARKER_WORD
	  PUSH  
	  AW	W#16#FF
	  SLD   3
	  LAR1  
	  POP   
	  CAW   
	  AW	W#16#FF
	  +AR1  
	  A	 M [AR1,P#0.0]
	  =	 #ADDRESS_REPRESENTATION
 
Thanks for that Simon.

I've never seen the PUSH and POP commands being used. I'll look through your example tomorrow when I've got access to the help file so that I can work out how its working.

A very eloquent solution as always mate :site:
 
I've got a question about your solution. When I was looking through it, it all makes perfect sense except I don't understand why you are using the AW?


I'll explain how I think its working and wondered if you could put me right..


L #MARKER_WORD // Puts MARKER_WORD into ACCU 1
PUSH // Moves contents of ACCU 1 into ACCU 2
AW W#16#FF // ANDing ACCU 1 and 2 and putting into ACCU 1
// Not sure why we need to do this as surely
// ACCU 1 will remain unchanged ??
SLD 3 // Shift ACCU 1 bit left by 3 bits
LAR1 // Move contents of ACCU 1 (3 bits left) into AR 1
POP // POP contents of ACCU 2 (original marker_word)
// into ACCU 1
CAW // Reverse the low and high byte in ACCU 1
AW W#16#FF // AND ACCU 1 and ACCU 2
// would this not mess up the contents of ACCU 1
// as now ACCU 1 is the reverse of ACCU 2??
+AR1 // Add ACCU 1 to the AR 1 which should add the bit addr
// to our byte address
A M [AR1,P#0.0] // Get state of marker indirectly
= #ADDRESS_REPRESENTATION // Pass state out of block



I've really enjoyed working through your example and would appreciate it if someone would let me know whether my dissection of it is correct and why the AW's are used.

Cheers

:)
 
AW will AND accumulators 1 & 2
AW w#16#ff will AND accumulator 1 with 00FF

The anding is required to separate the bit/byte addresses which you did in your original code by wrting the accumulators to byte variables.
 
Last edited:
L D[AR2 said:
AW will AND accumulators 1 & 2
AW w#16#ff will AND accumulator 1 with 00FF

The anding is required to separate the bit/byte addresses which you did in your original code by wrting the accumulators to byte variables.

Ofcourse!!

You're using the AW command to mask off the bits that are not wanted...

Superb, thanks for the explaination.

:)
 
Good spot jacekd - I had already made up my mind to use the CAW instruction as it doesn't get used very often.
 

Similar Topics

I have a 3-axis sensor that I'm working on integrating with a Micrologic PLC. The sensor has a RS-422 output and I'm using an RTA Automation PLC...
Replies
5
Views
3,240
Hello, I'm fairly new with Siemens PLC and I'm converting a S5-95U to a S7-300 with a 313C CPU. I have some issues with the conversion. On the...
Replies
0
Views
1,844
Hello all! I Have an issue with four new machines that were just installed in our plant. The PLC is a 1769-L32 compact logix. Iam new to 5K. no...
Replies
2
Views
2,231
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
208
Hello PLCs Forum, I am in a bit of a pickle and was hoping someone could offer me some help. I have a .rss file and just need to see the ladder...
Replies
2
Views
122
Back
Top Bottom