PLC S7-300: FC parameters

Join Date
Jul 2007
Location
Poznan
Posts
14
Hi

As a beginner with PLC I have a (hopeful easy) question. It’s about giving parameters for FC.

1. As shown at the picture below I made IN ports “slaveX” as bool type.

FCparam.JPG



And there is a problem with giving bool parameters as a value, I can use markers but I cannot give directly TRUE/FASLE value. I would like to give a value like for example for TimeBase IN port.

Is there a way to do that ?

2. I would like to made a BYTE type parameter and then in the FC to address single bits of this byte? Then instead of 4 IN ports “FCUseBitX” I would like to use one BYTE port. Is there a way for it?
 
Last edited:
True/False as input is not possible. When using bytes, decalre as b#16#00 or b#16#AB or whatever. Words must be declared as W#16#ABCD
 
Here's an example FC that uses several different methods to reference your port byte as bits. Use method 4 if you want to avoid indirect addressing and having to STL.

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

VAR_INPUT
  byPort : BYTE ; 
END_VAR
VAR_OUTPUT
  byTestPort1 : BYTE ; 
  byTestPort2 : BYTE ; 
  byTestPort3 : BYTE ; 
  byTestport4 : BYTE ; 
END_VAR
VAR_TEMP
  PORTAsArray : ARRAY  [0 .. 7 ] OF BOOL ; 
  PortAsStruct : STRUCT  
   bit0 : BOOL ; 
   bit1 : BOOL ; 
   bit2 : BOOL ; 
   bit3 : BOOL ; 
   bit4 : BOOL ; 
   bit5 : BOOL ; 
   bit6 : BOOL ; 
   bit7 : BOOL ; 
  END_STRUCT ; 
  TestResult : ARRAY  [0 .. 7 ] OF BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =method 1 - indirect addressing of input parameter
	  L	 P##byPort; 
	  LAR1  ; 
