getting started guide math and trig functions on cp1e · pagina 3 omron pronti… via! funzioni...

17
© OMRON Electronics 2011 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, mechanical, electronic, photocopying, recording, or otherwise, without the prior written permission of OMRON. No patent liability is assumed with respect to the use of the information contained herein. Moreover, because OMRON is constantly striving to improve its high-quality products, the information contained in this manual is subject to change without notice. Every precaution has been taken in the preparation of this manual. Nevertheless, OMRON assumes no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained in this publication. GSG001 Rev. B Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E Getting Started Guide “Getting Started Guide” is a collection of information that helps to speed up learning and easily start working with Omron products. It is not to be intended as a substitution of manuals. www.infoPLC.net

Upload: dinhbao

Post on 31-Jul-2019

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

© OMRON Electronics 2011 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by

any means, mechanical, electronic, photocopying, recording, or otherwise, without the prior written permission of OMRON.

No patent liability is assumed with respect to the use of the information contained herein. Moreover, because OMRON is

constantly striving to improve its high-quality products, the information contained in this manual is subject to change without

notice. Every precaution has been taken in the preparation of this manual. Nevertheless, OMRON assumes no responsibility for

errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained in

this publication.

GSG001 Rev. B

Getting Started Guide

MATH AND TRIG FUNCTIONS ON CP1E

Getting Started Guide

“Getting Started Guide” is a collection of information

that helps to speed up learning and easily start working

with Omron products. It is not to be intended as a

substitution of manuals.

www.infoPLC.net

Page 2: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 2

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

INDICE

1 INTRODUCTION ............................................................................................................. 3

1.1 SCOPE OF THIS GUIDE ............................................................................................ 3

1.2 TECHNICAL NOTES .................................................................................................. 3

2 SUBROUTINES ................................................................................................................. 4

2.1 SIN ............................................................................................................................. 4

2.2 COS .......................................................................................................................... 4

2.3 TAN ........................................................................................................................... 5

2.4 ASIN .......................................................................................................................... 6

2.5 ATAN ......................................................................................................................... 7

2.6 RAD ........................................................................................................................... 8

2.7 REARG ...................................................................................................................... 8

2.8 SQRT.......................................................................................................................... 9

3 PROGRAMMING PROCEDURE ................................................................................. 11

3.1 STEP BY STEP GUIDE ............................................................................................... 11

3.1.1 CREATION OF A NEW PROGRAM WITH MATH LIBRARY .......................... 11

3.1.2 CALLING A SUBROUTINE IN THE MAIN PROGRAM ................................... 11

3.1.3 PROGRAM ORGANISATION ........................................................................ 12

3.2 RESERVED MEMORY AREAS ................................................................................. 13

3.3 FREEING UP PROGRAM MEMORY ...................................................................... 13

3.4 NOTE ABOUT THE EXECUTION TIME ..................................................................... 14

3.5 EXAMPLE ................................................................................................................ 15

4 APPENDIX .................................................................................................................... 17

www.infoPLC.net

Page 3: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 3

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

1 INTRODUCTION

1.1 SCOPE OF THIS GUIDE

The present document is intended to help with the use of the trigonometric and

math subroutine library for CP1E, that in fact extends its set of functions.

1.2 TECHNICAL NOTES

The CP1E PLC instruction set doesn’t include trigonometric functions and some

math functions such as the square root or the power raise.

The CP1E_Math.cxp file contains nine sections whose the first (Sezione1) is empty

and must be used for the main program.

Each of the remaining eight sections contains the definition of one of these math

or trigonometric functions:

SIN: sine function;

COS: cosine function;

TAN: tangent function;

ASIN: arcsine function;

ATAN: arctangent function;

SQRT: square root function;

RAD: degree to radians conversion;

REARG: conversion from a generic angle to a -2π ÷ +2π range angle.

www.infoPLC.net

Page 4: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 4

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

2 SUBROUTINES

2.1 SIN

Calculates the sine of a radians-expressed angle, stored in the ARG global

variable, and outputs the result value in the RES global variable.

Subroutine definition number: 2.

Operands

Name Address Type Valid range Descrption

ARG D2021 REAL -205887.4 ; +205881.1 Input angle (in radians)

RES D2023 REAL -1 ; +1 Result

Accuracy

SIN vs CJ SIN

1E-10

1E-09

1E-08

1E-07

0.000001

0.00001

0.0

02

0.1

55

0.3

07

0.4

61

0.6

13

0.7

65

0.9

17

1.0

69

1.2

20

1.3

72

1.5

24

1.6

76

1.8

28

1.9

80

2.1

37

