Help needed with step 7

Q:is DIX0.0 the first bit of the PIW array
A:No. But first bit of TempPIW1 is L0.0. But this way of coding is potentially unsafe.
Q:Now I want to use FC11 in FC61...
A:You can't pass array as IN or OUT in S7. You should use ANY pointer.
 
thanks jacekd
Unfortunately i am not allowed to use pointers in this project. All I want to do is to access some bits of an array. I am moving 1st word of PIW to Temp_PIW1. So Is L0.0 the first bit of PIW array?
 
Last edited:
If you want to access your PIW array of words as an array of bools, copy the word array to a locally declared bool array using indirect addressing, example shown below. The correct syntax when using symbols is "M16".PIW

fc11001.JPG
 
Ranjith said:
thanks jacekd
Unfortunately i am not allowed to use pointers in this project. All I want to do is to access some bits of an array. I am moving 1st word of PIW to Temp_PIW1. So Is L0.0 the first bit of PIW array?


If your using an array, you have to use pointers to access the bits, even Simon's simple example uses a pointer.

You cannot program with one arm tied behind your back.
 
It is possible to avoid using pointers and indirect addressing by copying the inputs to a temp array of words, and then using sfc20 to block copy the temp words into the temp bools. However, the parameters to sfc20 are Anypointers......

fc11002.JPG
 
Step7 Help

Thank you all for the help.
I have a question for LD[AR2,#P#0.0]. What you have explained above makes sense to me. Now I want to take another step further and
1. copy 32 bits starting from bit16 of PIWBitArray to TempPID2(Dint).
2. copy TempPQD(Dint) to Bit 16-31 of PQWBitArray.Do I have to define the length?
Thanks again for your help.
 
If you specify one bit of the array as the source, sfc20 will only copy 1 bit.

Have you considered using a structure for the temp area instead of an array of bits? Please see below the source code as an alternative. I have created a drive structure which can be formatted to match the actual layout of the data from the PIW's read from the drive. You can refer to the structure elements by name in the program.
Code:
FUNCTION FC 11 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  PIW : ARRAY  [1 .. 8 ] OF WORD ; 
END_VAR
VAR_OUTPUT
  Connected : BOOL ; 
  rActualPosition : REAL ; 
END_VAR
VAR_TEMP
  Drive : STRUCT  
   StatusWord : STRUCT  
	bConnected : 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_STRUCT ; 
   diPositionFeedback : DINT ; 
   diSpeedFeedback : DINT ; 
   iFaultCode : INT ; 
   iFaultValue : INT ; 
   iSpareValue : INT ; 
  END_STRUCT ; 
  PIWWordArray : ARRAY  [1 .. 8 ] OF WORD ; 
  iSFC20Return : INT ; 
  rTemp : REAL ; 
END_VAR
BEGIN
NETWORK
TITLE =copy input parameters to local array of words
	  L	 #PIW[1]; 
	  T	 #PIWWordArray[1]; 
	  L	 #PIW[2]; 
	  T	 #PIWWordArray[2]; 
	  L	 #PIW[3]; 
	  T	 #PIWWordArray[2]; 
	  L	 #PIW[4]; 
	  T	 #PIWWordArray[4]; 
	  L	 #PIW[5]; 
	  T	 #PIWWordArray[5]; 
	  L	 #PIW[6]; 
	  T	 #PIWWordArray[6]; 
	  L	 #PIW[7]; 
	  T	 #PIWWordArray[7]; 
	  L	 #PIW[8]; 
	  T	 #PIWWordArray[8]; 
NETWORK
TITLE =copy array of words drive structure 
	  CALL SFC20 (
		   SRCBLK				   := #PIWWordArray,
		   RET_VAL				  := #iSFC20Return,
		   DSTBLK				   := #Drive);
	  NOP   0; 
NETWORK
TITLE =access named variable for drive
	  A	 #Drive.StatusWord.bConnected; 
	  =	 #Connected; 
NETWORK
TITLE =position feedback
	  A(	; 
	  L	 #Drive.diPositionFeedback; 
	  DTR   ; 
	  T	 #rTemp; 
	  SET   ; 
	  SAVE  ; 
	  CLR   ; 
	  A	 BR; 
	  )	 ; 
	  JNB   _001; 
	  L	 #rTemp; 
	  L	 1.000000e+001; 
	  /R	; 
	  T	 #rActualPosition; 
_001: NOP   0; 
END_FUNCTION
 
Blockmove

Thanks LD

In your STRUCT example how do you move the 1st word of PIW array to Status word bits. Then I would like to move PIW[1] and PIW[2] to a Act_Posn(Dint) PIW[3] to Act_Speed(Int) and so on.

I am having trouble defining the length in SFC 20. Could u pl tell me what have I done wrong?

Greatly appreciate your help

BlockMove3.JPG
 
Last edited:
Have you taken the source code I have posted and compiled it and looked at the block ?

Network 1 copies the input PIW array to a local array of words.
Network 2 copies the local array to the local structure called drive

From then on, drive.diPositionFeedback (for example) is referring to what is in PIW[2] and PIW[3].
 
Pl forgive me for my ignorance. I did not realize there is more to your code. When I first looked at it i could see only what's displayed on the screen. Noiticed the scroll down arrow only afetr reading your reply. I am trying to understand your source code. I am not very good at STL code. If it's not too much of a pain could u convert it to ladder.

Thanks for all the help
 
It will display in ladder if you compile it.

In simatic manager double click on the sources folder.
Click on Insert and then S7 Software, then select STL source.
A block called "STL Source(1)" (or something similar) will appear in the folder.
Double click on this block, this will open the source block editor.
The block will be empty, copy all the source code from the post and paste it into the block. Edit the FC number to a convenient free block number in your project.
Use File then select Compile. Compiling the block will create the block in your blocks folder (or overwrite if it already exists).
Exit the source block editor and save the file.
You should now be able to open the block in the normal block editor.
 

Similar Topics

Hey Guys I can’t seem to come up with the logic that I need on one of our operator stations Any points in the right direction would be much...
Replies
4
Views
2,278
Hello I am building a machine and i would like to get some suggestions about the right plc to choose for my application. My application: I need...
Replies
13
Views
6,630
Hi everybody! I have a problem with program monitoring in STEP 7. I have an OB1 from which I call five FCs. There are only 5 networks in OB1 used...
Replies
16
Views
4,239
I have an old PLC (circa 2007) consisting of Telemecanique/Modicon/Schneider Electric devices. The system has developed errors and unfortunately...
Replies
2
Views
221
Hi I’m after some help , I have a plc program with a baumer verisens vision camera attached I have got the signals working ect but I have an...
Replies
9
Views
954
Back
Top Bottom