s7-300 Bool into Word using Indirect Addressing

Boxy

Member
Join Date
Nov 2008
Location
Sydney
Posts
57
So far all the code i've written for PLC's has been simple ladder logic and I'm sure this will be simple once i know how.

I have an s7-300 setup with Danfoss Drives connected via profibus. I am trying to construct a function block that i can use for all drives to move bool run/quickstop/ramp/etc to operate the control word.

So far i have tried creating an array of Word stored in the temp area and then within the code referencing the LX.X
then moving this arrayed word to a word stored in the Out area of the declaration.

I have also tried referencing the Out word bools.

Both these only kind of word. When i use the array i end up getting a SF with an error which says area length error when reading.

If i look at the Out word, in the Address info it says theres an error with the format.

Am i doing it all wrong??
 
I apologise I have the SF was unrelated to the Array part.
I would still like to know if i have the right approach if i do it via the Array[0..0] of Word way?
 
The data to the drive has to be sent as a word to the PQW address.

Each bit within that word is a bool function eg(bit 6 high=run low=stop, bit 9 high=ramp 1 selected low=ramp 2 selected, etc) so to run the drive i need to set bit 6 to true.

I was going to create a block with my bool bits coming into the block, and the out of the block be a word. I can do it if i make it all symbols but i thought it might be better to do it in a function block that way i can use it for all 15 drives, so exactly the opposite of what LD[AR2..] posted. Also I'm writing in Ladder as i've never had any formal training in STL SCL
 
Here's the reverse function. Note remove the CAW if you do not wish to swap the bytes in the word.

Code:
FUNCTION FC 2 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  bBit0 : BOOL ; 
  bBit1 : BOOL ; 
  bBit2 : BOOL ; 
  bBit3 : BOOL ; 
  bBit4 : BOOL ; 
  bBit5 : BOOL ; 
  bBit6 : BOOL ; 
  bBit7 : BOOL ; 
  bBit8 : BOOL ; 
  bBit9 : BOOL ; 
  bBit10 : BOOL ; 
  bBit11 : BOOL ; 
  bBit12 : BOOL ; 
  bBit13 : BOOL ; 
  bBit14 : BOOL ; 
  bBit15 : BOOL ; 
END_VAR
VAR_OUTPUT
  wWord : WORD ; 
END_VAR
VAR_TEMP
  bTempBit0 : BOOL ; 
  bTempBit1 : BOOL ; 
  bTempBit2 : BOOL ; 
  bTempBit3 : BOOL ; 
  bTempBit4 : BOOL ; 
  bTempBit5 : BOOL ; 
  bTempBit6 : BOOL ; 
  bTempBit7 : BOOL ; 
  bTempBit8 : BOOL ; 
  bTempBit9 : BOOL ; 
  bTempBit10 : BOOL ; 
  bTempBit11 : BOOL ; 
  bTempBit12 : BOOL ; 
  bTempBit13 : BOOL ; 
  bTempBit14 : BOOL ; 
  bTempBit15 : BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =bit to word mapper
      A     #bBit0; 
      =     #bTempBit0; 
      A     #bBit1; 
      =     #bTempBit1; 
      A     #bBit2; 
      =     #bTempBit2; 
      A     #bBit3; 
      =     #bTempBit3; 
      A     #bBit4; 
      =     #bTempBit4; 
      A     #bBit5; 
      =     #bTempBit5; 
      A     #bBit6; 
      =     #bTempBit6; 
      A     #bBit7; 
      =     #bTempBit7; 
      A     #bBit8; 
      =     #bTempBit8; 
      A     #bBit9; 
      =     #bTempBit9; 
      A     #bBit10; 
      =     #bTempBit10; 
      A     #bBit11; 
      =     #bTempBit11; 
      A     #bBit12; 
      =     #bTempBit12; 
      A     #bBit13; 
      =     #bTempBit13; 
      A     #bBit14; 
      =     #bTempBit14; 
      A     #bBit15; 
      =     #bTempBit15; 
      LAR1  P##bTempBit0; 
      L     W [AR1,P#0.0]; 
      CAW   ; 
      T     #wWord; 
      SET   ; 
      SAVE  ; 
END_FUNCTION
 
With Q addresses it is blisfully simple, as you can assign symbols to the BOOLs as well as the WORDs (and BYTEs and DWORDs) for the same overlapping adresses.

However, you want to program a reusable block for all the drives, which is a reasonable idea, and then you no longer have direct access to the Q addresses.

There are several ways to solve it.
1. Program in SCL. In SCL you can use the AT declaration to access the same data in differing ways (i.e. BOOLs and WORDs at the same time).
2. Use indirect addressing.
3. Use intermediary Merker addresses. This looks not so 'pretty' but is very quick and easy. You can assign symbols to overlapping addresses with Merkers just as you can with I and Q addresses. Notice, do not use the Merkers to store the data, only to transfer to the final output pin of the FC or FB.

edit: The way you have done it (or attempted to do it), by accessing the Lx.x adresses, is not recommendable. It may work, but the slightest change of the declaration part will wreak havoc on the code. It is most difficult to maintain.
 
Last edited:
Most likely your problem is endianess.

You have that control word you need to sent to danfoss drive, when you manipulate bits by bits you need to swap bytes.

this is from my memory :)