// now use [ar1,p#0.x] to reference bits of byPort, e.g.
//
	  A	  [AR1,P#0.0]; //this is byPort.0
	  =	 #TestResult[0]; 
	  A	  [AR1,P#0.1]; //this is byPort.1
	  =	 #TestResult[1]; 
	  A	  [AR1,P#0.2]; //this is byPort.2
	  =	 #TestResult[2]; 
// etc

NETWORK
TITLE =test monitor for method 1
	  LAR1  P##TestResult; 
	  L	 B [AR1,P#0.0]; 
	  T	 #byTestPort1; 
NETWORK
TITLE =method 2 - copy byPort to temp named as an array
	  LAR1  P##PORTAsArray; 
	  L	 #byPort; 
	  T	 B [AR1,P#0.0]; 
// now use bPortAsArray[x] to reference bit of byPort e.g.
//
	  A	 #PORTAsArray[0]; 
	  =	 #TestResult[0]; 
	  A	 #PORTAsArray[1]; 
	  =	 #TestResult[1]; 
	  A	 #PORTAsArray[2]; 
	  =	 #TestResult[2]; 
// etc
NETWORK
TITLE =test monitor for method 2
	  LAR1  P##TestResult; 
	  L	 B [AR1,P#0.0]; 
	  T	 #byTestPort2; 
NETWORK
TITLE =method 2 - copy byPort to temp named as a structure
	  LAR1  P##PortAsStruct; 
	  L	 #byPort; 
	  T	 B [AR1,P#0.0]; 
// now use PortAsStruct.bitx to reference byPort e.g.
	  A	 #PortAsStruct.bit0; 
	  =	 #TestResult[0]; 
	  A	 #PortAsStruct.bit1; 
	  =	 #TestResult[1]; 
	  A	 #PortAsStruct.bit2; 
	  =	 #TestResult[2]; 
NETWORK
TITLE =test monitor for method 3
	  LAR1  P##TestResult; 
	  L	 B [AR1,P#0.0]; 
	  T	 #byTestPort3; 
NETWORK
TITLE =method 4 - copy byPort to a marker byt and use the marker bits
	  L	 #byPort; 
	  T	 MB   100; 
// now use m100.x to reference byPort e.g.
	  A	 M100.0; 
	  =	 #TestResult[0]; 
	  A	 M100.1; 
	  =	 #TestResult[1]; 
	  A	 M100.2; 
	  =	 #TestResult[2]; 

NETWORK
TITLE =test monitor for method 4
	  LAR1  P##TestResult; 
	  L	 B [AR1,P#0.0]; 
	  T	 #byTestport4; 
END_FUNCTION
 
Ok

The first issue is solved . Thanks

For the second issue I manage to understand the network code but I’ve 2 questions:

  • Where can I fill this part in the program? Then I can’t find it.
Some FUNCTION FC 7 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
byPort : BYTE ;
END_VAR
VAR_OUTPUT
byTestPort1 : BYTE ;
byTestPort2 : BYTE ;
byTestPort3 : BYTE ;
byTestport4 : BYTE ;
END_VAR
VAR_TEMP
PORTAsArray : ARRAY [0 .. 7 ] OF BOOL ;
PortAsStruct : STRUCT
bit0 : BOOL ;
bit1 : BOOL ;
bit2 : BOOL ;
bit3 : BOOL ;
bit4 : BOOL ;
bit5 : BOOL ;
bit6 : BOOL ;
bit7 : BOOL ;
END_STRUCT ;
TestResult : ARRAY [0 .. 7 ] OF BOOL ;
END_VAR
  • I would like to write FC that doesn’t use markers that aren’t IN/OUT parameters. Then I don’t want to accidentally change a value use by an other part of program.
So I’ve a question: Does this part of code in FC protect the MB100 of changes in global meaning?

//function begin – Network1

L MB 100

T #StoreBYTE //temp variable



//Function Code using MB100



//function end – last network Network

L #StoreBYTE

T MB100



Does other part of program recognize no changes, no edges, etc (some [font=&quot]actions that I don’t know[/font]) with MB100???
 
PawelStrzelecki said:
Ok

For the second issue I manage to understand the network code but I’ve 2 questions:
  • Where can I fill this part in the program? Then I can’t find it.


I don't understand your problem here, can you please re-state in another way?

PawelStrzelecki said:
So I’ve a question: Does this part of code in FC protect the MB100 of changes in global meaning?

//function begin – Network1

L MB 100
T #StoreBYTE //temp variable

//Function Code using MB100
//function end – last network Network

L #StoreBYTE
T MB100

Does other part of program recognize no changes, no edges, etc (some [font=&quot]actions that I don’t know[/font]) with MB100???

As long as MB100 is not used in an interrupt routine, yes it will protect it.
 
Ok.

Then in your example the FC interface seems to be written by hand using keyboard:

I only know this method:

FCinterface.JPG



I don’t know where should I go in SimaticManager Options to write FC interface using this structure (it's new for me)?

VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR_TEMP
END_VAR

----------------------------------------------------------------
I’ve also another question. Is it an error using L-values in function this way.

FCzmiennaL.JPG



Does this two values overwrite one another??

Then I programmed interface using word-type and in network2 the L 2.0 appeared when I translated LAD program into STL program
 
OK - I see your problem. The code I have posted is in source code format (simple text). In Simatic manager, click on the source folder, then insert, then select an STL source file. Double click on the resultant file and the source code editor will open. Copy the text from the FC7 I have posted and paste it into the editor. Now compile (control+B) and the compile will produce FC7 in your block folder which you can then open and look at.

If you want it to compile to another block number, just edit the text accordingly.
 
Last edited:
Concerning your L2.0 question:

When you create a ladder program, the editor will sometimes need to generate intermediate temporary variables as part of the logic. The ladder view hides these accesses but you can see them if you switch the view to STL. The editor automatically uses the L area immediately after any declaration you have made. Provided you stay in ladder mode, if you add more L declarations, the editor will shift the internally generated L variables for you. If you add a declaration whilst in STL view, it will not. Once you add a declaration in STL mode then any code that was using the auto generated L variables will now not be viewable in ladder.
 
Yes, L2.0 is bit 0 of setword.

If you've just created the temp variables and not used them much, the trick is to delete them (and access to them), then switch back to ladder view, then add the temp variables whilst in ladder mode. Switch back to STL if you need to code the access in STL.
 
Last edited:
L D[AR2 said:
[/font]



As long as MB100 is not used in an interrupt routine, yes it will protect it.

I disagree, he is copying MB100 into the TEMP and at the end placing the TEMP back into MB100. This is loading and saving the updated status of the TEMP.

His question was does this protect the memory of MB100 outside of the block (at least that's how I read the question).

If I am correct with how I read the question, then no this part of code in FC does not protect MB100 of changes globally, MB100 could be inadvertently effected outside the block, either directly or if someone accidently overlaps the address (uses MD98 for example).
 
L D[AR2,P#0.0] is seems that I made the last post when you send your reply.

Ok now I know "everything" :)

Till evening then I have to confirm another question about changing values in DBs.
So next post about 10 PM

Thank you for your time&help
 
Last edited:
PeterW said:
His question was does this protect the memory of MB100 outside of the block (at least that's how I read the question).

Yes it’s correct interpretation .

Exactly my question:

Network1

MB 100 has for example value B#16#FF

Network 2

My FC with protection code , MB 100 is used for store other values

After going out from FC, MB 100 has still B#16#FF

Network 3

MB 100 is used by another part of program (this part recognize no changes since Network 1 with MB100 - no edges, etc.).

Writes B#16#99 to MB 100 and get this value by next cycle
 
I see what you are saying now, yes the MB would contain the same value when it leaves the FC as when it entered and could be used elsewhere and have the original state. I thought you meant keeping its state externally.

This would be bad programming though and confusing to anyone trying to follow it, especially if the MB was used as normal logic elsewhere and its memory needed retaining.

Also the FC can be called more than once, in this case the MB becomes itself a TEMP (scratch) flag byte.

The only times really that you transfer memory from an outside storage area into a TEMP area, is along the the lines of your original question.

An example I can think of is that you have a status word where each bit has a meaning, perhaps read by a HMI. You store the word externally in a Data Block for HMI data. In the FC you want to be able to set/reset bits as per the current conditions.

You have two options here, the cumbersome way would be change bit status using words and masks, or the better way is to create 16 TEMP bits for the status word, then transfer the data word into these TEMP bits, then process those bits as normal boolean logic. At the end of the block place the 16 TEMP bits back into the word (or it could be 8 into a byte, etc).

This can only really be done by indirect addressing, Simon has shown a number of examples of this.

The method 4 he showed is a way to do this without indirect addressing, BUT the MB used should then be classed as a scratch byte and not be used to store any information elsewhere, basically it is lost to any other use apart from another scratch requirement.
 

Similar Topics

merry christmas and happy new year i have a click c0-00dr-d and allen bradley 2711c-t3m. can the panelview talk to the click plc via modbus...
Replies
1
Views
213
Hello. There is a problem with Siemens S7 300. We got a replacement PLC but it does not run the program from the MMC. The new PLC is dated 2011...
Replies
3
Views
682
Hi Any one here please helpmein simulation of s7 300 plc program with factory io. how to connect. plcsim 5 doesnot have option of s7 300 ..:
Replies
2
Views
1,004
Hello, I have a bit of a situation, and I think I know the answer but this font of knowledge may prove something. I want to do the unthinkable...
Replies
6
Views
2,164
hello guys, I'm trying to establish a connection between Indusoft 8.0 & simatic Plcsim but I keep getting the following error: error...
Replies
3
Views
1,354
Back
Top Bottom