Tricom Controls Here we will illustrate the type of data which PLC deals with its range, symbols, addresses…….etc. 3. PLC DATA & MEMORY Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 23 Tricom Controls Memory Areas of S7 CPUs Distribution of the Memory Areas The memory of an S7 CPU can be divided into three areas (see figure below): 1. The load memory is used for user programs without symbolic address assignments or comments (these remain in the memory of the programming device) The load memory can be either RAM or EPROM • Blocks that are not marked as required for startup will be stored only in the load memory. 2. The work memory (integrated RAM) contains the parts of the S7 program relevant for running your program, the program is executed only in the work memory and system memory areas. 3. The system memory (RAM) contains the memory elements provided by every CPU for the user program, such as the process-image input and output tables, bit memory, timers, and counters. The system memory also contains the block stack and interrupt stack. • In addition to the areas above, the system memory of the CPU also provides temporary memory (local data stack) that contains temporary data for a block when it is called, This data only remains valid as long as the block is active. Load Memory and Work Memory When you download the user program from the programming device to the CPU, only the logic and data blocks are loaded in the load and work memory of the CPU. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 24 Tricom Controls The symbolic address assignment (symbol table) and the block comments remain on the programming device. Dividing Up the User Program To ensure fast execution of the user program and to avoid unnecessary load on the work memory that cannot be expanded, only the parts of the blocks relevant for program execution are loaded in the work memory. Parts of blocks that are not required for executing the program (for example, block headers) remain in the load memory. The following figure shows a program being loaded in the CPU memory. Note Data blocks that are created in the user program with the help of system functions (for example, SFC22 CREAT_DB) are saved entirely in the work memory by the CPU. Some CPUs have separately managed areas for code and data in the work memory. The size and assignment of these areas is shown in the "Memory" tab of the Module Information for these CPUs. Load Memory Structure The load memory can be expanded using memory cards. Refer to your "S7-300 Programmable Controller, Hardware and Installation Manual" and your "S7-400, M7-400 Programmable Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 25 Tricom Controls Controllers Module Specifications Reference Manual" for the maximum size of the load memory. The load memory can also have an integrated EPROM part as well as an integrated RAM part in S7-300 CPUs. Areas in data blocks can be declared as retentive by assigning parameters in STEP 7 (see Retentive Memory Areas on S7-300 CPUs). In S7-400 CPUs, it is imperative that you use a memory card (RAM or EPROM) to expand the load memory. The integrated load memory is a RAM memory and is mainly used to reload and correct blocks. With the new S7-400 CPUs, additional work memory can also be plugged in. • Programs stored in RAM are lost when you reset the CPU memory (MRES) or if you remove the CPU or RAM memory card. • Programs saved on EPROM memory cards are not erased by a CPU memory reset and are retained even without battery backup (transport, backup copies). System Memory The system memory of the S7 CPUs is divided into address areas (see table below). Using instructions in your program, you address the data directly in the corresponding address area. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 26 Tricom Controls Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 27 Tricom Controls Process-Image Input/Output Tables If the input (I) and output (Q) address areas are accessed in the user program, the program does not scan the signal states on the digital signal modules but accesses a memory area in the system memory of the CPU and distributed I/Os. This memory area is known as the process image. Updating the Process Image The following figure shows the processing steps within a scan cycle. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 28 Tricom Controls One of the internal tasks of the operating system (OS) is to read the status of inputs into the process image input table (PII). Once this step is complete, the user program is executed with all blocks that are called in it. The cycle ends with writing the process image output table (PIQ) to the outputs for the modules. Reading in the process image input table and writing the process image output table to the outputs for the modules is all independently controlled by the operating system. One of the internal tasks of the operating system (OS) is to write the process image output table (PIQ) to the outputs for the modules and to read in the status of inputs into the process image input table (PII). Once this step is complete, the user program is executed with all blocks that are called in it. Writing the process image output table to the outputs for the modules and reading in the process image input table is all independently controlled by the operating system. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 29 Tricom Controls Advantages of the Process Image Compared with direct access to the input/output modules, the main advantage of accessing the process image is that the CPU has a consistent image of the process signals for the duration of one program cycle. If a signal state on an input module changes while the program is being executed, the signal state in the process image is retained until the process image is updated again in the next cycle. The process of repeatedly scanning an input signal within a user program ensures that consistent input information is always available. Access to the process image also requires far less time than direct access to the signal modules since the process image is located in the internal memory of the CPU. Local Data Stack The L stack saves the following: • • • • The temporary variables of the local data of blocks The start information of the organization blocks Information about transferring parameters Interim results of the logic in Ladder Logic programs When you are programming organization blocks, you can declare temporary variables (TEMP) that are only available when the block is executed and are then overwritten again. Before you access the local data stack for the first time, the local data must be initialized. In addition to this, every organization block also requires 20 bytes of local data for its start information. The CPU has a limited amount of memory for the temporary variables (local data) of blocks currently being executed. The size of this memory area, the local data stack, is dependent on the CPU. The local data stack is divided up equally among the priority classes (default). This means that every priority class has its own local data area, thus guaranteeing that higher priority classes and their OBs also have space available for their local data. The following figure shows the assignment of local data to the priority classes in an example in which in the L stack OB1 is interrupted by OB10 which is then interrupted by OB81. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 30 Tricom Controls Caution All the temporary variables (TEMP) of an OB and its associated blocks are saved in the L stack. If you use too many nesting levels when executing your blocks, the L stack can overflow. S7 CPUs change to STOP mode if the permitted L stack size for a program is exceeded. Test the L stack (the temporary variables) in your program. The local data requirements of synchronous error OBs must be taken into consideration. Interrupt Stack If program execution is interrupted by a higher priority OB, the operating system saves the current contents of the accumulators and address registers, and the number and size of the open data blocks in the interrupt stack. Once the new OB has been executed, the operating system loads the information from the I stack and resumes execution of the interrupted block at the point at which the interrupt occurred. When the CPU is in STOP mode, you can display the I stack on a programming device using STEP 7. This allows you to find out why the CPU changed to STOP mode. Block Stack If processing of a block is interrupted by the call of another block or by a higher priority class (interrupt/error servicing), the B stack stores the following data: • Number, type (OB, FB, FC, SFB, SFC), and return address of the block that was interrupted. • Numbers of the data blocks (from the DB and DI register) that were open when the block was interrupted. Using this data, the user program can then be resumed after the interrupt. If the CPU is in STOP mode, you can display the B stack with STEP 7 on a programming device. The B stack lists all Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 31 Tricom Controls the blocks that had not been completely executed when the CPU changed to STOP mode. The blocks are listed in the order in which processing was started (see figure below). Retentive Memory Areas on S7-300 CPUs If a power outage occurs or the CPU memory is reset (MRES), the memory of the S7-300 CPU (dynamic load memory (RAM), work memory, and system memory) is reset and all the data previously contained in these areas is lost. With S7-300 CPUs, you can protect your program and its data in the following ways: • You can protect all the data in the load memory, work memory, and in parts of the system memory with battery backup. • You can store your program in the EPROM (either memory card or integrated on the CPU, refer to the "S7-300 Programmable Controller, Hardware and Installation" Manual). • You can store a certain amount of data depending on the CPU in an area of the nonvolatile NVRAM. Retentive Memory Areas on S7-400 CPUs Operation without Battery Backup If you operate your system without battery backup, when a power outage occurs or when you reset the CPU memory (MRES), the memory of the S7-400 CPU (dynamic load memory (RAM), work memory, and system memory) is reset and all the data contained in these areas is lost. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 32 Tricom Controls Without battery backup, only a restart (warm restart) is possible and there are no retentive memory areas. Following a power outage, only the MPI parameters (for example, the MPI address of the CPU) are retained. This means that the CPU remains capable of communication following a power outage or memory reset. Operation with Battery Backup If you use a battery to back up your memory: • The entire content of all RAM areas is retained when the CPU restarts following a power outage. • During a restart (warm restart), the address areas for bit memory, timers, and counters is cleared. The contents of data blocks are retained. • The contents of the RAM work memory are also retained apart from bit memory, timers, and counters that were designed as non-retentive. Data Types Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 33 Tricom Controls Elementary data type: Elementary data types are predefined in accordance with IEC 61131-3. The data type determines the amount of memory space required. For example, the word data type takes up 16 bits in the user memory. Elementary data types are never more than 32 bits long and can be loaded into the accumulators of the S7 processor in full and processed with elementary STEP 7 instructions. Complex data type: Complex data types can only be used in conjunction with variables declared in global data blocks. Complex data types cannot be completely loaded into the accumulators with load instructions. You use standard blocks from the library ("IEC" S7 Program) to process complex data types. User-defined data type: A user-defined data type can be used for data blocks or as a data type in a variable declaration table. You use the Data Block Editor to create UDTs. The structure of a UDT can contain groups of elementary and/or complex data types. BOOL, BYTE, WORD, DWORD, CHAR: Variables of the BOOL data type consist of one bit. Variables of BYTE, WORD, and DWORD data types are sequences of 8, 16 and 32 bits respectively. The individual bits are not evaluated in these data types. Special forms of these data types are the BCD numbers and the count value used in conjunction with the count function. The CHAR data type represents a character in ASCII code. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 34 Tricom Controls S5TIME: Variables of the S5TIME data type are required for specifying time values in timer functions. The format is S5T#, followed by the time. You specify the time in hours, minutes, seconds or milliseconds. You can enter the timer values with an underline (1h_4m) or without an underline (1h4m).Functions FC 33 and FC40 from the library convert S5TIME to TIME format and TIME to S5TIME format. INT, DINT, REAL: Variables of these data types represent numbers that can be used in mathematical operations. TIME: A variable of data type TIME takes up a double word. This variable is used, for example, for specifying timer values in IEC timer functions. The contents of the variable are interpreted as a DINT number in milliseconds and can be either positive or negative (for example: T#1s=L#1 000, T#24d20h31m23s647msw = L#214748647). DATE: A variable of data type DATE is stored in a word in the form of an unsigned integer. The contents of the variable represent the number of days since 01.01.1990 (for example: D#216812-31 = W#16#FF62). TIME_OF_DAY: A variable of data type TIME_OF_DAY takes up a double word. This variable contains the number of milliseconds since the beginning of the day (0:00 o‘clock) in the form of an unsigned integer. (For example: TOD#23:59:59.999 = DW#16#05265B77). Each elementary data type has a defined length. The following table lists the elementary data types. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 35 Tricom Controls Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 36 Tricom Controls INTEGER DATA TYPE: An Integer data type value is a whole number value, that is, a value without a decimal point. SIMATIC S7 stores Integer data type values with sign in 16 bit code. This results in the value range shown in the slide above. As well, SIMATIC® S7 provides arithmetic operations for processing Integer values. STEP7 uses the Decimal (not BCD!) display format to specify the constants of the Integer data type. That is, with sign and without explicit format description. The use of constant Integer values in the Binary and Hexadecimal display formats is possible in principle, but because of the poor legibility, they are more or less not suitable. For this reason, the syntax of STEP7 provides the specification of Integer values only in the decimal display format. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 37 Tricom Controls DOUBLE INTEGER DATA TYPE: SIMATIC S7 stores Double Integer data type values with sign as 32 bit code. This results in the value range shown in the slide above. As well, SIMATIC® S7 provides arithmetic operations for processing DINT values. STEP7 uses a decimal number (not BCD!) to specify a constant of the Double Integer data type. That is, with sign and the format L# for "long" (double word, 32 bit). When a value smaller than -32768 or greater than 32767 is specified, the format L# is automatically added. For negative numbers smaller than -32768, the user must specify the format as L# - (for example: L# -32769). This is imperative if the value is to be further processed arithmetically as a double integer. Otherwise you would work with false values (value + sign!)! Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 38 Tricom Controls REAL DATA TYPE: The previously described INT and DINT data types are used to store whole number values with sign. Accordingly, only operations that supply a whole number value as the result can be performed with these data types. In cases where analog process variables such as voltage, current, and temperature have to be processed, it becomes necessary to use Real values (real numbers, "decimal numbers"). In order to be able to represent such values, binary digits have to be defined whose value is less than 1 (power of base 2 with negative exponent). REAL FORMAT In order to be able to form the greatest possible value range within a defined memory capacity (for SIMATIC S7: double word, 32 bit) (see slide), you must be able to select the decimal point position. Early on, IEEE defined a format for floating-point numbers. This format was laid down in IEC 61131 and was included in STEP 7. This format makes it easy to process a variable decimal point position. In a binary coded floating-point number, a portion of the binary digits contain the mantissa and the rest contain the exponent and the sign of the floating-point number. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 39 Tricom Controls When you specify real values, you do so without specifying the format. After you enter a constant real value (for example: 0.75), the Editor automatically makes a conversion (for example: 7.5000e-001). APPLICATION Floating-point numbers are used for "analog value processing", among others. A great advantage of floating-point numbers is in the number of operations possible with such numbers. These include, in addition to the standard operations such as: +, -, *, / also instructions such as sin, coos, exp, in, etc, that are used mainly in closed-loop control algorithms. Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 40 Tricom Controls Comments: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Tricom Controls S.A.E ا ام 20 Street 295, New Maadi, Cairo - Postal Code 11435 - Tel: 002 02/25181138, Fax: 002 02/25181137 Email: [email protected] ٠٠٢ ٠٢/٢٥١٨١١٣٧ : ف٠٠٢ ٠٢/٢٥١٨١١٣٨ : ت- ١١٤٣٥ ر ى- ا دى اة- ٢٩٥ رع٢٠ 41