Another Siemens Indirect Addressing Question

Code:
FUNCTION_BLOCK FB 3
TITLE =
VERSION : 0.1

VAR_INPUT
  Pnt_QB3 : BYTE ; 
  CmdByte : BYTE ; 
END_VAR
VAR_OUTPUT
  Ackd : BOOL ; 
  FaultBit : BOOL ; 
END_VAR
VAR
  Faulted : SFB 4; 
END_VAR
VAR_TEMP
  temp : BOOL ; 
  NotAckd : BOOL ; 
  DWPntr : DWORD ; 
END_VAR
BEGIN
NETWORK
TITLE =
 
      L     #Pnt_QB3; //Load command byte
      T     #DWPntr; //tranfer to outptu byte
      SLD   3; 
      L     #CmdByte; 
      T     QB [#DWPntr]; 
      L     IB [#DWPntr]; //load ack inputs
      L     QB [#DWPntr]; 
      ==I   ; //if equal
      =     #Ackd; //      set OUT ack bit
      AN    #Ackd; //if not ack'd
      =     #NotAckd; //set  temp for tmr IN
      CALL #Faulted (//run SFB4
           IN                       := #NotAckd,
           PT                       := T#2S,// after 2 seconds
           Q                        := #FaultBit);//    turn on OUT fault bit
      AN    #temp; //temp bit not on 
      SAVE  ; // save - set br
END_FUNCTION_BLOCK
 
Doh!, Yes, the SFB4 was why I went to an FB to start with. I can always set up the timer outside of the FC and check all three ack bits if I go that way.
But thanks for the heads up. I forgot about that.
 
I have a bit (M2.7) in OB1 that need to be on before enabling the FB.

I am using MB3 for Pnt_QB3 and setting it to 3.
I am using MB4 for CmdByte and setting it to 7.
Ackd is set to M2.1
Faulted is set to M2.0

And then I set M2.7
 
FB3 coding error:

Code:
      L     #Pnt_QB3; //Load command byte
      T     #DWPntr; //tranfer to outptu byte
      SLD   3;
should be

Code:
      L     #Pnt_QB3; //Load command byte
      SLD   3;     
      T     #DWPntr; //tranfer to outptu byte
 
One of the implications of coding this way means that QB3 will not appear in the cross-reference. When someone else is trying to figure out what controls QB3 they will not be able to (easily) find it.
 
When monitoring STL, the RH pane can be configured (via a Right click) to show various registers. The Indirect column is useful for tracking down this type of indirect address coding errors.

rob8.jpg
 
I did not try the right click. I was looking at that screen however. I am assuming that the lines each correspond the each line of the code. I think that would be easier to read if I turned on line numbers to help correlate the two screens. Something more for me to play with.

I have had no training in STL and have learned only from the help files, reading here, and toggling between ladder and STL view. (and Mike has given me some tips too, thanks Mike). Those little tips will come in handy.
 
I would rename Pnt_QBx as this is not a pointer (in Siemens terms), it is a byte number in this example.
 
That is extremely helpful. I can see that my pointer is now 3.1 instead of 4. I realize that I need to increment the original offset instead of the current.

debug.jpg
 
I would rename Pnt_QBx as this is not a pointer (in Siemens terms), it is a byte number in this example.
Yes, I will do that. This is just my temp project that i use for testing my FB's and FC's before actually implementing them into my customers program.
 
Here is your FB3 re-coded to pass in a pointer.

Code:
FUNCTION_BLOCK FB 4
TITLE =
VERSION : 0.1


VAR_INPUT
  pCmdAddress : POINTER ;    
  CmdByte : BYTE ;    
END_VAR
VAR_OUTPUT
  Ackd : BOOL ;    
  FaultBit : BOOL ;    
END_VAR
VAR
  Faulted : "TON";    
END_VAR
VAR_TEMP
  temp : BOOL ;    
  NotAckd : BOOL ;    
  DWPntr : DWORD ;    
  wDBNo : WORD ;    
END_VAR
BEGIN
NETWORK
TITLE =


      L     P##pCmdAddress; //pointer ro pointer
      AD    DW#16#FFFFF; //mask off area
      TAR2  ; //current instance address
      +D    ; //add offset to give absolute address 
      LAR1  ; //use AR1 to read pointer to Q
      L     DINO; //get instance DB number
      T     #wDBNo; 
      OPN   DB [#wDBNo]; //open instance DB as global DB
      L     D [AR1,P#2.0]; //finally get pointer to Q area

      T     #DWPntr; //tranfer to outptu byte 
      L     #CmdByte; 
      T     QB [#DWPntr]; 
      L     IB [#DWPntr]; //load ack inputs
      L     QB [#DWPntr]; 
      ==I   ; //if equal
      =     #Ackd; //      set OUT ack bit
      AN    #Ackd; //if not ack'd
      =     #NotAckd; //set  temp for tmr IN
      CALL #Faulted (//run SFB4
           IN                       := #NotAckd,
           PT                       := T#2S,// after 2 seconds
           Q                        := #FaultBit);//    turn on OUT fault bit

      AN    #temp; //temp bit not on 
      SAVE  ; // save - set br
END_FUNCTION_BLOCK
 
..which means you can pass QB3 (for example) as the base address and it will appear in the cross-reference.

rob9.JPG
 

Similar Topics

Hi Guys. Apologies for the long winded script but I want to give you the full script I imagine some of you guys have been in the same situation...
Replies
9
Views
2,252
Dear All, I have a machine of stone cutting CNC. with Siemens 810D system. I am very tired to maintain(Servo drive failure) it now wants to...
Replies
8
Views
4,940
Hi guys I need to transfer a tia license for a couple of days from one pc to another via usb and then back again after wards. What is right way...
Replies
10
Views
6,934
Yes, I'm sorry, I'm starting this topic again. In my defense, I promise I tried to read on this forum and using other sources to get a good idea...
Replies
8
Views
4,327
Hi all, I need some assistance. Does anyone know if it is possible to or how to copy a HMI project from one program to another program...
Replies
5
Views
4,928
Back
Top Bottom