ARRAY in SCL CPU 315 2DP/PN

kxe

Member
Join Date
Feb 2012
Location
Romania
Posts
18
The CPU 315 2DP/PN change from RUN to STOP and it give's me the next error in diagnostic: "FB1,210 / Error when accessing a datablock with the DI-register" . What i'm doing wrong? Thank you!

FB1 program
Code:
// vector
                                        
FUNCTION_BLOCK FB1                      // main function FB1;
VAR    
    
    i : INT := 1;
    j : INT := 1;
    cutii : ARRAY[1..15] OF BOOL;
    
    
END_VAR
                                        // input parameters
VAR_INPUT
    cutie_mica : BOOL ;
    cutie_mare : BOOL ;
    
    
END_VAR
                                        // output parameters
VAR_OUTPUT
   temp1 : BOOL;
END_VAR

BEGIN                                   // main program

temp1 := cutie_mica AND cutie_mare ;

    IF temp1 = TRUE THEN
        // Statement Section_IF
        cutii[i] := TRUE ;
        i := i + 1 ;
        ELSIF 
        temp1 = FALSE THEN
        // Statement Section_ELSIF
        cutii[i] := FALSE;
        i := i + 1;
    END_IF;
END_FUNCTION_BLOCK



DATA_BLOCK DB1  FB1
//
// Block Comment...
//
BEGIN

END_DATA_BLOCK
OB1 program
Code:
      CALL  FB     1 , DB1
       cutie_mica:=I0.0
       cutie_mare:=I0.1
       temp1     :=Q0.0
 
Last edited:
Yes - but you have no processing to reset i so it will carry on incrementing past the size of the array.
 
I sorted the problem with putting the value in the first array and now how should i increment the index without puting the same value in the whole array? Thank you!
 
I do not understand the functionality you are trying to achieve.
Please explain your requirements.
 
On every change of temp1 i want to put the new value in cutii array and increment the index i.
Should be like this:
temp1 = false -> cutii[1] := temp1
temp1 = true -> cutii[2] := temp1
.
.
.
temp1 = false -> cutii := temp1
 
after that we will clear it or i can make another array that can store the new values if the first array is full. Thank you!
 
this is the new code:


Code:
FUNCTION_BLOCK FB1                      
VAR    
    
    i : INT := 1;
    j : INT := 1;
    total_cutii : ARRAY[1..15] OF BOOL;
    
    
END_VAR
                                        //  parametri de intrare
VAR_INPUT
    senzor_cutie_mica : BOOL ;
    senzor_cutie_mare : BOOL ;
    
END_VAR
                                        // parametri de iesire
VAR_OUTPUT
   cutie_mica : BOOL;
   cutie_mare : BOOL;
END_VAR

   BEGIN                                   // program principal

cutie_mica := senzor_cutie_mica AND NOT senzor_cutie_mare ;    // cutie mica
cutie_mare := senzor_cutie_mica AND senzor_cutie_mare ;        // cutie mare

    IF cutie_mica = TRUE  AND cutie_mare = FALSE THEN
        // Statement Section_IF
        total_cutii[i] := cutie_mica ;   
        //i := i + 1  ;
       
        ELSIF cutie_mare = TRUE  THEN
        // Statement Section_ELSIF
        total_cutii[i] := cutie_mare ;
        //i := i + 1;   
    END_IF;
    
END_FUNCTION_BLOCK


DATA_BLOCK DB1  FB1
//
// Block Comment...
//
BEGIN

END_DATA_BLOCK
 
Last edited:
Here's my implementation:

Code:
FUNCTION_BLOCK FB111                      // main function FB1;111
VAR    
    
    i : INT := 1;
    j : INT := 1;
    cutii : ARRAY[1..15] OF BOOL;
    bPreviousTemp1:BOOL;
    
    
END_VAR
                                        // input parameters
VAR_INPUT
    cutie_mica : BOOL ;
    cutie_mare : BOOL ;
    bReset:BOOL;
    
END_VAR
                                        // output parameters
VAR_OUTPUT
   temp1 : BOOL;
   bFull: BOOL;
END_VAR

BEGIN                                   // main program
IF bReset THEN 
  i:=1;
END_IF;
bFull:=(i>15);
IF NOT bFull THEN    
 temp1 := cutie_mica AND cutie_mare ;
 IF temp1 <> bPreviousTemp1 THEN 
    cutii[i]:=temp1;
     i:=i+1;
 END_IF;
 bPreviousTemp1:=Temp1;    
END_IF;
END_FUNCTION_BLOCK
 
Neater version:

Code:
FUNCTION_BLOCK FB111                      // main function FB1;111
VAR    
    i : INT := 1;
    cutii : ARRAY[1..15] OF BOOL;
    bPreviousTemp1:BOOL;
END_VAR
                                        // input parameters
VAR_INPUT
    cutie_mica : BOOL ;
    cutie_mare : BOOL ;
    bReset:BOOL;    
END_VAR
                                        // output parameters
VAR_OUTPUT
   temp1 : BOOL;
END_VAR

BEGIN
temp1 := cutie_mica AND cutie_mare ;
IF bReset THEN 
  i:=1;
  bPreviousTemp1:=Temp1;
END_IF;
IF i<=15 THEN    
 IF temp1 <> bPreviousTemp1 THEN 
    cutii[i]:=temp1;
     i:=i+1;
 END_IF;    
END_IF;
bPreviousTemp1:=Temp1;
END_FUNCTION_BLOCK
 
Neater version:

Code:
FUNCTION_BLOCK FB111                      // main function FB1;111
VAR    
    i : INT := 1;
    cutii : ARRAY[1..15] OF BOOL;
    bPreviousTemp1:BOOL;
END_VAR
                                        // input parameters
VAR_INPUT
    cutie_mica : BOOL ;
    cutie_mare : BOOL ;
    bReset:BOOL;    
END_VAR
                                        // output parameters
VAR_OUTPUT
   temp1 : BOOL;
END_VAR

BEGIN
temp1 := cutie_mica AND cutie_mare ;
IF bReset THEN 
  i:=1;
  bPreviousTemp1:=Temp1;
END_IF;
IF i<=15 THEN    
 IF temp1 <> bPreviousTemp1 THEN 
    cutii[i]:=temp1;
     i:=i+1;
 END_IF;    
END_IF;
bPreviousTemp1:=Temp1;
END_FUNCTION_BLOCK

Thank you very much it work perfectly !!
 

Similar Topics

Hello I wanna know if are some function to check what is the max value from an array or if I have to loop the array to compare all numbers to get...
Replies
4
Views
1,892
Hello, When you want compare values of an array to a range of numbers is it a right way to do that? FUNCTION ADD VAR_IN_OUT A:ARRAY[1..50]...
Replies
5
Views
2,071
Hi guys. I have a challenge that I'm struggling with and I can't help thinking there's a really easy solution. I want to move a series of...
Replies
18
Views
5,845
Hi, I just can't wrap my head around this one so all ideas and comments are more than welcome. My SCL programming skills are beginner level. What...
Replies
3
Views
1,937
Hello I am writing a small code, I have two problems populating the arrays? I am getting an error Non-existing identifier. I also need help to...
Replies
12
Views
5,930
Back
Top Bottom