11/1/2008 1:36 PM | |
Joined: 10/7/2005 Last visit: 6/1/2023 Posts: 2966 Rating:
|
Hello Hubieg
A #Trigger; A #Trigger_Pulse; //Temp END_FUNCTION |
Cheers |
|
This contribution was helpful to
1 thankful Users |
11/4/2008 10:23 AM | |
Joined: 10/7/2005 Last visit: 6/1/2023 Posts: 2966 Rating:
|
Hello again Huebig I'll try to explain (this was the subject for "another day" and I guess that day has come. This is unfortunately not easily explained and I hope my attempt at doing so does not cause more confusion). Some background info first: - I/Q/M/L/V addresses (e.g. "I 5.1", "M 24.6", L 0.7etc.) require 4 Bytes to be stored. - Fully qualified DB addresses (e.g. "DB10.DBW14", "DB10.DBX5.4" etc.) on the other hand require6 Bytes to be stored (the DB number takes up 2 Bytes, the area identifier together with the BYTE.BIT address takes up another 4 bytes. Attached is a picture fromtheStep 7 online help for"Pointer"format, which describes the structure). - S7CPU's have 4 Byte long registers (be it accu1 or 2, address registers etc.). There isno 6 Bytelong register available that could potentially be used to pass the address ofa fullyqualified DB accesson to aBlockcall. Here is now what happens in you logic: Let's say you create this call of FC100 from within your FC240 CALL FC 100 Trigger :=M7.0 // TYPE: IN Output :=DB6.DBX837.1// TYPE:OUT TriggerPulse:=M7.1 // TYPE:IN_OUT OneShot :=M242.2//TYPE:IN_OUT Step 7 has no problems passing the "M" addressesfor every formal operand directly over toFC100 when it is called. What Step 7 can NOT do is pass "DB6.DBX837.1" over as an address (since it would require a 6 byte long register to do so). Being IEC compliant, Step7 does also not have topass addresses over, but ratherjust the value. Unbeknown to you (and "hidden" from yourview), Step7 willallocate the next free/available TEMP variable inFC240 and use this topass on the bit value of Parameter"Output". It then copies the value of this (invisble)TEMP variable over to DB6.DBX837.1after the call of FC100 is finished. Here is how Step 7 will actually handle/execute this and every followingFC100 call in FC240: CALL FC 100 Trigger :=M7.0 // TYPE: IN Output :=#FC240_INVISIBLE_TEMP_BIT// TYPE:OUT TriggerPulse:=M7.1 // TYPE:IN_OUT OneShot :=M242.2 //TYPE:IN_OUT A #FC240_TEMP_BIT = DB6.DBX837.1 What this menas for your original logic is: When FC100 is calledand you do a READ accessto the(OUT) Paramater "Output", you are actually reading from a TEMP variable in FC240which has NOT yet been written too in this FC100 call and contains a "leftover rubbish" value from the other FC100 call (for which the same invisible TEMP variable in FC240 was used by the Step7 to intermittently store their"Output" value). It will "work" if you only call FC100 oncefrom FC240 assuming no other calls "destroy" the value of the invisible TEMP variable until FC100 is called again next time round. It mayalso work if you use an M bit instead of DB6.DBX837.1 as you observed (Step7 may choose to directly work with the M address inside FC100, I would not bet on it though and it alsodepends on the Step7 version that you are using). There is alsoa way todetermineifStep7 allocated"invisible" TEMP variables, which is via Program structurein the Cross reference list. Have a look at the "Local Data(for blocks) column. You'll see that your FC240 will have local data usage even ifyouyourself did NOT declare any TEMP variables (Step 7 needs to know this to be able to save and restorethe correct amount ofTEMP datawhen it has to (e.g. OB Interrupt call, other FC/FB calls from within)). By the way, if your FC100 would be FB100, your original code would work too (as an FBuses the Instance DBto access the Block paramater values and doing aREADfrom an OUT declared parameter will work (even though i wouldn't do it asI am old fashioned in that sense and would declare an IN_OUT instead)). Needless to say that it would be nice if the Step7 Editor would check for correct Paramter access within an FC (and/or FB) and alert the programmer ifa WRITE access to an IN or READ access from an OUT type is being programmed in it. Perhaps one day Siemens will add this as a"feature" to Step7 (ifanyone from the Siemens Step7 developmentteam is reading this, pelase make this feature selectable/deselectable from the Block Options). And last but not least, if you really want to keep #TriggerPulseas an FC100 parameter, please make sure to declare it as an IN_OUT too (it currently works because you use an L address whichneeds4 bytes, use a DBa.DBBx.y address and it won't work any longer. I hope this sheds some light on the fascinating internal workings of an S7 PLC. |
Cheers |
|
This contribution was helpful to
4 thankful Users |
Follow us on