• 沒有找到結果。

Programming instructions 6

6.2 Extended instructions

6.2.5 Interrupt instructions

6.2.5.1 Attach and detach instructions

You can activate and deactivate interrupt event-driven subprograms with the ATTACH and DETACH instructions.

● ATTACH enables interrupt OB subprogram execution for a hardware interrupt event.

● DETACH disables interrupt OB subprogram execution for a hardware interrupt event.

LAD

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

Programming instructions 6.2 Extended instructions

Parameter Parameter

type Data type Description

OB_NR IN INT Organization block identifier:

Select from the available hardware interrupt OBs that were created using the "Add new block" feature.

Double-click on the parameter field, then click on the helper icon to see the available OBs.

EVENT IN DWORD Event identifier:

Select from the available hardware interrupt events that were enabled in PLC device configuration for digital inputs or high-speed counters. Double-click on the parameter field, then click on the helper icon to see the available events.

ADD (ATTACH only) IN BOOL ADD = 0 (default): This event replaces all previous event attachments for this OB.

ADD = 1: This event is added to previous event attachments for this OB.

RET_VAL OUT INT Execution condition code

S7-1200 hardware interrupt events

The following hardware interrupt events are supported by the S7-1200:

● Rising edge events (all built-in CPU digital inputs plus 2 signal card digital inputs) – A rising edge occurs when the digital input transitions from OFF to ON as a response

to a change in the signal from a field device connected to the input.

● Falling edge events (all built-in CPU digital inputs plus 2 signal card digital inputs) – A falling edge occurs when the digital input transitions from ON to OFF.

● High-speed counter (HSC) current value = reference value (CV = RV) events (HSC 1 through 6)

– A CV = RV interrupt for a HSC is generated when the current count transitions from an adjacent value to the value that exactly matches a reference value that was previously established.

● HSC direction changed events (HSC 1 through 6)

– A direction changed event occurs when the HSC is detected to change from increasing to decreasing, or from decreasing to increasing.

● HSC external reset events (HSC 1 through 6)

– Certain HSC modes allow the assignment of a digital input as an external reset that is used to reset the HSC count value to zero. An external reset event occurs for such a HSC, when this input transitions from OFF to ON.

Enabling hardware interrupt events in the PLC device configuration

Hardware interrupts must be enabled during the PLC device configuration. You must check the enable-event box in the device configuration for a digital input channel or a HSC, if you want to attach this event during configuration or run time.

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

Programming instructions 6.2 Extended instructions

Check box options within the PLC device configuration:

● Digital input

– Enable rising edge detection – Enable falling edge detection

● High-speed counter (HSC)

– Enable this high-speed counter for use

– Generate interrupt for counter value equals reference value count – Generate interrupt for external reset event

– Generate interrupt for direction change event

Adding new hardware interrupt OB code blocks to your program

By default, no OB is attached to an event when the event is first enabled. This is indicated by the "HW interrupt:" device configuration "<not connected>" label. Only hardware-interrupt OBs can be attached to a hardware interrupt event. All existing hardware-interrupt OBs appear in the "HW interrupt:" drop-down list. If no OB is listed, then you must create an OB of type "Hardware interrupt" as follows. Under the project tree "Program blocks" branch:

1. Double-click "Add new block", select "Organization block (OB)" and choose "Hardware interrupt".

2. Optionally, you can rename the OB, select the programming language (LAD or FBD), and select the block number (switch to manual and choose a different block number than that suggested).

3. Edit the OB and add the programmed reaction that you want to execute when the event occurs. You can call FCs and FBs from this OB, to a nesting depth of four.

OB_NR parameter

All existing hardware-interrupt OB names appear in the device configuration "HW interrupt:"

drop-down list and in the ATTACH / DETACH parameter OB_NR drop-list.

EVENT parameter

When a hardware interrupt event is enabled, a unique default event name is assigned to this particular event. You can change this event name by editing the "Event name:" edit box, but it must be a unique name. These event names become tag names in the "Constants" tag table, and appear on the EVENT parameter drop-down list for the ATTACH and DETACH instruction boxes. The value of the tag is an internal number used to identify the event.

General operation

Each hardware event can be attached to a hardware-interrupt OB which will be queued for execution when the hardware interrupt event occurs. The OB-event attachment can occur at configuration time or at run time.

You have the option to attach or detach an OB to an enabled event at configuration time. To attach an OB to an event at configuration time, you must use the "HW interrupt:" drop-down list (click on the down arrow on the right) and select an OB from the list of available

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

Programming instructions 6.2 Extended instructions

hardware-interrupt OBs. Select the appropriate OB name from this list, or select "<not connected>" to remove the attachment.

You can also attach or detach an enabled hardware interrupt event during run time. Use the ATTACH or DETACH program instructions during run time (multiple times if you wish) to attach or detach an enabled interrupt event to the appropriate OB. If no OB is currently attached (either from a "<not connected>" selection in device configuration, or as a result of executing a DETACH instruction), the enabled hardware interrupt event is ignored.

