Area length error when reading

manmeetvirdi

Member
Join Date
Oct 2004
Location
India.
Posts
750
Hi there
Iam unable to understand as to why PLC gives "Area Length error when reading" if I add "A#call_fwd_I" at the very end of the block.

Code:
FUNCTION_BLOCK FB 100
TITLE =
//1)check if station is enabled.
//2)if enabled then wait for the demand of that station.
//3)iF demand of all the active stations comes then generate the sequence 
//number orderly.
VERSION : 0.1


VAR_INPUT
  stn1_ena_hmi : BOOL ;    
  stn2_ena_hmi : BOOL ;    
  stn3_ena_hmi : BOOL ;    
  stn4_ena_hmi : BOOL ;    
END_VAR
VAR_IN_OUT
  stn4_call_I : BOOL ;    
  stn3_call_I : BOOL ;    
  stn2_call_I : BOOL ;    
  stn1_call_I : BOOL ;    
  call_fwd_I : BOOL ;    
END_VAR
VAR
  stn1_active : BOOL ;    
  stn2_active : BOOL ;    
  stn3_Active : BOOL ;    
  stn4_active : BOOL ;    
  call_fwd : BOOL ;    
  fp_st1 : BOOL ;    
  fp_st2 : BOOL ;    
  fp_st3 : BOOL ;    
  fp_st4 : BOOL ;    
  ena_inc : INT ;    
  fn_st1 : BOOL ;    
  fn_st2 : BOOL ;    
  fn_st3 : BOOL ;    
  fn_st4 : BOOL ;    
  fwd_demand : INT ;    
  fp_st1_f : BOOL ;    
  fp_st2_f : BOOL ;    
  fp_st3_f : BOOL ;    
  fp_st4_f : BOOL ;    
  fn_st1_f : BOOL ;    
  fn_st2_f : BOOL ;    
  fn_st3_f : BOOL ;    
  fn_st4_f : BOOL ;    
  stn4 : INT ;    
  stn3 : INT ;    
  stn2 : INT ;    
  stn1 : INT ;    
  fp_reset : BOOL ;    
END_VAR
VAR_TEMP
  count : INT ;    
  count1 : INT ;    
END_VAR
BEGIN
NETWORK
TITLE =to know number of the active stuffing station

//increment the counter

      A     #stn1_ena_hmi; 
      FP    #fp_st1; 
      JCN   st2; 
      L     #ena_inc; 
      L     1; 
      +I    ; 
      T     #ena_inc; 



st2:  A     #stn2_ena_hmi; 
      FP    #fp_st2; 
      JCN   st3; 
      L     #ena_inc; 
      L     1; 
      +I    ; 
      T     #ena_inc; 

st3:  A     #stn3_ena_hmi; 
      FP    #fp_st3; 
      JCN   st4; 
      L     #ena_inc; 
      L     1; 
      +I    ; 
      T     #ena_inc; 

st4:  A     #stn4_ena_hmi; 
      FP    #fp_st4; 
      JCN   end1; 
      L     #ena_inc; 
      L     1; 
      +I    ; 
      T     #ena_inc; 

end1: NOP   0; 

//decrement the counter


      A     #stn1_ena_hmi; 
      FN    #fn_st1; 
      JCN   st2n; 
      L     #ena_inc; 
      L     -1; 
      +I    ; 
      T     #ena_inc; 

st2n: A     #stn2_ena_hmi; 
      FN    #fn_st2; 
      JCN   st3n; 
      L     #ena_inc; 
      L     -1; 
      +I    ; 
      T     #ena_inc; 

st3n: A     #stn3_ena_hmi; 
      FN    #fn_st3; 
      JCN   st4n; 
      L     #ena_inc; 
      L     -1; 
      +I    ; 
      T     #ena_inc; 


st4n: A     #stn4_ena_hmi; 
      FN    #fn_st4; 
      JCN   end2; 
      L     #ena_inc; 
      L     -1; 
      +I    ; 
      T     #ena_inc; 
end2: NOP   0; 




NETWORK
TITLE =to know number of the call forward demands

//increment the counter
      A     #stn4_ena_hmi; 
      A     #stn4_call_I; 
      FP    #fp_st1_f; 
      JCN   st2f; 
      L     #fwd_demand; 
      L     1; 
      +I    ; 
      T     #fwd_demand; 

st2f: A     #stn3_call_I; 
      A     #stn3_ena_hmi; 
      FP    #fp_st2_f; 
      JCN   st3f; 
      L     #fwd_demand; 
      L     1; 
      +I    ; 
      T     #fwd_demand; 

st3f: A     #stn2_call_I; 
      A     #stn2_ena_hmi; 
      FP    #fp_st3_f; 
      JCN   st4f; 
      L     #fwd_demand; 
      L     1; 
      +I    ; 
      T     #fwd_demand; 

st4f: A     #stn1_call_I; 
      A     #stn1_ena_hmi; 
      FP    #fp_st4_f; 
      JCN   end3; 
      L     #fwd_demand; 
      L     1; 
      +I    ; 
      T     #fwd_demand; 

end3: NOP   0; 

//decrement the counter


      A     #stn4_call_I; 
      A     #stn4_ena_hmi; 
      FN    #fn_st1_f; 
      JCN   st2r; 
      L     #fwd_demand; 
      L     -1; 
      +I    ; 
      T     #fwd_demand; 

st2r: A     #stn3_call_I; 
      A     #stn3_ena_hmi; 
      FN    #fn_st2_f; 
      JCN   st3r; 
      L     #fwd_demand; 
      L     -1; 
      +I    ; 
      T     #fwd_demand; 

st3r: A     #stn2_call_I; 
      A     #stn2_ena_hmi; 
      FN    #fn_st3_f; 
      JCN   st4r; 
      L     #fwd_demand; 
      L     -1; 
      +I    ; 
      T     #fwd_demand; 


st4r: A     #stn1_call_I; 
      A     #stn1_ena_hmi; 
      FN    #fn_st4_f; 
      JCN   end4; 
      L     #fwd_demand; 
      L     -1; 
      +I    ; 
      T     #fwd_demand; 

end4: NOP   0; 









NETWORK
TITLE =
//to check is number of active stations are equal to call fwd demand
      O(    ; 
      L     #fwd_demand; 
      L     0; 
      ==I   ; 
      )     ; 
      O     #call_fwd; 
      JC    end5; 
      L     #fwd_demand; 
      L     #ena_inc; 
      ==I   ; 
      JCN   end5; 

      S     #call_fwd_I; 
end5: NOP   0; 
////reset the set bit after the acknowledgement is received

      A     #call_fwd_I; 
      FN    #fp_reset; 
      JCN   end6; 
      R     #call_fwd; 
      R     #stn1_call_I; 
      R     #stn2_call_I; 
      R     #stn3_call_I; 
      R     #stn4_call_I; 

      L     0; 
      T     #stn4; 
      T     #stn3; 
      T     #stn2; 
      T     #stn1; 
end6: NOP   0; 


NETWORK
TITLE =
//once the call_fwd is set now name the stations according to priority basis

      A     #call_fwd_I; 
      AN    #call_fwd; 
      JCN   fin; 

      SET   ; 
      S     #call_fwd; 


      LAR1  P##stn4_call_I; 
      LAR2  P##stn4; 
      L     5; 
      T     #count1; 

      L     4; 
