beautypg.com

Rockwell Automation 1747-PT1, D1747NP002 Hand-Held Terminal User Manual

Page 290

background image

Chapter 20
Math Instructions

20–14

Example 2 (Fixed, SLC 5/01, and SLC 5/02 Processors)

In the following example, the integer value 32760 stored at N7:3 is converted
to BCD. The 5-digit BCD value is stored in the math register. The lower 4
digits of the BCD value is moved to output word O:2 and the remaining digit
is moved thru a mask to output word O:3.

When using the math register as the destination parameter in the TOD
instruction, the maximum BCD value possible is 32767. However, for BCD
values above 9999, the overflow bit is set, resulting in minor error bit S:5/0
also being set. Your ladder program can unlatch S:5/0 before the end of the
scan to avoid major error 0020, as done in this example.

TOD

TO BCD
Source

N7:3

32760

Dest

S:13

00032760

(U)

S:5

0

] [

S:0

1

APS displays S:13 and S:14
in BCD.

MOV

MOVE
Source

S:13

10080

Dest

O:2.0
10080

MVM

MASKED MOVE
Source

S:14

3

Mask

000F

Dest

O:3.0

3

] [

0

0

0

3

2

7

6

0

3 2 7 6 0

0

0

15

15

N7:3 Decimal

S:13 & S:14 5–digit BCD

S:14

S:13

This example will output the absolute value (0–32767) contained in N7:3 as 5 BCD digits in output slots 2 and 3.

Minor Error Bit

0010 0111 0110 0000

0000 0000 0000 0011

Overflow bit

2

7

6

0

3

F1

F2

F3

F4

F5

ZOOM on TOD –(TOD)– 2.3.0.0.2
NAME: TO BCD
SOURCE: N7:3 32760
DEST: S:13 10080

EDT_DAT

Destination is displayed as
10080, decimal
(equivalent to 2760 BCD).