Introduction

Add to My manuals
704 Pages

advertisement

Introduction | Manualzz

Chapter 6 Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)

Square Root (SQR)

Operands:

The SQR instruction computes the square root of the Source and places the result in the Destination.

dest := SQRT(source);

Relay Ladder

Operand

Source

Type

SINT

INT

DINT

Format

immediate tag

Description

find the square root of this value

REAL

A SINT or INT tag converts to a DINT value by sign-extension.

Destination SINT tag tag to store the result

INT

DINT

REAL

Structured Text

Use SQRT as a function. This expression computes the square root of source and stores the result in dest.

See Appendix C, Structured Text Programming for information on the syntax of expressions within structured text.

270

Publication 1756-RM003K-EN-P - July 2008

Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com

Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS) Chapter 7

Function Block

Operand

SQR tag

Type

FBD_MATH_ADVANCED

FBD_MATH_ADVANCED Structure

Format

structure

Description

SQR structure

Input Parameter

EnableIn

Source

Data Type

BOOL

REAL

Output Parameter

EnableOut

Dest

Data Type

BOOL

REAL

Description

Enable input. If cleared, the instruction does not execute and outputs are not updated.

Default is set.

Find the square root of this value.

Valid = any float

Description

The instruction produced a valid result.

Result of the math instruction. Arithmetic status flags are set for this output.

Description:

If the Destination is not a REAL, the instruction handles the fractional portion of the result as follows:

If The Source Is

not a REAL a REAL

Then The Fractional

Portion Of The Result

truncates

Example

rounds

Source

Destination

Source

Destination

DINT

DINT

REAL

DINT

3

1

3.0

2

If the Source is negative, the instruction takes the absolute value of the Source before calculating the square root.

Arithmetic Status Flags:

Arithmetic status flags are affected.

Fault Conditions:

none

Publication 1756-RM003K-EN-P - July 2008

Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com

271

Chapter 6 Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)

Condition

prescan rung-condition-in is false rung-condition-in is true postscan

Condition

prescan instruction first scan instruction first run

EnableIn is cleared

EnableIn is set postscan

Execution:

Relay Ladder

Action

The rung-condition-out is set to false.

The rung-condition-out is set to false.

Destination

=

Source

The rung-condition-out is set to true.

The rung-condition-out is set to false.

Function Block

Action

No action taken.

No action taken.

No action taken.

EnableOut is cleared.

The instruction executes.

EnableOut is set.

No action taken.

272

Publication 1756-RM003K-EN-P - July 2008

Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com

Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS) Chapter 7

Example:

Calculate the square root of value_1 and place the result in sqr_result.

Relay Ladder

Structured Text

sqr_result := SQRT(value_1);

Function Block

Publication 1756-RM003K-EN-P - July 2008

Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com

273

advertisement

Related manuals

advertisement

Table of contents