2.2

95

2.4

52

2.6

10

2.7

68

2.9

26

3.0

84

3.2

42

3.4

00

3.5

58

3.7

16

3.8

74

4.0

29

4.1

75

4.3

21

4.4

66

4.6

12

4.7

58

4.9

04

5.0

50

5.1

95

5.3

41

5.4

87

5.6

33

5.7

78

5.9

24

6.0

70

6.2

16

Figure 1: Measured error between SIN subroutine and standard SIN instruction in the 0 ÷ 2π range

Requested subroutines

REARG.

2.2 COS

Calculates the cosine of a radians-expressed angle, stored in the ARG global

variable, and outputs the result value in the RES global variable.

Subroutine definition number: 3.

www.infoPLC.net

Page 5: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 5

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

Operands:

Name Address Type Valid range Descrption

ARG D2021 REAL -205887.4 ; +205881.1 Input angle (in radians)

RES D2023 REAL -1 ; +1 Result

Accuracy:

COS vs CJ COS

0.00000001

0.0000001

0.000001

0.00001

0.0

02

0.1

58

0.3

13

0.4

70

0.6

25

0.7

80

0.9

35

1.0

89

1.2

44

1.3

99

1.5

54

1.7

09

1.8

63

2.0

19

2.1

80

2.3

41

2.5

02

2.6

63

2.8

24

2.9

85

3.1

46

3.3

07

3.4

68

3.6

29

3.7

90

3.9

51

4.1

04

4.2

52

4.4

01

4.5

49

4.6

98

4.8

47

4.9

95

5.1

44

5.2

92

5.4

41

5.5

90

5.7

38

5.8

87

6.0

36

6.1

84

Figure 2: Measured error between COS subroutine and standard COS instruction in the 0 ÷ 2π range

Requested subroutines

REARG.

2.3 TAN

Calculates the tangent of a radians-expressed angle, stored in the ARG global

variable, and outputs the result value in the RES global variable.

Subroutine definition number: 4.

Operands:

Name Address Type Valid range Descrption

ARG D2021 REAL -205887.4 ; +205881.1 Input angle (in rad.)

RES D2023 REAL -3.402823e38 ; +3.402823e38 Result

www.infoPLC.net

Page 6: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 6

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

Accuracy:

TAN vs CJ TAN

1E-10

0.00000001

0.000001

0.0001

0.01

1

100

10000

1000000

100000000

0.0

01

7

0.1

51

5

0.3

01

4

0.4

51

8

0.6

01

1

0.7

50

0

0.8

98

8

1.0

47

7

1.1

96

5

1.3

45

4

1.4

94

3

1.6

43

1

1.7

92

0

1.9

40

9

2.0

93

3

2.2

48

1

2.4

02

9

2.5

57

8

2.7

12

6

2.8

67

4

3.0

22

2

3.1

77

0

3.3

31

8

3.4

86

7

3.6

41

5

3.7

96

3

3.9

51

1

4.0

97

8

4.2

40

7

4.3

83

6

4.5

26

5

4.6

69

4

4.8

12

3

4.9

55

2

5.0

98

1

5.2

41

0

5.3

84

0

5.5

26

9

5.6

69

8

5.8

12

7

5.9

55

6

6.0

98

5

Figure 3: Measured error between TAN subroutine and standard TAN instruction in the 0 ÷ 2π range

Requested subroutines

REARG;

SIN;

COS.

2.4 ASIN

Calculates the arcsine of a REAL value, stored in the ARG global variable, and

outputs the result (in radians) in the RES global variable.

Subroutine definition number: 6.

Operands:

Name Address Type Valid range Descrption

ARG D2021 REAL -1 ; +1 Argument

RES D2023 REAL -3.141593 ; +3.141593 Result angle(in radians)

Accuracy:

ERR_ASIN

1E-11

1E-10

1E-09

1E-08

1E-07

1E-06

1E-05

0.0001

0.001

0.01

0.1

-0.9

99

-0.9

51

-0.9

02

-0.8

54

-0.8

05

-0.7

56

-0.7

08

-0.6

59

-0.6

11

-0.5

62

-0.5

14

-0.4

65

-0.4

16

-0.3

68

-0.3

19

-0.2

71

-0.2

22

-0.1

75

-0.1

27

-0.0

79

-0.0

31

0.0

17

0.0

65

0.1

13

0.1

61

0.2

09

0.2

57

0.3

05

0.3

54

0.4

02

0.4

51

0.4

99

0.5

48

0.5

97

0.6

45

0.6

94

0.7

42

0.7

91

0.8

40

0.8

88

0.9

37

0.9

