Você está na página 1de 116

Instruction Bulletin

63230-300-221/A1
February 2002
LaVergne, TN, USA
POWERLOGIC

Series 4000 Programming Language


(CMPL)
63230-300-221/A1
2/2002
ii 2002 Schneider Electric All Rights Reserved
63230-300-221/A1 Contents
2/2002
iii 2002 Schneider Electric All Rights Reserved
CONTENTS CHAPTER 1INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
WHAT IS THE CIRCUIT MONITOR
PROGRAMMING LANGUAGE UTILITY? . . . . . . . . . . . . . . . . . . . . . . . . . . 1
A WORD OF CAUTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
ORGANIZATION OF THIS INSTRUCTION BULLETIN . . . . . . . . . . . . . . . 2
Notational Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
TECHNICAL SUPPORT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CHAPTER 2CREATING A PROGRAMMING LANGUAGE
SOURCE FILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
THE CIRCUIT MONITOR PROGRAMMING LANGUAGE . . . . . . . . . . . . . 5
CREATING A SOURCE FILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Naming the Source File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Inserting Comments and Blank Lines . . . . . . . . . . . . . . . . . . . . . . . . . 6
Source File Line Limit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Case Sensitivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
REQUIRED ELEMENTS IN A SOURCE FILE . . . . . . . . . . . . . . . . . . . . . . 6
Program Version/Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
The Declaration Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The Initialize Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
The Metercycle Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
OTHER ELEMENTS IN A SOURCE FILE . . . . . . . . . . . . . . . . . . . . . . . . . 9
Timer and Event Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Timer Task Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Event Task Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
ORDER OF EXECUTION OF CMPL PROGRAM ELEMENTS . . . . . . . . 13
Posting of Program Name and Program Version . . . . . . . . . . . . . . . 13
Initialize Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Metercycle Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Event and Timer Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Possible Program Termination Due To Excessive Scan Time . . . . . 14
CHAPTER 3DEFINING MEMORY REGISTERS IN THE
DECLARATION SECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
CM4000 MEMORY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
MODBUS Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
DECLARING DATA VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Assigning a Name to a Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
ARRAYS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Declaring an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
REDEFINING A REGISTER WITH EQUATE . . . . . . . . . . . . . . . . . . . . . . 18
CREATING CONSTANTS WITH DEFINE . . . . . . . . . . . . . . . . . . . . . . . . 19
A SAMPLE DECLARATION SECTION . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Contents 63230-300-221/A1
2/2002
iv 2002 Schneider Electric All Rights Reserved
CHAPTER 4THE CIRCUIT MONITOR
PROGRAMMING LANGUAGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
ASSIGNING VALUES TO DATA ITEMS . . . . . . . . . . . . . . . . . . . . . . . . . 21
Assigning Constant Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Assigning Variables to Other Data Items . . . . . . . . . . . . . . . . . . . . . . 23
MATHEMATICAL AND LOGICAL OPERATIONS . . . . . . . . . . . . . . . . . . 23
Add, Subtract, Multiply, Divide, Modulus . . . . . . . . . . . . . . . . . . . . . . 24
Logical Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Bitwise Shifts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Logical Shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Arithmetic Shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
TRIGONOMETRY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Sine, Cosine, Arctan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Square Root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
CONVERTING DATA TYPES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
CONTROL OF PROGRAM EXECUTION . . . . . . . . . . . . . . . . . . . . . . . . . 31
Conditional Execution Using IF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Repeated Execution Using FOR...NEXT . . . . . . . . . . . . . . . . . . . . . . 33
Subroutine Execution Using CALL . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Terminating a Task or Subroutine Using RETURN . . . . . . . . . . . . . . 34
Terminating a CMPL Program Using HALT . . . . . . . . . . . . . . . . . . . . 35
Restarting a CMPL Program Using RESTART . . . . . . . . . . . . . . . . . 35
CONTROL OF THE CIRCUIT MONITOR USING CMDREQ . . . . . . . . . . 35
CONTROL OTHER DEVICES USING COMMSREQ . . . . . . . . . . . . . . . . 35
Communication Control Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
CHAPTER 5COMPILER OPERATION . . . . . . . . . . . . . . . . . . . . . . . . . 39
STARTING THE PROGRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
OPENING A SOURCE FILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
SETTING COMMUNICATION PARAMETERS . . . . . . . . . . . . . . . . . . . . . 40
SETTING THE ENVIRONMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Formatting the Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Setting the Background or Text Color . . . . . . . . . . . . . . . . . . . . . . . . 41
Changing the Tab Width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Setting the Save Reminder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
SETTING THE COMPILER OPTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Turning Output Generation On and Off . . . . . . . . . . . . . . . . . . . . . . . 42
Compiling/Assembling a .src File . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
DOWNLOADING AND VIEWING THE CMPL PROGRAM . . . . . . . . . . . . 43
Downloading the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Verifying the Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Viewing Circuit Monitor On-Board Information . . . . . . . . . . . . . . . . . . 44
RUNNING AND DEBUGGING THE PROGRAM . . . . . . . . . . . . . . . . . . . 44
Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Using the Compiler to Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Viewing the CMPL Program Memory . . . . . . . . . . . . . . . . . . . . . . . . . 46
Reading and Writing to Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
63230-300-221/A1 Contents
2/2002
v 2002 Schneider Electric All Rights Reserved
CHAPTER 6RUNNING A PROGRAM . . . . . . . . . . . . . . . . . . . . . . . . . 47
PREPARING TO RUN A PROGRAM: READING AND WRITING
CM4000 REGISTERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
VERIFYING PROGRAM DOWNLOAD . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
SETTING REGISTERS BEFORE PROGRAM EXECUTION . . . . . . . . . . 48
RUNNING AND HALTING A PROGRAM . . . . . . . . . . . . . . . . . . . . . . . . . 48
CHAPTER 7DEBUG TECHNIQUES FOR CMPL PROGRAMS . . . . . 51
EXAMINING PROGRAM CONTROL REGISTERS . . . . . . . . . . . . . . . . . 51
USING RUNTIME ERROR CODES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
DETERMINING THE NAME, VERSION, AND DATE OF A PROGRAM . 51
DETERMINING THE EFFECTS OF CUSTOM CODE ON THE TOTAL
METER CYCLE TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
INSERTING A DEBUG CODE INTO A PROGRAM . . . . . . . . . . . . . . . . . 53
APPENDIX APROGRAMMING LANGUAGE RESERVED WORDS . . 55
APPENDIX BPROGRAMMING LANGUAGE SYNTAX . . . . . . . . . . . . 57
APPENDIX CPROGRAMMING LANGUAGE ASSEMBLER
AND COMPILER ERROR CODES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
APPENDIX DPROGRAMMING LANGUAGE RUNTIME
ERROR CODES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
APPENDIX ESAMPLE PROGRAM LIBRARY . . . . . . . . . . . . . . . . . . . 65
APPENDIX FCMPL CONTROL REGISTER LIST . . . . . . . . . . . . . . . . 91
APPENDIX GALARMS (EVENTS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
APPENDIX HPROGRAMMING TIPS . . . . . . . . . . . . . . . . . . . . . . . . . 101
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Contents 63230-300-221/A1
2/2002
vi 2002 Schneider Electric All Rights Reserved
63230-300-221/A1 Chapter 1Introduction
2/2002 What is the Circuit Monitor Programming Language Utility?
1 2002 Schneider Electric All Rights Reserved
CHAPTER 1INTRODUCTION
This chapter defines the Circuit Monitor Programming Language utility and
describes the uses for which it is intended. The last sections of the chapter
describe this manual and explain terms and notation conventions used
throughout.
WHAT IS THE CIRCUIT MONITOR
PROGRAMMING LANGUAGE UTILITY?
The Circuit Monitor Programming Language (CMPL) is a tool designed to
tailor the capabilities of the Series 4000 Circuit Monitor to meet specialized
application requirements. Based on external, timer, or metercycle events,
CMPL provides a means for the end user to customize the following:
data calculation
logging and reporting
I/O point operation
remote device communication
command interface control
Using the Windows-based compiler environment included in the CMPL
Developers Kit, you can develop and test application-specific firmware for the
circuit monitor. Once you are satisfied with the program you develop, you can
use the POWERLOGIC Downloadable Firmware Utility (DLF-3000, version
3.0 or higher) to install it in a circuit monitor.
A CMPL program is capable of reading data from registers within the circuit
monitor and from devices on a communications daisy chain. It can also sense
external events that pass from true to false or the reverse.
Processing this information according to the instructions in the source
program, a custom program can control output relays, write values to a range
of registers designated for that purpose, and write entries into a data log or
waveform capture files.
When you purchase CMPL, you receive:
the CMPL compiler program that runs on a personal computer (with the
Microsoft Windows NT or 2000 operating system)
this instruction bulletin
a help file that contains instructions for creating and executing CMPL
program files
example files
A WORD OF CAUTION CMPL provides rapid, flexible responses to customer needs. However, critical
control functions should be provided by specialized equipment designed for a
specific purpose and tested for reliability. Users should not use CMPL to
replace sophisticated equipment engineered for and dedicated to control
tasks.
Application engineers who use CMPL must verify that their programs
accurately solve the problems they address. This manual surveys the
programming tools available and explains debug facilities that can verify
logical operations while programs are executing. However, since the creators
of CMPL cannot anticipate all of its possible uses, application engineers using
this product must ensure the accuracy of the programs they wish to include in
the circuit monitor.
Chapter 1Introduction 63230-300-221/A1
Organization of this Instruction Bulletin 2/2002
2002 Schneider Electric All Rights Reserved 2
Pay particular attention to the time constraints beyond which CMPL
programs will be terminated to preserve the integrity of other circuit monitor
operations. Most standard circuit monitor operations may be configured by
the user, and some features may be entirely disabled. Therefore, the amount
of free (or idle) time available to CMPL will vary widely from one circuit
monitor to the next. In most cases, a CMPL program should not be placed in
a circuit monitor that is configured to execute many of the advanced features,
such as CVMT analysis, WFC of several types with high sample rates, and a
large number of subcycle events. Worst-case conditions for both the time
required to execute custom programs and the memory used by each
program should be tested.
ORGANIZATION OF THIS INSTRUCTION
BULLETIN
This bulletin provides the information necessary to write, compile, load, and
run custom circuit monitor programs. The bulletin includes seven chapters
and eight appendixes. There is a table of contents for the entire manual at
the beginning of the document.
The first four chapters describe CMPL and explain procedures and
requirements for writing custom programs. Chapters 5 and 6 describe how to
compile, load, and run a program, and how to read output values. Chapter 7
explains debugging methods.
The appendixes provide additional programming language information with
a listing of reserved words, a language syntax outline, compiler and runtime
error codes, and a library of sample programs. A supplemental guide to the
CM4000 registers that pertain to CMPL is included.
This manual includes only minimal technical specifications and functional
information for the CM4000 circuit monitor. It does not include
comprehensive coverage of DLF3000 or any of several available user
interfaces to the circuit monitor. For complete information on these topics,
see the appropriate technical publications.
Notational Conventions To more easily distinguish CMPL commands from explanatory text, this
document uses the following notational conventions:
Type Style. A typewriter-style type face is used for text that is typed into
the computer by the programmer, such as programming commands,
variable names, and control directives. In the program examples, words
and characters displayed in boldface are required instructions for the
program. Two forward slashes (//) represent the beginning of comments.
Comments, in a different type style, are not required.
Example 1-1
data_float = 0.0 //Sets data_float to zero
(required program line) (commentnot required)
Brackets. The syntax for some CMPL commands allows for assignment
of multiple values or parameters. These values are indicated inside
brackets ([]) as a way of showing they are optional. The brackets
themselves are not included in the code.
Example 1-2
The format for a DEFINE is as follows:
DEFINE value_name value [value] [value]
63230-300-221/A1 Chapter 1Introduction
2/2002 Technical Support
3 2002 Schneider Electric All Rights Reserved
Actual program lines might be:
The values assigned to end_date are separated by at least one space. The
brackets are not included.
Capitalization. Program examples are shown using both upper- and
lower-case letters. CMPL is not case sensitive and will accommodate
each programmers preference. For example, the compiler sees
END_date and end_Date as the same.
TECHNICAL SUPPORT Programming services, programming instruction, and POWERLOGIC
training classes are available for a fee. Contact your local representative for
information on any of these services. Or visit our website at:
www.powerlogic.com
DEFINE True 1
DEFINE end_date 0x090e 0x5e0b 0x0f27 0x0064
Chapter 1Introduction 63230-300-221/A1
Technical Support 2/2002
2002 Schneider Electric All Rights Reserved 4
63230-300-221/A1 Chapter 2Creating a Programming Language Source File
2/2002 The Circuit Monitor Programming Language
5 2002 Schneider Electric All Rights Reserved
CHAPTER 2CREATING A PROGRAMMING LANGUAGE SOURCE FILE
This chapter describes the structure of the Circuit Monitor Programming
Language (CMPL) and tells how to create a source file using the language.
THE CIRCUIT MONITOR
PROGRAMMING LANGUAGE
CMPL is similar to the BASIC language used to program computers. It
performs integer and floating-point math, including square root and the basic
trigonometric functions. Its syntax allows looping and conditional execution.
Custom programs written with this language can read from and write to
registers within the CM4000 circuit monitor and remote devices, and can test
circuit monitor events.
Because CMPL contains features that resemble BASIC and other languages
used in general-purpose computer programming, experience with any high-
level computer language will benefit engineers who begin to write custom
programs for the CM4000 circuit monitor. Training in some form of computer
programming will make the methods outlined here seem familiar and is highly
recommended.
As illustrated in Figure 21, implementing a CMPL program requires three
steps:
1. Create a source program file using the CM4000PL compiler editor on a
Microsoft Windows based computer (Windows NT or 2000).
2. Use the CM4000PL compiler to convert the source program file into
instructions that can be executed by the CMPL function of the circuit
monitor.
3. Download the instructions created in Step #2 to the circuit monitor disk
on chip using the POWERLOGIC Downloadable Firmware Utility (DLF-
3000 v. 2.02 or higher) provided with the CM4000 Program Developers
Kit. Or, for testing purposes, download the program using the CM4000PL
compiler/debugger to the circuit monitor random access memory (RAM).
source file
.fw file download
PROG.SRC
CMPL
compile
PROG.lst
DLF3000
compile
compiler listing file
debug
(CMPL.dbg)
PROG.fw
Figure 21: Implementing a CMPL Program
CMPL
compile
Chapter 2Creating a Programming Language Source File 63230-300-221/A1
Creating a Source File 2/2002
2002 Schneider Electric All Rights Reserved 6
CREATING A SOURCE FILE A CMPL source file contains a series of instructions written according to the
rules given in this manual. (For details, see Chapter 3, beginning on page 15,
and Chapter 4, beginning on page 21.) These instructions consist of simple
English commands and terms relating to the operation of the circuit monitor
and to its internal registers.
Naming the Source File Use standard Windows file-naming conventions (one to 256 characters in
length using letters, numbers, underscores, and selected symbols). The
CMPL compiler requires a filename extension of .SRC. (Files created in the
editor/compiler automatically include the .SRC extension when they are
saved.) Example 2-1 illustrates a correctly named source file.
Example 2-1
PROG_01.SRC
Inserting Comments and Blank Lines Comments and blank lines are not required but will help to clarify and
document a program. The CMPL compiler ignores blank lines and lines that
begin with two right slant characters (//). Inserting the two / characters in the
middle of a line makes the remainder of that line a comment that will also be
ignored. (There must be at least one blank space between the source code
and the beginning of the comment.) Be sure to use two right slant characters
and not two left slant characters (\\).
Blank lines help to clarify a program by separating different logical sections.
Inserting blank space will make any program easier to read.
Use comment lines to label each section of a program or to explain program
logic. Comments serve as reminders and are useful to other programmers
who need to understand or modify the original program.
Source File Line Limit A line of code can contain up to 200 characters. Each source file must
contain no more than 32,767 lines. Blank lines and lines containing
comments are included in this number. However, this is a very large number
of lines, and the limit is not likely to restrict any program.
Case Sensitivity CMPL is not case sensitive. Use lower or upper case letters or any
combination of the two.
Examples in this manual show some lines in lower case and some in all caps.
These are only suggestions used to clarify program elements. Different
patterns of capitalization are possible-depending on each programmers
preference.
REQUIRED ELEMENTS IN A SOURCE
FILE
See the following sections for descriptions of the required elements in CMPL
programs:
Program Version/Security on page 7
The Declaration Section on page 8
The Initialize Task on page 9
The Metercycle Task on page 9
Include these in this order in each source file. Mark each of these sections
by inserting lines beginning with two pound sign characters (##). All lines
63230-300-221/A1 Chapter 2Creating a Programming Language Source File
2/2002 Required Elements in a Source File
7 2002 Schneider Electric All Rights Reserved
beginning with the ## notation are called control directives. See Example
2-2.
The first two required sections have one line. The other three required
sections must contain two control directives, and the two tasks must also
contain at least one instruction line. The minimum entries required for these
sections follow:
Example 2-2
## PROGRAM SECURITY: 1234567
## PROGRAM VERSION: 1234
## DECLARATION SECTION:
## END DECLARATION
## INITIALIZE TASK:
RETURN
## END INITIALIZE
## METERCYCLE TASK:
RETURN
## END METERCYCLE
Notice that the first line of each pair of control directives ends with a colon (:),
and that there is a space following the ## notation. These are required. Also
notice that the instruction RETURN appears in each task. It must appear
between the control directives that mark the beginning and end of the
initialize task, and of the Metercycle task. This is true even though there are
no other instructions within the task sections.
The source file lines shown above will do no useful work, but they illustrate
the shortest possible example of a program that will compile into
downloadable instructions without error.
Program Version/Security he Program Version code is required. It has two purposes:
DLF-3000 uses it to verify downloads.
Programmers use it to identify program changes.
The program name, which is optional, and version must be entered before
the declaration section in the formats given below:
Each entry must be on a separate line that begins with the ## notation (with
a blank space following the colon and the ##) reserved for control directives.
These are the only lines, besides comments and blank lines, that can appear
before the required declaration section. They can be very useful. Values
entered here are placed in designated circuit monitor registers when 1 or 5
## PROGRAM NAME: name_of_program //optional
## PROGRAM VERSION: number_of_version //required
where name_of_program contains up to 16 ASCII characters (letters, numbers,
or punctuation)
and number_of_version is a decimal integer in the range 0 to 9999
Chapter 2Creating a Programming Language Source File 63230-300-221/A1
Required Elements in a Source File 2/2002
2002 Schneider Electric All Rights Reserved 8
is entered in register 8189. They provide a convenient way to determine
which version of which program is currently installed and ready for execution.
NOTE: The program name is stored in registers 81758182. The version
number of the program is stored in register 8183.
In Example 2-6, note that, by convention, an integer value of 100 denotes
version 1.00; 101, version 1.01; and so on.
Example 2-6
The Program Security code is used in conjunction with the circuit monitor
revenue security. If revenue security is enabled, the CMPL Program Security
section is required (by the circuit monitor). If revenue security is disabled, set
Program Security to 0. When enabled, programmers can only access circuit
monitor functions allowed by their security level.
The Declaration Section The declaration section of a custom program defines the circuit monitor
registers used by that program to store data or to read data generated by
other circuit monitor functions. Because the declaration section contains
definitions and declarations instead of instructions, it does not require a
return instruction. Like other required sections, however, it does require two
control directives to mark the beginning and end of the sectioneven in the
unlikely event that there are no declarations included.
The declaration section must be the first major section in the source file. Only
the program security, program name, and program version lines can appear
before the data declarations.
Lines in Example 2-3 and the examples that follow are marked with the
comment Example of Entry and illustrate typical entries in the various
program sections. These lines are not required and only represent a sample
of the types of entries that can appear in these sections. The instructions
used are explained in Chapter 3, beginning on page 15, and in Chapter 4,
beginning on page 21. As given here, they are not a part of any specific
program.
The control directives beginning with ## are required parts of any CMPL
program. There must be a colon at the end of the control directive that begins
each of these sections. There must be a blank space following the ##
notation and between the elements of all lines of code (e.g., between
REGISTER and cyclecount in the second line of Example 2-3).
## PROGRAM NAME: CMPL_EXAMP1 //Name is CMPL_EXAMP1
## PROGRAM VERSION: 101 //Version is 1.01
63230-300-221/A1 Chapter 2Creating a Programming Language Source File
2/2002 Other Elements in a Source File
9 2002 Schneider Electric All Rights Reserved
Example 2-3
The Initialize Task The initialize task must immediately follow the declaration section. It begins
and ends with required control directives, and its beginning line must end
with a colon. Instructions within this section execute only when a custom
program is initiated or restarted.
The CMPL compiler requires two control directives and a return instruction
for the initialize task section, even if there are no other instruction lines in the
section.
Example 2-4
The Metercycle Task The metercycle task section must immediately follow the initialize task. It
begins and ends with control directives, and its beginning line must end with
a colon. Instructions within this section execute as a part of each 1-second
meter cycle update.
The CMPL compiler requires two control directives and a return instruction
for the metercycle task, even if there are no other instruction lines in the
section.
Example 2-5
OTHER ELEMENTS IN A SOURCE FILE The CMPL compiler requires that the program version, program security (if
using revenue security), declaration section, initialize task, and metercycle
task be in every source code file, but it also permits other kinds of tasks and
allows embedding of program name and version information.
Timer and Event Tasks The timer task and event task sections use the same format as the initialize
task and metercycle task. The timer and event task sections must follow the
metercycle task section and must precede any subroutines that may be
used. (See the Subroutines section in this chapter.) As with the required
tasks, each optional task section must begin and end with a control directive
## DECLARATION SECTION: //Required Line
REGISTER cyclecount S14090 //Example of Entry
REGISTER stepcnt S14091 //Example of Entry
BITREG Inputvals S10022 //Example of Entry
## END DECLARATION //Required Line
## INITIALIZE TASK: //Required Line
cyclecount = 0 //Example of Entry
return //Required Line
## END INITIALIZE //Required Line
## METERCYCLE TASK: //Required Line
cyclecount = cyclecount + 1 //Example of Entry
return //Required Line
## END METERCYCLE //Required Line
Chapter 2Creating a Programming Language Source File 63230-300-221/A1
Other Elements in a Source File 2/2002
2002 Schneider Electric All Rights Reserved 10
(indicated by ##) and must contain at least one return command at the end
of the event task or the timer task.
A program can contain more than one timer task and more than one event
task. Each must specify the elapsed time or the event that will trigger its
execution. The number of timer and event task sections, taken together, may
not exceed 36.
The instructions within a timer task or an event task execute during the
current meter cycle in which the time lapse or the trigger event specified
occurred. When more than one section is performed during a single meter
cycle, they execute in the order that they appear in the program source file.
Timer Task Format The control directive that begins each timer task must be in one of the
following two formats, indicating the time that must elapse before the task is
performed:
The first format measures seconds elapsed, and the second format
measures both elapsed time and offset in minutes. The offset value is
measured from midnight (12:00 a.m.) every day. For example, if a timer task
were to execute beginning at 8:00 a.m. each day, an offset of 480 minutes
would be required. After 8:00 a.m. the timer task is executed at the specified
interval until 11:59 p.m.
Vary the value of the offset in the second format when a program contains
more than one timer task with the same time interval delay. Otherwise, all of
the tasks with the same interval will occur in the same meter cycle. The end
of each timer task must be marked by a control directive like this:
## END TIMER
Each timer task section must also include at least one return instruction at
the end of the timer task.
Example 2-7
## TIMER TASK: INTERVAL x SECONDS
where x is a decimal integer in the range 1 to 32767
or
## TIMER TASK: INTERVAL x MINUTES OFFSET y MINUTES
where x is a decimal integer in the range 1 to 1440
and y is a decimal integer in the range 0 to 1439
## TIMER TASK: INTERVAL 45 SECONDS //Required Line
if (event2state = false) //Example of Entry
{ //Example of Entry
false_count = false_count + 1 //Example of Entry
} //Example of Entry
return //Required Line
## END TIMER //Required Line
63230-300-221/A1 Chapter 2Creating a Programming Language Source File
2/2002 Other Elements in a Source File
11 2002 Schneider Electric All Rights Reserved
Example 2-8
Event Task Format Event tasks all begin with a control directive in one of the following formats:
Each event task section must terminate with a control directive in this format:
## END EVENT
Each event task must also contain at least one return instruction at the end
of each event task. Examples 2-9 and 2-10 illustrate event tasks.
## TIMER TASK: INTERVAL 1 MINUTES OFFSET 0 MINUTES //Required
if (event2state = false) //Example
{ //Example
false_count = false_count + 1 //Example
} //Example
return //Required
## END TIMER //Required
## EVENT TASK: EVENT event_number FALSE-TO-TRUE
or
## EVENT TASK: EVENT event_number TRUE-TO-FALSE
where event_number is a decimal integer used to refer to a legal CM-4000 event
(See Appendix G, Alarms (Events), for information on how to set up user-
defined alarms. See Table 21 below for valid event numbers.)
Table 21:Valid Event Numbers
Event No.
1
Description
10011080 Normal alarms
20012020 High speed alarms
30013020 Disturbance alarms
40014040 Digital alarms
50015015 Boolean alarms
60016004 Waveshape fault alarms
7001 Transient alarm
1 Event numbers contain two pairs of digits:
The first pair describes the alarm type. 10 = standard, 20 = high-speed, etc.
The second pair describes the alarm position for that alarm type. By default, 01 = over
current phase A for standard-speed alarms, and 01 = voltage swell A-D for disturbance
alarms. However, keep in mind that you can change the defaults.
Chapter 2Creating a Programming Language Source File 63230-300-221/A1
Other Elements in a Source File 2/2002
2002 Schneider Electric All Rights Reserved 12
Example 2-9
Example 2-10
NOTE: Before an event task program can be executed, the event must be
enabled using POWERLOGIC application software (such as SMS-3000), or
through Setup > Alarms on the circuit monitor display.
Subroutines Subroutines use the same format as other sections containing instructions
and must follow all other sections in the source file. The number of
subroutines is limited only by the memory available to the CMPL program.
Each subroutine begins with a control directive that assigns it a unique name
and concludes with another control directive marking the end of the
subroutine. The required format for the control directives that define a
subroutine is as follows:
Each subroutine must also contain at least one return instruction at the end
of the section.
The instructions in a subroutine execute each time it is called by name from
within any task section or from another subroutine. (For details, see
Subroutine Execution Using CALL on page 34.) After the completion of a
subroutine, the task or other subroutine that called it continues its execution
beginning with the line immediately following the subroutine call.
Example 2-11
You can use subroutines to reduce the total number of program lines
required. For example, if a sequence of instructions more than two or three
lines in length appears in two or more different task sections, or if such a
sequence is written more than once in a single section, replace the sequence
with a subroutine.
## EVENT TASK: EVENT 1002 FALSE-TO-TRUE //Required Line
event1002 = event1002 + 1 //Example of Entry
return //Required Line
## END EVENT //Required Line
## EVENT TASK: EVENT 1002 TRUE-TO-FALSE //Required Line
event1002 = event1002 + 1 //Example of Entry
return //Required Line
## END EVENT //Required Line
## SUBROUTINE: subr_name
## END SUBROUTINE
where subr_name is a unique name by which this subroutine is called. This
name can contain up to 27 letters, numbers, and underscore characters.
No other punctuation or characters may be used.
## SUBROUTINE: COMPUTE_TOTAL_CURRENT //Required Line
totalamps = ia + ib + ic //Example of Entry
return //Required Line
##END SUBROUTINE //Required Line
63230-300-221/A1 Chapter 2Creating a Programming Language Source File
2/2002 Order of Execution of CMPL Program Elements
13 2002 Schneider Electric All Rights Reserved
Experienced programmers who prefer to use structured techniques to
organize their programs will also find subroutines useful. Note that all data
items are global in scope, and that subroutines and all other tasks access all
values by direct address.
Subroutines can contain instructions to call other subroutines. The CMPL
compiler permits up to eight layers of nesting of subroutines within other
subroutines.
ORDER OF EXECUTION OF CMPL
PROGRAM ELEMENTS
CMPL program elements execute in the following order (described in the
following paragraphs):
program name and version
initialize task
metercycle task
event and timer tasks
subroutines
NOTE: A CMPL program downloaded to a CM4000 circuit monitor, using the
Downloadable Firmware Utility (DLF-3000), remains inactive until a register
is set or a compiler command is issued to run the program.
Posting of Program Name and Program
Version
If the program name or the program version are included in the source file,
their values are inserted into specific circuit monitor registers at the time the
custom program is downloaded. This permits users to see what custom
program is installed in the circuit monitor even when the program logic is not
being executed.
Initialize Task When program execution first occurs, the instructions in the initialize task
section execute, followed by those in the metercycle task section and then
any appropriate timer task or event task sections. The initialize task section
does not execute again until the custom program is halted and restarted.
(Loss of control power or any reset of the circuit monitor will cause a program
to halt.)
Metercycle Task The instructions within the metercycle task section are the first to be
performed except in the first meter cycle of program operation. Only in the
very first meter cycle does the initialize task section execute first.
Event and Timer Tasks The instructions in the event task and timer task sections, if any, execute after
the metercycle task instructions if their specific event or timer conditions are
met. For example, if an event occurs for which an event task exists, the
instructions in that event task will execute following the metercycle task
during the current meter cycle.
Similarly, if a time interval specified by a timer task has elapsed (plus any
specified offset), the instructions in that timer task will execute following the
metercycle task instructions during the current meter cycle. If coincidence or
design causes more than one timer task or event task to be eligible for
execution during the same meter cycle, the tasks will be completed in the
order in which they appear in the program source file.
Until program execution is halted, the instructions in all of the task sections
are considered for execution during each meter cycle in the circuit monitor.
Event tasks and timer tasks will likely not all be executed during each meter
Chapter 2Creating a Programming Language Source File 63230-300-221/A1
Order of Execution of CMPL Program Elements 2/2002
2002 Schneider Electric All Rights Reserved 14
cycle, but they will be considered for execution each time in the order in which
they appear in the source file. Instructions in the metercycle task will be
executed each time unless they are prevented by the logic in the metercycle
task instructions themselves.
Subroutines Instructions within subroutine sections execute only when called from inside
other sections. They may occur many times during a single meter cycle or
they may not be performed at all, depending upon logic that appears in other
sections of the program.
Possible Program Termination Due To
Excessive Scan Time
Terminated programs will not automatically restart, and forced termination
can cause a failure to collect expected data or perform programmed
operations.
Program designers must consider that simultaneous triggering of timer and
event task sections, in addition to the regularly performed metercycle task
section, may increase program execution time during specific meter cycles.
Invoking too many instructions during a single cycle could force the
unexpected termination of the entire custom program. Overly complex
programs may not be allocated sufficient processing time to complete all
tasks. These programs will be terminated because of excessive scan time,
and will generate runtime error 1101 or 1102. These errors may also be
caused by a logic error, such as endless loops, in the program.
63230-300-221/A1 Chapter 3Defining Memory Registers in the Declaration Section
2/2002 CM4000 Memory
15 2002 Schneider Electric All Rights Reserved
CHAPTER 3DEFINING MEMORY REGISTERS IN THE DECLARATION SECTION
This chapter describes the storage registers available in the CM4000 circuit
monitor for access by the Circuit Monitor Programming Language (CMPL)
utility. It tells how to use the Declaration section of a CMPL program to make
the registers available for use within that program.
CM4000 MEMORY The circuit monitor contains both a program memory area and an extended
series of data registers. Program memory is an extension of the circuit
monitors operating system. The POWERLOGIC DLF-3000 Downloadable
Firmware Utility (DLF-3000) will insert instruction codes (created from
source program files by the language compiler) into the program memory
area. This is also how a compiled custom program is installed in the circuit
monitor.
Data registers are storage areas used by custom programs or by other
functions within the circuit monitor. Some registers contain information
generated by specific circuit monitor functions. A CMPL program can read
from any of these registers but cannot write data into them. Other registers
(read/write registers) are designated specifically for use by custom programs
and are available for the long- or short-term storage of data.
The register read/write capability of POWERLOGIC application software,
such as SMS-3000, allows users to communicate commands to the circuit
monitor by writing to a small number of registers. Each register contains 16
data bits and corresponds to what experienced programmers will recognize
as a 16-bit word of accessible memory.
MODBUS Registers MODBUS registers are available both to CMPL programs and to other circuit
monitor functions. They are addressed by the letter S followed by a 4- or
5-digit number in the range 1000 through 65535.
Many of these registers are CMPL volatile registers (S40000S41999),
meaning that a loss of power erases the values stored there. The CMPL non-
volatile registers that are both read from and written to by custom programs
are S14000 through S14499.
Both sets of registers are reserved for the exclusive use of the CMPL
function. They serve both as information storage during the execution of a
program and as the principal means of communication between CMPL
programs and any external user interface.
DECLARING DATA VARIABLES Before a custom program can read from or write to any register, the register
must be assigned a name in the declaration section of that program. Any
declaration of a name for a register must also give the data type to be
associated with that name. The choice of data type determines the uses that
can be made of any declared register by the custom program.
Table 31 on page 16 shows the types of data that can be declared in CMPL.
It defines the range of values permitted for each type and suggests some
potential uses for each. It also shows the number of registers required to
support that data type.
Some data types require only one register. Others require two or more. If, for
example, register S14001 is defined as a data type requiring two registers,
then register S14002 is included in the definition although it is not mentioned
by name.
Chapter 3Defining Memory Registers in the Declaration Section 63230-300-221/A1
Declaring Data Variables 2/2002
2002 Schneider Electric All Rights Reserved 16
Assigning a Name to a Register There is one form of declaration that assigns a name and a data type to a
register. It must be written on a single line and has the following format:
data_type name_of_register
The data type chosen determines the possible uses of this data item.
Throughout the custom program that uses this declaration, the name of the
data item will be the same as the register name used in the declaration. Data
types requiring more than one register are known only by the register name
used in the declaration.
A more advanced form of declaration makes it possible to label data items
with names that are easier to remember or understand. These names are
sometimes called variable names or just variables to parallel the use of
variables in many computer programming languages. CMPL data items can
refer to read-only registers as well as read/write registers.
Declarations of these names are also entered on a single line and have the
following format:
Using this format to declare data items makes programs more easily
understood by those without a complete knowledge of the circuit monitor
registers. Using descriptive variable names also simplifies the programmers
task by replacing register addresses with meaningful terms that are easier to
remember.
Table 31:Data Types
Data Type Range of Values
Required
Registers
Description of Use Existing Use in CM-4000
REGISTER 32768 to +32767 1 Signed integer values
within permitted range
Amperes, Volts
BITREG 16 single-bit values 1 Logical flags or switches I/O or status flags
LONGREG 2,147,483,648 to +2,147,483,647 2 Large signed integers
FLOAT 1.2 E 38 to 3.4 E +38 2 Floating point values to
7 digits of precision
POWFACT 0.999 to +1.000 1 Power factors Power factors
MOD10L2 9999 9999 to +9999 9999 2 Signed counters to 8 digits Digital input operation
counter
MOD10L3 9999 9999 9999 to +9999 9999 9999 3 Signed counters to 12 digits Energy
MOD10L4 9999 9999 9999 9999 to +9999 9999 9999 9999 4 Signed counters to 16 digits Energy
DATETIME 1/1/2000 00:00:00 to 12/31/2099 23:59:59 4 Date and time accurate to
nearest second
D/T of events, resets,
min/max demand, etc.
data_type name_of_variable name_of_register
where data_type is the name of any valid data type
name_of_variable is an easily understood and remembered
name consisting of up to 27 letters, numbers, and underscores
and name_of_register is the name (beginning with S) of any
register
63230-300-221/A1 Chapter 3Defining Memory Registers in the Declaration Section
2/2002 Arrays
17 2002 Schneider Electric All Rights Reserved
To parallel the earlier example, the following declaration defines a variable
named max_value of type FLOAT that occupies register S14000 and, by
extension, register S14001 (because variables of type FLOAT require two
register).
Example 31:
Throughout a program that uses this declaration, this data item can be
referred to by the variable name max_value or by the register name
S14000. The register address S14001 is also defined and cannot be used for
any other purpose. S14001 is not a legal name for this data item.
ARRAYS CMPL permits the declaration of arrays of up to 256 data items. Each data
item in an array is of the same type. All items in an array have the same
name. A reference to a specific member in the array consists of the variable
name or register name used to declare the array plus an integer in the range
1 to 256 contained in square brackets ([]). The integer value indicates which
of the entries in the array is intended.
Indicate the total number of entries in each array as a part of its declaration.
Arrays can contain up to 256 data items, but it is common to have fewer. For
example, the following line declares an array of 10 variables. The array is
named sample_array and each of its ten members is a separate data item
having a data type of FLOAT.
Example 32:
Within a custom program that uses this declaration, the 10 individual data
items will be called sample_array[1], sample_array[2], and so on.
Each data item of type FLOAT requires two registers, so this declaration of
10 items requires a total of 20 registers. The array sample_array uses
twenty registers beginning with S14000 and extending through S14019.
These registers are not available for other uses within the custom program
that contains this declaration.
Arrays are useful in more advanced programs that compute the value of the
number in square brackets (sometimes called a subscript or index) while the
program is running. This permits a program to write to or read from different
parts of an array under different conditions that occur during the programs
execution.
FLOAT max_value S14000 //S14000 and S14001
FLOAT sample_array[10] S14000
Chapter 3Defining Memory Registers in the Declaration Section 63230-300-221/A1
Redefining a Register With Equate 2/2002
2002 Schneider Electric All Rights Reserved 18
Declaring an Array Declare an array as you would a simple data item and insert the value
indicating the number of array entries into the declaration formats as follows:
NOTE: The array index, n, cannot be a mathematical expression, such as
(value + 1); n must be a decimal integer.
Access members of an array using either the array name and the subscript
(as in sample_array[3]) or the declared register name and the subscript
(as in S14000[3]). Use either of these when the declaration is in the first
format and includes both an array name and a register name.
REDEFINING A REGISTER WITH
EQUATE
Never declare any data register as a part of more than one data item;
doing so will cause a compiler error. Take care when using data types
that require more than one register or when creating arrays containing
multiple data items. Exclude all of the registers encompassed by one
declaration statement from any other declaration.
The one exception to this rule is the declaration of an EQUATE. An EQUATE
is not a true data type, but this term can appear in a declaration statement as
if it were a data type. The format for declaring an EQUATE is as follows:
The requirements for declaring an EQUATE are exactly opposite those for
all other data declarations. An earlier data declaration must already include
the register named in name_of_register. The CMPL compiler only
permits the redefinition of single registers in this manner, and custom
programs can only use names declared with EQUATE as if they were of the
data type REGISTER.
Declaring an EQUATE makes it possible to address a single register
contained in a multi-register data type or to attach a special name to an
individual register that lies within an array definition. When declaring an
EQUATE, be certain that the register to be redefined is already included in
another declaration. The other declaration must appear above the EQUATE
in the declaration section of the source file.
data_type name_of_array[n] name_of_register
where data_type is the name of any valid data type
name_of_array is an easily understood and remembered
name consisting of up to 27 letters, numbers, and
underscores.
name_of_register is the name (beginning with S) of
any register
and n is a decimal integer in the range 1 to 256
EQUATE name_of_variable name_of_register
where
name_of_variable is an easily understood and remembered name
consisting of up to 27 letters, numbers, and underscores.
and name_of_register is the name (beginning with S) of any register
63230-300-221/A1 Chapter 3Defining Memory Registers in the Declaration Section
2/2002 Creating Constants With DEFINE
19 2002 Schneider Electric All Rights Reserved
CREATING CONSTANTS WITH DEFINE Another kind of statement that can appear in the declaration section is a
DEFINE. A DEFINE does not affect the use of data registers. It is a feature
that is included to make custom programs easier to create and read by giving
easily remembered names to constant numeric values.
The format for a DEFINE is as follows:
To define constants, use numeric values that are decimal integers or floating-
point values or hexadecimal integers in the format 0xnnnn where nnnn
represents from 1 to 4 digits of a hexadecimal value. To create constants that
occupy multiple registers, DEFINE the name of the constant as equal to
multiple numeric values, one for each register used.
As a simple example of a DEFINE, the following statements substitute the
words FALSE and TRUE for the numeric values 0 and 1. This reduces the risk
that a programmer may reverse the numeric values and forget which one
indicates which logical state.
Example 33:
Use DEFINE to substitute a name for any value (such as a delay time or a
threshold value) that is used several times in a program, and that may
change in the future. When this value changes, only the DEFINE will need to
be modified and the correction will be carried throughout the program.
What follows is a more complex example in which a multiple-register
constant is defined using separate numeric values for each register:
Example 34:
The value of max_energy established by this DEFINE is the equivalent of a
data item requiring four registers. Constants created with DEFINE can only
appear in arithmetic expressions with variables whose size in number of
registers and whose range of numeric values are consistent with the value of
the constant. (See the Converting Data Types on page 29 for more
information on matching data types within expressions.)
DEFINE value_name value [value] [value]
where
value_name is an easily understood and remembered name
consisting of up to 27 letters, numbers, and underscores.
and value represents a numeric value or, in some cases, multiple
numeric values in each register. (Do not include the brackets in
the code.) See Example 3-5.
DEFINE FALSE 0
DEFINE TRUE 1
DEFINE max_energy 1234 5678 9000 0000
Chapter 3Defining Memory Registers in the Declaration Section 63230-300-221/A1
A Sample Declaration Section 2/2002
2002 Schneider Electric All Rights Reserved 20
A SAMPLE DECLARATION SECTION
## DECLARATION SECTION:
DEFINE OFF 0
DEFINE ON 1
DEFINE NO 0
DEFINE YES 1
BITREG OUTPUT_STATUS S4006
REGISTER IA_AMPS S1100
REGISTER IB_AMPS S1101
REGISTER IC_AMPS S1102
REGISTER TOTAL_CURRENT S14101
REGISTER AVERAGE_TOTAL_CURR S14102
REGISTER S14103
REGISTER PEAK_CURRENT S14104
REGISTER DISPLAY_LIST[10] S14110
DATETIME START_TIME S14120
MOD10L4 ENERGY_VAL S14124
POWFACT POWER_FACT_TOT S14130
## END DECLARATION //------- end declarations
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Assigning Values to Data Items
21 2002 Schneider Electric All Rights Reserved
CHAPTER 4THE CIRCUIT MONITOR PROGRAMMING LANGUAGE
This chapter describes the commands that make up the Circuit Monitor
Programming Language (CMPL). These are the keywords and expressions
that specify actions to take place in each of the task sections of a custom
program. See Required Elements in a Source File on page 6 for complete
discussions of the different kinds of tasks and of the required and optional
elements in each custom program written for the CM4000. See Defining
Memory Registers in the Declaration Section on page 15 for a description of
the declaration section that defines data items for use with the commands
discussed below.
ASSIGNING VALUES TO DATA ITEMS The declaration section of a CMPL program does not assign any values to
data items. The registers that can only be read by custom programs will, of
course, receive values from other functions within the circuit monitor. All
other data items will have indeterminate values until the CMPL program
assigns values to them within the initialize task or one of its other task
sections.
Make sure that each program initializes all of its variables. Never assume that
any of the writable registers in the circuit monitor will contain any particular
value unless it is explicitly initialized within a custom program.
In the initialize task section, assign a starting value to each item that must
equal 0, 1, or some other value. This ensures that the program performs as
expected. The initialize task section provides a one-time opportunity to
ensure that variables usedsuch as counters and pointershave
appropriate beginning values. Initialize all remaining data items within the
other task sections of the program. Depending on the logic of the
program, data items initialized in the initialize task section may need to be
reset during program execution. Any task section can contain instructions to
change the contents of any declared, writable data register at any time.
Remember that all data items are global in scope. This means that any
value set in one section of the program immediately becomes effective in all
other parts of the program. Be careful that one task section does not reset a
variable that is used in another task.
Assigning Constant Values The simplest format for assigning a value to a data name (called an
assignment statement) is as follows:
The data name of the variable that is to receive the value must be on the left-
hand side of the equals sign. The constant numeric value or values must be
on the right. An assignment statement looks like an algebraic equation, but it
always indicates that the value on the right-hand side of the statement is
assigned to the data item on the left. These positions cannot be reversed.
data_name = value [value] [value] [value]
where data_name is a variable name or subscripted member
of an array that has been declared in the Declaration
section
and value is either a decimal constant, a hexadecimal
constant, or, if data_name is of a data type that uses
multiple registers, represents the value in each
register. (Do not include the brackets in the code.)
Example: count = 4 6 8 10
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Assigning Values to Data Items 2/2002
2002 Schneider Electric All Rights Reserved 22
Example 45:
data_name[2] = 4
The name of a data item receiving a value in an assignment statement can
be either the register address of that item or a variable name, depending on
the format used to declare it in the declaration section. One member of an
array of data items can also receive a value in an assignment statement. To
assign a value to one member of an array, give the data name declared for
the array. After the data name, in square brackets, enter the subscript
number of the selected array member.
The numeric value assigned to any variable must not exceed the values
permitted for items of that variables data type. (See Table 31 on page 16 for
a complete list of data types and their associated value ranges.) Data items
of type REGISTER, for example, can only have integer values that lie between
32768 and +32767. LONGREG data items are also restricted to integer
values, but they can be in a range from 2,147,483,648 to +2,147,483,647,
which is the range supported by that data type. See Example 4-1.
Data items of types MOD10L2, MOD10L3, and MOD10L4 (sometimes called
the MODULO 10K types) define multiple registers. They accept multiple
values in a single assignment statementa separate value for each register
included in the data item.
DATETIME data items can also accept four values that correspond to the four
registers included in the data item. However, it is less common to assign
values to items of type DATETIME. These are usually values supplied by the
circuit monitor; they are used in custom programs to compute elapsed time
or to record times when events occur.
All numeric constants assigned to data items can be preceded by a plus (+)
or minus () sign. Positive values are assumed unless a negative is specified.
Be careful that a signed value is not outside of the allowed range for the data
type used. Of all the data types, only DATETIME and BITREG items do not
permit any negative values. (See Example 47.)
The following examples show valid assignment statements and specify the
declarations that are necessary for each.
Example 46:
Example 47:
The numeric constants 0 and 0.0 have the same value, of course, as do 1
and 1.0, etc. Constants assigned to data types that support only integers
must not include decimals.
When an assignment statement includes a constant expressed in
hexadecimal (or numeric base 16) the value is always an integer.
data_int = 0 Sets the data item to zero.
This is a valid assignment statement if data_int
has been declared to be of data type REGISTER,
LONGREG, or FLOATeach of which accepts the
integer 0 as a valid value.
data_int = 0x00ff Sets the data item to 00ff hex or 255 decimal
This is a valid assignment statement if data_int
has been declared to be of data type BITREG or
REGISTER.
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Mathematical and Logical Operations
23 2002 Schneider Electric All Rights Reserved
Example 48:
Assigning Variables to Other Data Items The value of one data item or variable can be assigned to another data item
by an assignment statement. Example 49 assigns the value of
counter_val to hold_counter:
Example 49:
Notice that the value of the variable on the right is always assigned to the
variable on the left-hand side of the equation. In this example, counter_val
does not change, but hold_counter takes on the same value as
counter_val. An assignment statement such as this is useful to preserve
the current value of counter_val before re-initializing counter_val for
further use within the program.
Data items used in an assignment statement must all be of the same data
type. (Use the CONVERT function, described in Converting Data Types on
page 29 to transfer values from one data type to another.) Any of the
variables in the assignment statement can be a subscripted member of an
array.
Do not include signs (+, ) in an assignment statement that assigns one
variables value to another.
MATHEMATICAL AND
LOGICAL OPERATIONS
Special cases of the assignment statement make it possible to perform both
arithmetic and logical operations using data items. Through all of the
variations on the basic assignment statement that appear below, remember
these three rules:
1. All data items in an assignment statement must be of the same data type.
The only exception to this is in the use of the CONVERT function to move
values from one data type to another.
2. Values on the right-hand side of the equationwhether numeric
constants, arithmetic expressions, or other expressionsare always
assigned to a single data item on the left-hand side. Only one data item
can appear on the left-hand side of any assignment statement.
3. Functions cannot be combined with arithmetic operations. For example,
the expression x = sin(angle_value + 1) is invalid.
meter_mod10 = 0 0 Sets meter_mod10 to zero.
This example assumes that meter_mod10 is of
data type MOD10L2which uses two registers.
hold_counter = counter_val
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Mathematical and Logical Operations 2/2002
2002 Schneider Electric All Rights Reserved 24
Add, Subtract, Multiply, Divide, Modulus To perform any of the five arithmetic operations, write an assignment
statement in which the value of an arithmetic expression on the right-hand
side of the equation is assigned to a single data item on the left. Use the
operators:
+

*
/
%
to add, subtract, multiply, divide, and perform modulus division.
Arithmetic expressions are evaluated from left to right. Parentheses or
brackets are not permitted within expressions, and it is not possible to alter
the order of evaluation. Limit each expression to a maximum of six operators.
Complex arithmetic operations may require a series of assignment
statements to perform the operation one part at a time.
Numeric constants used in arithmetic expressions can be decimal integers
or floating-point decimal values. See Assigning Constant Values on page
21 for a discussion of appropriate values for use with different data types.
Remember that all data items within an assignment statement must be of the
same data type. All numeric constants used in arithmetic expressions must
be in a format that is consistent with the data type of the variables in that
statement.
Some data types cannot be used in some arithmetic operations because it is
illogical to perform these operations on those types of data. Do not use data
types BITREG or DATETIME in any arithmetic operations. MOD10L2,
MOD10L3, and MOD10L4 are generally considered to be counters or meters.
Do not use these in multiplication or division.
The following examples show some typical assignment statements used to
perform basic arithmetic (note the blank space between each element):
Example 410:
Example 411:
Example 412:
Example 412 demonstrates a common and important use of arithmetic in
an assignment statement. The CMPL program will evaluate the expression
on the right-hand side of the equation (new_value + 1) and then assign
the result to the data item on the left (new_value), thereby incrementing
new_value by 1.
This contradicts the rules of traditional algebra, but it is a very common
feature of most computer programming languages. The principle that it
demonstrates underlies all types of assignment statements: CMPL fully
evaluates the right-hand side of the equation and then assigns that value to
the single data item on the left-hand side.
new_value = 3 * old_value Multiplies old-value by three and
assigns the result to new_value.
new_value = 3 * old_value + 7 Multiplies old-value by three; adds 7
to the result, and assigns the total to
new_value.
new_value = new_value + 1 Increases the value of new_value by 1.
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Mathematical and Logical Operations
25 2002 Schneider Electric All Rights Reserved
Logical Operations CMPL includes several functions that generate values based on a logical
comparison of the individual bits in the functions operand(s). The AND, OR,
and XOR functions are similar to the trigonometric and square root functions
(see Trigonometry on page 27), but they have two operandscontained
within a single set of parentheses and separated by a comma. The NOT
function has only one operand.
All data items used as operands of these logical functions must be of data
type BITREG. Values produced by these functions are always assigned to a
BITREG variable. The BITREG data type consists of a single register whose
individual binary bits are examined or set one at a time. A bit (or BInary digiT)
can only have one of two values. It is always equal to either 1 (on or true) or
0 (off or false).
Subscripts are permitted when a BITREG data item is a part of an array.
Signs (+ or ) are not permitted with logical functions.
One of the operands of an AND, OR, or XOR logical function can be a numeric
integer constant expressed in either numeric base 10 or base 16. The value
of any numeric constant should be between 32768 and +32767 if written in
numeric base 10 or between 0x0000 and 0xffff if written in numeric base 16.
The AND function sets each bit in the result if, and only if, the corresponding
bits in the operands are set. Otherwise, the bit is reset.
The OR function sets each bit in the assigned value to on if the corresponding
bit is set in either of the operand registers.
The XOR (eXclusive OR) function sets the assigned value bits on only if the
corresponding bits are set in only one of the two operand registers.
AND
A B Result
0 0 0
0 1 0
1 0 0
1 1 1
OR
A B Result
0 0 0
0 1 1
1 0 1
1 1 1
XOR
A B Result
0 0 0
0 1 1
1 0 1
1 1 0
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Mathematical and Logical Operations 2/2002
2002 Schneider Electric All Rights Reserved 26
The NOT function assigns a value in which the pattern of bits turned on and
off is the opposite of the pattern found in its single operand.
The following examples assume that a_var, b_var, and c_var are all of
data type BITREG. They show typical uses of these functions:
Example 413:
Example 414:
Example 415:
Example 416:
Bitwise Shifts Advanced program engineers may want to write assignment statements that
use the CMPL SHIFT function. The SHIFT function has two operands. They
are written within a single pair of parentheses and separated by a comma.
The first operand is always the name of a data item of data type BITREG or
of data type REGISTER. The second operand consists of either the letter L
(left) or R (right) followed by a numeric constant in the range 1 to 15,
inclusive. As with any assignment statement, the data item that receives the
value produced by the SHIFT function should be of the same data type as
the data item that is the first operand.
Like the logical functions shown above, subscripts are permitted as a part of
data names. Signs (+ or ) are not permitted.
NOT
A Result
0 1
1 0
a_var = AND(b_var, c_var) A bitwise AND of b_var and c_var is
performed and the result is assigned to
a_var.
a_var = OR(b_var, c_var) A bitwise OR of b_var and c_var is
performed and the result is assigned to
a_var.
a_var = XOR(bar_var, c_var) A bitwise eXclusive OR of b_var and
c_var is performed and the result is
assigned to a_var.
a_var = NOT(b_var) A bitwise NOT of b_var is assigned to
a_var.
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Trigonometry
27 2002 Schneider Electric All Rights Reserved
The following are examples of assignment statements using the SHIFT
function:
Example 417:
Example 418:
Logical Shift The SHIFT function performs differently with data items of type BITREG than
with data items of type REGISTER. If the first operand and the receiving value
are of data type BITREG, a logical shift is performed. A logical shift one bit to
the right causes a zero to be inserted in the leftmost, or most significant bit
position. Any value in the rightmost, or least significant bit position, displaced
by the shift is dropped. A logical shift to the left inserts a zero in the least
significant bit position and drops any value in the most significant bit position.
Arithmetic Shift If the operand and receiving variable are of data type REGISTER, the SHIFT
command executes an arithmetic shift. An arithmetic shift will continually
copy the sign bit to the most significant bit position. Any value in the least
significant bit position displaced by the shift is dropped. An arithmetic shift to
the left inserts a zero in the least significant bit position and drops any value
in the most significant bit position.
Example 419:
Arithmetic shifts are useful to programmers familiar with binary arithmetic
(using numeric base 2). Data items of type REGISTER are rapidly multiplied
or divided by 2 or multiples of 2 using this specialized technique.
TRIGONOMETRY CMPL can perform the basic trigonometric functions: sine, cosine, arctan,
and square root. If necessary, other trigonometric operations are easily
derived from the basic functions. For example, arcsine = 1/sine; and
arccosine = 1/cosine.
a_var = SHIFT(b_var, L4) The pattern of bits in the register
indicated by b_var are duplicated in the
register indicated by a_var, but they
are shifted 4 bits to the left.
Before: b_var = 0000 1111 1111 0000
After a_var = 1111 1111 0000 0000
a_var = SHIFT(b_var, R4) The pattern of bits in the register
indicated by b_var are duplicated in the
register indicated by a_var, but they
are shifted 4 bits to the right.
Before: b_var = 0000 1111 1111 0000
After a_var = 0000 0000 1111 1111
a_var = SHIFT(b_var, R1) The pattern of bits in the register
indicated by b_var are duplicated in the
register indicated by a_var, but they
are shifted 1 bit to the right.
Before: b_var = 1000 1111 0000 1111
After: a_var = 1100 0111 1000 0111
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Trigonometry 2/2002
2002 Schneider Electric All Rights Reserved 28
Sine, Cosine, Arctan The examples below demonstrate the use of the SINE, COSINE, and
two-argument ARCTAN functions. Notice that these always appear on the
right-hand side of the assignment statement and that the computed values
are then assigned to a data name on the left-hand side.
Example 420:
Example 421:
Example 422:
Data items receiving values from the SINE, COSINE, and ARCTAN functions
must all be of data type FLOAT. The value within the parentheses of each
function (the operand of that function) must also be a data item of data type
FLOAT. Arithmetic expressions are not permitted as operands.
Do not use numeric constants as function operands. The constant value can
be calculated outside the program and inserted into the source file to help
minimize the run time.
All angular values for SINE and COSINE are expressed in radians and must
be within the range /2 to /2 (i.e., 90 to 90 degrees), inclusive.
ARCTAN returns a value in the range of to radians. ARCTAN uses the
sign of the two arguments to decide which quadrant the value is in. There is
not a limited range for the operands of ARCTAN. Value_2 cannot equal 0.
Square Root The SQROOT function computes square roots in much the same way that the
trigonometric functions compute their values. The SQROOT function must
appear on the right-hand side of an assignment statement. Its operand (in
parentheses) must be a data item of type FLOAT with a positive numeric
value. The square root of the operand is computed and assigned to the data
item, also of data type FLOAT, that appears on the left side of the assignment
statement. This function returns positive roots only.
sin_value = SINE(angle_val) Assigns sine of angle-val to
sin-value.
cos_value = COSINE(angle_val) Assigns cosine of angle-val to
cos_value.
arct_value = ARCTAN(value_1,
value_2)
Evaluates (value_1/value_2) where
value_1 is the Y coordinate and
value_2 is the X coordinate; assigns
arctan of result to arct_value.
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Converting Data Types
29 2002 Schneider Electric All Rights Reserved
An example follows:
Example 423:
CONVERTING DATA TYPES In all of the forms of the assignment statement discussed above, all data
items in any statement must be of the same data type. Data items of different
data types cannot appear in a single arithmetic expression, but the CONVERT
function makes it possible to assign the value of one data item to another
data item of a different data type.
In the examples that follow, assume that data_int has been declared with
a data type of REGISTER and data_float has been declared with a data
type of FLOAT:
Example 424:
In Example 424, no information is lost because the floating-point variable
data_float can contain any integer value that can possibly be stored by
the REGISTER variable, data_int. This statement makes the integer value
contained in data_int available in floating-point format (data_float) to
be used with other floating-point values.
Example 425:
In Example 425, the data item of data type REGISTER (data_int)
cannot store any fractional part of the value of data_float. Only the integer
portion of the value of data_float is assigned to data_int.
NOTE: The use of the CONVERT function includes this possibility for the
distortion or truncation of values. Avoid value conversions where possible.
Approach all uses of the CONVERT function with caution to prevent
unexpected distortion or loss of data.
You cannot convert from a data type FLOAT having a value greater than
32767 to a data type REGISTER.
sqrt_value = SQROOT(x_value) The square root of x_value is assigned
to sqrt_value.
data_float = CONVERT(data_int) Assigns the value of the REGISTER
data_int to the FLOAT data_float.
data_int = CONVERT(data_float) Assigns the integer part of the value of
the FLOAT data_float to the
REGISTER data_int.
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Converting Data Types 2/2002
2002 Schneider Electric All Rights Reserved 30
CMPL limits the number of different conversions that the CONVERT function
can perform. The following table shows the conversions that are permitted:
Table 41:Permitted Data Conversions
From Data Type To Data Type
BITREG
REGISTER LONGREG
FLOAT
REGISTER
BITREG LONGREG
FLOAT
REGISTER
LONGREG
BITREG
FLOAT
DATETIME
REGISTER
FLOAT
BITREG
LONGREG
POWFACT
MOD10L2
MOD10L3
MOD10L4
FLOAT POWFACT
MOD10L2
MOD10L4
MOD10L3
LONGREG DATETIME
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Control of Program Execution
31 2002 Schneider Electric All Rights Reserved
CONTROL OF PROGRAM EXECUTION Custom programs use various forms of the assignment statement to
compute values and initialize data items, but other commands exist that
permit powerful control over the specifics of program execution. It is possible
to test the values of data items and execute or not execute parts of task
sections depending on the values found. It is also possible to designate a
part of a task section to be performed more than once, which can significantly
reduce the number of lines in a program.
Subroutine sections, which were introduced in Chapter 2, can also help to
reduce the number of lines in a program. Combining conditional execution
with subroutines provides a basis for more complex program organization.
Conditional Execution Using IF To define commands that execute only under certain conditions, use the IF
command, also sometimes called the IF...ELSE command. The two
formats for the IF command (with and without the ELSE phrase) follow:
The IF command must appear as the first word on a line in a source file. It
must be followed on that same line by a comparison (also called a
conditional expression) enclosed in parentheses. Write a comparison using
two data items or numeric constants joined by a comparison operator.
The comparison operators are as follows:
Other combinations of these operators, such as = > or > < are not
recognized by the CMPL compiler.
Data items used in comparisons must be the same data type. Numeric
constants used in comparisons must be consistent with the data items to
which they are compared.
IF (cond_expr)
{program_command(s)}
or
IF (cond_expr)
{prog_command(s)}
ELSE
{alt_prog_command(s)}
where cond_expr is a conditional expression to be evaluated
prog_command(s) are one or more valid programming
language commands to be executed if the cond_expr is true
and
alt_prog_command(s) are one or more valid programming
language commands to be executed if the cond_expr is not
true
OPERATOR DEFINITION
= equate
< less than
> greater than
< > not equal to
< = less than or equal to
> = greater than or equal to
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Control of Program Execution 2/2002
2002 Schneider Electric All Rights Reserved 32
The examples below demonstrate the use of the IF statement.
Example 426:
Example 427:
Example 428:
Conditional expressions such as these are meaningless until other
commands are defined to be executed or not depending on the outcome of
the IF comparison. Immediately following an IF command, there must
appear an opening curly brace ({) character to mark the beginning of the
conditional block. The { must be on a separate line following the IF
command, but it can be followed with a program instruction.
The conditional block of commands should be indented for readability, as in
Example 429. The final line of program instruction concludes with a closing
curly brace (}). This character must be the last character on a line. Custom
logic commands that appear between the { and the } are performed only
when the condition tested by the IF command is true.
Example 429:
Any number of valid CMPL commands can appear between the { and } of
an IF command. These are all conditional commands.
An IF command can appear inside the conditional block of another IF
command, creating a nested series of conditional commands. The nested IF
is only tested if the outer condition is true and the conditional commands of
which it is a part are executed. CMPL permits IF statements to be nested up
to nine layers deep.
The ELSE phrase, in the IF...ELSE format, is optional. If used, the
command ELSE must be the first and only item on a line. It must follow a }
that terminates the conditional commands associated with the IF and must
be followed by another series of conditional commands enclosed in braces.
NOTE: Only one ELSE statement is permitted for each IF statement.
As with the conditional commands following the IF, the { must be on a
separate line following the IF command, but it can be followed with a
program instruction. Likewise, a } must be the final item on a line, although
it can be preceded by a program instruction. Commands between these
characters will be performed if the condition tested by the IF command is
false.
IF (a_var < b_var) Tests if a_var is less than b_var
IF (b_var = 3) Tests if b_var is equal to the numeric constant 3
IF (b_var < = a_var) Tests if b_var is less than or equal to a_var
IF (b_var < > 10) If b_var does not equal 10
{a_var = a_var + 1 Increment a_var by 1
b_var = a_var * 2}
And make b_var equal a_var
multiplied by 2
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Control of Program Execution
33 2002 Schneider Electric All Rights Reserved
Repeated Execution Using FOR...NEXT Use the FOR...NEXT command when a program requires repeated
execution of a block of code or set of command lines. The format for the
FOR...NEXT command is as follows:
The word FOR must be the first item other than spaces on a line. It must be
followed, on the same line, by the index variable and the expression shown
above that defines the range of values for the index variable.
The word NEXT and the name of the index variable must be the only items on
the line that marks the end of the commands to be repeated.
The index variable, which must be of data type REGISTER, will be initialized
to the first numeric value given. All commands within the FOR...NEXT loop
will be executed; then the value of the index variable will be incremented by
1, unless you increment or decrement the counter inside the loop. If, after
being incremented, the index variable does not exceed the second numeric
value given following the FOR command, the commands within the loop will
be performed again and the index variable will again be incremented.
The commands within the loop continue to be performed until the index
variable, having been incremented by 1, exceeds the defined upper limit.
Execution of the program will then continue immediately following the NEXT
command line.
The FOR...NEXT loop provides a way to specify the number of times a task
is performed. The index variable can also be used within the loop to cause a
different action on each successive repetition.
Example 430 shows a FOR...NEXT loop used in a program. This assumes
that rpt_count is a variable of data type REGISTER, that the array
wk_tble is declared to have at least 25 members, and that wk_tble and
iaamps are of the same data type:
Example 430:
This example shows that the REGISTER data item used to count repetitions
can also appear in commands inside the FOR...NEXT loop. In this case,
rpt_count serves as a subscript to the array wk_tble. This is a common
procedure that places the value of iaamps in a different member of the array
during each repetition of the loop.
FOR ndx_var = n TO m
prog_command(s)
NEXT ndx_var
where ndx_var is an index variable of data type REGISTER
n and m are decimal constants that set the lower and upper
limits, respectively, of the index variable (n must always be
lower than m)
and prog_command(s) are one or more valid programming
language commands to be executed once for each value of
ndx_var.
FOR rpt_count = 1 TO 25 Rpt_count ranges from 1 to 25
wk_tble [rpt_count] = iamps Value of iaamps is assigned to the
member of wk_tble determined by
rpt_count.
NEXT rpt_count Rpt_count is incremented and
compared to 25.
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Control of Program Execution 2/2002
2002 Schneider Electric All Rights Reserved 34
No explicit command is provided to abruptly terminate a loop before the index
variable has been incremented to exceed its defined upper limit. However, it
is possible to assign a different value to the index variable during the
execution of the loop.
In Example 430, a line could be inserted between the FOR and NEXT
commands that would assign a value of 25 or more to the rpt_count
variable. Execution would continue until the NEXT command incremented
rpt_count at the bottom of the loop. Since rpt_count would certainly be
greater than 25, the loop would not be repeated again.
In a realistic programming application, a line setting an index variable equal
to its upper limit would probably be a part of a conditional expression using
IF...ELSE.
IF...ELSE commands can appear within FOR...NEXT loops, and
FOR...NEXT loops can be a part of conditional commands controlled by
IF...ELSE.
FOR...NEXT loops can also be nested within other FOR...NEXT loops up
to four levels deep.
Subroutine Execution Using CALL The CALL command, used with the name of a specific subroutine, causes
that subroutine to be executed. When the subroutine ends, program
operation continues immediately following the CALL command. The syntax
of the CALL command is very simple. It consists of the word CALL followed
by the name of a valid subroutine, as follows:
Subroutines can contain the CALL command, so subroutine calls can be
nested. Up to eight levels of nesting are permitted. Use CALL commands
carefully within subroutines to be certain no circumstance will arise to cause
more than eight levels of nested subroutines.
Terminating a Task or Subroutine Using
RETURN
The RETURN command appeared in Example 2-2 on page 7 as a required
part of all task sections and subroutines. At least one RETURN command is
required at the end of the task or subroutine in each of these sections, but
more than one RETURN can be used.
Programs that include IF...ELSE commands may have different sets of
commands that are executed under different conditions. If required by the
logic of the program, RETURN commands can be included in sets of
conditional commands.
The rule is simple: When a RETURN command is encountered, the task
section or subroutine in which it appears will be immediately terminated.
When a subroutine executes a RETURN, control passes to the command
following the CALL that invoked the subroutine. When a task section
executes a RETURN, that task is ended. Control will pass to the next task in
the program, or, if no other tasks exist, CMPL will relinquish control to the
other circuit monitor functions and will not execute more commands until the
next meter cycle.
CALL subr_name
where subr_name is the name of a subroutine defined elsewhere in
the custom program
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Control of the Circuit Monitor Using CMDREQ
35 2002 Schneider Electric All Rights Reserved
Terminating a CMPL Program Using HALT Two other commands are available to control the execution of a custom
program in the circuit monitor. The HALT command causes the custom
program to stop. A halted program will not resume unless another instruction
is submitted to the circuit monitor to execute its resident program. A halted
program does continue to reside in the program memory area of the circuit
monitor.
Restarting a CMPL Program Using RESTART The RESTART command causes the program to stop as if it were halted, but
it then begins a new program execution as if a command had been entered
to run the resident program. RESTART causes the initialize task section to be
re-executed and all data items under program control will be reset.
CONTROL OF THE CIRCUIT MONITOR
USING CMDREQ
A powerful feature of CMPL is its ability to transmit certain commands to the
circuit monitor. Commands can be invoked under custom program control.
Up to 19 parameters can be attached to any of these commands, as
appropriate. (A full explanation of the command interface and parameters is
given in the instruction bulletin for the POWERLOGIC Series 4000 Circuit
Monitor.)
To issue a command to the command interface, use the CMDREQ instruction.
Example 431 illustrates the format for this command.
Example 431:
* cmd_params must be written in the 14000 range of registers, not the 40000 range.
The arguments are separated by commas followed by a space and enclosed
in a single set of parentheses. Example 432 shows a typical use of the
CMDREQ command.
Example 432:
CONTROL OTHER DEVICES USING
COMMSREQ
The circuit monitor can initiate communication requests for data transfer with
remote PMO devices. For a full explanation of this feature, see the instruction
bulletin for the POWERLOGIC Circuit Monitor Series 4000.
All COMMSREQ functions require a communication control array and an
array for storing data involved in the transfer. The scattered read option
requires an additional array that lists the desired register numbers. All arrays
declared for use with the COMMSREQ function must be defined as the
REGISTER data type.
CMDREQ (cmd_num, num_of_params, cmd_params)
where cmd_num is the number of a command
and
num_of_params is the length of the command parameter list
(019)
and cmd_params is a REGISTER ARRAY variable containing
parameters*
REGISTER CMD_PARAMS[10] S14400
cmd_params[1] = 3710
CMDREQ (3320, 1, CMD_PARAMS) Sends command to turn off the relay
indicated by the bitmap stored in
register 3710.
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Control Other Devices Using COMMSREQ 2/2002
2002 Schneider Electric All Rights Reserved 36
Communication Control Array The following is a list of required elements in the communication control
array. See Example 433 for typical use of these elements.
1. CM4000 Port
0 = RS485
1 = RS232
2 = ECC Subnet
2. Remote Device Address
3. Request Type
1 = Read Register Block
2 = Read Scattered Registers
3 = Write Register Block
4. Register Count (number of registers)
5. Starting Register Address (not required for Scattered Read)
Example 433:
To issue a command that requests communications with a remote PMO
device, use the COMMSREQ instruction. The format for this command is as
follows:
COMMSREQ (status, ctl_tab, data_tab, reglist_tab)
When using the COMMSREQ command, the status of the request is posted in
the status variable passed to the function. The status is defined as:
While the request is pending, avoid writing to the variables passed in the
COMMSREQ function. Otherwise, the request will be lost and time-outs may
occur.
REGISTER
ctl_tab[5] S14400
ctl_tab[1] 2 // ECC
ctl_tab[2] 1 // Device 1
ctl_tab[3] 1 // Read reg block
ctl_tab[4] 10 // number of registers
ctl_tab[5] 4000 // start reg
0 Request complete; no errors
1 Request is pending
1 to 202 Error in request or reply.
63230-300-221/A1 Chapter 4The Circuit Monitor Programming Language
2/2002 Control Other Devices Using COMMSREQ
37 2002 Schneider Electric All Rights Reserved
Example 434 shows a typical use of the COMMSREQ command.
Example 434:
Declaration Section:
REGISTER comm_status s14025 // status reported by comms server
REGISTER comm_ctl[5] s14030 // control parameters
REGISTER comm_data[25] s14100 // data values read/written
REGISTER comm_rlist[25] s14200 // register list
End Declaration
Initialize Task:
comm_ctl[1] = 2 // [1] port-ecc
comm_ctl[2] = 1 // [2] address @ 1
comm_ctl[3] = 2 // [3] request_typescattered read
comm_ctl[4] = 5 // [4] register count
comm_ctl[5] = 0 // [5] (scattered read)n/a
comm_rlist[1] = 1001
comm_rlist[2] = 1003
comm_rlist[3] = 1004
comm_rlist[4] = 1005
comm_rlist[5] = 1006
End Initialize
...
...
Subroutine: Request_RemoteMeter_Data
if (comm_busy=0) // if not busy send a request
{
comm_status=1
reqcnt =reqcnt+1
COMMSREQ(comm_status,comm_ctl,comm_data,comm_rlist)
}
End Subroutine
Chapter 4The Circuit Monitor Programming Language 63230-300-221/A1
Control Other Devices Using COMMSREQ 2/2002
2002 Schneider Electric All Rights Reserved 38
63230-300-221/A1 Chapter 5Compiler Operation
2/2002 Starting the Program
39 2002 Schneider Electric All Rights Reserved
CHAPTER 5COMPILER OPERATION
This chapter tells how to use the Windows-based compiler.
STARTING THE PROGRAM Click Start > Programs > Square D CM4000PL Compiler.
Or, double click the shortcut on your desktop:
A splash screen displays followed by the Tip of the Day. You can disable the
tips by deselecting the box called Show Tips on StartUp. The tips are also
located under the Help menu on the toolbar.
The initial CMPL screen displays.
OPENING A SOURCE FILE To open a source file, do one of the following:
1. From the compiler window, click File > Open. Locate and select the file;
click Open.
or
2. If the file is in the recent documents list, click File and the document
name.
or
3. From within the compiler, click the folder icon . Select the location of
the source (.src) file. Select the file and click Open.
Figure 51: Initial CMPL screen (no source file open)
Chapter 5Compiler Operation 63230-300-221/A1
Setting Communication Parameters 2/2002
2002 Schneider Electric All Rights Reserved 40
A screen similar to the following displays:
SETTING COMMUNICATION
PARAMETERS
The compiler can communicate with the circuit monitor through the serial
port or via TCP/IP. To access the Communications Settings screen, click
Setup > Communication Settings;
or
click the Communications icon: .
The Communications Settings screen displays, as illustrated below.
Enter the following information:
Figure 52: Source File screen
Select the appropriate port:
TCP/IP or the COM port
connected to the CM4000
For serial communication,
select the parity the
CM4000 uses for error
checking.
For serial communication, enter
the device ID assigned to the
CM4000, depending on the port
you are using.
For TCP/IP, enter the RS-485
device ID
Select the
communications protocol
the CM4000 uses.
For serial communication, select
the baud rate the CM4000 uses to
communicate.
For TCP/IP, enter the IP
address assigned to the
CM4000.
Figure 53: Using the Communication Settings screen to set parameters
63230-300-221/A1 Chapter 5Compiler Operation
2/2002 Setting the Environment
41 2002 Schneider Electric All Rights Reserved
SETTING THE ENVIRONMENT You can change the viewing environment of CMPL. This includes the type
face and size of the font, background and text colors, and the length of tab
stops.
All of the environment settings are located under Setup > Environment.
Formatting the Font To change the size or type face of a font, click Setup > Environment > Font.
The Font screen displays. The default font is 12-point Courier regular.
From the lists on the screen, select the font, style, and size. In the Script box,
you may be able to select specific scripts used in various languages. Select
the appropriate script for your language (use Western for English). Note that
as you make selections, the information in the Sample window changes.
Once you are satisfied with the changes, click OK.
Setting the Background or Text Color To change the color of the background and/or text, click Setup > Environment
> Editor Colors. The Editor Colors screen displays. The default is black text
on a white background.
To change either the background or text, click the colored rectangle. The
Windows Color palette displays. The custom palette is disabled, but you can
choose from the 48 colors displayed. Click on a color, then click OK. The
Editor Colors screen displays again. Click Apply to view the new color.
When you are satisfied with the colors, click OK.
Changing the Tab Width To change the width of a tab, click Setup > Environment > Tab Stops. The Set
Tab Stops screen displays. The default is 5, which means that a single tab is
indented 5 characters.
Enter any integer from 1 to 16. Click OK to save the change.
Setting the Save Reminder The Save Reminder, when enabled, prompts the user to save changes every
three minutes. The default setting is disabledno reminders are displayed.
To enable or disable this setting, click File > Save Reminder. When it is
checked, it is enabled; when unchecked, it is disabled.
Chapter 5Compiler Operation 63230-300-221/A1
Setting the Compiler Options 2/2002
2002 Schneider Electric All Rights Reserved 42
SETTING THE COMPILER OPTIONS There are several options you can set for the compiler. To begin, click Build
> Settings. The Compiler Options screen displays. Make the appropriate
settings for the manner in which you want the compiler to work. Click OK
when you have finished making changes.
Turning Output Generation On and Off To be able to download with DLF3000 or write directly to the circuit monitor
RAM, you must turn on output generation. To toggle it on/off, click Build >
Generate Output. When Generate Output is checked, output generation is
enabled.
Compiling/Assembling a .src File Use one of the following methods to compile a .src file or assemble a .src file
for which opcodes are already present. (See Figure 54 for instructions on
changing between compiling and assembling the .src file.)
Click Build > Compile.
or
Click the check icon: .
or
Press the F7 function key.
Choose a Mode:
To compile a .src file, check Compile.
To assemble a .src file (when the
opcodes are already present) check
Assemble.
If you want debug information to be
generated, check this field.
Three debug files are created:
cmpl.tm1 (results of first compiler pass)
cmpl.tm2 (results of second pass)
cmpl.dbg (memory image var info)
Each time you compile, these files are
overwritten.
Choose an Output Type:
For release output (the program
generates a .fw file, used by
DLF to write to the CM4000
disk), check Release.
For debug output (the program
is written directly to the CM4000
RAM), check Debug.
Figure 54: Using the Compiler Options screen to set options
63230-300-221/A1 Chapter 5Compiler Operation
2/2002 Downloading and Viewing the CMPL Program
43 2002 Schneider Electric All Rights Reserved
The Compile Results screen displays. See Figure 55 for an example of this
screen. It lists such information as start and stop information about the
compile, which can be useful if the compile fails.
It also lists individual errors that occurred during the compile and the line
each error occurred on. To locate an error in the source code, double-click
either the error number or description in the Compile Results screen. The
corresponding line in the source code will be highlighted.
DOWNLOADING AND VIEWING THE
CMPL PROGRAM
Once you have compiled the program, viewed the results, and corrected the
errors, you can download the program to the circuit monitor and view circuit
monitor on-board information.
Downloading the Program To download for debug purposes, follow these steps:
1. Select the Debug output type button in the Compiler Options screen (see
Figure 54).
2. Select the Generate Output menu item (checkmark is beside Generate
Output). See Turning Output Generation On and Off on page 42.
3. Compile the source code (Build > Compile, , or F7 key).
The program is automatically downloaded to the circuit monitor RAM.
To download for normal execution, follow these steps:
1. Select the Release output type in the Compiler Options screen (see
Figure 54).
2. Select the Generate Output menu item (checkmark is beside Generate
Output). See Turning Output Generation On and Off on page 42.
3. Compile the source code (Build > Compile, , or F7 key).
4. Use DLF-3000 to download the .fw file (click the DLF tab on the toolbar
to launch DLF-3000). The file you want to download has the same name
as the .src file; the two files will be located in the same directory.
Verifying the Download Once you have downloaded a program to the circuit monitor, you can verify
that the download was successful. On the circuit monitor display, choose the
CMPL option from the main menu. The display lists the name, version, date,
and status (Run, Halt, or Program not Present) of the program.
Figure 55: Compile Results screen
Chapter 5Compiler Operation 63230-300-221/A1
Running and Debugging the Program 2/2002
2002 Schneider Electric All Rights Reserved 44
From within CMPL, select View > Onboard Program Statistics, or click Ctrl +
R. The Onboard Program Information screen displays. See Viewing Circuit
Monitor On-Board Information for information about this screen.
Viewing Circuit Monitor On-Board Information To view of snapshot of the program that has been downloaded to the circuit
monitor, click View > On Board Program Statistics, click the icon, or press
Ctrl + R. The On Board Program Information screen displays. Figure 56
shows a sample screen.
You can change the initial processor mode. Options are:
Program Not Present
Halt
Run
Click Exit to close the screen.
RUNNING AND DEBUGGING THE
PROGRAM
This section describes how to run the program for debugging or normal
execution, and how to use the compiler to debug the program.
Running the Program To run the program, click the Go icon ( ), click Debug > Run, or Press Ctrl
+ F5.
To run the program for normal execution, click View > On Board Program
Statistics or press Ctrl + R. Then change the Initial Processor Mode to run.
After the circuit monitor downloads the CMPL program and resets, the
program will execute.
Using the Compiler to Debug To debug a program from within CMPL, follow these steps:
build the file
set breakpoints (this is a future enhancement)
run the program
Additionally, you may want to:
view variables
add additional variables to the watch window
Figure 56: On Board Program Information screen
63230-300-221/A1 Chapter 5Compiler Operation
2/2002 Running and Debugging the Program
45 2002 Schneider Electric All Rights Reserved
To build a debug file, follow these steps:
1. Select the Debug output type in the Compiler Options screen (see
Figure 54).
2. Select the Generate Output menu item (checkmark is beside Generate
Output). See Turning Output Generation On and Off on page 42.
3. Compile the source code (Build > Compile, , or F7 key).
The program is automatically downloaded to the circuit monitor RAM.
Run the program as described in Running the Program on page 44.
To view variables, do the following:
After compiling, highlight the name of the variable in the source code.
Click View > Watch, click the icon, or press Ctrl + W.
The Watch screen displays. Figure 57 shows a sample Watch screen.
The Watch screen displays the variable name (or its register number), as well
as its value. Click the Display Type to change from decimal to hexadecimal
display of the value.
To add additional variables to the Watch screen, follow these steps:
1. With the Watch screen displayed, type the new variable in the Register
Number/Variable Name field.
2. Click Add.
The variable is added.
Figure 57: Watch screen
Chapter 5Compiler Operation 63230-300-221/A1
Running and Debugging the Program 2/2002
2002 Schneider Electric All Rights Reserved 46
Viewing the CMPL Program Memory To view the CMPL program memory, click View > Memory or click .
The Memory screen displays with the address 0x0000.Figure 58 illustrates
this screen.
To view specific memory information, type the memory location in the
Address field, then press Enter. The memory location corresponds to the
memory addresses displayed at the bottom of the cmpl.dbg file.
Reading and Writing to Registers To view the current status of any CM4000 register, and to write directly to
writable registers, click Debug > Read/Write Registers or click .
The Read/Write Registers screen displays. Figure 59 displays this screen.
To read the status of any register(s), enter the register name(s). Click Read.
The current value of each register displays in the right-hand column.
To write to any CM4000 register, enter the register number and a valid value.
Click Write. Although there is no confirmation message, the data is written
into the register(s).
Figure 58: Memory screen
Figure 59: Read/Write screen
63230-300-221/A1 Chapter 6Running a Program
2/2002 Preparing to Run a Program: Reading and Writing CM4000 Registers
47 2002 Schneider Electric All Rights Reserved
CHAPTER 6RUNNING A PROGRAM
This chapter explains how to start and halt execution of a CMPL program in
a circuit monitor. See Chapter 2 for details on the creation of a custom
program and Chapter 5 for instructions on compiling a program and
downloading the resulting code to a circuit monitor. Note that a new feature
in the CM4000 allows users to view the status of a program, as well as start
and stop programs, from the circuit monitor display.
PREPARING TO RUN A PROGRAM:
READING AND WRITING CM4000
REGISTERS
You can use POWERLOGIC application software, such as SMS-3000, to
read and write circuit monitor registers. It is also possible to read and write
registers from the circuit monitor remote display. You can also write to the
CMPL registers in a CM4000 using the Read/Write Registers screen in
CMPL. See See Reading and Writing to Registers on page 46 for
directions.
The CM4000 instruction manual explains how to use the display to read
values contained in circuit monitor registers and to enter new values into
registers capable of read/write operations. Both reading and writing are
accomplished in Diagnostics > Read/Write Regs mode on the circuit monitor
display.
The circuit monitor internal registers can be manipulated to verify a program
download and to start or halt that program.
VERIFYING PROGRAM DOWNLOAD You can verify that a program is downloaded and available for execution in
one of three ways:
1. Examine the value in register 8192. This read-only register will have one
of the following three values:
0: No program present
1: Program present and currently halted
5: Program present and currently running
2. From the circuit monitor main menu, select CMPL. The program name,
version, date, and status display.
3. This information is also viewable from the Onboard Program Information
screen in CMPL (View > Onboard Program Statistics or Ctrl R).
If a Program Name and Program Version are included in the source file
for the program (See Chapter 2.), the name and version are also
available, but they are difficult to read because the program name spans
multiple registers. See Chapter 7 for instructions on decoding a program
name from circuit monitor registers.
If a value of 1 in register 8190 indicates that a program is present and
halted, the value in register 8191 is an error register that indicates the
status of the program at the time it halted. A value of zero in register
8191 when a program is present in the circuit monitor indicates that
the program has never been halted. Any other value in register 8191
indicates the reason for the most recent program halt.
Chapter 6Running a Program 63230-300-221/A1
Setting Registers Before Program Execution 2/2002
2002 Schneider Electric All Rights Reserved 48
Table 6 1 illustrates the relationship between these two registers.
Appendix D, Programming Language Runtime Error Codes, lists all of the
codes that can appear in Register 8191 along with brief descriptions of their
meanings. Most of these codes indicate errors, but notice that values 1011
through 1014 indicate predictable conditions under which a user may have
intentionally caused a program to halt.
SETTING REGISTERS BEFORE
PROGRAM EXECUTION
If register 8189 is set to a value of 5, the program begins execution
immediately following a reset of the circuit monitor. This means that the
custom program will begin execution immediately after the program is
downloaded. A value of 1 in register 8189 causes the selected program to
remain halted following a reset.
Registers 8196 through 8199 are usually set to zero, so it is rarely necessary
to change their values except for special debug processes described in
Chapter 7. In the event of unexplained program pauses (as indicated in
registers 8190 and 8191, described above), verify that these debug registers
all contain zeros.
RUNNING AND HALTING A PROGRAM To issue a command to the circuit monitor command interface, enter the
4-digit numeric value of the command into register 8000 (the command
register). As soon as a numeric command is entered and confirmed in this
register, the circuit monitor accepts it for execution.
The CMPL function adds a command to those already documented for
Series 4000 circuit monitors:
After starting a program with the compiler or command interface, you can
examine registers using the compiler watch window. You can also use
computer software such as the System Manager Software (SMS) to access
and interpret output from custom circuit monitor programming.
Notice that a command code of 1110, placed into register 8000, causes the
circuit monitor to perform a reset. An alternative method of executing a
custom program is to write 5 to register 8189indicating that the selected
program is to be run following a reset. Then enter a command code of 1110
Table 6 1:Registers 8190 and 8191
Register Value Description
8190 0 No program present
1 Program present and currently halted
5 Program present and currently running
8191 nnnn Condition or error at the time program
execution terminated (See Appendix D)
CMD
8101
Params
8001 = 1
8002 = 1 for halt
or
5 for run
63230-300-221/A1 Chapter 6Running a Program
2/2002 Running and Halting a Program
49 2002 Schneider Electric All Rights Reserved
into register 8000. The circuit monitor is reset, which may be desirable before
beginning some custom programs, and then the program will begin
execution.
NOTE: The initialization task is executed after every reset. Relays will be de-
energized.
Chapter 6Running a Program 63230-300-221/A1
Running and Halting a Program 2/2002
2002 Schneider Electric All Rights Reserved 50
63230-300-221/A1 Chapter 7Debug Techniques for CMPL Programs
2/2002 Examining Program Control Registers
51 2002 Schneider Electric All Rights Reserved
CHAPTER 7DEBUG TECHNIQUES FOR CMPL PROGRAMS
This chapter describes techniques that enable programmers to analyze the
operation of a custom program running within a CM4000 circuit monitor.
Some methods are appropriate for use by less experienced programmers
while others are intended for advanced software engineers.
EXAMINING PROGRAM CONTROL
REGISTERS
Registers 8175 through 8199 in the circuit monitor contain information about
the name and performance of any CMPL program that has been downloaded
to become a part of the resident circuit monitor operating system. See
Appendix F for a list of registers.
Use the Diagnostics > Read/Write Regs option of the circuit monitor display
to examine these registers individually, or view them in the On Board
Program Information screen. Where appropriate computer software is
available, you can use a POWERLOGIC System Manager Software (SMS)
program to read these values.
USING RUNTIME ERROR CODES Chapter 6, Running a Program, included a discussion of registers 8190 and
8191. A value of zero in register 8190 indicates that no custom program is
currently loaded in the circuit monitor. Values of 1 or 5 indicate that a program
is currently loaded and that it is either halted or runningin that order.
Register 8192 either contains a value of zeroindicating that the current
program has never been haltedor else it contains an explanatory code that
was generated by the most recent program halt. Most values that appear in
register 8192 indicate an error that caused an unexpected program halt, but
codes 1011 through 1014 describe normal program halts under program or
user control.
A list of the codes that can appear in register 8192 is given in Appendix D,
Programming Language Runtime Error Codes.
DETERMINING THE NAME, VERSION,
AND DATE OF A PROGRAM
Registers 8184 through 8187 contain the date and time that the current
program was compiled, or you can view the date and time in the On Board
Program Information screen. This value is expressed in the standard four-
register date format used in Series CM4000 devices. Register 8184 stores
the month (112) in the high byte, the day (131) in the low byte. Register
8185 stores the year (0199) in the high byte, the hour (023) in the low byte.
Since the year byte holds only a maximum of three characters, you must add
1900 to obtain the correct year. Register 8186 stores the minute (059) in the
high byte, the seconds (0-59) in the low byte. Register 8187 stores
milliseconds. The date and time can be used to verify that multiple instances
of a program are actually copies made from a single hex file produced at a
particular time.
If the source file for a custom program includes entries for Program Name
and Program Version, these values are stored in registers 8175 through 8183
when the program is loaded into a circuit monitor. The value of the Program
Version is in register 8183. This is an integer value in the range 032767. By
convention, a value of 101 indicates release 1.01; a value of 200 indicates
release 2.00; and so on.
Chapter 7Debug Techniques for CMPL Programs 63230-300-221/A1
Determining the Name, Version, and Date of a Program 2/2002
2002 Schneider Electric All Rights Reserved 52
Extracting the Program Name from registers 8175 through 8182 is a more
complex task. The steps for performing this conversion follow:
1. Determine the value in each register, starting with register 8175 and
continuing through register 8182.
2. Each register value stands for two characters in the name of the program.
Beginning with register 8175, divide the value in the register by 256. The
left part of the result (the quotient) is the first character in the name; the
right part of the result (the remainder) is multiplied by 256 to yield the
second character in the name.
3. Table 72 lists both hexadecimal and ASCII codes and their
corresponding characters. The hexadecimal register entry needs no
conversion. If youre viewing the CM40000 registers in decimal format,
follow instructions in step 2 to convert the numeric values into characters.
Example: 0x7261 (hexadecimal) or 29281 (decimal):
Hexadecimal: 72 = r; 61 = a
Decimal: 29281/256 = 114.37890625
114 = r; 0.37890625 * 256 = 97 = a
4. Repeat this process for each of the Program Name registers, in order.
Table 72:ASCII Codes and Characters
Hex
Code
ASCII
Code
Character
Hex
Code
ASCII
Code
Character
Hex
Code
ASCII
Code
Character
Hex
Code
ASCII
Code
Character
0x20 032 (space) 0x38 056 8 0x50 080 P 0x68 104 h
0x21 033 ! 0x39 057 9 0x51 081 Q 0x69 105 i
0x22 034 0x3A 058 : 0x52 082 R 0x6A 106 j
0x23 035 # 0x3B 059 ; 0x53 083 S 0x6B 107 k
0x24 036 $ 0x3C 060 < 0x54 084 T 0x6C 108 l
0x25 037 % 0x3D 061 = 0x55 085 U 0x6D 109 m
0x26 038 & 0x3E 062 > 0x56 086 V 0x6E 110 n
0x27 039 0x3F 063 ? 0x57 087 W 0x6F 111 o
0x28 040 ( 0x40 064 @ 0x58 088 X 0x70 112 p
0x29 041 ) 0x41 065 A 0x59 089 Y 0x71 113 q
0x2A 042 * 0x42 066 B 0x5A 090 Z 0x72 114 r
0x2B 043 + 0x43 067 C 0x5B 091 [ 0x73 115 s
0x2C 044 , 0x44 068 D 0x5C 092 \ 0x74 116 t
0x2D 045 - 0x45 069 E 0x5D 093 ] 0x75 117 u
0x2E 046 . 0x46 070 F 0x5E 094 ^ 0x76 118 v
0x2F 047 / 0x47 071 G 0x5F 095 _ 0x77 119 w
0x30 048 0 0x48 072 H 0x60 096 0x78 120 x
0x31 049 1 0x49 073 I 0x61 097 a 0x79 121 y
0x32 050 2 0x4A 074 J 0x62 098 b 0x7A 122 z
0x33 051 3 0x4B 075 K 0x63 099 c 0x7B 123 {
0x34 052 4 0x4C 076 L 0x64 100 d 0x7C 124 |
0x35 053 5 0x4D 077 M 0x65 101 e 0x7D 125 }
0x36 054 6 0x4E 078 N 0x66 102 f 0x7E 126 ~
0x37 055 7 0x4F 079 O 0x67 103 g
63230-300-221/A1 Chapter 7Debug Techniques for CMPL Programs
2/2002 Determining the Effects of Custom Code on the Total Meter Cycle Time
53 2002 Schneider Electric All Rights Reserved
DETERMINING THE EFFECTS OF
CUSTOM CODE ON THE TOTAL METER
CYCLE TIME
Runtime error codes 1101, 1102, and 1103, described in Appendix D,
Programming Language Runtime Error Codes, indicate that the CMPL
program has caused excessive delay in the meter cycle. When this occurs,
the custom program halts and does not resume execution until it is manually
restarted.
Such an error can occur in the very first meter cycle of program operation if
the demands of the custom program are too great. However, such a halt can
occur whenever the tasks triggered by various events or timers and the
routine tasks performed in each meter cycle coincide, delaying the meter
cycle beyond the permitted limit.
INSERTING A DEBUG CODE INTO A
PROGRAM
Verification that a user-specific problem has been correctly solved by a
CMPL program is solely the responsibility of the application engineer.
After a programmer has completed the design and writing of any program,
the program must be tested for correct operation.
Time-honored programming techniques provide some means of testing
custom programs without encountering the complexity of the debug feature
in the CMPL. The simplest test of any program is to provide it with known,
controlled input values and verify that it produces expected results.
An extension of this technique is to provide a program with known input
values that exceed the values for which it was designed. Verify that
unexpected values cause the program to fail in a manner that is expected and
acceptable.
Create a diagnostic version of the program source file containing statements
that store intermediate values while computations are being performed.
Examine these values to be certain that correct results are returned at every
stage of the calculation. Similarly, insert lines to store significant values at
every decision point or IF statement within the program logic.
Note: Despite all tests and precautions, keep in mind that CMPL is not
designed to manage critical control functions. These functions should be
relegated to specialized equipment designed for a specific purpose and
tested for reliability. Do not attempt to make the CMPL programming
capability replace sophisticated equipment engineered for and dedicated to
a particular control task.
Chapter 7Debug Techniques for CMPL Programs 63230-300-221/A1
Inserting a Debug Code into a Program 2/2002
2002 Schneider Electric All Rights Reserved 54
63230-300-221/A1 Appendix AProgramming Language Reserved Words
2/2002
55 2002 Schneider Electric All Rights Reserved
APPENDIX APROGRAMMING LANGUAGE RESERVED WORDS
This appendix contains a list of keywords reserved for use by the CMPL
compiler. These keywords should not be used as variable or data names or
as subroutine labels. For more information on a specific keyword, refer to the
page number given.
Table A1:Programming Language Keywords
Keyword Page # Keyword Page #
{ } 32 IF 31
// 6 INITIALIZE 9
## 6
NAME 7
AND 31 NEXT 33
ARCTAN 27 NOT 31
BITREG 16 OR 31
CALL 34 POWFACT 16
CMDREQ 35 PROGRAM 7
COMMSREQ 35
CONVERT 29 REGISTER 16
COSINE 27 RESTART 35
RETURN 34
DATETIME 16
DECLARATION 8 SECTION 6
DEFINE 19 SECURITY 7
SHIFT 26
ELSE 31 SINE 28
END 6 SQROOT 28
EQUATE 18 SUBROUTINE 34
EVENT 9
TASK 6
FLOAT 16 TIMER 9
FOR 33 TO 33
HALT 35 VERSION 6
XOR 31
Appendix AProgramming Language Reserved Words 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 56
63230-300-221/A1 Appendix BProgramming Language Syntax
2/2002
57 2002 Schneider Electric All Rights Reserved
APPENDIX BPROGRAMMING LANGUAGE SYNTAX
This appendix contains descriptions of the correct syntax to be used in the
following phrases:
Data Definitions
Mathematical Expressions
Conditional Expressions
Assignment Statement Format
Programming Language Verbs
Programming Language Functions
NOTE: The array index, n, cannot be a mathematical expression, such as
(value + 1); n must be a decimal integer.
Table B 1:Data Definition
data_type name_of_register
where data_type is the new name of any valid type
and name_of_register is the name (beginning with S) of any
MODBUS register
data_type name_of_variable name_of_register
where data_type is the name of any valid data type
name_of variable is an easily understood and remembered
name consisting of up to 27 letters, numbers, and underscores
and name_of_register is the name (beginning with S) of any
MODBUS register
EQUATE name_of_variable name_of_register
where name_of variable is an easily understood and remembered
name consisting of up to 27 letters, numbers, and underscores
and ame_of_register is the name (beginning with S) of any
MODBUS register that is already included in a data definition
DEFINE value_name value [value] [value]
where value_name is an easily understood and remembered name
consisting of up to 27 letters, numbers, and underscores
and value is a numeric value or, in some cases, multiple numeric
values
data_type name_of_array[n] name_of_register
where data_type is the name of any valid data type
name_of_array is an easily understood and remembered name
consisting of up to 27 letters, numbers, and underscores.
name_of_register is the name (beginning with S) of any
register
and n is a decimal integer in the range 1 to 256
Appendix BProgramming Language Syntax 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 58
Table B 2:Mathematical Expressions
The following operators are supported. Parentheses are not supported. No
more than six operations can occur within any expression.
+ addition
subtraction
* multiplication
/ division
% modulus division
Table B 3:Conditional Expressions
The following operators are supported. Other combinations of these operators,
such as => or ><, are not supported.
= equals
< less than
> greater than
<> not equal to
<= less than or equal to
>= greater than or equal to
Table B 4:Assignment Statement Format
variable = value or expression
63230-300-221/A1 Appendix BProgramming Language Syntax
2/2002
59 2002 Schneider Electric All Rights Reserved
Table B 5:Programming Language Verbs
CALL subr_name
where subr_name is the name of a subroutine defined elsewhere in
the custom program
FOR ndx_var = n TO m
prog_commands
NEXT ndx_var
where ndx_var is an index variable of data type REGISTER
n and nn are decimal constants that set the lower and upper
limits, respectively, of the index variable
and prog_command(s) are one or more valid programming
language commands to be expected once for each value of
ndx_var
HALT
IF (cond_expr)
{
prog_command(s)
}
OR
IF (cond_expr)
{
prog_command(s)
}
ELSE
{
alt_prog_command(s)
}
where cond_expr is a conditional expression to be evaluated
prog_command(s) are one or more valid programming
language commands to be expected if the cond_expr is true
and alt_prog_command(s) are one or more valid programming
language commands to be executed if the cond_expr is not
true
RESTART
RETURN
Appendix BProgramming Language Syntax 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 60
Table B 6:Programming Language Functions
Trigonometric
ARCTAN (name_of_variable_1, name_of_variable_2)
where the expression (name_of_variable_1/name_of_variable_2)
yields the tangent to be evaluated
COSINE (name_of_variable)
SINE (name_of_variable)
Mathematical
CONVERT (name_of_variable_)
SHIFT (name_of_variable, degree_of_shift) [arithmetic shift]
SQROOT (name_of_variable)
Logical
AND (name_of_variable_1, name_of_variable_2)
NOT (name_of_variable)
OR (name_of_variable_1, name_of_variable_2)
SHIFT (name_of_variable, degree_of_shift) [logical shift]
XOR (name_of_variable_1, name_of_variable_2)
CM4000 Interface
CMDREQ (cmd_num, num_of_params, cmd_params)
where cmd_num is the number of a command,
and num_of_params is the length of the command parameter list (019),
and cmd_params is a register array variable containing parameters
COMMSREQ (status, ctl_tab, data_tab, reglist_tab)
where status is the status of the request: complete, pending, or error
and ctl_tab is the communication control array of registers
and data_tab is the array of registers for data reads and writes
and reglist_tab is the addresses of the registers to read
63230-300-221/A1 Appendix CProgramming Language Assembler and Compiler Error Codes
2/2002
61 2002 Schneider Electric All Rights Reserved
APPENDIX CPROGRAMMING LANGUAGE ASSEMBLER AND COMPILER ERROR
CODES
If an error condition is encountered during the compile phase, a code for that
error (defined in the list below) is displayed in the Compile Results screen.
The programmer must correct the errors.
Table C 1:Error Codes
Assembler Error Code Definition
2101 Source file not found
2102 Cannot open work file
2103 Disk file read/write error
2110 No task, Initialize
2111 No end task, Initialize
2112 No task, Metercycle
2113 No end task, Metercycle
2114 Task sequence error
2115 Missing End or Return
2116 Too many timer/event tasks
2117 Too many subroutines or labels
2118 Bad timer/event parameter
2119 Duplicate label or subroutine name
2120 Invalid instruction
2121 Invalid or missing datatype
2122 Invalid or missing operands
2123 Program too large
2124 Invalid security code
2125 Invalid program version number
2201 Disk file error on .LST file
2202 Cannot open work file
2211 Invalid target address
2212 Assembler phase error
Compiler Error Code Definition
3101 Source file not found
3102 Cannot open work file
3103 Disk file read/write error
3110 No program version
3111 No Declaration Section
3112 No END Declaration Section
3113 Invalid DEFINE EQUATE
3114 Too many DEFINE Equates
3115 Invalid program name, version, or security
3121 Invalid datatype declaration
3122 Invalid array subscript
3123 Invalid register number
Appendix CProgramming Language Assembler and Compiler Error Codes 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 62
3124 Insufficient memory space
3125 Memory space already assigned
3126 Invalid variable name
3127 Too many variables declared
3128 Duplicate variable name
3141 No Task Header
3142 No Task END
3151 Invalid IF statement
3152 Invalid IF comparison
3153 Too many nested IF levels
3154 Invalid IF comparison
3155 Unbalanced IF statement
3156 Bad or missing block control
3161 Invalid FOR statement
3162 Invalid index values
3163 Too many nested FOR levels
3164 Index register already used
3165 Invalid NEXT index register
3166 Unbalanced FOR statement
3167 Invalid NEXT statement
3181 Invalid instruction
3182 Invalid or missing parameter
3183 Invalid datatype
3184 Different datatypes
3185 Invalid memory reference
3186 Invalid index register
3187 Invalid constant
3188 Invalid math operator
3189 Too many terms in equation
3190 Extraneous items on line
3191 Division by zero
3201 Disk file error on .LST file
3202 Cannot open work file
Table C 1:Error Codes
63230-300-221/A1 Appendix DProgramming Language Runtime Error Codes
2/2002
63 2002 Schneider Electric All Rights Reserved
APPENDIX DPROGRAMMING LANGUAGE RUNTIME ERROR CODES
If an error condition is encountered while running a CMPL program, a code
for that error (defined in the list below) is placed in Control Register 8191. No
warning messages are produced. You must correct program errors in the
source file, then recompile and reload the source file in the circuit monitor.
Table D 1:Runtime Error Codes
Error Code Definition
1001 Selected CMPL program has incorrect CRC value
1002 Invalid CMPL generator version
1011 Halt resulted from user command
1012 Halt resulted from program instruction
1013 Pause at indicated breakpoint
1014 Executed CMPL program RESTART instruction
1101 Excessive addition to update cycle time-task too large
1102 Excessive addition to update cycle time-task queue filled
1103 Excessive addition to update cycle time-metercycle delayed
1104 Attempt to fetch from invalid address
1201 Attempt to execute invalid instruction
1202 Attempt to execute instruction with invalid parameters
1211 Attempt to read invalid register
1212 Attempt to write invalid register
1221 Attempt to send invalid or restricted command
1222 Attempt to send command failed: interface busy
1231 Overflow of subroutine callstack
1241 Overflow of arithmetic: divide by zero
1242 Overflow of arithmetic: result out of range
Appendix DProgramming Language Runtime Error Codes 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 64
63230-300-221/A1 Appendix ESample Program Library
2/2002
65 2002 Schneider Electric All Rights Reserved
APPENDIX ESAMPLE PROGRAM LIBRARY
//----------------------------------------------------------------------------
//
// EXAMPLE1.SRC: A Minimal Program
//
// CM4000 CMPL example program for demo of the compiler syntax.
//
// Last Modified: 11-20-2001
// Modified for use with CM4000PL.EXE v01.05: 11-20-2001
//----------------------------------------------------------------------------
## PROGRAM NAME: CMPL_EXAM1
## PROGRAM VERSION: 0100
## PROGRAM SECURITY: 1234567
//----------------------------------------------------------------------------
//
// Program requirements for the minimal problem:
//
// a - Establish a counter (in reg S14090) for the number of metercycle
// updates.
// b - Establish a 'step' counter (in reg S14091) for the number of
// metercycle updates, with values of 0,3,6,9,...
//
// c - With every metercycle update:
// - read the status inputs
// - mask out all input bits except from I/O Point #5
// - place the masked value into register S14100
//----------------------------------------------------------------------------
//---- begin declaration of data variables
## DECLARATION SECTION:
REGISTER cyclecount s14090
REGISTER stepcnt s14091
BITREG inputvals s4001
BITREG inputthree s14100
BITREG reportthree s14101
## END DECLARATION //---- end declarations
//----------------------------------------------------------------------------
63230-300-221/A1 Appendix ESample Program Library
2/2002
66 2002 Schneider Electric All Rights Reserved
//---- instructions performed once at CUL restart
## INITIALIZE TASK:
cyclecount = 0
return
## END INITIALIZE //---- end initialize instructions
//----------------------------------------------------------------------------
//---- instructions performed per meter cycle
## METERCYCLE TASK:
cyclecount = cyclecount + 1
stepcnt = cyclecount / 3 * 3
inputthree = AND(inputvals, 0x0004)
reportthree = inputthree
return
## END METERCYCLE //---- end per meter cycle instructions
//----------------------------------------------------------------------------
//
63230-300-221/A1 Appendix ESample Program Library
2/2002
67 2002 Schneider Electric All Rights Reserved
// EXAMP2.SRC : Timer and Event Tasks
// CM4000 CMPL example program for demo of the compiler syntax.
//
// Last Modified: 11-20-2001
// Modified for use with CM4000PL.EXE v01.05: 11-20-2001
//----------------------------------------------------------------------------
## PROGRAM NAME: CMPL_EXAM2
## PROGRAM VERSION: 0200
## PROGRAM SECURITY: 1234567
//----------------------------------------------------------------------------
//
// Program requirements for the Timer and Event tasks problem:
//
// a - If (and only if) event 1002 is true, make an entry in data log
// #7 every 45 seconds.
//
// b - If (and only if) event 1002 is true, make an entry in data log
// #5 every minute (with secs=00, i.e. on the minute)
//
//----------------------------------------------------------------------------
//---- begin declaration of data variables
## DECLARATION SECTION:
DEFINE FALSE 0
DEFINE TRUE 1
BITREG Param_List[19] S14400 // for storing params for command
REGISTER event1002state s14200
## END DECLARATION //---- end declarations
//----------------------------------------------------------------------------
//---- instructions performed once at CUL restart
## INITIALIZE TASK:
event1002state = FALSE
return
## END INITIALIZE //---- end initialize instructions
63230-300-221/A1 Appendix ESample Program Library
2/2002
68 2002 Schneider Electric All Rights Reserved
//----------------------------------------------------------------------------
//---- instructions performed per meter cycle
## METERCYCLE TASK:
return // note no program requirement
## END METERCYCLE //---- end per meter cycle instructions
//
//----------------------------------------------------------------------------
//---- instructions to perform at 45 sec interval
## TIMER TASK: INTERVAL 45 SECONDS
if (event1002state = FALSE)
{ return } // return if log entry not required
// request writing of entry into data log #7
Param_List[1] = 0x0040
CMDREQ (7510, 1, Param_List)
return
## END TIMER //---- end of 45 second timer instructions
//----------------------------------------------------------------------------
63230-300-221/A1 Appendix ESample Program Library
2/2002
69 2002 Schneider Electric All Rights Reserved
//---- instructions to perform at 1 min interval
## TIMER TASK: INTERVAL 1 MINUTES OFFSET 0 MINUTES
if (event1002state = FALSE)
{ return } // return if log entry not required
// request writing of entry into data log #5
Param_List[1] = 0x0010
CMDREQ (7510, 1, Param_List)
return
## END TIMER //---- end of 1 minute timer instructions
//----------------------------------------------------------------------------
//---- instructions to perform when event 2 turns on
## EVENT TASK: EVENT 1002 FALSE-TO-TRUE
event1002state = TRUE
return
## END EVENT //---- end of event 2 transit true instructions
//----------------------------------------------------------------------------
//---- instructions to perform when event 2 turns off
## EVENT TASK: EVENT 1002 TRUE-TO-FALSE
event1002state = FALSE
return
## END EVENT //---- end of event 2 transit false instructions
//----------------------------------------------------------------------------
//
63230-300-221/A1 Appendix ESample Program Library
2/2002
70 2002 Schneider Electric All Rights Reserved
// EXAMP3.SRC : Subroutine Usage
// CM4000 CMPL example program for demo of the compiler syntax.
//
// Last Modified: 11-20-2001
// Modified for use with CM4000PL.EXE v1.05: 11-20-2001
//----------------------------------------------------------------------------
## PROGRAM NAME: CMPL_EXAM3
## PROGRAM VERSION: 0300
## PROGRAM SECURITY: 1234567
//----------------------------------------------------------------------------
//
// Program requirements for the Subroutine Usage problem:
//
// a - Compute the sum of three phase currents, and place in Register
// S14200.
//
// b - If the total current is > 600 amps, turn on the relay at IO Point #1,
// else turn off relay at IO Point #1.
//
//----------------------------------------------------------------------------
//---- begin declaration of data variables
## DECLARATION SECTION:
REGISTER Param_List[19] s14400 // for storing params for command
REGISTER iaamps s1100
REGISTER ibamps s1101
REGISTER icamps s1102
REGISTER cyclecount s14200
REGISTER totalamps s14201
## END DECLARATION //---- end declarations
//----------------------------------------------------------------------------
//---- instructions performed once at CUL restart
63230-300-221/A1 Appendix ESample Program Library
2/2002
71 2002 Schneider Electric All Rights Reserved
## INITIALIZE TASK:
cyclecount = 0
totalamps = 0
Param_List[1] = 1
CMDREQ (3310, 1, Param_List) // set IO Point 1 to external ctl
Param_List[1] = 1
CMDREQ (3320, 1, Param_List) // turn the relay at IO Point 1 off
return
## END INITIALIZE //---- end initialize instructions
//----------------------------------------------------------------------------
//---- instructions performed per meter cycle
## METERCYCLE TASK:
cyclecount = cyclecount + 1
CALL COMPUTE_TOTAL_CURRENT
CALL SET_RELAY_ONE
return
## END METERCYCLE //---- end per meter cycle instructions
//----------------------------------------------------------------------------
63230-300-221/A1 Appendix ESample Program Library
2/2002
72 2002 Schneider Electric All Rights Reserved
//---- instructions performed to compute total current
## SUBROUTINE: COMPUTE_TOTAL_CURRENT
totalamps = iaamps + ibamps + icamps
return
## END SUBROUTINE //---- end of compute total current
//----------------------------------------------------------------------------
//---- instructions to determine state of the relay at IO Point #1
## SUBROUTINE: SET_RELAY_ONE
if (totalamps > 600)
{
Param_List[1] = 1
CMDREQ (3321, 1, Param_List) // turn the relay at IO Point #1 on
}
else
{
Param_List[1] = 1
CMDREQ (3320, 1, Param_List) // turn the relay at IO Point #1 off
}
return
## END SUBROUTINE //---- end of instructions to set the relay at IO Point #1
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//
63230-300-221/A1 Appendix ESample Program Library
2/2002
73 2002 Schneider Electric All Rights Reserved
// EXAMP4.SRC : Nested IF and FOR Statements
// CM4000 CMPL example program for demo of the compiler syntax.
//
// Last Modified: 11-20-2001
// Modified for use with CM4000PL.EXE v1.05: 11-20-2001
//----------------------------------------------------------------------------
## PROGRAM NAME: CMPL_EXAM4
## PROGRAM VERSION: 0400
## PROGRAM SECURITY: 1234567
//----------------------------------------------------------------------------
//
// Program requirements for the Nested IF and FOR Statements problem:
//
// a - For each of three phase currents, maintain an array for the
// last 10 meter readings. Place the array for phase A at S14200,
// phase B at S14210, and phase C at S14220.
//
//----------------------------------------------------------------------------
//---- begin declaration of data variables
## DECLARATION SECTION:
REGISTER PHASEAMPS[3] s1100
REGISTER ONECURRENT s14000
REGISTER CURRENT_A_LIST[10] s14200
REGISTER CURRENT_B_LIST[10] s14210
REGISTER CURRENT_C_LIST[10] s14220
REGISTER IXPH s14001
REGISTER IXM s14002
REGISTER IXMLO s14003
REGISTER IXMHI s14004
## END DECLARATION //---- end declarations
//----------------------------------------------------------------------------
//---- instructions performed once at CUL restart
63230-300-221/A1 Appendix ESample Program Library
2/2002
74 2002 Schneider Electric All Rights Reserved
## INITIALIZE TASK:
FOR IXM = 1 TO 10 // clear the list for all three phases
CURRENT_A_LIST[IXM] = 0
CURRENT_B_LIST[IXM] = 0
CURRENT_C_LIST[IXM] = 0
NEXT IXM
RETURN
## END INITIALIZE //---- end initialize instructions
//----------------------------------------------------------------------------
//---- instructions performed per meter cycle
## METERCYCLE TASK:
CALL MAINTAIN_CURRENT_LISTS
RETURN
## END METERCYCLE //---- end per meter cycle instructions
//----------------------------------------------------------------------------
//---- instructions performed to maintain currents list
63230-300-221/A1 Appendix ESample Program Library
2/2002
75 2002 Schneider Electric All Rights Reserved
## SUBROUTINE: MAINTAIN_CURRENT_LISTS
FOR IXPH = 1 TO 3 // for each of three phases
ONECURRENT = PHASEAMPS[IXPH]
// push down values in one list
IF (IXPH = 1)
{
FOR IXM = 1 TO 9
IXMLO = 11 - IXM
IXMHI = 10 - IXM
CURRENT_A_LIST[IXMLO] = CURRENT_A_LIST[IXMHI]
NEXT IXM
CURRENT_A_LIST[1] = ONECURRENT
} // ENDIF PHASE A
ELSE
{
IF (IXPH = 2)
{
FOR IXM = 1 TO 9
IXMLO = 11 - IXM
IXMHI = 10 - IXM
CURRENT_B_LIST[IXMLO] = CURRENT_B_LIST[IXMHI]
NEXT IXM
CURRENT_B_LIST[1] = ONECURRENT
} // ENDIF PHASE B
ELSE
{
IF (IXPH = 3)
{
FOR IXM = 1 TO 9
IXMLO = 11 - IXM
IXMHI = 10 - IXM
CURRENT_C_LIST[IXMLO] = CURRENT_C_LIST[IXMHI]
NEXT IXM
CURRENT_C_LIST[1] = ONECURRENT
} // ENDIF PHASE C
} // ENDELSE
} // ENDELSE
NEXT IXPH
RETURN
## END SUBROUTINE //---- end of maintain currents list
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//
63230-300-221/A1 Appendix ESample Program Library
2/2002
76 2002 Schneider Electric All Rights Reserved
// EXAMP5.SRC : A Typical User Specific Problem
// CM4000 CMPL example program for demo of the compiler syntax.
//
// Last Modified: 11-20-2001
// Modified for use with CM4000PL.EXE v1.05: 11-20-2001
//----------------------------------------------------------------------------
## PROGRAM NAME: CMPL_EXAM5
## PROGRAM VERSION: 0500
## PROGRAM SECURITY: 1234567
//----------------------------------------------------------------------------
//
//
//
// Program to solve this user specific logic problem:
//
//
// a - Compute the present total three phase current in the circuit
// monitored and record the value in Register 14201.
// b - Turn on the relay at IO Point 7 (IOC Slot A)
// whenever this total exceeds 550 amps.
//
// c - Maintain a "push down list" containing the last 10 total values
// in Registers 14210-14219.
//
// d - Maintain a moving average for the last 10 total current values
// in Register 14202.
//
// e - Every 5 seconds test the moving average value in Register 14202:
// if the moving average is more than 450 amps,
// put a value of 1 in Register 14203.
// if the moving average is less than or equal 450 amps,
// put a value of 0 in Register 14203.
//
// f - Record the peak total since last unit reset in Register 14204.
// g - Toggle the state of the relay at IO Point 1 each time a new peak occurs.
// h - Make a log entry in data log #5 each time a new peak occurs.
//
//
//
//
//----------------------------------------------------------------------------
//---- begin declaration of data variables
63230-300-221/A1 Appendix ESample Program Library
2/2002
77 2002 Schneider Electric All Rights Reserved
## DECLARATION SECTION:
DEFINE OFF 0
DEFINE ON 1
DEFINE NO 0
DEFINE YES 1
REGISTER Param_List[19] S14400 // for storing params for command
REGISTER IA_AMPS S1100
REGISTER IB_AMPS S1101
REGISTER IC_AMPS S1102
REGISTER TOTAL_CURRENT S14201
REGISTER AVERAGE_TOTAL_CURR S14202
REGISTER EXCESS_AVERAGE_FLAG S14203
REGISTER PEAK_CURRENT S14204
REGISTER DISPLAY_LIST[10] S14210
REGISTER CURRENT_LIST[10] S14000
REGISTER RELAY_1_STATUS S14100
REGISTER IX S14101
REGISTER CURRENT_SUM S14102
REGISTER IXM S14103
REGISTER IXMLO S14104
REGISTER IXMHI S14105
## END DECLARATION //---- end declarations
//----------------------------------------------------------------------------
//---- instructions performed once at CMPL restart
## INITIALIZE TASK:
PEAK_CURRENT = 0
Param_List[1] = 1
CMDREQ (3310, 1, Param_List) // set relays 1 & 7 to external ctl
Param_List[1] = 7
CMDREQ (3310, 1, Param_List)
Param_List[1] = 1
CMDREQ (3320, 1, Param_List) // turn relays 1 & 7 off
Param_List[1] = 1
CMDREQ (3320, 1, Param_List)
63230-300-221/A1 Appendix ESample Program Library
2/2002
78 2002 Schneider Electric All Rights Reserved
RELAY_1_STATUS = OFF // remember status of relay 1
FOR IX = 1 TO 10 // clear the current list
CURRENT_LIST[IX] = 0
NEXT IX
RETURN
## END INITIALIZE //---- end initialize instructions
//----------------------------------------------------------------------------
//---- instructions performed per meter cycle
63230-300-221/A1 Appendix ESample Program Library
2/2002
79 2002 Schneider Electric All Rights Reserved
## METERCYCLE TASK:
// compute total current
TOTAL_CURRENT = IA_AMPS + IB_AMPS + IC_AMPS
// set status of relay 7 depending on value
// of total current
IF (TOTAL_CURRENT >= 550)
{
Param_List[1] = 7
CMDREQ (3321, 1, Param_List) // turn the relay on
}
ELSE
{
Param_List[1] = 7
CMDREQ (3320, 1, Param_List) // turn the relay off
}
// maintain the list of last 10 values and
// compute average of last 10 values
CALL MAINTAIN_LIST
// test for new peak and if true perform the
// new peak subroutine
IF (TOTAL_CURRENT > PEAK_CURRENT)
{ CALL NEW_PEAK_ACTION }
RETURN
## END METERCYCLE //---- end per meter cycle instructions
//----------------------------------------------------------------------------
//---- instructions to perform at 5 sec interval
## TIMER TASK: INTERVAL 5 SECONDS
IF (AVERAGE_TOTAL_CURR <= 450)
{ EXCESS_AVERAGE_FLAG = NO }
ELSE
{ EXCESS_AVERAGE_FLAG = YES }
RETURN
## END TIMER //---- end of 5 second timer instructions
63230-300-221/A1 Appendix ESample Program Library
2/2002
80 2002 Schneider Electric All Rights Reserved
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//---- instructions performed at new peak
## SUBROUTINE: NEW_PEAK_ACTION
// update the peak value
PEAK_CURRENT = TOTAL_CURRENT
// request writing of entry into data log #5
Param_List[1] = 0x0010
CMDREQ (7510, 1, Param_List)
// toggle the state of the relay at IO Point 1
IF (RELAY_1_STATUS = OFF)
{
Param_List[1] = 1
CMDREQ (3321, 1, Param_List) // turn the relay on
}
ELSE
{
Param_List[1] = 1
CMDREQ (3320, 1, Param_List) // turn the relay off
}
// update relay status flag variable
IF (RELAY_1_STATUS = OFF)
{ RELAY_1_STATUS = ON }
ELSE
{ RELAY_1_STATUS = OFF }
RETURN
## END SUBROUTINE //---- end of new peak instructions
//----------------------------------------------------------------------------
//---- instructions to maintain last 10 list
## SUBROUTINE: MAINTAIN_LIST
63230-300-221/A1 Appendix ESample Program Library
2/2002
81 2002 Schneider Electric All Rights Reserved
// push down values in the list
FOR IXM = 1 TO 9
IXMLO = 11 - IXM
IXMHI = 10 - IXM
CURRENT_LIST[IXMLO] = CURRENT_LIST[IXMHI]
NEXT IXM
CURRENT_LIST[1] = TOTAL_CURRENT
// COMPUTE THE NEW MOVING AVERAGE
CURRENT_SUM = 0
FOR IXM = 1 TO 10
CURRENT_SUM = CURRENT_SUM + CURRENT_LIST[IXM]
NEXT IXM
AVERAGE_TOTAL_CURR = CURRENT_SUM / 10
// place the new list values into regs 14210-14219
FOR IXM = 1 TO 10
DISPLAY_LIST[IXM] = CURRENT_LIST[IXM]
NEXT IXM
RETURN
## END SUBROUTINE //---- end of last 10 list instructions
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//
63230-300-221/A1 Appendix ESample Program Library
2/2002
82 2002 Schneider Electric All Rights Reserved
// C4U_X006.SRC : A Firmware Test Program for CM4000 CMPL, to
// demo operation for:
// (1) the comms request COMMSREQ
//
// Last Modified: 12-03-01
//----------------------------------------------------------------------------
## PROGRAM NAME: C4U_X006
## PROGRAM VERSION: 1000
## PROGRAM SECURITY: 2097153
//----------------------------------------------------------------------------
//
// Program requirements for the minimal problem:
//
// a - The program will reside in the USER partition
//
// b - Establish a counter (in reg S14000) for the number of metercycle
// updates.
//
// c - Establish a counter (in reg S14001) for the number of timer
// intervals (each 1 sec in duration)
//
// d - Add code to the one second timer task to test
// proper operation for the comms request COMMSREQ function using:
//
// (1) Read 4 remote devices connected to the ECC Sub-Net
// (2) Copy data from the remote devices to a common array
// (3) If errors or time-outs are detected in the requests
// mark the data as N/A (-32768)
//
//----------------------------------------------------------------------------
//---- begin declaration of data variables
## DECLARATION SECTION:
REGISTER cyclecount s14000 // counter for number of meter cycles
REGISTER timecnt s14001 // counter for timer task
REGISTER firstpass s14002 // flag for first execution
REGISTER ix s14003 // general purpose counter
REGISTER reqcnt s14004 // request counter
REGISTER readcnt s14005 // read counter
REGISTER comm1_busy s14021 // when busy, cannot make request
REGISTER comm2_busy s14022
REGISTER comm3_busy s14023
REGISTER comm4_busy s14024
REGISTER comm1_status s14025 // status reported by comms server
REGISTER comm2_status s14026
REGISTER comm3_status s14027
REGISTER comm4_status s14028
63230-300-221/A1 Appendix ESample Program Library
2/2002
83 2002 Schneider Electric All Rights Reserved
REGISTER comm1_ctl[6] s14030 // control parameters
REGISTER comm2_ctl[6] s14040
REGISTER comm3_ctl[6] s14050
REGISTER comm4_ctl[6] s14060
REGISTER comm1_data[25] s14100 // data values read/written
REGISTER comm2_data[25] s14125
REGISTER comm3_data[25] s14150
REGISTER comm4_data[25] s14175
REGISTER comm1_rlist[25] s14200 // register list
REGISTER comm2_rlist[25] s14225
REGISTER comm3_rlist[25] s14250
REGISTER comm4_rlist[25] s14275
// combined array [4][5]
REGISTER combine_tab[20] s14300
## END DECLARATION //---- end declarations
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
//---- instructions performed once at CUL restart
63230-300-221/A1 Appendix ESample Program Library
2/2002
84 2002 Schneider Electric All Rights Reserved
## INITIALIZE TASK:
cyclecount = 0
timecnt = 0
firstpass = 1
// all remote access is idle
comm1_busy = 0
comm2_busy = 0
comm3_busy = 0
comm4_busy = 0
// ****************************
// * Clear the control arrays *
// ****************************

for ix = 1 to 6
comm1_ctl[ix] = 0
comm2_ctl[ix] = 0
comm3_ctl[ix] = 0
comm4_ctl[ix] = 0
next ix
// ********************************************
// * Clear the data_value and reg list arrays *
// ********************************************

for ix = 1 to 25
comm1_data[ix] = 0
comm2_data[ix] = 0
comm3_data[ix] = 0
comm4_data[ix] = 0
comm1_rlist[ix] = 0
comm2_rlist[ix] = 0
comm3_rlist[ix] = 0
comm4_rlist[ix] = 0
next ix
//
// *******************************
// * Init the reg control arrays *
// *******************************
comm1_ctl[1] = 2 // [1] port - ecc
comm1_ctl[2] = 2 // [2] address - @1
comm1_ctl[3] = 2 // [3] request_type - scattered read
comm1_ctl[4] = 5 // [4] request_param1 - reg cnt
comm1_ctl[5] = 0 // [5] request_param2 - n/a
63230-300-221/A1 Appendix ESample Program Library
2/2002
85 2002 Schneider Electric All Rights Reserved
comm1_ctl[6] = 0 // [6] request_param3 - n/a
comm2_ctl[1] = 2 // [1] port - ecc
comm2_ctl[2] = 3 // [2] address - @2
comm2_ctl[3] = 2 // [3] request_type - scattered read
comm2_ctl[4] = 5 // [4] request_param1 - reg cnt
comm2_ctl[5] = 0 // [5] request_param2 - n/a
comm2_ctl[6] = 0 // [6] request_param3 - n/a
comm3_ctl[1] = 2 // [1] port - ecc
comm3_ctl[2] = 4 // [2] address - @3
comm3_ctl[3] = 2 // [3] request_type - scattered read
comm3_ctl[4] = 5 // [4] request_param1 - reg cnt
comm3_ctl[5] = 0 // [5] request_param2 - n/a
comm3_ctl[6] = 0 // [6] request_param3 - n/a
comm4_ctl[1] = 2 // [1] port - ecc
comm4_ctl[2] = 5 // [2] address - @4
comm4_ctl[3] = 2 // [3] request_type - scattered read
comm4_ctl[4] = 5 // [4] request_param1 - reg cnt
comm4_ctl[5] = 0 // [5] request_param2 - n/a
comm4_ctl[6] = 0 // [6] request_param3 - n/a
//
// ****************************
// * Init the reg list arrays *
// ****************************
comm1_rlist[1] = 1000 // Phase A Current
comm1_rlist[2] = 1001 // Phase B Current
comm1_rlist[3] = 1002 // Phase C Current
comm1_rlist[4] = 1005 // 3-Phase Average Current
comm1_rlist[5] = 1006 // Apparent Current RMS
comm2_rlist[1] = 1000 // Phase A Current
comm2_rlist[2] = 1001 // Phase B Current
comm2_rlist[3] = 1002 // Phase C Current
comm2_rlist[4] = 1005 // 3-Phase Average Current
comm2_rlist[5] = 1006 // Apparent Current RMS
comm3_rlist[1] = 1000 // Phase A Current
comm3_rlist[2] = 1001 // Phase B Current
comm3_rlist[3] = 1002 // Phase C Current
comm3_rlist[4] = 1005 // 3-Phase Average Current
comm3_rlist[5] = 1006 // Apparent Current RMS
63230-300-221/A1 Appendix ESample Program Library
2/2002
86 2002 Schneider Electric All Rights Reserved
comm4_rlist[1] = 1000 // Phase A Current
comm4_rlist[2] = 1001 // Phase B Current
comm4_rlist[3] = 1002 // Phase C Current
comm4_rlist[4] = 1005 // 3-Phase Average Current
comm4_rlist[5] = 1006 // Apparent Current RMS
return
## END INITIALIZE //---- end initialize instructions
//
//----------------------------------------------------------------------------
//---- instructions performed per meter cycle
## METERCYCLE TASK:
cyclecount = cyclecount + 1
return
## END METERCYCLE //---- end per meter cycle instructions
//----------------------------------------------------------------------------
## TIMER TASK: INTERVAL 1 SECONDS
timecnt = timecnt + 1
call Read_RemoteMeter_Data // get data from last read
call Request_RemoteMeter_Data // request next read
firstpass = 0
return
## END TIMER
//
//----------------------------------------------------------------------------
## SUBROUTINE: Read_RemoteMeter_Data
if (firstpass = 1) // first time request has not been proccessed
{
comm1_busy = 0
comm2_busy = 0
comm3_busy = 0
comm4_busy = 0
return
}
63230-300-221/A1 Appendix ESample Program Library
2/2002
87 2002 Schneider Electric All Rights Reserved
// ****************************************************************************
// ********************** CHECK REQUEST 1 *************************************
// ****************************************************************************
if (comm1_status = 1) // request is pending data not available yet
{ // mark busy
comm1_busy = 1
}
if (comm1_status = 0) // request is a success, copy data to combined
{ // array then mark as not busy
comm1_busy = 0
readcnt = readcnt + 1 // increment the read counter
combine_tab[1] = comm1_data[1]
combine_tab[2] = comm1_data[2]
combine_tab[3] = comm1_data[3]
combine_tab[4] = comm1_data[4]
combine_tab[5] = comm1_data[5]
}
if (comm1_status < 0) // Errors returned, mark data as N/A in the
{ // combined array
comm1_busy = 0 // mark as not busy
readcnt = readcnt + 1 // increment the read counter
combine_tab[1] = -327687
combine_tab[2] = -327687
combine_tab[3] = -327687
combine_tab[4] = -327687
combine_tab[5] = -327687
}
//
// ****************************************************************************
// ********************** CHECK REQUEST 2 *************************************
// ****************************************************************************
if (comm2_status = 1) // request is pending data not available yet
{ // mark busy
comm2_busy = 1
}
if (comm2_status = 0) // request is a success, copy data to combined
{ // array then mark as not busy
comm2_busy = 0
readcnt = readcnt + 1 // increment the read counter
combine_tab[6] = comm2_data[1]
combine_tab[7] = comm2_data[2]
combine_tab[8] = comm2_data[3]
combine_tab[9] = comm2_data[4]
combine_tab[10] = comm2_data[5]
}
63230-300-221/A1 Appendix ESample Program Library
2/2002
88 2002 Schneider Electric All Rights Reserved
if (comm2_status < 0) // Errors returned, mark data as N/A in the
{ // combined array
comm2_busy = 0 // mark as not busy
readcnt = readcnt + 1 // increment the read counter
combine_tab[6] = -327687
combine_tab[7] = -327687
combine_tab[8] = -327687
combine_tab[9] = -327687
combine_tab[10] = -327687
}
//
// ****************************************************************************
// ********************** CHECK REQUEST 3 *************************************
// ****************************************************************************
if (comm3_status = 1) // request is pending data not available yet
{ // mark busy
comm3_busy = 1
}
if (comm3_status = 0) // request is a success, copy data to combined
{ // array then mark as not busy
comm3_busy = 0
readcnt = readcnt + 1 // increment the read counter
combine_tab[11] = comm3_data[1]
combine_tab[12] = comm3_data[2]
combine_tab[13] = comm3_data[3]
combine_tab[14] = comm3_data[4]
combine_tab[15] = comm3_data[5]
}
if (comm3_status < 0) // Errors returned, mark data as N/A in the
{ // combined array
comm3_busy = 0 // mark as not busy
readcnt = readcnt + 1 // increment the read counter
combine_tab[11] = -327687
combine_tab[12] = -327687
combine_tab[13] = -327687
combine_tab[14] = -327687
combine_tab[15] = -327687
}
//
63230-300-221/A1 Appendix ESample Program Library
2/2002
89 2002 Schneider Electric All Rights Reserved
// ****************************************************************************
// ********************** CHECK REQUEST 4 *************************************
// ****************************************************************************
if (comm4_status = 1) // request is pending data not available yet
{ // mark busy
comm4_busy = 1
}
if (comm4_status = 0) // request is a success, copy data to combined
{ // array then mark as not busy
comm4_busy = 0
readcnt = readcnt + 1 // increment the read counter
combine_tab[16] = comm4_data[1]
combine_tab[17] = comm4_data[2]
combine_tab[18] = comm4_data[3]
combine_tab[19] = comm4_data[4]
combine_tab[20] = comm4_data[5]
}
if (comm4_status < 0) // Errors returned, mark data as N/A in the
{ // combined array
comm4_busy = 0 // mark as not busy
readcnt = readcnt + 1 // increment the read counter
combine_tab[16] = -327687
combine_tab[17] = -327687
combine_tab[18] = -327687
combine_tab[19] = -327687
combine_tab[20] = -327687
}
//
return
## END SUBROUTINE
//
//----------------------------------------------------------------------------
## SUBROUTINE: Request_RemoteMeter_Data
if (comm1_busy = 0) // if not busy send a request 1
{
comm1_status = 1
reqcnt = reqcnt + 1
COMMSREQ (comm1_status, comm1_ctl, comm1_data, comm1_rlist)
}
63230-300-221/A1 Appendix ESample Program Library
2/2002
90 2002 Schneider Electric All Rights Reserved
if (comm2_busy = 0) // if not busy send a request 2
{
comm2_status = 1
reqcnt = reqcnt + 1
COMMSREQ (comm2_status, comm2_ctl, comm2_data, comm2_rlist)
}
if (comm3_busy = 0) // if not busy send a request 3
{
comm3_status = 1
reqcnt = reqcnt + 1
COMMSREQ (comm3_status, comm3_ctl, comm3_data, comm3_rlist)
}
if (comm4_busy = 0) // if not busy send a request 4
{
comm4_status = 1
reqcnt = reqcnt + 1
COMMSREQ (comm4_status, comm4_ctl, comm4_data, comm4_rlist)
}
return
## END SUBROUTINE
63230-300-221/A1 Appendix FCMPL Control Register List
2/2002
91 2002 Schneider Electric All Rights Reserved
APPENDIX FCMPL CONTROL REGISTER LIST
The following list includes the CM4000 registers that pertain to CMPL.
Table F 1:CMPL Register List
Name CM4000 Size Type Access NV Range Additional Information
CMPLProgram Name 8175 8 Integer RO Y ASCII PMO Program Name up to 16 ASCII characters
CMPL Program Version
Number
8183 1 Integer RO Y 032767 Program Version 00.000 to 37.767
CMPL Compile Date/Time 8184 4 Date RO Y See Determining the Name,
Version, and Date of a
Program on page 51.
Date/Time of CMPL program compilation.
CMPL Security User/Number 8188 1 Integer RO Y 032767 Secure User Number
CMPLInitial Processor Mode 8189 1 Integer R/W Y 05 Initial state of the CMPL processor after reset0 = Program
not present1 = Halt2 = Debug Pause3 = Debug Step4 =
Debug Run to Break5 = Run
CMPLPresent Processor
Mode
8190 1 Integer RO Y 05 Present state of the CMPL processor 0 = Program not
present1 = Halt2 = Debug Pause3 = Debug Step4 =
Debug Run to Break5 = Run
CMPLError Number at Last
Halt/Pause
8191 1 Integer RO Y 032,767 Error number at last Halt.
CMPLExecution Line
Number
8192 1 Integer RO Y 0 32,767 Presently executing line number in run mode or next line
number in pause mode.
CMPLSMS Program ID 8193 1 Integer RO Y 0 Unique number assigned to the CMPL program signifying
an Official PMO program to SMS
Reserved 8194 2 Integer RO x xxxxxxx Reserved for future development
Appendix FCMPL Control Register List 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 92
63230-300-221/A1 Appendix GAlarms (Events)
2/2002
93 2002 Schneider Electric All Rights Reserved
APPENDIX GALARMS (EVENTS)
You can define any alarm in any position. Each alarm type has a certain
number of default alarms. However, each alarm type has more positions than
are used by the defaults. For example, there are 80 standard alarm positions.
The standard alarm defaults are 0142, leaving 38 unused standard
positions.
When setting up Event tasks, remember that event numbers include a pair of
two digits: the first two digits describe the alarm type (10 = standard, 20 =
high-speed, 30 = disturbance, etc.). The second two digits are the alarm
position (in the default alarms, 01 = over current phase A; however, keep in
mind that you can change defaults).
Table G1 lists the default alarms. Table G2 lists the alarm types. Table G
3, Table G4, and Table G5 list the templates.
Table G1: List of Default Alarms by Alarm Number
Alarm
Number
Alarm Description
Abbreviated
Display Name
Test
Register
Units
Scale
Group
Alarm
Type
1
Standard Speed Alarms (1 Second)
01 Over Current Phase A Over Ia 1100 Amperes A 010
02 Over Current Phase B Over Ib 1101 Amperes A 010
03 Over Current Phase C Over Ic 1102 Amperes A 010
04 Over Current Neutral Over In 1103 Amperes B 010
05 Over Current Ground Over Ig 1104 Amperes C 010
06 Under Current Phase A Under Ia 1100 Amperes A 020
07 Under Current Phase B Under Ib 1101 Amperes A 020
08 Under Current Phase C Under Ic 1102 Amperes A 020
09 Current Unbalance, Max I Unbal Max 1110 Tenths % 010
10 Current Loss Current Loss 3262 Amperes A 053
11 Over Voltage Phase AN Over Van 1124 Volts D 010
12 Over Voltage Phase BN Over Vbn 1125 Volts D 010
13 Over Voltage Phase CN Over Vcn 1126 Volts D 010
14 Over Voltage Phase AB Over Vab 1120 Volts D 010
15 Over Voltage Phase BC Over Vbc 1121 Volts D 010
16 Over Voltage Phase CA Over Vca 1122 Volts D 010
17 Under Voltage Phase AN Under Van 1124 Volts D 020
18 Under Voltage Phase BN Under Vbn 1125 Volts D 020
19 Under Voltage Phase CN Under Vcn 1126 Volts D 020
20 Under Voltage Phase AB Under Vab 1120 Volts D 020
21 Under Voltage Phase BC Under Vbc 1121 Volts D 020
22 Under Voltage Phase CA Under Vca 1122 Volts D 020
23 Voltage Unbalance LN, Max V Unbal L-N Max 1136 Tenths % 010
24 Voltage Unbalance LL, Max V Unbal L-L Max 1132 Tenths % 010
25 Voltage Loss (loss of A,B,C, but not all) Voltage Loss 3262 Volts D 052
26 Phase Reversal Phase Rev 3228 051
27 Over kVA Demand Over kVA Dmd 2181 kVA F 011
28 Over kW Demand Over kW Dmd 2151 kW F 011
29 Over kVAR Demand Over kVAR Dmd 2166 kVAR F 011
30 Over Frequency Over Freq. 1180 Hundredths of Hertz 010
1 Alarm Types are described in Table G2 on page 95.
Appendix GAlarms (Events) 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 94
31 Under Frequency Under Freq. 1180 Hundredths of Hertz 020
32 Lagging true power factor Lag True PF 1163 Thousandths 055
33 Leading true power factor Lead True PF 1163 Thousandths 054
34 Lagging displacement power factor Lag Disp PF 1171 Thousandths 055
35 Leading displacement power factor Lead Disp PF 1171 Thousandths 054
36 Over Current Demand Phase A Over Ia Dmd 1961 Amperes A 010
37 Over Current Demand Phase B Over Ib Dmd 1971 Amperes A 010
38 Over Current Demand Phase C Over Ic Dmd 1981 Amperes A 010
39 Over THD Voltage AN Over THD Van 1207 Tenths % 010
40 Over THD Voltage BN Over THD Vbn 1208 Tenths % 010
41 Over THD Voltage CN Over THD Vcn 1209 Tenths % 010
42 Over THD Voltage AB Over THD Vab 1211 Tenths % 010
43 Over THD Voltage BC Over THD Vbc 1212 Tenths % 010
44 Over THD Voltage CA Over THD Vca 1213 Tenths % 010
45-80 Reserved for custom alarms.
High Speed Alarms (100 ms)
01 Over Current A Over Ia HS 1,000 Amperes A 010
02 Over Current B Over Ib HS 1001 Amperes A 010
03 Over Current C Over Ic HS 1002 Amperes A 010
04 Over Current N Over In HS 1003 Amperes B 010
05 Over Current G Over Ig HS 1004 Amperes C 010
06 Over Voltage AN Over Van HS 1024 Volts D 010
07 Over Voltage BN Over Vbn HS 1025 Volts D 010
08 Over Voltage CN Over Vcn HS 1026 Volts D 010
09 Over Voltage A-B Over Vab HS 1020 Volts D 010
10 Over Voltage B-C Over Vbc HS 1021 Volts D 010
11 Over Voltage C-A Over Vca HS 1022 Volts D 010
12 Over Voltage N-G Over Vng HS 1027 Volts E 010
13 Under Voltage AN Under Van HS 1024 Volts D 020
14 Under Voltage BN Under Vbn HS 1025 Volts D 020
15 Under Voltage CN Under Vcn HS 1026 Volts D 020
16 Under Voltage A-B Under Vab HS 1020 Volts D 020
17 Under Voltage BC Under Vbc HS 1021 Volts D 020
18 Under Voltage CA Under Vca HS 1022 Volts D 020
19-20 Reserved for custom alarms
Disturbance Monitoring (1/2 Cycle)
01 Voltage Swell AN Swell Van 4 Volts D 080
02 Voltage Swell BN Swell Vbn 5 Volts D 080
03 Voltage Swell CN Swell Vcn 6 Volts D 080
04 Voltage Swell NG Swell Vng 7 Volts E 080
05 Voltage Swell AB Swell Vab 1 Volts D 080
06 Voltage Swell BC Swell Vbc 2 Volts D 080
07 Voltage Swell CA Swell Vca 3 Volts D 080
08 Voltage Sag AN Sag Van 4 Volts D 090
09 Voltage Sag BN Sag Vbn 5 Volts D 090
Table G1: List of Default Alarms by Alarm Number
Alarm
Number
Alarm Description
Abbreviated
Display Name
Test
Register
Units
Scale
Group
Alarm
Type
1
1 Alarm Types are described in Table G2 on page 95.
63230-300-221/A1 Appendix GAlarms (Events)
2/2002
95 2002 Schneider Electric All Rights Reserved
10 Voltage Sag CN Sag Vcn 6 Volts D 090
11 Voltage Sag AB Sag Vab 1 Volts D 090
12 Voltage Sag BC Sag Vbc 2 Volts D 090
13 Voltage Sag CA Sag Vca 3 Volts D 090
14 Current Swell A Swell Ia 8 Amperes A 080
15 Current Swell B Swell Ib 9 Amperes A 080
16 Current Swell C Swell Ic 10 Amperes A 080
17 Current Swell N Swell In 11 Amperes B 080
18 Current Sag A Sag Ia 8 Amperes A 090
19 Current Sag B Sag Ib 9 Amperes A 090
20 Current Sag C Sag Ic 10 Amperes A 090
Digital
01 End of incremental energy interval End Inc Enr Int N/A 070
02 End of power demand interval End Power Dmd Int N/A 070
03 End of 1-second update cycle End 1s Cyc N/A 070
04 End of 100ms update cycle End 100ms Cyc N/A 070
05 Power up/Reset Pwr Up/Reset N/A 070
06-40 Reserved for custom alarms
Table G1: List of Default Alarms by Alarm Number
Alarm
Number
Alarm Description
Abbreviated
Display Name
Test
Register
Units
Scale
Group
Alarm
Type
1
1 Alarm Types are described in Table G2 on page 95.
Table G2: Alarm Types
Type Description Operation
Standard Speed (CMPL Type 10)
010 Over Value Alarm
If the test register value exceeds the setpoint long enough to satisfy the pickup delay period, the
alarm condition will be true. When the value in the test register falls below the dropout setpoint long
enough to satisfy the dropout delay period, the alarm will dropout. Pickup and dropout setpoints
are positive, delays are in seconds.
011 Over Power Alarm
If the absolute value in the test register exceeds the setpoint long enough to satisfy the pickup delay
period, the alarm condition will be true. When the value in the test register falls below the dropout
setpoint long enough to satisfy the dropout delay period, the alarm will dropout. Pickup and dropout
setpoints are positive, delays are in seconds.
012 Over Reverse Power Alarm
If the absolute value in the test register exceeds the setpoint long enough to satisfy the pickup delay
period, the alarm condition will be true. When the value in the test register falls below the dropout
setpoint long enough to satisfy the dropout delay period, the alarm will dropout. This alarm will only
hold true for reverse power conditions. Positive power values will not cause the alarm to occur.
Pickup and dropout setpoints are positive, delays are in seconds.
020 Under Value Alarm
If the test register value is below the setpoint long enough to satisfy the pickup delay period, the
alarm condition will be true. When the value in the test register rises above the dropout setpoint
long enough to satisfy the dropout delay period, the alarm will dropout. Pickup and dropout
setpoints are positive, delays are in seconds.
021 Under Power Alarm
If the absolute value in the test register is below the setpoint long enough to satisfy the pickup delay
period, the alarm condition will be true. When the value in the test register rises above the dropout
setpoint long enough to satisfy the dropout delay period, the alarm will dropout. Pickup and dropout
setpoints are positive, delays are in seconds.
051 Phase Reversal
The phase reversal alarm will occur whenever the phase voltage waveform rotation differs from the
default phase rotation. The ABC phase rotation is assumed to be normal. If a CBA phase rotation
is normal, the user should reprogram the circuit monitors phase rotation ABC to CBA phase
rotation. The pickup and dropout setpoints and delays for phase reversal do not apply.
Appendix GAlarms (Events) 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 96
052 Phase Loss, Voltage
The phase loss voltage alarm will occur when any one or two phase voltages (but not all) fall to the
pickup value and remain at or below the pickup value long enough to satisfy the specified pickup
delay. When all of the phases remain at or above the dropout value for the dropout delay period, or
when all of the phases drop below the specified phase loss pickup value, the alarm will dropout.
Pickup and dropout setpoints are positive, delays are in seconds.
053 Phase Loss, Current
The phase loss current alarm will occur when any one or two phase currents (but not all) fall to the
pickup value and remain at or below the pickup value long enough to satisfy the specified pickup
delay. When all of the phases remain at or above the dropout value for the dropout delay period, or
when all of the phases drop below the specified phase loss pickup value, the alarm will dropout.
Pickup and dropout setpoints are positive, delays are in seconds.
054 Leading Power Factor
The leading power factor alarm will occur when the test register value becomes more leading than
the pickup setpoint (such as closer to 0.010) and remains more leading long enough to satisfy the
pickup delay period. When the value becomes equal to or less leading than the dropout setpoint,
that is 1.000, and remains less leading for the dropout delay period, the alarm will dropout. Both
the pickup setpoint and the dropout setpoint must be positive values representing leading power
factor. Enter setpoints as integer values representing power factor in thousandths. For example, to
define a dropout setpoint of 0.5, enter 500. Delays are in seconds.
055 Lagging Power Factor
The lagging power factor alarm will occur when the test register value becomes more lagging than
the pickup setpoint (such as closer to 0.010) and remains more lagging long enough to satisfy the
pickup delay period. When the value becomes equal to or less lagging than the dropout setpoint,
that is 1.000, and remains less lagging for the dropout delay period, the alarm will dropout. Both
the pickup setpoint and the dropout setpoint must be positive values representing lagging power
factor. Enter setpoints as integer values representing power factor in thousandths. For example, to
define a dropout setpoint of 0.5, enter 500. Delays are in seconds.
High Speed (CMPL Type 20)
010 Over Value Alarm
If the test register value exceeds the setpoint long enough to satisfy the pickup delay period, the
alarm condition will be true. When the value in the test register falls below the dropout setpoint long
enough to satisfy the dropout delay period, the alarm will dropout. Pickup and dropout setpoints
are positive, delays are in hundreds of milliseconds.
011 Over Power Alarm
If the absolute value in the test register exceeds the setpoint long enough to satisfy the pickup delay
period, the alarm condition will be true. When the value in the test register falls below the dropout
setpoint long enough to satisfy the dropout delay period, the alarm will dropout. Pickup and dropout
setpoints are positive, delays are in hundreds of milliseconds.
012 Over Reverse Power Alarm
If the absolute value in the test register exceeds the setpoint long enough to satisfy the pickup delay
period, the alarm condition will be true. When the value in the test register falls below the dropout
setpoint long enough to satisfy the dropout delay period, the alarm will dropout. This alarm will only
hold true for reverse power conditions. Positive power values will not cause the alarm to occur.
Pickup and dropout setpoints are positive, delays are in hundreds of milliseconds.
020 Under Value Alarm
If the test register value is below the setpoint long enough to satisfy the pickup delay period, the
alarm condition will be true. When the value in the test register rises above the dropout setpoint
long enough to satisfy the dropout delay period, the alarm will dropout. Pickup and dropout
setpoints are positive, delays are in hundreds of milliseconds.
021 Under Power Alarm
If the absolute value in the test register is below the setpoint long enough to satisfy the pickup delay
period, the alarm condition will be true. When the value in the test register rises above the dropout
setpoint long enough to satisfy the dropout delay period, the alarm will dropout. Pickup and dropout
setpoints are positive, delays are in hundreds of milliseconds.
051 Phase Reversal
The phase reversal alarm will occur when ever the phase voltage waveform rotation differs from the
default phase rotation. The ABC phase rotation is assumed to be normal. If a CBA normal phase
rotation is normal, the user should reprogram the circuit monitors phase rotation ABC to CBA
phase rotation. The pickup and dropout setpoints and delays for phase reversal do no apply.
052 Phase Loss, Voltage
The phase loss voltage alarm will occur when any one or two phase voltages (but not all) fall to the
pickup value and remain at or below the pickup value long enough to satisfy the specified pickup
delay. When all of the phases remain at or above the dropout value for the dropout delay period, or
when all of the phases drop below the specified phase loss pickup value, the alarm will dropout.
Pickup and dropout setpoints are positive, delays are in seconds.
Table G2: Alarm Types
Type Description Operation
63230-300-221/A1 Appendix GAlarms (Events)
2/2002
97 2002 Schneider Electric All Rights Reserved
053 Phase Loss, Current
The phase loss current alarm will occur when any one or two phase currents (but not all) fall to the
pickup value and remain at or below the pickup value long enough to satisfy the specified pickup
delay. When all of the phases remain at or above the dropout value for the dropout delay period, or
when all of the phases drop below the specified phase loss pickup value, the alarm will dropout.
Pickup and dropout setpoints are positive, delays are in hundreds of milliseconds.
054 Leading Power Factor
The leading power factor alarm will occur when the test register value becomes more leading than
the pickup setpoint (closer to 0.010) and remains more leading long enough to satisfy the pickup
delay period. When the value becomes equal to or less leading than the dropout setpoint, that is
1.000, and remains less leading for the dropout delay period, the alarm will dropout.Both the pickup
setpoint and the dropout setpoint must be positive values representing leading power factor. Enter
setpoints as integer values representing power factor in thousandths. For example, to define a
dropout setpoint of 0.5, enter 500. Delays are in hundreds of milliseconds.
055 Lagging Power Factor
The lagging power factor alarm will occur when the test register value becomes more lagging than
the pickup setpoint (closer to 0.010) and remains more lagging long enough to satisfy the pickup
delay period. When the value becomes equal to or less lagging than the dropout setpoint, that is.
1.000 and remains less lagging for the dropout delay period, the alarm will dropout. Both the pickup
setpoint and the dropout setpoint must be positive values representing lagging power factor. Enter
setpoints as integer values representing power factor in thousandths. For example, to define a
dropout setpoint of 0.5, enter 500. Delays are in hundreds of milliseconds.
Disturbance (CMPL Type 30)
080 Voltage/Current Swell
The voltage and current swell alarms will occur whenever the continuous rms calculation is above
the pickup setpoint and remains above the pickup setpoint for the specified number of cycles. When
the continuous rms calculations fall below the dropout setpoint and remain below the setpoint for
the specified number of cycles, the alarm will dropout. Pickup and dropout setpoints are positive
and delays are in cycles.
090 Voltage/Current Sag
The voltage and current sag alarms will occur whenever the continuous rms calculation is below
the pickup setpoint and remains below the pickup setpoint for the specified number of cycles. When
the continuous rms calculations rise above the dropout setpoint and remain above the setpoint for
the specified number of cycles, the alarm will drop out. Pickup and dropout setpoints are positive
and delays are in cycles.
Digital (CMPL Type 40)
060 Digital Input On
The digital input transition alarms will occur whenever the digital input changes from off to on. The
alarm will dropout when the digital input changes back to off from on. The pickup and dropout
setpoints and delays do not apply.
061 Digital Input Off
The digital input transition alarms will occur whenever the digital input changes from on to off.The
alarm will dropout when the digital input changes back to on from off. The pickup and dropout
setpoints and delays do not apply.
070 Unary
This is a internal signal from the circuit monitor and can be used, for example, to alarm at the end
of an interval or when the circuit monitor is reset. The pickup and dropout delays do not apply.
Boolean (CMPL Type 50)
100
Logic AND
The AND alarm will occur when all of the combined enabled alarms are true (up to 4). The alarm
will dropout when any of the enabled alarms drops out.
101
Logic NAND
The NAND alarm will occur when any, but not all, or none of the combined enabled alarms are true.
The alarm will dropout when all of the enabled alarms drop out, or all are true.
102
Logic OR
The OR alarm will occur when any of the combined enabled alarms are true (up to 4). The alarm
will dropout when all of the enabled alarms are false.
103
Logic NOR
The NOR alarm will occur when none of the combined enabled alarms are true (up to 4). The alarm
will dropout when any of the enabled alarms are true.
104
Logic XOR
The XOR alarm will occur when only one of the combined enabled alarms is true (up to 4). The
alarm will dropout when the enabled alarm drops out or when more than one alarm becomes true.
Table G2: Alarm Types
Type Description Operation
Appendix GAlarms (Events) 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 98
Table G3:Template 1: Normal/High Speed/Disturbance/Digital Alarm Setup (CMPL Types 10, 20, 30, and 40)
Name Offset Size Type Access NV Scale Units Range Additional Information
Unique Identifier 00 2 Long R/CW Y xx xxxxxxx 0
0xFFFFFFFF
Unique number to identify the alarm
Bits 0007 = Level (09)
Bits 0815 = Alarm Type
Bits 1631 = Test Register
For Disturbance alarms, Test Register is:
1 = Vab
2 = Vbc
3 = Vca
4 = Van
5 = Vbn
6 = Vcn
7 = Vng
8 = Ia
9 = Ib
10 = Ic
11 = In
12 = Ig
13 = Alt V2
14 = Alt I2
15 = Alt I4
For Unary Alarms, Test Register is:
1 = End of Incremental Energy Interval
2 = End of Power Demand Interval
3 = End of 1s Meter Update Cycle
4 = End of 100ms Meter Update Cycle
5 = Power up/ Reset
For Binary Alarm, Test Register is 120
For Time Of Day Alarm, Test Register is 160
Enable/Disable,
Priority
02 1 Integer R/W Y xx xxxxxxx MSB: 0FF
LSB: 03
MSB:
0x00 = Disabled, not learning (default)
0xAA = Disabled, learning
0xCC = Enabled with fixed histogram setpoints, not learning
0xDD = Enabled with dynamic (learned) setpoints, learning
0xEE = Enabled with fixed setpoints, learning
0xFF = Enabled with fixed setpoints, not learning
LSB: Specifies the priority level 0 - 3
Label 03 8 Chars R/W Y xx xxxxxxx Alpha-Numeric 16 character label
Pickup Value
*Pickup Mask
Binary Alarm
**Pickup Date
Time of Day Alarm
11 1 Integer
Bitmap
Integer
R/CW
R/CW
R/CW
YYY A-F
xx
xx
Units/
Scale
xxxxxxx
xxxxxxx
032,767
00x7FFF
0x0111
0x208D
Pickup alarm limit
(does not apply to digital or unary alarms)
*For a Binary Alarm, this mask indicates the level of each bit selected in the
Pickup Mask Bit Select needed to activate the alarm
**For Time Of Day Alarm, this register holds the Pickup Date:
Bits 815 = Day (1-32); 32 = Any Day
Bits 47 = Day Of Week (1 - 8); 8 = Any DOW
Bits 03 = Month (113); 13 = Any Month
Pickup Delay
*Pickup Mask Bit
Select for Binary
Alarm
**Pickup Time
Time of Day Alarm
12 1 Integer
Bitmap
Integer
R/CW
R/CW
R/CW
Y
Y
Y
xx
xx
xx
1s
100ms
Cycle
xxxxxxx
xxxxxxxx
032,767
0999
0999
00x7FFF
0x0000
0x172B
Pickup delay time
(does not apply to digital or unary alarms)
*For a Binary Alarm, this register identifies the bits selected for binary pickup
evaluation. A '1' indicates the bit is selected, a '0' indicates a Don't Care bit.
**For Time of Day Alarm, this register holds the Pickup Time:
Bits 815 = Hour (0 - 24); 24 = Any Hour
Bits 07 = Minute (0 - 59);
Dropout Value
*Dropout Mask-
Binary Alarm
**Dropout Date
Time of Day alarm
13 1 Integer
Bitmap
Integer
R/CW
R/CW
R/CW
Y
Y
Y
A-F
xx
xx
Units/
Scale
xxxxxxx
xxxxxxx
032,767
00x7FFF
0x0111
0x208D
Dropout alarm limit(does not apply to digital or unary alarms)
*For a Binary Alarm, this mask indicates the level of each bit selected in the
Dropout Mask Bit Select needed to de-activate the alarm.
**For a Time Of Day Alarm, this register holds the Dropout Date:
Bits 815 = Day (132); 32 = Any Day
Bits 47 = Day Of Week (18); 8 = Any DOW
Bits 03 = Month (113); 13 = Any Month
63230-300-221/A1 Appendix GAlarms (Events)
2/2002
99 2002 Schneider Electric All Rights Reserved
Dropout Delay
*Dropout Mask Bit
Select for Binary
Alarm
** Dropout Time
Time of DayD Alarm
14 1 Integer
Bitmap
Integer
R/CW
R/CW
R/CW
Y
Y
Y
A-F
xx
xx
1s
100ms
Cycle
xxxxxxx
xxxxxxx
032,767
0999
0999
00x7FFF
0x0000
0x172B
Dropout delay time (does not apply to digital or unary alarms)
*For Binary Alarm, this register identifies the bits selected for binary dropout
evaluation. A '1' indicates the bit is selected, a '0' indicates a Don't Care bit.
**For Time of Day Alarm, this register holds the Dropout Time:
Bits 815 = Hour (024); 24 = Any Hour
Bits 07 = Minute (059)
Reserved 15 1 xx xx xx xx xxxxxxx xxxxxxx Reserved for future development
Datalog Specifier 16 2 Bitmap R/CW Y xx xxxxxxx 0
0xFFFFFFFF
Datalog Specifier:
Bit 00 = Datalog #1
Bit 01 = Datalog #2
..
Bit 13 = Datalog #14
Bit 14 = Reserved
..
Bit 21 = Reserved
WFC Mode 18 1 Integer R/CW Y xx xxxxxxx 0 0xFFFF WFC Modes:
Bits 00 03 = Channel Format (010)
Bits 0407 = Decimation (0 6)
Bits 0811 = History Cycles (010)
Bits 1215 = Mode Select
Bit 12: Steady State
Bit 13: Fixed
Bit 14: Variable
Bit 15: Variable w/early termination
WFC Cycles 19 1 Integer R/CW Y xx xxxxxxx 00xFFFF Number of Cycles

Table G3:Template 1: Normal/High Speed/Disturbance/Digital Alarm Setup (CMPL Types 10, 20, 30, and 40)
Name Offset Size Type Access NV Scale Units Range Additional Information
Table G4:Template 2: Boolean Alarm Setup (CMPL Type 50)
Name Offset Size Type Access NV Scale Units Range Additional Information
Unique Identifier 00 2 Long R/CW Y xx xxxxxxx 0
0xFFFFFFFF
Unique number to identify the alarm
Bits 0007 = Level (0 - 9)
Bits 0815 = Alarm Type
Bits 1631 = Test Register
Enable/Disable,
Priority
02 1 Integer R/W Y xx xxxxxxx MSB: 0FF
LSB: 03
MSB: 0x00 = Disable; 0xFF = Enable
LSB: Specifies the priority level 03
Label 03 8 Chars R/W Y xx xxxxxxx Alpha-numeric 20 character label
Alarm test list 11 4 Long R/CW Y xx xxxxxxx 0185 Alarm test list (position # in the normal alarm list)
Reserved 15 1 xx xx xx xx xxxxxxx xxxxxxx Reserved for future development
Datalog Specifier 16 2 Bitmap R/CW Y xx xxxxxxx 0
0xFFFFFFFF
Datalog Specifier:
Bit 00 = Datalog #1
Bit 01 = Datalog #2
..
Bit 13 = Datalog #14
Bit 14 = Reserved
..
Bit 21 = Reserved
WFC Mode 18 1 Integer R/CW Y xx xxxxxxx 0 0xFFFF WFC Modes:
Bits 0003 = Channel Format (010)
Bits 0407 = Decimation (06)
Bits 0811 = History Cycles (010)
Bits 1215 = Mode Select
Bit 12: Steady State
Bit 13: Fixed
Bit 14: Variable
Bit 15: Variable w/early termination
WFC Cycles 19 1 Integer R/CW Y xx xxxxxxx 0 - 0xFFFF Number of Cycles
Appendix GAlarms (Events) 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 100
Table G5:Template 3: Transient Alarm Setup (Waveshape Fault/Impulsive Transients) (CMPL Types 60 and 70)
Name Offset Size Type Access NV Scale Units Range Additional Information
Unique Identifier 00 2 Long R/CW Y xx xxxxxxx 0
0xFFFFFFFF
Unique number to identify the alarm
Bits 0007 = Level (09)
Bits 0815 = Alarm Type
Bits 1631 = Test Register
Level = 0 (Additional levels are not allowed)
Alarm Type:
110 = waveshape fault
111 = impulse transient
Test Register for Waveshape:
1 = phase voltage
2 = N-G voltage
3 = phase current
3 = neutral current
Test Register for Impulse is a bitmap of channels: 1
Bit 00 = phase A
Bit 01 = phase B
Bit 02 = phase C
Enable/Disable,
Priority
02 1 Integer R/W Y xx xxxxxxx MSB: 0FF
LSB: 03
MSB:
0x00 = Disabled, not learning (default)
0xAA = Disabled, learning
0xCC = Enabled with fixed histogram setpoints, not learning
0xDD = Enabled with dynamic (learned) setpoints, learning
0xEE = Enabled with fixed setpoints, learning
0xFF = Enabled with fixed setpoints, not learning
LSB: Specifies the priority level 03
Label 03 8 Chars R/W Y xx xxxxxxx Alpha-numeric 16 character label
Threshold Magnitude 11 1 Integer R/CW Y A-F Units/
Scale
032,767
110,000
Transient Threshold Magnitude (RMS)
Waveshape Fault Threshold (Default = 10000)
Minimum Pulse
Duration
Waveshape Fault
Detection Sensitivity
12 1 Integer R/CW Y 1us
xxxxxxx
032,767
15
Impulsive Detection = 200ns
(number of points that exceed pickup magnitude)
Waveshape Fault Detection Sensitivity
(Evaluation Window Size)
1 = Low Sensitivity (default)
2 = Medium3 = High
4 = Very High
5 = Extreme Sensitivity
Waveshape Fault
Detection Resolution
13 1 Integer R/CW Y xx xxxxxxx 15 Waveshape Fault Detection Resolution
1 = 32 points/cycle (only selection for currents)
2 = 64 points/cycle
3 = 128 points/cycle (default for voltages)
4 = 256 points/cycle5 = 512 points/cycle
Waveshape Fault
Detection Upper
Limit
14 1 Integer R/CW Y xx xxxxxxx 110,000 Waveshape fault value above which alarm is not reported
Waveshape Fault
Detection Operation
Mode
15 1 Integer R/CW Y xx xxxxxxx 01 Waveshape Fault Detection Operation Mode:
SAD = Sum of the Absolute Difference
ASD = Absolute Sum of Difference
0 = SAD (default)
1 = ASD
Datalog Specifier 16 2 Bitmap R/CW Y xx xxxxxxx 0
0xFFFFFFFF
Datalog Specifier:
Bit 00 = Datalog #1
Bit 01 = Datalog #2
..
Bit 13 = Datalog #14
Bit 14 = Reserved
..
Bit 21 = Reserved
WFC Mode 18 1 Integer R/CW Y xx xxxxxxx 00xFFFF WFC Modes:
Bits 0003 = Channel Format (010)
Bits 04 07 = Decimation (06)
Bits 0811 = History Cycles (010)
Bits 1215 = Mode Select
Bit 12: Steady State (does not apply for Impulse)
Bit 13: Fixed
Bit 14: Variable (does not apply for Impulse)
Bit 15: Variable w/early termination (does not apply for Impulse)
WFC Cycles 19 1 Integer R/CW Y xx xxxxxxx 00xFFFF Number of Cycles
63230-300-221/A1 Appendix HProgramming Tips
2/2002
101 2002 Schneider Electric All Rights Reserved
APPENDIX HPROGRAMMING TIPS
Below are some programming tips to keep in mind when writing CMPL
programs.
Program Format
There must be at least one blank space between the source code and the
two forward slashes (//) that begin a comment.
The first and last line of each control directive and task must begin with
two pound sign characters (##) followed by one (1) space.
The first line of each control directive must end with a colon (:).
Opening and closing braces ({}) must each be on a separate line.
Program Execution
All data items must be initialized.
All data items within an assignment statement must be of the same data
type.
You cannot convert from a data type FLOAT having a value greater than
32767 to a data type REGISTER.
A RETURN statement must appear in each task section, even if there are no
other instructions within the task section.
Up to eight layers of nested subroutines are permitted. However, try to
minimize.
Up to nine layers of nested IF statements are permitted.
Vary the value of the offset for a Timer Task when a program contains
more than one Timer Task with the same time interval delay. Otherwise,
all of the tasks will occur in the same interval.
Invoking too many instructions during a single cycle could force the
unexpected termination of the program.
Arithmetic expressions are evaluated from left to right. Parentheses or
brackets are not permitted within expressions, and it is not possible to alter
the order of evaluation.
The following are general tips about CMPL.
You can create a new source file by clicking File then New.
Inline debug support is coming soon.
You can compile a Circuit Monitor 4000 source file by pressing F7.
Every comment must be preceded by "//".
Every program must have an "Initialize" and a "Metercycle" Task.
Every program must have a "Program Name" and "Declaration" section.
The CMPL program can contain "If" statements nested up to nine levels.
Registers 14000 to 14499 are non-volatile, writable registers.
Registers 40000 to 41999 are volatile, writable registers.
Double click on an error in the compile output box to locate the source line
of a compiler error.
To toggle on/off output creation, click Build then Generate Output.
To create a file to aid in program debugging, click Build then Options, and
check the "Debug Text Support" box.
To change the background and/or text colors, click Setup, Environment
then Editor Colors.
Events must be setup and enabled to trigger an "Event Task".
Appendix HProgramming Tips 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 102
Programming services, programming inistruction, and POWERLOGIC
training classes are available for a fee. Contact your local representative
for information on any of these services. Or visit our website at:
www.powerlogic.com
The first and last line of each control directive and task must begin with
two pound sign characters (##) followed by one (1) space.
The first line of each control directive must end with a colon (:).
Opening and closing braces ({}) must each be on a separate line.
All data items must be initialized.
All data types within an assignment statement must be of the same data
type.
You cannot convert from a data type FLOAT having a value greater than
32767 or less than -32768 to a data type REGISTER.
A RETURN statement must appear in each task section, even if there are
no other instructions within the task section.
Up to eight layers of nested subroutines are permitted.
Invoking too many instructions during a single cycle could force the
unexpected termination of the program.
Arithmetic expressions are evaluated from left to right. Parentheses or
brackets are not permitted within expressions, and it is not possible to alter
the order of evaluation.
You can pause the watch window update by clicking on any value being
displayed. To resume updates, click Update.
"FOR" loops must use a constant range.
63230-300-221/A1 Index
2/2002
103 2002 Schneider Electric All Rights Reserved
Symbols
## 101
used to begin a line of code 7
(
) used to end a control directive 101
.fw file output 42
.src file
compiling and assembling 42
// 101
used in comments and blank lines 6
{ (begin block) 32
} (end block) 32
A
alarm number
discussion 93
alarm position 11, 93
alarm type 11, 93
alarms 93
abbreviated names defined 93
alarm types 93, 95
AND function 25
ARCTAN function 28
arithmetic shift 27
arrays 17
ASCII codes and characters
table 52
Assembler error codes 61
assembling a source file 42
assigning a name to a register 16
assigning constant values 21
assigning values to data items 21
assigning variables to other variables 23
assignment statement format (table) 58
B
background
changing the color 41
background and text color
setting 41
BASIC language 5
binary arithmetic 27
BITREG data type 2425, 27
bitwise shifts 26
Boolean alarms
logic gates 97
build a debug file 45
C
CALL command 34
case sensitivity 6
caution statement 1
changing the tab width 41
check icon 42
circuit monitor on-board information 44
closing brace (}) 32
CM4000
verifying custom program download 43
CM4000 memory 15
CMDREQ command 35
CMPL
defined 1
materials included 1
CMPL control register list 91
CMPL functions 5
CMPL program elements
order of execution 13
CMPL program memory
viewing 46
CMPL source file
line limit 6
required elements 6
color
setting background and text 41
comments and blank lines
inserting into a program 6
COMMSREQ function 35
communication parameters
setting 40
communications daisy chain 1
Communications icon 40
comparison operators 31
compiler error codes 61
compiler operation 39
compiler options 42
compiling a source file 42
compiling/assembling a .src file 42
conditional execution using IF 31
conditional expressions (table) 58
constant values
assigning 21
control directives 7
control of program execution 31
control of the circuit monitor using CMDREQ 35
control other devices using COMMSREQ 35
control register list 91
CONVERT function 2930
converting data types 29
COSINE function 28
creating constants with DEFINE 19
curly brace ({) 32
custom code
effects on total meter cycle time 53
custom programs 31
D
data conversions permitted 30
data definition 57
data items
assigning values 21
data registers
CM4000 15
INDEX
Index 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 104
data types
converting 29
data variables 15
DATETIME data type 22, 24
debug code
inserted into a program 53
inserting into a program 53
debug techniques 51
debug techniques for CMPL programs 51
debugging 44
debugging the program 44
decimal points in constants 22
Declaration section 8
sample 20
declaring a table 18
DEFINE 19
desktop shortcut to launch CMPL 39
determining the effects of custom code on the total
meter cycle time 53
determining the name, version, and date of a pro-
gram 51
DLF tab on the toolbar 43
DLF-3000 1, 7, 15, 43
verifying download 43
download
verifying 43
download for debug purposes 43
download for normal execution 43
downloading and viewing the cmpl program 43
downloading the program 43
E
ELSE phrase 31
environment
setting 41
EQUATE term 18
error codes 61, 63
Event and Timer tasks 13
Event task 9
examining program control registers 51
excessive scan time 14
F
F5 44
F7 function key 42
FLOAT data type 28, 101
floating point values 22
font
changing size and type face 41
formatting 41
formatting the font 41
functions performed by CMPL 5
G
Go icon 44
H
HALT command 35
hexadecimal expression of constants 22
I
IF statement 53, 101
IF...ELSE command 31
Initialize task 9, 13
inserting a debug code into a program 53
inserting comments and blank lines 6
instruction bulletin organization 2
L
line limit
source file 6
logic gates for Boolean alarms 97
logical operations 31
logical shift 27
LONGREG data type 22
M
mathematical and logical operations 23
mathematical expressions (table) 58
memory
viewing 46
meter cycle time
affected by custom code 53
Metercycle task 9, 13
MOD10L2 data type 22, 24
MOD10L3 data type 22, 24
MOD10L4 data type 22, 24
MODBUS registers 15
N
naming the source rile 6
NEXT command 33
NOT function 25
notational conventions in the instruction bulletin 2
O
on-board information
circuit monitor 44
opening a source file 39
OR function 25
order of execution
CMPL program elements 13
organization of this instruction bulletin 2
other elements in a source file 9
output generation
setting 42
63230-300-221/A1 Index
2/2002
105 2002 Schneider Electric All Rights Reserved
P
permitted data conversions (table) 30
possible program termination due to excessive
scan time 14
POWERLOGIC Downloadable Firmware Utility
(DLF-3000) 1
program
running and debugging 44
running and halting 48
viewing on-board 44
program control registers
examining 51
program name
extracting from registers 8175-8182 52
program name, version, and date
determining 51
program name, version, date
determining 51
program security 8
program version 7
programming language Assembler and compiler
error codes 61
programming language functions (table) 60
programming language reserved words 55
programming language runtime error codes 63
programming language syntax 57
programming language verbs (table) 59
programming tips 101
programs
custom 31
R
radians 28
read/write capability
SMS-3000 15
Read/Write Registers screen 46
reading and writing CM4000 registers 47
reading and writing registers 47
reading and writing to CM4000 registers 46
redefining a register with Equate 18
register
assigning a name 16
register 8184 51
register 8185 51
register 8186 51
register 8187 51
register 8193 47
REGISTER data type 22, 2627, 29, 33, 101
registers
assigning a name 16
examining individually 51
reading and writing 4647
setting before program execution 48
repeated execution using FOR...NEXT 33
required elements in a source file 6
reserved words 55
restart command 35
return command 10, 34
return statement 101
running a program 47
running and debugging the program 44
running and halting a program 48
runtime error codes 51, 63
S
sample Declaration section 20
sample program library 65
save reminder
setting 41
setting communication parameters 40
setting compiler options 42
setting registers before program execution 48
setting the background or text color 41
setting the environment 41
setting the Save Reminder 41
SHIFT function 2627
Signs (+ or --) 26
SINE function 28
SMS-3000 15
source file
line limit 6
naming 6
opening 39
required elements 6
SQROOT function 28
square brackets 17
starting the program 39
subroutine execution using CALL 34
subroutines 12
syntax 57
T
tab width
changing 41
table
declaring 18
tables of variables 17
terminating a CMPL program using HALT 35
terminating a task or subroutine using RETURN 34
text color
changing 41
Timer task 9
Timer task format 10
Tip of the Day
disabling 39
trigonometry 27
turning off .fw file output 42
types of alarms 95
Index 63230-300-221/A1
2/2002
2002 Schneider Electric All Rights Reserved 106
U
using runtime error codes 51
using the compiler to debug 44
V
variables
assigning to other variables 23
viewing 45
verifying program download 47
register 8192 47
view variables 45
viewing circuit monitor on-board information 44
viewing the CMPL program memory 46
viewing the program 43
X
XOR function 25
63230-304-201/A1
3/2001
107 2001 Schneider Electric All Rights Reserved
63230-304-201/A1
3/2001
108
Bulletin No. 63230-300-221/A1 February 2002 2002 Schneider Electric All Rights Reserved. Class No. 3020
63230-300-221/A1
2/2002
ii 2002 Schneider Electric All Rights Reserved

Você também pode gostar