S7 - strange loop problem [ begginers pointer problem ]

adfox

Member
Join Date
Jun 2006
Location
Poland
Posts
334
Hi, i've got a serious looping problem over a fc input bool variables list - it should be easy but the heat makes me a heavy-thinker.

The function should read inputs set status bit in word and reset it if ack bit comes up.

And here is the problem - i'm not able to shift register for input variables. I've tried shifting like below ( +P#0.1 ) and the strange problem was - if I entered flags m55.0 and M55.1 for 2 first parameters, and other were left blocked with always 0 flag - trying on simulator the whole M55 word was read - even when not entered as function's parameter.

What am I doing wrong ?



Code:
FUNCTION "Alarm_W" : VOID
TITLE =
VERSION : 0.1


VAR_INPUT
  Alarm_00 : BOOL ;    
  Alarm_01 : BOOL ;    
  Alarm_02 : BOOL ;    
  Alarm_03 : BOOL ;    
  Alarm_04 : BOOL ;    
  Alarm_05 : BOOL ;    
  Alarm_06 : BOOL ;    
  Alarm_07 : BOOL ;    
  Alarm_08 : BOOL ;    
  Alarm_09 : BOOL ;    
  Alarm_10 : BOOL ;    
  Alarm_11 : BOOL ;    
  Alarm_12 : BOOL ;    
  Alarm_13 : BOOL ;    
  Alarm_14 : BOOL ;    
  Alarm_15 : BOOL ;    
  ACK_Group : BOOL ;    
  ACK_Tick : BOOL ;    
END_VAR
VAR_IN_OUT
  StatusWord : WORD ;    
  ACK_WORD : WORD ;    
  NewEvent : BOOL ;    
END_VAR
VAR_TEMP
  loop_count : INT ;    
END_VAR
BEGIN
NETWORK
TITLE =

      L     P##ACK_WORD; 
      LAR1  ; 

      L     P##StatusWord; 
      LAR2  ; 

NETWORK
TITLE =



      L     10; 
L:    T     #loop_count; 
      A     #Alarm_00; 
      S      [AR2,P#0.0]; 

      A      [AR1,P#0.0]; 
      A      [AR2,P#0.0]; 
      AN    #Alarm_00; 
      R      [AR2,P#0.0]; 

      A     #ACK_Tick; 
      AN    #Alarm_00; 
      R      [AR1,P#0.0]; 

      L     P#0.1
      +AR1  
      +AR2  


      L     #loop_count; 
      LOOP  L; 
END_FUNCTION
 
Yet another alternative

Use an FB instead of an FC, you can loop through the inputs using indirect addressing.
Why not pass a pointer to the first bit and use that pointer to do indirect addressing? This seems to be more efficient. The only problem I see with this is knowing the increment between bits. If these 16 bits are all packed in the same 16 bit word then life is easy. There must be some way to pack the 16 bits together.

I would prefer to pass one pointer than 16 bits.
 
as suggested by TurpoUrpo and Peter, pack the alarms and index through them. Code as below (untested)

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

VAR_INPUT
  Alarm_00 : BOOL ; 
  Alarm_01 : BOOL ; 
  Alarm_02 : BOOL ; 
  Alarm_03 : BOOL ; 
  Alarm_04 : BOOL ; 
  Alarm_05 : BOOL ; 
  Alarm_06 : BOOL ; 
  Alarm_07 : BOOL ; 
  Alarm_08 : BOOL ; 
  Alarm_09 : BOOL ; 
  Alarm_10 : BOOL ; 
  Alarm_11 : BOOL ; 
  Alarm_12 : BOOL ; 
  Alarm_13 : BOOL ; 
  Alarm_14 : BOOL ; 
  Alarm_15 : BOOL ; 
  ACK_Group : BOOL ; 
  ACK_Tick : BOOL ; 
END_VAR
VAR_IN_OUT
  StatusWord : WORD ; 
  ACK_WORD : WORD ; 
  NewEvent : BOOL ; 
END_VAR
VAR_TEMP
  loop_count : INT ; 
  abAlarms : ARRAY  [0 .. 15 ] OF BOOL ; 
  bAlarm : BOOL ; 
  dwalarmPtr : DWORD ; 
  dwAr1Saved : DWORD ; 
END_VAR
BEGIN
NETWORK
TITLE =pack alarm bits into temp
      A     #Alarm_00; 
      =     #abAlarms[0]; 
      A     #Alarm_01; 
      =     #abAlarms[1]; 
      A     #Alarm_02; 
      =     #abAlarms[2]; 
      A     #Alarm_03; 
      =     #abAlarms[3]; 
      A     #Alarm_04; 
      =     #abAlarms[4]; 
      A     #Alarm_05; 
      =     #abAlarms[5]; 
      A     #Alarm_06; 
      =     #abAlarms[6]; 
      A     #Alarm_07; 
      =     #abAlarms[7]; 
      A     #Alarm_08; 
      =     #abAlarms[8]; 
      A     #Alarm_09; 
      =     #abAlarms[9]; 
      A     #Alarm_10; 
      =     #abAlarms[10]; 
      A     #Alarm_11; 
      =     #abAlarms[11]; 
      A     #Alarm_12; 
      =     #abAlarms[12]; 
      A     #Alarm_13; 
      =     #abAlarms[13]; 
      A     #Alarm_14; 
      =     #abAlarms[14]; 
      A     #Alarm_15; 
      =     #abAlarms[15]; 
NETWORK
TITLE =
      L     P##abAlarms; //pointer to packed alarm bits
      T     #dwalarmPtr; 
      L     P##ACK_WORD; 
      LAR1  ; 
      L     P##StatusWord; 
      LAR2  ; 
NETWORK
TITLE =
      L     10; 
L:    T     #loop_count; 
      TAR1  #dwAr1Saved; //save ar1
      LAR1  #dwalarmPtr; //get pointer to packed alarm bits
      A      [AR1,P#0.0]; //current alarm ...
      =     #bAlarm; //...to temp
      LAR1  #dwAr1Saved; //restore AR1
      A     #bAlarm; 
      S      [AR2,P#0.0]; //status word
      A      [AR1,P#0.0]; //ack word
      A      [AR2,P#0.0]; //status word
      AN    #bAlarm; 
      R      [AR2,P#0.0]; //status word
      A     #ACK_Tick; 
      AN    #bAlarm; 
      R      [AR1,P#0.0]; //ack word
      L     P#0.1; 
      +AR1  ; 
      +AR2  ; 
      L     #dwalarmPtr; 
      +D    ; 
      T     #dwalarmPtr; 

      L     #loop_count; 
      LOOP  L; 
END_FUNCTION
 
Thank You LD [AR2,P#0.0].
This code works great. I need to learn more about indirect addressing.
Do You know where i can find knowledge to master the pointer programming ?

I've always used FBD and STL for simple tasks but the power and flexibility of STL is still in about 10% available to me.
Can you recommend reading some materials for this subject ?
Step 7 help system is ok, but you must know what to look for.

I'd like to learn more by myself because begging for some code isn't good for all the time :)

Thanks again everyone, cheers.
 

Similar Topics

Hello all, I am facing an issue with my Commander SK that I cannot solve on my own, I am struggling on it since several days :confused: The...
Replies
9
Views
1,039
Hi. I'm doing an upgrade of an old 1400e to a new panel view plus 7 standard using ftv studio v 12,which will be communicating to a slc 5/04 via...
Replies
15
Views
2,614
Can someone explain the jumper between the elements? Does it do anything? See attached jpeg.
Replies
4
Views
684
We have an OPC server getting data from a Compactlogix PLC. The PLC also communicates with a Panelview and a couple VFDs via Ethernet/IP...
Replies
3
Views
1,163
I have a small system controlled by a Siemens S7-1200 PLC. I created a totalizer function block (TIA v17), where I'm counting total revolutions...
Replies
16
Views
3,123
Back
Top Bottom