cw byte1

start1
start2
start3
...
...
...
...

cw byte2

...
...
...
...
...
...
...

when you load that 47f (run command yes?)

to lw 0, if you want to access bit start2

you need to write to l1.1 not l0.1
 
heres how i do it with a danfoss.

Mapping danfoss data in;

L #Address; // Grab address reference (start address of the VLT)
SLW 3;
LAR1 ;
L PIW [AR1,P#0.0]; //pass in status word
T #TEMP1;
L PIW [AR1,P#4.0]; //pass in PCD 3
T #TEMP2;

A L 0.3;
= #Running; //Set running status
A L 3.4; // check FC300 input status at terminal 29
= #Term_29;
A L 3.5; // check FC300 input status at terminal 27
= #Term_27;
A L 3.6; // check FC300 input status at terminal 19
= #Term_19;
A L 3.7; // check FC300 input status at terminal 18
= #Term_18;

Writing data to danfoss

NETWORK
TITLE = Write FCD Data

L W#16#43C; // prepare control word for stop mode
T #TEMP1; //(temp 1 is at mem position 0)
A #Relay01; //map in value
= L 0.3;
A #Reverse; //map in value
= L 0.7;
A #Go_Drive; //map in value
= L 1.6;
L #TEMP1;
T PQW [AR1,P#0.0]; //control word

L #Speed_out;
T PQW [AR1,P#2.0]; // Output speed

this can be set up in a FB or FC and via the declarations may be called for as many drives at once, ive hade 500 running in one PLC no probs, has a very low overhead.
 
Last edited:
Hey thanks guys. I used the method shown by LD[AR2..]
It worked a treat.
I guess i should learn STL then.
Thanks again
 

Similar Topics

Hi Sir, I am using S7-300/400. I am usually using FC 03 and FC04 to transfer (R/W) bool values by moving them DBs. However i want to R/W bool...
Replies
1
Views
2,082
in allen bradley kinetix 300 drive first E31 error shows after resting drive E11 error occurs need solution to reset E11 fault code
Replies
4
Views
157
Hi, I'm setting up a modbus master on an S7-300. It seems to work in OB1 but not when I use it in OB35. Does anyone have any ideas why? Could...
Replies
10
Views
132
So basically i have 2 queries : 1. I have a program file of S7-300 PLC which i want to migrate in RSLogix500.In short i want to convert my simatic...
Replies
15
Views
300
Hi i using Kinetik 300 2097 driver control by EIP with using move absolute and incremental for motion , but i want to add same driver and motor as...
Replies
0
Views
79
Back
Top Bottom