85

Figure 4: Measured error between ASIN subroutine and standard ASIN instruction in the -1 ÷ +1 range

www.infoPLC.net

Page 7: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 7

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

Requested subroutines

None.

2.5 ATAN

Calculates the arctangent of a REAL value, stored in the ARG global variable,

and outputs the result (in radians) in the RES global variable.

Subroutine definition number: 5.

Operands:

Name Address Type Valid range Descrption

ARG D2021 REAL -3.402823e38 ; +3.402823e38 Argument

RES D2023 REAL -3.141593 ; +3.141593 Result angle(in rad.)

Accuracy:

ATAN vs CJ ATAN

0.0000001

0.000001

0.00001

0.0001

-1E

+06

-1E

+06

-9E

+05

-9E

+05

-8E

+05

-8E

+05

-7E

+05

-7E

+05

-6E

+05

-6E

+05

-5E

+05

-5E

+05

-4E

+05

-4E

+05

-3E

+05

-3E

+05

-2E

+05

-2E

+05

-1E

+05

-69367

-20416

28535

77486

126437

175388

224339

273290

322241

371192

420143

469094

518045

566996

615947

664898

713849

762800

811751

860702

909653

958604

Figure 5: Measured error between ATAN subroutine and standard ATAN instruction in the -106 ÷ +106 range

ATAN vs CJ ATAN

0.000000001

0.00000001

0.0000001

0.000001

0.00001

0.0001

0.001

0.01

-3

-2.9

-2.7

-2.6

-2.4

-2.3

-2.2 -2

-1.9

-1.8

-1.6

-1.5

-1.3

-1.2

-1.1

-0.9

-0.8

-0.7

-0.5

-0.4

-0.2

-0.1

0.0

4

0.1

7

0.3

1

0.4

5

0.5

9

0.7

3

0.8

6 1

1.1

4

1.2

8

1.4

2

1.5

5

1.6

9

1.8

3

1.9

7

2.1

1

2.2

4

2.3

8

2.5

2

2.6

6

2.8

2.9

3

Figure 6: Measured error between ATAN subroutine and standard ATAN instruction in the -3 ÷ +3 range

Requested subroutines

None.

www.infoPLC.net

Page 8: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 8

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

2.6 RAD

Converts a degree-expressed angle stored in the ARG global variable to a

radians-expressed angle in the RES global variable.

Subroutine definition number: 1.

Operands:

Name Address Type Valid range Descrption

ARG D2021 REAL -3.402823e38 ; +3.402823e38 Degrees

RES D2023 REAL -5.93904e36 ; +5.93904e36 Radians

Accuracy:

RAD vs CJ RAD

1E-10

1E-09

1E-08

1E-07

1E-06

1E-05

0.0001

0.001

0.01

0 8

17

25

33

41

50

58

66

75

83

91

10

0

10

8

11

7

12

5

13

3

14

2

15

0

15

9

16

7

17

6

18

4

19

2

20

1

20

9

21

8

22

6

23

4

24

3

25

1

26

0

26

8

27

6

28

5

29

3

30

2

31

0

31

9

32

7

33

5

34

4

35

2

36

0

Figure 7: Measured error between RAD subroutine and standard RAD instruction in the 0° ÷ 360° range

Requested subroutines

None.

2.7 REARG

Calculates the -2π to +2π equivalent of a generic radians-expressed angle;

furthermore it overwrites the output on the same ARG input global variable.

Note: REARG subroutine is for internal use in SIN, COS and TAN subroutines; no

equivalent instruction in the standard instruction set.

Subroutine definition number: 8.

www.infoPLC.net

Page 9: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 9

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

Operands:

Name Address Type Valid range Descrption

ARG D2021 REAL -205887.4 ; +205881.1 Input angle (in rad.)

Requested subroutines

None.

2.8 SQRT

Calculates the square root of a real value stored in the ARG global variable and

outputs the resut in the RES global variable.

Subroutine definition number: 7.

Operands:

Name Address Type Recommended range Descrption

ARG D2021 REAL 0 ; +13000 Input

RES D2023 REAL 0 ; +114.0175 Result

Accuracy:

SQRT vs CJ SQRT

0.0000001

0.000001

0.00001

0.0001

0.001

0.01

0.1

1

10

100

57

5264

10475

15700

20881

26056

31230

36476

41752

47028

52304

57580

62856

68132

73408

78684

83960

89236

94512

99788

105064

110340

115616

120892

126168

131415

136285

141155

146025

150895

155766

160636

165506

170376

175246

180116

184986

189856

194727

199597

204467