DETACH operation

Use the DETACH instruction to detach either a particular event or all events from a particular OB. If an EVENT is specified, then only this one event is detached from the specified

OB_NR; any other events currently attached to this OB_NR will remain attached. If no EVENT is specified, then all events currently attached to OB_NR will be detached.

Condition codes

RET_VAL

(W#16#....) ENO status Description

0000 1 No error

0001 0 Nothing to Detach (DETACH only)

8090 0 OB does not exist

8091 0 OB is wrong type

8093 0 Event does not exist

6.2.5.2 Start and cancel time delay interrupt instructions

You can start and cancel time delay interrupt processing with the SRT_DINT and CAN_DINT instructions. Each time delay interrupt is a one-time event that occurs after the specified delay time. If the time delay event is cancelled before the time delay expires, the program interrupt does not occur.

● SRT_DINT starts a time delay interrupt that executes an OB (organization block) subprogram when the delay time specified by parameter DTIME has elapsed.

● CAN_DINT cancels a time delay interrupt that has already started. The time delay interrupt OB is not executed in this case.

LAD FBD

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

Programming instructions 6.2 Extended instructions

SRT_DINT parameters

Parameter Parameter

type Data type Description

OB_NR IN INT Organization block (OB) to be started after a time-delay:

Select from the available time-delay interrupt OBs that were created using the "Add new block" project tree feature.

Double-click on the parameter field, then click on the helper icon to see the available OBs.

DTIME IN TIME Time delay value (1 to 60000 ms)

You can create longer delay times, for example, by using a counter inside a time delay interrupt OB.

SIGN IN WORD Not used by the S7-1200; any value is accepted RET_VAL OUT INT Execution condition code

CAN_DINT parameters

Parameter Parameter

type Data type Description

OB_NR IN INT Time delay interrupt OB identifier. You can use an OB number or symbolic name.

RET_VAL OUT INT Execution condition code

Operation

The SRT_DINT instruction specifies a time delay, starts the internal time delay timer, and associates a time delay interrupt OB subprogram with the time delay timeout event. When the specified time delay has elapsed, a program interrupt is generated that triggers the execution of the associated time delay interrupt OB. You can cancel an in-process time delay interrupt before the specified time delay occurs by executing the CAN_DINT

instruction. The total number of active time delay and time cyclic interrupt events must not exceed four.

Adding time delay interrupt OB subprograms to your project

Only time delay interrupt OBs can be assigned to the SRT_DINT and CAN_DINT

instructions. No time delay interrupt OB exists in a new project. You must add time delay interrupt OBs to your project. To create a time-delay interrupt OB, follow these steps:

1. Double-click the "Add new block" item in the "Program blocks" branch of the project tree, select "Organization block (OB)", and choose "Time delay interrupt".

2. You have the option to rename the OB, select the programming language, or select the block number. Switch to manual numbering if you want to assign a different block number than the number that was assigned automatically.

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

Programming instructions 6.2 Extended instructions

3. Edit the time delay interrupt OB subprogram and create programmed reaction that you want to execute when the time delay timeout event occurs. You can call other FC and FB code blocks from the time delay interrupt OB, with a maximum nesting depth of four.

4. The newly assigned time delay interrupt OB names will be available when you edit the OB_NR parameter of the SRT_DINT and CAN_DINT instructions.

Condition codes

RET_VAL

(W#16#...) Description 0000 No error occurred

8090 Incorrect parameter OB_NR 8091 Incorrect parameter DTIME 80A0 Time delay interrupt has not started

6.2.5.3 Disable and Enable alarm interrupt instructions

Use the DIS_AIRT and EN_AIRT instructions to disable and enable alarm interrupt processing.

LAD

Parameter

Parameter Parameter

type Data type Description

RET_VAL OUT INT Number of delays = number of DIS_AIRT executions in the queue.

Operation

DIS_AIRT delays the processing of new interrupt events. You can execute DIS_AIRT more than once in an OB. The DIS_AIRT executions are counted by the operating system. Each of these remains in effect until it is cancelled again specifically by an EN_AIRT instruction, or until the current OB has been completely processed.

Once they are enabled again, the interrupts that occurred while DIS_AIRT was in effect are processed, or the interrupts are processed as soon as the current OB has been executed.

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

Programming instructions 6.2 Extended instructions

EN_AIRT enables the processing of interrupt events that you previously disabled with the DIS_AIRT instruction. Each DIS_AIRT execution must be cancelled by an EN_AIRT execution. If, for example, you have disabled interrupts five times with five DIS_AIRT executions, you must cancel these with five EN_AIRT executions. The EN_AIRT executions must occur within the same OB, or any FC or FB called from the same OB, before interrupts are enabled again for this OB.

Parameter RET_VAL indicates the number of times that interrupt processing was disabled, which is the number of queued DIS_AIRT executions. Interrupt processing is only enabled again when parameter RET_VAL = 0.