• 沒有找到結果。

Program control instructions

Programming instructions 6

6.2 Extended instructions

6.2.3 Program control instructions

6.2.3.1 Reset scan cycle watchdog instruction

RE_TRIGR (Re-trigger scan time watchdog) is used to extend the maximum time allowed before the scan cycle watchdog timer generates an error.

LAD/FBD

The RE_TRIGR instruction is used to re-start the scan cycle timer during a single scan cycle.

This has the effect of extending the allowed maximum scan cycle time by one maximum cycle time period, from the last execution of the RE_TRIGR function.

The S7-1200 CPUs restrict the use of the RE_TRIGR instruction to the program cycle, for example, OB1 and functions that are called from the program cycle. This means that the watchdog timer is reset, and ENO = EN, if RE_TRIGR is called from any OB of the program cycle OB list.

ENO = FALSE and the watchdog timer is not reset if RE_TRIGR is executed from a start up OB, an interrupt OB, or an error OB.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

Setting the PLC maximum cycle time

You can set the value for maximum scan cycle time in the PLC device configuration for

"Cycle time".

Cycle time monitor Minimum value Maximum value Default value

Maximum cycle time 1 ms 6000 ms 150 ms

Watchdog timeout

If the maximum scan cycle timer expires before the scan cycle has been completed, an error is generated. If the error handling code block OB80 is included in the user program, the PLC executes OB 80 where you may add program logic to create a special reaction. If OB80 is not included, the first timeout condition is ignored.

If a second maximum scan time timeout occurs in the same program scan (2 times the maximum cycle time value), an error is triggered that causes the PLC to transition to STOP mode.

In STOP mode, your program execution stops while PLC system communications and system diagnostics continue.

6.2.3.2 Stop scan cycle instruction LAD

STP (Stop PLC scan cycle) puts the PLC in Stop mode. When the PLC is in Stop mode, the execution of your program and output Q address updates from the process image are stopped.

Stop transition output safe states for integrated, signal board, and signal module outputs (digital or analog) are set in the PLC device configuration properties tab. You have the option to freeze outputs in the last state or set up (digital or analog) output safe states. The default state for digital outputs is FALSE and the default value for analog outputs is 0.

If EN = TRUE, then the PLC will enter STOP mode, program execution stops, and the ENO state is meaningless. Otherwise, EN = ENO = 0.

6.2.3.3 Get Error instructions

The get error instructions provide information about program block execution errors.

Program blocks must have the "handle errors within block:" attribute checked in the block properties configuration before using the GET_ERROR or GET_ERR_ID instructions.

● GET_ERROR indicates that a program block execution error has occurred and fills a predefined error data structure with detailed error information.

● GET_ERR_ID indicates that a program block execution error has occurred and reports the ID (identifier code) of the error.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

GET_ERROR

LAD FBD

Parameter Data type Description

ERROR ErrorStruct Error data structure

Parameter ERROR data structure

You can rename the structure, but not the members within the structure.

ErrorStruct data element Data

type Description

ERROR_ID WORD Error identifier

FLAGS BYTE Indicates whether the error occurred during a call to another block:

16#01 if error was during a call

16#00 otherwise REACTION BYTE Reaction to the error:

0 = Ignore; nothing written (write error)

1 = Substitute: a 0 was used for the value (read error)

2 = Skip the instruction (system error) BLOCK_TYPE BYTE Block type where error occurred:

1 = OB

2 = FC

3 = FB

PAD_0 BYTE Internal fill byte for alignment purposes, will be 0 CODE_BLOCK_NUMBER UINT Block number where error occurred

ADDRESS UDINT Internal memory location of instruction which encountered error

Internal mapping for how the remaining fields will be interpreted

Mode (A) (B) (C) (D) (E)

0

1 Offset

2 Area

3 Location Scope Number

4 Area Offset

5 Area DB no. Offset

MODE BYTE

6 PtrNo./Acc Area DB no. Offset

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

