Siemens PLC SIM "Error when allocating local data"

rocket

Member
Join Date
Jun 2007
Location
MP
Posts
29
Hi

I have the attached code and am testing it using PLC SIM. The PLC goes to STOP mode with an "Error when allocating local data", requested OB88. I have never had this type of error before and would appreciate any insight please.

Thanks
 
Where's the code that calls the FB ?

Create a library, copy all the blocks to the library and then post the archived library. We can then run what you are running.
 
The string processing (I_STRNG) in FB300 is generating the requirement for large amounts of local data due the fact that the default compiler setting is to allocate space for strings of length 254 bytes.

As your strings are of length 4, change the compiler setting to 4, recompile and all will be well.

sclscl.jpg
 
An alternative coding that does not require the same amount of local data and works with the default compiler string length is as follows:

Code:
DATA_BLOCK DB_Test FB_DT_String
//
// Block Comment...
//
BEGIN


END_DATA_BLOCK


FUNCTION_BLOCK FB_DT_String

VAR_TEMP
    SFC_Error   : INT;
    CurrentDT   : DT;
    TempDT AT CurrentDT : ARRAY[1..6] OF BYTE;
    
END_VAR

VAR
    MyTimeInt   : STRUCT
        Year    : INT;
        Month   : INT;
        Day     : INT;
        Hour    : INT;
        Minute  : INT;
        Second  : INT;
    END_STRUCT;

    MyTimeStr   : STRUCT
        Year    : STRING[4];
        Month   : STRING[4];
        Day     : STRING[4];
        Hour    : STRING[4];
        Minute  : STRING[4];
        Second  : STRING[4];
END_STRUCT;  
     aS AT MyTimeStr: ARRAY[0..5] OF STRING[4];
     aI AT MyTimeInt:ARRAY[0..5] OF INT;
     iI:INT;

END_VAR
    // Get Current Date and Time
    SFC_Error := READ_CLK(CDT :=  CurrentDT); 
    IF SFC_Error = 0 THEN
        MyTimeInt.Year     := WORD_BCD_TO_INT(TempDT[1]);
        MyTimeInt.Month    := WORD_BCD_TO_INT(TempDT[2]);
        MyTimeInt.Day      := WORD_BCD_TO_INT(TempDT[3]);
        MyTimeInt.Hour     := WORD_BCD_TO_INT(TempDT[4]);
        MyTimeInt.Minute   := WORD_BCD_TO_INT(TempDT[5]);
        MyTimeInt.Second   := WORD_BCD_TO_INT(TempDT[6]);
    END_IF;
    
    // Convert to strings
    FOR iI:=0 TO 5 DO
        as[iI]:=I_STRNG(aI[iI]);
    END_FOR;    
END_FUNCTION_BLOCK
 
Thank you very much. I have used your-recoding suggestion. Is it because MyTimeStr is a STRUCT that the compiler allocates local memory to EACH member of the structure being called in my original attempt at string conversion?
 
Yes.

Here's the block re-coded without using STRUCTS, the local data requirement is now only 28 bytes.

Code:
FUNCTION_BLOCK FB300

VAR_TEMP
    CurrentDT   : DT;
    TempDT AT CurrentDT : ARRAY[1..6] OF BYTE;    
END_VAR

VAR
        sYear    : STRING[4];
        sMonth   : STRING[4];
        sDay     : STRING[4];
        sHour    : STRING[4];
        sMinute  : STRING[4];
        sSecond  : STRING[4];
END_VAR
    // Get Current DATE AND TIME and convert to string
      IF READ_CLK(CDT :=  CurrentDT) = 0 THEN
        sYear     := I_STRNG(WORD_BCD_TO_INT(TempDT[1]));
        sMonth    := I_STRNG(WORD_BCD_TO_INT(TempDT[2]));
        sDay      := I_STRNG(WORD_BCD_TO_INT(TempDT[3]));
        sHour     := I_STRNG(WORD_BCD_TO_INT(TempDT[4]));
        sMinute   := I_STRNG(WORD_BCD_TO_INT(TempDT[5]));
        sSecond   := I_STRNG(WORD_BCD_TO_INT(TempDT[6]));
    END_IF; 
END_FUNCTION_BLOCK
 

Similar Topics

Hello Everybody, Is there a way to connect factory talk ME with siemens plcim. So that i can simulate my simatic step 7 logic and factory talk hmi?
Replies
1
Views
1,930
Ok so I know that SIMATIC S7-PLCSIM is out there to act as an emulator if you don't have a physical PLC to write and test programs with... but it...
Replies
4
Views
8,675
Hello, I would like to use PLC-SIM together with some PC-software, for instance VB, and have my PLC-program connected to a PC-based plant model...
Replies
14
Views
6,679
I have been using PLCSIM v5.2 with hotfix 1 in conjunction with S7 V5.2 SP1.. it works very nicely. I have not yet been able to make my Protool...
Replies
13
Views
12,335
The past week we received a new piece of equipment from Germany which utilizes siemens controls. Typically in our company we use A.B. controls for...
Replies
4
Views
48
Back
Top Bottom