Another Siemens Indirect Addressing Question

I hoped you weren't going to say that - pointers passed to FC's are processed differently to FB's!!!

FC's do not have instance data. Another layer of this onion will have to be peeled.
 
Since I am going to use the FB I think it mght be better to test all three and embed the timing.

How would I access QB4 and QB5?
 
Go back to post #31 - does that make more sense now ? - I see the answer is yes :)
 
Last edited:
Well, I do not know what P# means, but I see how it is used. What is the P an acronym for? Pointer + #? It is a pointer offset fom AR1? If so, can it be negative?
 
Yes P# means pointer and the offset follows.
I can be negative but you cannot use P#-1.0, you have to load a positive number and then negate it and then strip off the top 8 bits.
Enter
Code:
+AR1 P#1.0

and hit the F1 key to see what is going on.
 
Final FB

I created a function block (FB5) with what I have learned here today. It takes in a pointer to the output data area required, three (3) bytes of data and two (2) data bits. These bytes are output to 3 consectutive output bytes and the data bits are used to set two indvidual output bits.

Once set, the appropriate input bytes and bits are monitored to see that they reflect the data output. Once the inputs match the output data an acknowledgement bit is set.

If the acknowledgement bit is not set within a given time (2 seconds) then a fault bit it set on. The fault bit is configured as IN/OUT to allow it to be seal in with an SR and reset with a fault reset signal.

Thank you for your patience today in teaching me about handling pointers.
Code:
FUNCTION_BLOCK FB 5
TITLE =
VERSION : 0.1
 
VAR_INPUT
  pCmdAddress : POINTER ; 
  CmdByte : BYTE ; 
  XData : BYTE ; 
  YData : BYTE ; 
  XNeg : BOOL ; 
  YNeg : BOOL ; 
END_VAR
VAR_OUTPUT
  Ackd : BOOL ; 
END_VAR
VAR_IN_OUT
  FaultBit : BOOL ; 
END_VAR
VAR
  Faulted : SFB 4; 
END_VAR
VAR_TEMP
  NotAckd : BOOL ; 
  wDBNo : WORD ; 
  AckByt0 : BOOL ; 
  AckByt1 : BOOL ; 
  AckByt2 : BOOL ; 
  AckBits : BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =
      L     P##pCmdAddress              //pointer to 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                      //store to internal
      OPN   DB [#wDBNo]                 //open instance DB as global DB
      L     D [AR1,P#2.0]               //finally get pointer to Q area
      LAR1  
      L     #CmdByte                    //load command byte
      T     QB [AR1,P#0.0]              // set outputs
      L     #XData                      //load Data X Register
      T     QB [AR1,P#1.0]              // set outputs
      L     #YData                      //load Data Y Register
      T     QB [AR1,P#2.0]              // set outputs
      A     #XNeg                       //Check if Data X Register is Negative
      =     Q [AR1,P#3.1]               // set output if negative
      A     #YNeg                       //Check if Data Y Register is Negative
      =     Q [AR1,P#3.2]               // set output if negative
      L     IB [AR1,P#0.0]              //load ack input byte 0
      L     QB [AR1,P#0.0]
      ==I                               //if equal
      =     #AckByt0                    //      set ack bit 0
      L     IB [AR1,P#1.0]              //load ack input byte 1
      L     QB [AR1,P#1.0]
      ==I                               //if equal
      =     #AckByt1                    //      set ack bit 1
      L     IB [AR1,P#2.0]              //load ack input byte 2
      L     QB [AR1,P#2.0]
      ==I                               //if equal
      =     #AckByt2                    //      set ack bit 2
      A(    
      A     #XNeg                       // if XNeg and
      A     I [AR1,P#3.1]               //       if AckXNeg
      O                                 //or
      AN    #XNeg                       //if NOT XNeg and
      AN    I [AR1,P#3.1]               //       if NOT AckXNeg
      )     
      A(                                //AND
      A     #YNeg
      A     I [AR1,P#3.2]               // if YNeg and
      O                                 //       if AckYNeg
      AN    #YNeg                       //or
      AN    I [AR1,P#3.2]               //if NOT YNeg and
      )                                 //       if NOT AckYNeg
      =     #AckBits                    //set AckBits
      A     #AckByt0                    //if byte 0 ackd
      A     #AckByt1                    //  and byte 1 ackd
      A     #AckByt2                    //    and byte 2 ackd
      A     #AckBits                    //      and bits ackd
      =     #Ackd                       //set OUT acknowledge 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
       ET:=
      +AR1  P#1.0
      O     #Ackd                       //whether on
      ON    #Ackd                       //or off
      SAVE                              // save - set br
 
 
END_FUNCTION_BLOCK
 
How come all the semicolons are missing from the code section of FB5 - this cannot be the AWL contents.
 
Here's an alternative implementation that uses ladder for the FB (STL required for the FCs with convert bits to byte and byte to bits). Every input and output is referenced. If an output/input fails then the program can be easily changed to use spare I/O and does not rely on the outputs being sequential or the the inputs being at the same address as the outputs.
 

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,226
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,909
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,861
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,305
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,912
Back
Top Bottom