SFB4 in FC Step 7

Join Date
Sep 2008
Location
Denmark
Posts
27
[FONT=&quot]Hi All
I managed to use SFB4 in a FC using the IN_OUT interface, but I would like to improve if possible.

Can I determine where the "timer area" starts?

The code seems to work perfect, but if the UDT is changed I would like the offset to change as well with a minimum of code change.

I want to get rid of those lines in my code:

L P#14.0
L P#22.0

I prefer "L First Timer" or similar


My UDT

28-09-2013%2019-45-59.png
28-09-2013%2019-47-37.png
28-09-2013%2019-48-22.png
28-09-2013%2019-49-06.png
[/FONT]
 
I had trouble uploading pic.

Here is my comment
Pic 1: My UDT
PIC 2: [FONT=&quot]My FC Interface with the UDT
Pic 3: [/FONT][FONT=&quot]My FC with first STL Code and then the ladder logic
Pic 4: [/FONT][FONT=&quot]My FC calls

And thanks to L D[AR2,P#0.0] since it was an old answer from him, to a tread regarding SFB4, that bring me in this direction :)
[/FONT]
 
If you add the udt to the temp area, you can call another FC to determine the offsets.
I've only transferred the offsets to AR1 for monitoring purposes.

t001.jpg
 
Source for FC8

Code:
FUNCTION FC 8 : DWORD
TITLE =
VERSION : 0.1


VAR_INPUT
  pBaseAddress : POINTER ;    
  pElementAddress : POINTER ;    
END_VAR
VAR_TEMP
  dwBase : DWORD ;    
  dwElement : DWORD ;    
END_VAR
BEGIN
NETWORK
TITLE =calc offset (in pointer format) from base to element

      L     P##pElementAddress; 
      LAR1  ; 
      L     D [AR1,P#2.0]; 
      L     P##pBaseAddress; 
      LAR1  ; 
      TAK   ; 
      L     D [AR1,P#2.0]; 
      -D    ; 
      T     #RET_VAL; 
      SET   ; 
      SAVE  ; 


END_FUNCTION
 
Thanks a lot L D[AR2,P#0.0], it works great.
It took me some time to figure out how you do it, but I think I almost got it now. You get the offset from the V-Stack?


L D[AR1,P#2.0] //
Are you reading point value in the V-Stack from the calling FC?
 
Yes.

When you call a function with a pointer, the editor generates the absolute address of the variable to pass to the function.

I notice from your code that you are relying on the contants of the accumulators when you call your FCs. You should not do this but instead read the DB and area pointer from the V area.
 
Yes I get this thought as well.
My code need to be in top to work.
I am also a little concerned if an interrupt appear, will I then could trust the content of the ACCU's ?
 
How powerful this is. :)
I improved my code so I don't depend on the contents of my ACCU's as you suggest
Code:
      L     P##T_InOut
      LAR1  
      L     D [AR1,P#2.0]               // Read Start Address
      T     #Start_Address              // Transfer start address to pointer
      L     W [AR1,P#0.0]               // Read Instance DB No.
      T     #DB_No                      // Transfer actual DB to DB pointer
      OPN   DI [#DB_No]                 // Open actual instance Data Block
 

Similar Topics

Hi, I have a simple function block that does not function when I use multi instance SFB4 IEC Timer On Delay. I could not attached a zip of the...
Replies
7
Views
9,089
Ok, with the help of other here I am getting pretty good with the use of SFB's. I do have a simple question though. In the attached picture you...
Replies
30
Views
9,986
Hello! I have used two instances of the iec function block SFB4. They are defined as STAT instances within a calling function block. The presets...
Replies
1
Views
1,607
Hi! Is it possible to declare several SFB4 (TON) in a UDT and then create several DB of type (from our UDT)? I was hoping not to have them...
Replies
4
Views
2,212
If I want to force a TON (SFB4) to be complete can I use a one-shot to initiate a move where I will take the PT value and place it in the ET...
Replies
12
Views
4,543
Back
Top Bottom