Figure 8: Measured error between SQRT subroutine and standard SQRT instruction in the 0 ÷ 2*105 range

www.infoPLC.net

Page 10: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 10

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

SQRT vs CJ SQRT

0.0000001

0.000001

0.00001

0.0001

0.001

0.01

0.1

1

0

322.7

645.3

968

1291

1613

1936

2259

2581

2904

3227

3549

3872

4195

4517

4840

5163

5485

5808

6131

6453

6776

7099

7421

7744

8067

8389

8712

9035

9357

9680

10003

10325

10648

10971

11293

11616

11939

12261

12584

12907

Figure 9: Measured error between SQRT subroutine and standard SQRT instruction in the 0 ÷ 13000 range

(recommended range)

Requested subroutines

None.

NOTE:

Calculations with arguments out of the valid range of use will cause invalid results.

www.infoPLC.net

Page 11: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 11

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

3 PROGRAMMING PROCEDURE

3.1 STEP BY STEP GUIDE

The sequent steps explain the way to insert the math/trig subroutines in a ladder

program.

3.1.1 CREATION OF A NEW PROGRAM WITH MATH LIBRARY

Launch the CP1E_Math.cxp file, eventually renamed, and open the Sezione1

section in the Programma1 main program. If not renamed save it with another

name.

Figure 10: CP1E_Math program view in CX-Programmer

3.1.2 CALLING A SUBROUTINE IN THE MAIN PROGRAM

Before calling the subroutines in the program, you should define an input variable

(the argument of the function) and an output variable to put the result.

In order to call one of the subroutines follow these steps:

1. Copy the input variable content to the ARG variable.*

www.infoPLC.net

Page 12: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 12

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

2. Execute the SBS instruction with the name (or the definition number) of the

desired subroutine to be called;

3. Copy the RES variable content to the defined output variable.*

Figure 11: Calling a subroutine in the program

NOTE:

(*) Use MOVL instruction to copy values, because ARG and RES variables are REAL

(32-bit).

3.1.3 PROGRAM ORGANISATION

Start programming the empty section Sezione1; do not modify the subroutines

sections.

Other sections can be added, but they must be put before the first subroutine

section.

www.infoPLC.net

Page 13: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 13

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

Figure 12: Adding a new section

3.2 RESERVED MEMORY AREAS

The memory channels reserved for the subroutines are:

D2021 – D2022 : ARG data exchange variable from the main program to

the subroutine;

D2023 – D2024 : RES data exchange variable from the subroutine to the

main program;

D2025 – D2047 : Subroutines internal data;

W90 : Subroutines internal data.

3.3 FREEING UP PROGRAM MEMORY

An empty program with all the subroutines described above occupy 1495 steps.

Figure 13: Program memory occupation for CP1E-NA

www.infoPLC.net

Page 14: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 14

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

If some subroutines are unused, it is possible to free up memory by deleting the

correspondent section.

Some of the subroutines, however, are called inside others, so before deleting a

subroutine it is necessary to check the “Requested subroutines” field in the

subroutine reference in paragraph 2, or the following table:

Subroutine

name

Subroutines where

it is called

SIN TAN

COS TAN

TAN

ASIN

ATAN

RAD

REARG SIN, COS, TAN

SQRT

Example: If in a program are used only TAN and COS subroutines, then the

following can be removed: ASIN, ATAN, RAD, SQRT.

3.4 NOTE ABOUT THE EXECUTION TIME

The execution time of mathematical subroutines is generally greater than that of

the same standard instructions, whereby a wide use of these subroutines can

weigh on the program in terms of cycle time slowdown. It is advisable to check

that the final program cycle time respects design specifications.

www.infoPLC.net

Page 15: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 15

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

3.5 EXAMPLE

Calculate the cosine of alpha_deg degree-expressed angle:

Figure 14: Programming example

www.infoPLC.net

Page 16: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 16

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

In the first rung alpha_deg is converted from a degree-expressed to a radians-

expressed angle through the RAD subroutine, then the result is pasted to an

alpha_rad variable, while in the second rung the cosine of alpha_rad is

calculated through the COS subroutine, then the result is pasted to the cos_alpha

variable.

www.infoPLC.net

Page 17: Getting Started Guide MATH AND TRIG FUNCTIONS ON CP1E · PAGINA 3 OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E 1. INTRODU CTION 1.1 SCOPE OF THIS GUIDE The present document is

PAGINA 17

www.omron.it

OMRON PRONTI… VIA! FUNZIONI MATEMATICHE IN CP1E

4 APPENDIX

You can find more documents related to this tool and interesting information

visiting the web site www.myomron.com.

www.infoPLC.net