indirect addressing to instance db in step7 SCL

italo2008

Member
Join Date
Feb 2009
Location
Padova
Posts
95
Hi all

In a step7 SCL FB (NOT TIA portal) , I have declared many variables as IEC timers (SFB4). Now I need to iterate this variables (hundreds of) in a loop cycle ( bits .IN, .Q etc.). How can I do it? I think that one possibility is to iterate bits of instance DB but I don't know how to do it in SCL. I know that, for example, this instruction

Code:
idx1:=4;
idx2:=2;
TEST:=db100.dx[idx2,idx1];

points to DB100.DBX2.4 , but what if i don't want to point at DB100 but at the instance DB?

any suggestion?

thank you
 
Make an ARRAY of TON.
Then you can easily loop through the ARRAY.

If you cannot format the timers as an ARRAY, but have a series TON's, then you can manipulate the data in an alternative AT view.
Something like this:

Code:
VAR
timer_1 : TON ;
timer_2 : TON ;   
timer_3 : TON ;
timers AT timer_1 : ARRAY[1..3] OF TON ;
status : ARRAY[1..3] OF BOOL ;
END_VAR ;

FOR i:=1 to 3 DO
status[i] := timers[i].Q ; // Not sure if this is correct
END_FOR ;
 
thank you, but it seems that it doesn't work.. the compiler doesn't recognize array of TONs, so the line

Code:
timers AT timer_1 : ARRAY[1..3] OF TON ;

generate an error (unrecognized data type)
 
in this line
Code:
YV0_TIMER(IN:=DB101.DX[0,2] AND NOT DB100.DX[0,2],PT:=T#5S );

YV0_Timer is a SFB4 variable declared in the STAT vars of FB. There are hundreds of timer (YV1_TIMER,YV2_TIMER,...), and what I want to do is write the same command for all of these, using a LOOP in order not to write hundreds of lines....

is it possible?
 
I thought that you could make an ARRAY of any kind of variable, including complex types. Appearantly not.
I wonder what is the problem af just specifying an ARRAY of TON directly ?
From STEP7 help:
An ARRAY is a complex data type with up to six dimensions. All elements in an ARRAY can be of any data type (except parameter types),
Parameter types are TIMER, COUNTER, BLOCK_FB, POINTER and ANY.
 
Here's an example implementation that allows you to process IEC timers as an array.

thank you

I tried your software, just some little modification to adapt to my DBs

Code:
TYPE UDT1
//mimic SFB4 interface
    STRUCT
      IN:BOOL;
      PT:TIME;
      Q:BOOL;
      ET:TIME;
      STATE:BYTE;
      STIME:TIME;
      ATIME:TIME;

    // Type Description
    END_STRUCT
END_TYPE

FUNCTION_BLOCK FB3
//Wrapper for SFB4
VAR_IN_OUT
TT:udt1;
end_var    
VAR
T:sfb4;
END_VAR
BEGIN
T.IN:=TT.IN;
T.PT:=TT.PT;
T.STATE:=TT.STATE;
T.STIME:=TT.STIME;
T.ATIME:=TT.ATIME;
T();
TT.Q:=T.Q;
TT.ET:=T.ET;
TT.STATE:=T.STATE;
TT.STIME:=T.STIME;
TT.ATIME:=T.ATIME;    
END_FUNCTION_BLOCK

FUNCTION_BLOCK FB1
VAR
iecTimer:ARRAY[0..179] OF udt1;
ValvesAlarm:ARRAY[0..179] OF BOOL;
sfbTimer:FB3;
iIndex:INT;
END_VAR

VAR_TEMP
    ValveStatus_index:INT;
END_VAR

BEGIN

FOR iIndex:=0 TO 179 DO
    ValveStatus_index:=iIndex*2;
    iecTimer[iindex].IN:=DB101.DX[ValveStatus_index,2] AND NOT DB100.DX[ValveStatus_index,2];
    iecTimer[iindex].PT:=t#3s;
    sfbTimer(TT:=iectimer[iIndex]);
    ValvesAlarm[iIndex]:=iectimer[iIndex].Q;
END_FOR;    
END_FUNCTION_BLOCK
in my version, instance db for FB1 is DB99, so I have the array of timers in DB99

I want to start each timer according to the status of the two bits in DB100 and DB101. The strange thing is that, if I start, for example, IecTimer[0], i see in DB99 that only the .IN bit of iecTimer[0] goes ON (and it's correct), but all the timers start to count (.ET of all timers goes up)... I don't understand why...
 
I've run your code and I only get one timer timing - see screen shot. Are you using a real plc or plcsim?. Older version of plcsim have a bug in the SFB4 implementation.

ita1.jpg
 
I had tried with a real plc... VIPA 313... Just one .IN was ON but all the timers start timing and all the .Q was ON at the end of the set time.. 🔨
 
I tried your project in plcsim and it behaves as expected with the data in DB100 and DB101 - only certain ValveAlarms are on.

I've coded the method using 180 SFB4's as well and it produces exactly the same results in a second array of ValveAlarms.
 

Similar Topics

Howdy folks, I am an Allen Bradley guy currently living in an Emerson world. Working with Rx3i on PacSystems Machine Edition v. 9.6? i think...
Replies
3
Views
554
Hello, I'm very new to programming with absolutely zero schooling in this field and pretty hands off training in my new role, it's been fun...
Replies
4
Views
640
Hello Friends, I am trying to index M Bits, however GX Works2 is not allowing it with following message. https://ibb.co/zPcqj6M...
Replies
3
Views
1,285
Hi All, which the best way to do the indirect addressing in an optimize DB? Ccurrently this is my partial code inside an FB...
Replies
7
Views
2,233
Hey everyone, Just used the PLC5/Logix migration utility to convert a program, and while addressing the PCEs, I noticed a lot of errors for "XIC...
Replies
12
Views
1,898
Back
Top Bottom