ErrorStruct data element Data

type Description

7 PtrNo./Acc Slot No./

Scope Area DB no. Offset PAD_1 BYTE Internal fill byte for alignment purposes; not used, will be 0 OPERAND_NUMBER UINT Internal instruction operand number

POINTER_NUMBER_

LOCATION UINT (A) Internal instruction pointer location SLOT_NUMBER_SCOPE UINT (B) Internal memory storage location

AREA BYTE (C) Memory area referenced when the error was encountered:

L: 16#40 – 4E, 86, 87, 8E, 8F, C0 – CE

I: 16#81

Q: 16#82

M: 16#83

DB: 16#84, 85, 8A, 8B

PAD_2 BYTE Internal fill byte for alignment purposes; not used, will be 0 DB_NUMBER UINT (D) DB which was referenced when a DB error occurred, 0

otherwise

OFFSET UDINT (E) The bit offset referenced when the error occurred (example: 12 = byte 1, bit 4)

GET_ERR_ID

LAD FBD

Parameter Data type Description

ID WORD Error identifier

Parameter ID: Error identifier values for the ErrorStruct ERROR_ID member

ERROR_ID

Hexadecimal ERROR_ID

Decimal Program block execution error 2503 9475 Uninitialized Pointer Error

2522 9506 Operand Out of Range Read Error 2523 9507 Operand Out of Range Write Error 2524 9508 Invalid Operand Read Error 2525 9509 Invalid Operand Write Error

2528 9512 Data Alignment Read Error

2529 9513 Data Alignment Write Error

2530 9520 DB Write Error

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

ERROR_ID

Hexadecimal ERROR_ID

Decimal Program block execution error

253A 9530 Global DB Does Not Exist

253C 9532 Wrong Version or FC Does Not Exist

253D 9533 SFC Does Not Exist

253E 9534 Wrong Version or FB Does Not Exist

253F 9535 SFB Does Not Exist

2575 9589 Program Nesting Depth Error

2576 9590 Local Data Allocation Error 2942 10562 Direct Input Read Error 2943 10563 Direct Output Write Error

Operation

By default, the PLC will respond to a block execution error by logging an error in the diagnostic buffer and transitioning to STOP mode. However, if you place one or more GET_ERROR or ERR_ID instructions within a code block, this block is now set to handle errors within the block. In this case, the PLC does not transition to STOP and does not log an error in the diagnostics buffer. Instead, the error information is reported in the output of the GET_ERROR or GET_ERR_ID instruction. You can read the detailed error information with the GET_ERROR instruction, or read just the error identifier with GET_ERR_ID instruction. Normally the first error is the most important, with the following errors only consequences of the first error.

The first execution of a GET_ERROR or GET_ERR_ID instruction within a block returns the first error detected during block execution. This error could have occurred anywhere between the start of the block and the execution of either GET_ERROR or GET_ERR_ID.

Subsequent executions of either GET_ERROR or GET_ERR_ID return the first error since the previous execution of GET_ERROR or GET_ERR_ID. The history of errors is not saved, and execution of either instruction will re-arm the PLC system to catch the next error.

The ErrorStruct data type used by the GET_ERROR instruction can be added in the Data block editor and block interface editors, so your program logic can access these values.

Select ErrorStruct from the data type drop-down list to add this structure. You can create multiple ErrorStructs by using unique names. The members of an ErrorStruct cannot be renamed.

Error condition indicated by ENO

If EN = TRUE and GET_ERROR or GET_ERR_ID executes, then:

● ENO = TRUE indicates a code block execution error occurred and error data is present

● ENO = FALSE indicates no code block execution error occurred

You can connect error reaction program logic to ENO which activates after an error occurs. If an error exists, then the output parameter stores the error data where your program has access to it.

GET_ERROR and GET_ERR_ID can be used to send error information from the currently executing block (called block) to a calling block. Place the instruction in the last network of the called block program to report the final execution status of the called block.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions