You are on page 1of 19

Tips and Tricks for Programming the 2500 Series Processors

Instructor: Fred Wilson, Sr. Applications Engineer

Memory Access
2500-C400 has 3MBytes of useraccessible memory.
Up to 2MBytes can be dedicated to Vmemory providing a valid address range of V1-V999936

The Discrete Image Register (X/Y) and Control Relays (C) reside in DRAM and can be accessed up to 5X faster than other memory types. Bit of Word is the slowest type of contact or coil (i.e., WX9.16 or V12.2).

RLL PID Fast Loop Instruction

Performs PID Loop calculation inline within RLL scan. All PID features can be used except Ramp/Soak operation. Must use Loop numbers > 128. Runs each scan Box Input is TRUE (usually set by Timer or Cyclic RLL task). Use when Sample Rate < 100 ms or very precise time interval is required.

SF Programs / SF Subroutines

Ideal for arithmetic and simple logic operations. Feature set based on SIMATIC 555 PowerMath
Executes compiled code at 10-25X of SIMATIC 555 PowerMath CPU compiled programs (25-1000X+ compared to Siemens 505 interpreted programs). No restrictions on SF instructions Declare value in memory address as any type: Signed Integer, Unsigned Integer, Long (32-bit) Integer, or Real number. Execute In-Line or queue to run in SF Analog Tasks (compatible with all Siemens 505 programs)

Queued SF Execution
Only method available to SIMATIC 505 non-PowerMath controllers to run SFP and SFS. When Input transitions False->True, the SFP/SFS is queued according to its Type for execution during the appropriate Analog Task. To take advantage of the 2500 Series CPUs processing power, all SFP/SFS queues have been expanded to hold unlimited entries. If the time slice is large enough, all programs can be executed during a single PLC scan. This method allows precise control

SF In-Line Execution
Runs to completion within the RLL scan. Results are available for next instruction. Runs each scan Input = TRUE. Therefore, the SF program can be executed every scan with simple programming. Applies to Normal / Priority SF Programs, SF Subroutines, and SFSUB0. Cyclic SFP must be queued and executed in the Cyclic SF time

SF Instruction Tips
Complete set of arithmetic and logic operators MATH includes intrinsic functions for trigonometry, logarithmic, and floating point operations. IMATH performs integer arithmetic and logic computations. The fractional part of all results are truncated. MATH converts values to Real Numbers. Results expressed as integers round fractions to nearest whole number. IMATH instructions execute faster.

SF Instruction Tips
Complex expressions
An expression can include basically unlimited numbers of operations. The only limitation is only one Assignment operation is allowed in an expression.

Bit manipulation
Word.Bit addressing is not supported. Discrete addresses: Zero= OFF / NonZero=ON Set Bit: Perform Bit-wise OR (Bit Value | 1) Clear Bit: Perform Bit-wise AND (Bit Value & 0) Toggle Bit: Perform Bit-wise XOR (Bit Value

SF Instruction Tips
Variable indexing
Works like one-dimensional array Access a memory location as an offset from a starting address Offset is 1-relative Word Index (absolute Word offset) Element Index (Offset based on type of variable) SF Variable Index (Loop and Alarm values)

SF Instruction Tips
Use of T-memory
Same as local variables Block of 16 consecutive words T1-T7 contain information about how the program was called and Sample Rate when applicable. T8-T16 are initialized to 0 each time program is executed. Provide performance improvement

SF Instruction Tips
Use of PACK instruction
Intended to consolidate data for sending to/from an HMI. Four different instructions

Also serves as type of memcpy() function for up to 32K consecutive memory locations

SF Instruction Tips
Using SFSUB Parameters
Can be constant, memory address, or arithmetic expression Address actually passed as pointer Parameter variable can be indexed Parameter syntax (use of . suffix)

Error Reporting and Debug

Special Function Error Code (SFEC)
Creates of 3-word memory block Provides detailed information (Error Code, Program ID, and Line Number executing when error detected) Provides permanent indication that error has occurred (until cleared by user).

SFEC Reporting
B it 0 0 0 0 0 0 0 0 0

00 00 00 00 0

W o rd 0 W o rd 0 W o rd 0

0 0 0 0 0 0 0 0 0 0
C ontrol Bloc k T y pe

Error C ode C ontrol Bloc k N um ber

S F Program /Subroutine Statem ent N um ber

Words1-2 initialized to 0 each time SF program called. Word3 holds last value until cleared by user.


Error response is specified by entry in Continue/Stop on Error field.
Stop on Error terminates immediately when SFEC variable set to non-zero value. Continue on Error allows user-defined action.

Referencing SFEC variable in SFP/SFS

Number reference (i.e., SFEC1) is required. Only the SFEC variable associated with the

Task Execution Time Reporting Use Special Function variables

TPET1 (Main RLL) TPET2 (Cyclic RLL ) LPETx (Loop Number) APETx (Alarm Number) PPETx (SFP Number) SPETx (SFS Number)

SFP/SFS Execution Time Reporting PPETx / SPETx

For RLL queued programs, it holds peak time between point the program was triggered and completion. Otherwise, value is set to 65535 to indicate the SF program executed. Value is reset to 0 when PLC is set to PROGRAM mode.

SFSUB Example
CTI SFSUB Profibus-DP Driver for Siemens COROS HMI Panels
State-driven application reads and writes Word I/O, decodes messages from HMI units, and executes commands to read/write PLC memory. Use of indexed parameters Use of SFEC variable

SFSUB Application
0 0 Series CPU 00 HMI Panel Online and Operational Error


Online and Operational Ready for New Command


Command to Read/ Write PLC memory

Acknowledge Ready for PLC Reply Response to Command Acknowledge Idle