c2:   T     #count; 
      A      [AR1,P#0.0]; 
      JCN   c1; 
      L     #count1; 
      L     #count; 
      -I    ; 
      T     W [AR2,P#0.0]; 
      JU    c3; 

c1:   L     #count1; 
      L     -1; 
      +I    ; 
      T     #count1; 



c3:   +AR1  P#0.1; 
      +AR2  P#2.0; 

      L     #count; 
      LOOP  c2; 


fin:  NOP   0; 


     [COLOR=Red] A     #call_fwd_I[/COLOR]; 
END_FUNCTION_BLOCK
What on?

regards
 
From Siemens web site

Description:
The area length error appears if references are made to addresses that do not exist in the STEP 7 program or when parameterizing the block call. The Online Help in STEP 7 gives two reasons for this:

  • The value addressed by the access address is outside or not entirely inside the permissible address area (CPU-specific size).
  • Due to an incorrect address calculation the addressed value is >65535. In the case of indirect addressing, an address value of greater than 65535 might occur through incorrect calculation. This value can no longer be entered correctly in the detail information of the event. Then for S7-300 a 0 is entered and displayed as access address and the calculated value modulo 65535 for S7-400.
 
May have something to do with using AR2 to store your pointer offsets when AR2 points to the Instance DB when using FB's.

Set some breakpoints and step through your code keeping an eye on the DB,AR registers.
 
Last edited:
Hi
504bloke i have used #call_fwd_I as in_out variable, so even if I use M0.0 for it, it give me error.So no problem with outside the access area. Incorrect calculation cannot apprehend why.
But some thing to do with AR2 as STL?? said. Because when I write

LAR2 P##call_fwd_I
A #call_fwd_I

Problem disappears!!

Also problem only comes when logic in network 4 gets executed.
Some more light.................
 
.. I've just been searching for a relevant post but to no avail.

ALL FB interface variables (IN/IN_OUT/OUT/STAT) are accessed using the instance DB and AR2.

If you modify AR2 inside an FB you cannot access an interface variable whilst AR2 is being used for something.

You must save AR2 in the temp area,
Do your processing using AR2 (only using temps).
Restore AR2 from the temp area.
All interface variable access is now allowed.
 
Always restore AR2 inside FB after using it !!

Ah L D[AR2,P#0.0] great
Am feeling relived now...

1) I declared a variable in TEMP Area (TEMP0) with data type DW.
2) Before using AR2 in network 4 i wrote "TAR2 #TEMP0"
3) After using AR2 i restored it by "LAR2 #TEMP0"

Now PLC has no problem !!

OR

Just Point AR2 to any interface variable declared inside IN/OUT/IN_OUT/STAT (THIS IS WRONG)




Lesson:Always restore AR2 inside FB after using it !! else if you access an interface variable you will have RED LIGHT.

Thanks and Cheers !🍺
 
Last edited:
You were lucky to get an area read error and a red light - this is not always the case.

Let say that you have two ints in the stat area (iFred then iBert).
AR2 gets incremented by 2 bytes

L iFred is actually loading iBert.... the possibilities for confusion are endless.
 
Ok LD I got the point.

Just pointing AR2 to any interface variable declared inside IN/OUT/IN_OUT/STAT (it will remove RED light though) and then performing actions like "L #iFred" will load some value which is not present in #iFred. Great point !

In my code itself if I just add
LAR2 P##stn1_active
L #stn4
A #call_fwd_I

accumulator does not show the right value in #stn4 even though RED LIGHT is gone !!

Thats Mind blowing !!!!

LD you can make a puzzle based on this :)
 
Last edited:

Similar Topics

Kindly , in Siemens PCS7 , has anyone seen and solved this problem ? " Maximum length of code area reached (max. 64 Kbytes) "
Replies
3
Views
2,255
System is an IPC547D running GRAPH in WinAC RTX. Six S7-1200 (CPU 1215C) running a little code for manual operations, but mostly running as...
Replies
16
Views
7,971
Hello fellow programmers! I've come to you with a new problem... currently I am working on a project involving a network of 8 Siemens PLCs...
Replies
4
Views
11,216
guys, I am trying to commission a software redundant system siemens S7 300. the SF led's are on with both processors, looking in the...
Replies
7
Views
6,481
Hi all, I have a problem, when i try to run my application an error appear on the PLC S-300 CPU 313C. The diagnostic buffer says area lenght...
Replies
14
Views
8,882
Back
Top Bottom