Maxim cannot assume responsibility for use of any circuitry other than circuitry entirely embodied in a Maxim product. No circuit
patent licenses are implied. Maxim reserves the right to change the circuitry and specifications without notice at any time.
Maxim Int egrated Products, 120 San Gabriel Drive, Sunnyvale, CA 9408 6 408-737-7600
2010 Maxim Integrated Products Maxim is a registered trademark of Maxim Integrated Products.
6 Contact Information .......................................................................................................................... 42
Revision History ........................................................................................................................................ 43
Figure
Figure 1: High Level Host/Firmware Interface Architecture
Tables
Table 1: CE Configuration ........................................................................................................................... 10
This document describes the Metrology Appl icat ion Pro gr am ming Interface (M-API) version 2.00 firmware
libraries available from Teridian for use with the 78M6612 IC. These libraries are specifically designed for
measurement and switch control of two (2) single-phase AC outlets (same phase).
The firmware delivery is a set of metrology libraries that configure and operate the measurement front
end (e.g. MUX, ADC, CE, etc.) and provides simplified access to measurement output data such as
Power, Voltage, Current, accumulated Energy and Line Frequency. All measurement calculations are
computed by the MAPI library every accumulation interval and mapped to a dedicated block of registers
reserved by the library.
Measurement data are made available to the user application via API calls. A demo application making
use of the M-API library set and serial UART interface is included as part of the 78M6612 OMU
Evaluation Kit.
Timer functions using the hardware RTC are also available and can be accessed directly by the
application. APIs specific to RTC are not available in the current library. Contact a Teridian
representative for more information on non-Volatile RTC operation (e.g. battery backup modes).
1.1 Terminology
The following terminology is used throughout this document:
• CREEP – Threshold value where meas urem ent outp ut s are sque lched t o zero.
• IMAX – External RMS current corresponding to 250 mVpk at the current input of the 78M6612. It should be set
IMAX= (Vpk/√2)/R
•VARs – Reactive Power (Q)
SENSE
.
• VAs – Apparent Power (S).
• Watts – Active Power (P).
• VMAX – External RMS voltage corresponding to 250 mVpk at the voltage input of the 78M6612 (VA, VB). It
must be set high enough to account for over-voltages.
• NB – Narrowband values.
• WB – Wideband values.
Rev. 1.00 5
Page 6
78M6612 M-API Library User Guide UG_6612_036
1.2 Library Measurement Equations
The integrated Compute Engine (CE) accumulates the raw samples from the ADC and provides to the
80515 MPU the critical *atomic measurements needed to derive all other data. This consists of RMS
Voltage, Voltage Sag Status , and AC Line Freq uency data as well as RMS Current, Active Po wer, and
Reactive Power for each outlet. The MAPI library provides the application developer with two equation
options for processing the atomic values before updating the libraries output data registers. One equation
option is defined as “Narrowband” (NB) and the other is defined as “Wideband” (WB).
When using NB equations; RMS Voltage, Active Power, and Reactive Power data is provided by
the CE and used to derive RMS Current, Apparent Power, and Power Factor in the MPU for each
outlet. Harmonic content is not included in the reported current measurement.
*Voltage (V
Current (I
) = √∑v(t)2
RMS
) = S/V
RMS
RMS
*Active Power (P) = ∑ (i(t) * v(t))
*Reactive Power (Q) = ∑ (i(t) * v(t) shift 90º)
Apparent Power (S) = √(P
2
+ Q2)
Power Factor (PF) = P/S
When using WB equations (recommended); RMS Voltage, RMS Current, and Active Power data
provided by the CE is used to derive Reactive Power, Apparent Power, and Power Factor in the
MPU for each outlet.
*Voltage (V
*Current (I
) = √∑v(t)2
RMS
) = √∑i(t)2
RMS
*Active Power (P) = ∑ (i(t) * v(t))
RMS
2
– P2)
* I
RMS
Reactive Power (Q) = √(S
Apparent Power (S) = V
Power Factor (PF) = P/S
6 Rev. 1.00
Page 7
UG_6612_036 78M6612 M-API Library User Guide
1.3 Library Parameters
This section describes critical constants and variable parameters of the MAPI library and their
recommended usage.
1.3.1 Global Symbols
The following symbols are fixed constants for the MAPI v2.00 firmware library:
The following variables are unique to the sensor configuration and represent the real world values
mapped to the upper range of the 78M6612 analog front end.
IMAX : 52 Amps for 4mOhm shunt
VMAX : 471.5 Volts
1.3.2 Formulae for Scaled Parameters
The measurement outputs (and respective alarm thresholds) for the M-API library are stored in a raw
format to preserve native resolution of the computed measurements. When using API calls to access or
fetch measurement data, the values are automatically scaled and converted according to the data types,
below.
I
rms
V
rms
Watts = float(Val)* POWERSCALE*IMAX*VMAX/1000
Frequency = integer(Val)/100
Val : library data
In some rare cases, when raw measurement data (Val) is directly accessed without going through the
library, which is not recommended, scaling to and from real world or usable values must be done using
the formulae above.
This example demonstrates the calculation of IMAX and VMAX for the default sensor configuration. For
more information on sensor selection and configuration, refer to the 78M6612 Hardware Design Guidelines.
The 78M6612 firmware provided by Teridian is partitioned into three main components:
•The Compute Engine (CE) firmware, although a separate set of source code, is a component of the
MAPI libraries responsible for precision Voltage, Current, Watts, and VARs measurements handled
by a dedicated processor. The source code for the CE is not described in this document or made
available for user modification.
•The 80515-based M-API firmware, in combination with the CE firmware, completes the M-API librar y
set and provides all the necessary IC configuration, calibration sub-routines, scaling, data conversion,
and timing control. This set of libraries is to be linked to the application firmware specific to the
desired host interface.
•The Application firmware exercises the M-API library and manages the communication to the host
controller/application. Teridian provides an example Serial Driver to be used as sample code as well
as the application firmware that uses this Serial Driver to exercise the MAPI library. Refer to the
applicable Firmware Description Document for more information on the application firmware.
Figure 1 shows a high level partitioning of the firmware architecture. The black boxes indicate object
and
code to be provided by Teridian. The white box indicates object
source code provided by Teridian.
Figure 1: High Level Host/Firmware Interface Architecture
Rev. 1.00 9
Page 10
78M6612 M-API Library User Guide UG_6612_036
3 Build Environment and Software/Firmware Configurati ons
The Metrology Application Programming Interface (MAPI) is built using Keil Compiler version 8.02,
although any Keil version 7.00 or higher is also compatible.
The MAPI is built using specific default configuration as listed below.
3.1 Firmware Library and CE Memory Configurations
Processing of ADC inputs is done by the CE. The MAPI libraries are built to link to the specific CE code
according to the specific hardware conf ig urati on. The table below shows the different libraries as built
with specific CE code to support different configurations:
Table 1: CE Configuration
Library Name Default Accumulation Interval = 500ms
6612S22_WB_MAPI.lib Built for Wide-Band.
6612S22_NB_MAPI.lib Built for Narrow-Band.
3.2 Program and RAM Memory
The embedded 80515 MPU within the 78M6612 has separate program memory (32K bytes) and data
memory (2K bytes).
3.2.1 Pr ogr am Memory
The Flash program memory is non-volatile and is segmented into 512-byte pages. The last 2.5K (five
512-byte pages) of Flash space is reserved for CE data, CE code and default values used for Energy
Calibration and Measurement. The code for the Compute Engine program resides in the MPU program
memory (flash) and must begin on 1K-byte boundary.
Table 1 below shows the partitions of Flash memory.
Table 2: Flash Memory Map
Address (hex) Type Typical Usage
0000-75FF
7600-773E
777F-7FFF Non-volatile
Non-volatile
Non-volatile
Program and any non-volatile
data. Shared by the MAPI and
application layer.
Reserved for MAPI energy
measurement constants
(defaults).
Reserved for CE code and CE
data.
Wait States
(at 5 MHz)
0
0
0
Size (bytes)
29.5KB
< ~350B
2KB
10 Rev. 1.00
Page 11
UG_6612_036 78M6612 M-API Library User Guide
3.2.2 RAM/Data Memory
The 78M6612 has 2K bytes of Data Memory for exclusive use by the embedded 80515 MPU library and
application layers. In addition, there are 512 bytes reserved for the Compute Engine.
Table 3: Data RAM Shared by CE and MPU
Address (hex) Type Typical Usage Size (bytes)
0000-07FF Volatile MPU data XRAM, 2KB
1000-11FF Volatile CE data 512
2000-20FF Volatile
Miscellaneous I/O RAM
(configuration RAM)
256
3.3 Build Configuration
The accompanying example application source code has been set up to link to each library under specific
hardware configuration. Each configuration is defined under a different ‘Target’. However, for all ‘Targets’,
specific area of Flash is reserved for specific function as described below.
3.3.1 Flash/Code and RAM Size
The attached zipped file (78M6612MAPIv200.zip) contains a sample Application code, of which source
code is also included. The functions of this application are detailed in Section 6.
This sample applic at ion is taking up Flash/RAM usage according to the table below. It was written to
demonstrate the use of the MAPI libraries via two types of commands: the ‘M’ commands (as shown in
Section 6) to specifically address the MAPI calls; and the ‘CLI’, aka Command Line Interface, commands
for backward compatibility to support those who have evaluated, or are familiar with, Teridian OMU
products in the past.
The following tables show RAM and Flash consumptions by this sample application. They also show a
breakdown of Flash consumption by different features as implemented in the MAPI libraries.
Table 4: Flash and RAM Consumption by MAPI and Sample Application
Firmware Module
6612S22_WB_MAPI.lib
6612S22_NB_MAPI.lib
6612IVIV_50F0_v200WB.hex
6612IVIV_50F0_v200NB.hex
Table 5: Breakdown of M-API’s Flash Consumption
Library:
6612S22_WB_MAPI.lib
6612S22_NB_MAPI.lib
Calibration 5.7K Includes calibration for: Temperature, Current, Voltage,
MAPI Interface (to App) 1.5K Direct interface to the library from application.
Flash Manager 2K Flash Read/Write management.
Rev. 1.00 11
RAM
Used
~ 26K The RAM usage is overlay-able. See the
1.7K 6K + 26K(lib) The app from this build uses every single API
Flash Used Features
Flash Used Note
breakdown of Flash usage in Table 5.
library call.
Watt and Phase.
Registers, etc.
Page 12
78M6612 M-API Library User Guide UG_6612_036
Metering 6K Metrology functions (alarms, power factor, RMS, etc.)
Measurement 2K Metrology computations
Serial Driver 1K Serial 0/RS232 I/O
Timer < 0.5K Timer 0 driver.
Relay Management/Misc . 2K Relay Control/On/Off, some math logic, IRQ.
3.3.2 Flash/Code Space Assignment
As shown in Table 1, in order to reserve specific regions of Flash for specific MAPI default data, CE code
and CE data, the build file of the firmware application must be setup to specify where the modules will
reside. It is necessary to keep images of CE code/data and default data isolated at the application’s build
file. The accompanying application code has setup these assignments as follows: Default data is at
starting address 0x7600. CE Data is at starting address 0x777E. CE Code is at starting address
0x77FE.
This information is represented in the mapped file (.M51) as follows:
SEGMENTS (?CO?DEFAULTS(C:0X7600),
The firmware application source code, as shipped with this document, is setup such that its project file
contains all the supported libraries as built for the specific CE code and data to support different
configuration options. As sho wn in the projec t, the libr ar ies built for Narrow-Band and Wide-Band are
included in the project but only one library shall be selected to be built with a specific ‘Target’ at a time.
The ‘Target’s as defin ed in the Keil proj ec t file for the sample application are shown below. When modify
this project’s targets, it is important that the correct library is selected:
Rev. 1.00 13
Page 14
78M6612 M-API Library User Guide UG_6612_036
3.3.4 Module’s Selection within a Library
The M-API libraries are organized into separate modules based on their functions so that code size and
RAM size can be easily optimized during Keil’s build/link time. Some of the modules are mandatory and
must be included while others can be de-selected to save Flash space if the functions/features are not
used. Typically, when an API is called directly, the Keil Linker would automatically include the module.
However, in some cases, a needed module used by the library would not be included as it is only called
within the library. In this case, the application would need to exclusively include the module. Table 6
shows the individual modules as built with the library and the selection criteria that an application is
recommended to follow.
This byte indicates presentation format of the register
content defined as follows:
10 – Tenth unit factor.
100 – Hundredth unit factor.
1000 – Thousandth unit factor.
Return Codes MAPI_OK – successful operation.
MAPI_RESTRICTED – specified address is restricted.
Rev. 1.00 19
Page 20
78M6612 M-API Library User Guide UG_6612_036
MAPI_MeterStatus() for
4.2.1.1 Auto-Scaling
When retrieving measurement data using the MAPI_GetSetRegister() call, the returned data value is
automatically converted to usable data according to the TypeSize of the register location. The
ScaleFactor is for information only.
When writing alarm thresholds to library input registers, usable data values are automatically converted to
raw values according to the TypeSize of the target register address.
4.2.1.2 Output Data Address Locations
The following output data is updated once per accumulation interval and available via the
MAPI_GetSetRegister() call.
MPU
Address
NB WB
00 20 Delta Temperature 0.1 °C FLOAT Temperature difference from 22 °C.
01 21 Line Frequency 0.01 Hz FREQ Line Frequency.
02 22
03 23
Name LSB Type Description
Alarm Status
(common)
OverCurrent Event
Count
STATUS
1
INTEGER
See Section 4.4.3 –
details.
Number of event counts where value
exceeded over current alarm thresh old.
04 24
05 25
06 26 Volts mVrms VRMS_M AC Line Voltage (RMS)
Under Voltage Event
Count
Over Voltage Event
Count
1 INTEGER
1 INTEGER
Number of event counts where value
exceeded under voltage alarm threshold.
Number of event counts where value
exceeded over voltage alarm threshold.
MPU Address
Name LSB Type Description Outlet 1 Outlet 2
NB WB NB WB
07 27 47 67
08 28 48 68 Energy mWh ENERGY
09 29 49 69 Cost mUnits FLOAT Accumulated Cost.
Power factor.
(output will be between -1.00 and 1.00)
20 Rev. 1.00
Page 21
UG_6612_036 78M6612 M-API Library User Guide
D0
D2
D6
Max Voltage (A) Alarm Threshold
DA
DC
E0
E2
Current -Outlet 1
A1
Imin(IA) - "creep" or squelch level
4.2.1.3 MPU Library Inputs
The following inputs can be modified (and saved to Flash) using API calls. For more information on
register descriptions, refer to the 6612_OMU Firmware Description Document.
Category
Common Alarm
Threshold
Name
Temperature
Frequency
Voltage (A)
LSB
MPU
Address
D1
D3
D4
D5
Description
Min Temperature Alarm Threshold
Max Temperature Alarm Threshold
Min Frequency Alarm Threshold
Max Frequency Alarm Threshold
SAG (A) Voltage Alarm Threshold
Min Voltage (A) Alarm Threshold
Outlet Specific
Alarm Thresholds
Alarm Mask
Alarm Mask
Sensor Scaling
Cost Factor Cost AA
Relay Control Relay Configuration AC
Calibration Calibration
Creep Threshold
Current - Outlet 1 D8 D9 Max Current Alarm Threshold
Power Factor - Outlet 1
Current - Outlet 2 DE DF Max Current Alarm Threshold
Power Factor - Outlet 2
Total Current E4 E5 Max Current Alarm Threshold
Alarm Mask for Status Registers E6
Alarm Mask for Alarm DIO4 E7
Voltage - V(A)
Current -Outlet 1
Current - Outlet 2
Configuration
Parameters
Current - Outlet 2
NB
DB
E1
A0
A2
A4
AB
AD
AE
AF
BF
C0
C1
C2
C3
C4
C5
C6
C7
C8
C9
CA
CB
CC
CD
CE
CF
A3
WB
Power Factor Alarm - Threshold
DD
Power Factor Alarm + Threshold
Power Factor Alarm - Threshold
E3
Power Factor Alarm + Threshold
32-BIT alarm mask (0=masked)
32-BIT alarm mask (0=masked)
VMAX A
IMAX Outlet 1 (IA)
IMAX Outlet 2 (IB)
Cost per KWh
Cost Unit string
Polarity, Latch type
Sequence Delay
Energize Delay
De-energize Delay
Tolerance on Phase Calibration
Calibration Type
Calibration Voltage (Target)
Calibration Current (Target)
Calibration Phase (Target)
Tolerance on Voltage Calibration
Tolerance on Current Calibration
Average Count for Voltage
Average Count for Current
Max Iterations for Voltage
Max Iterations for Current
Tolerance on Watts Calibration
Average Count for Watts
Max Iterations for Watts
Calibration WRATE
Calibration Temperature
Calibration Wattage (Target)
Imin(IB) - "creep" or squelch level
Rev. 1.00 21
Page 22
78M6612 M-API Library User Guide UG_6612_036
4.2.1.4 CE Library Inputs
The following inputs can
only
be modified (and saved to Flash) using API calls. For more information on
register descriptions, refer to the 6612 OMU Firmware Description Document.
CATEGORY CE Address Description
Calibration
0A-0B Calibration Gain VA, VB
Phase Adjust
CE Configuration
Pulse Rate
Quantization Corrections
Temperature Compensation
SAG Threshold
More Temperature
Compensation
08-09 Calibration Gain IA-IB (Outlet 1-2)
0C-0D Phase Adjust IA - IB
0E CE State
0F Wrate
12-13 Quantization offset Watt 1 to Watt 2
14-15 Quantization offset VAR A – VAR B
16-17 Quantization offset IA – IB
19 Temperature Gain Adjust
10 SAG Threshold on kVar
11 SAG Threshold
A6 Temperature Nominal
A7 Degree Scale
A8 ppm / ˚c
A9
ppm / ˚c2
22 Rev. 1.00
Page 23
UG_6612_036 78M6612 M-API Library User Guide
4.3 CE and MPU Control
4.3.1 MAPI_CEOn()
Purpose Turn CE on. After calling MAPI_Init(), CE is automatically turned on. This
API is provided as a convenience for the Application level to control the CE,
especially when reading/writing to Flash is necessary (writing to Flash is not
allowed when CE is on).
Synopsis void MAPI_CEOn ( void );
Parameters None.
Return Codes None.
4.3.2 MAPI_CEOff()
Purpose Turn CE off. When writing to flash, the CE must be turned off. This API is
necessary with MAPI_UpdateCE, MAPI_UpdateMPU or memcpy_rx calls.
Synopsis void MAPI_CEOff ( void );
Parameters None.
Return Codes None.
4.3.3 MAPI_GetCEName()
Purpose Get the CE name embedded as part of the CE data. The CE name size is 24
bytes and these exact 24 bytes will be returned in the XDATA string pointed to by
The CE name will be returned at the xdata location pointed to by
ptr. For version 2.00 Library release, the string will look as follows:
CE6612_OMU_S2+2_A01_V1_4.
Return Codes None.
4.3.4 MAPI_SoftReset()
Purpose Reset the MPU, this includes stopping the CE, and setting all registers to
Purpose Update the MPU contents permanently into Flash. The MPU measurement input
and calibration default values are stored in Flash. During power up, its content is
copied to XRAM to be used as a working copy. The application can change
some of the registers’ values using the MAPI_SetGetRegister(). This
change only takes effect in the XRAM copy of the data. To permanently save the
new data into Flash, the application must exclusively call this function to perform
the permanent save. This function is not to, and should not, be called too often
as Flash Write does have a life-expectancy. It is typically used after the part is
calibrated successfully to save the coefficient values. See the
OMU_MAPICLI.uproj for sample usage of this API. In order for this function to
perform properly, the CE must be turned off by calling MAPI_CEOff().
Synopsis Bool MAPI_UpdateMPU ( void );
Parameters none
Return Codes TRUE – Successful write of MPU data to Flash.
FALSE – Write was not successful; perhaps CE is still running.
4.3.7 MAPI_UpdateCE()
Purpose Update the CE Data contents permanently into Flash. The CE Data Image is
programmed into Flash, starting at address 0x775E. During power up, its
content is copied to XRAM to be used as a working copy. Thou gh it is NOT
recommended to change any CE Data, occasionally such needs arise, such as
changing the IMAX, VMAX or WRATE values. The application can change some
of the registers’ values using the MAPI_SetGetRegister(). This change only
takes effect in the XRAM copy of the data. To permanently save the data into
Flash, the application must exclusively call this function to perform the permanent
save into its specific location of Flash. This function is not, and should not, be
called too often as Flash Write does have a life-expectancy. See the
OMU_MAPICLI.uproj for sample usage of this API. In order for this function to
perform properly, the CE must be turned off by calling MAPI_CEOff().
Synopsis Bool MAPI_UpdateCE ( void );
Parameters None.
Return Codes TRUE – Successful write of MPU data to Flash.
FALSE – Write was not successful; perhaps CE is still running.
24 Rev. 1.00
Page 25
UG_6612_036 78M6612 M-API Library User Guide
4.4 Calibration and Power Measurement
4.4.1 MAPI_CalSetGet()
Purpose Set or Get Calibration referenced and tolerance parameters as specified in the
MPU_CParms_t structure. New values are kept in RAM only. When all
calibration data is setup and calibrated correctly, it shall be kept and recorded,
permanently in Flash by calling MAPI_UpdateCE() and MAPI_UpdateMPU().
A typical calibration of the part proceeds as follows:
1. Call MAPI_CalSetGet (FALSE, ….) to get current calibration data.
2. If necessary, call MAPI_SetGetCal (TRUE,…) to set new calibration data
(tolerance values, referenced values, etc.).
3. Call MAPI_Calibrate() to start the calibration. If calibration passes,
continue to step 4. If calibration fails, repeat step 1.
4. Call MAPI_UpdateCE() and MAPI_UpdateMPU() to permanently update
the new values in Flash.
5. Call MAPI_CalSetGet (FALSE,…) to make sure the new data is written,
preserved and correct.
float C_Wcal; // Wattage calibration value (Watts).
float C_Vcal; // Voltage calibration value (Vrms).
float C_Ical // Current calibration value (Arms).
int16_t C_Pcal; // Phase calibration value (Degrees).
Return Codes MAPI_OK //Calibration succeeded.
MAPI_ERROR //Calibration failed.
//For more detailed descriptions of the failure, call MAPI_CALStatus().
26 Rev. 1.00
Page 27
UG_6612_036 78M6612 M-API Library User Guide
4.4.2 MAPI_Calibrate()
Purpose Calibrate the part using referenced meter values and tolerance values as
specified in the MPU_CParms_t data structure (see the MAPI_CalSetGet API
for more information).
1. Call MAPI_CalSetGet (FALSE, ….) to get current calibration data.
2. If necessary, call MAPI_CalGetSet (TRUE,…) to set new calibration data
(tolerance values, referenced values, average count, maximum count, etc.).
3. Call MAPI_Calibrate() to start the calibration.
4. Call MAPI_UpdateCE() and MAPI_UpdateMPU() to permanently update
the new values in Flash.
5. Call MAPI_CalSetGet (FALSE,…) to make sure the new data is
written/preserved.
It is up to the application level to select the CAL_TYPE appropriately. It is
recommended that temperature calibration (CTYPE = C_TEMP) shall always be
part of CAL_TYPE; thus, C_TEMP shall always be OR’ing with c_type. When
this API is called with multiple CAL_TYPEs, calibration will be done in the
following order:
A typical application shall use this API as follows:
Temperature,
Phase,
Voltage,
Current,
Wattage.
Make sure the referenced values are setup correctly, using MAP_CalSetGet();
otherwise, calibration will not pass. See Section 4for default valu es .
When the return code is not MAPI_OK, call MAPI_CalStatus() to get detailed
descriptions of the calibration error(s). If an error occurs during this call, the part
is NOT calibrated. It is the task of the application to call this API again if
recalibration of the part is necessary.
Calibration source. The values can be OR’ing. For example: C_WATT | C_VOLT
indicate calibration to be done on Voltage first, then Wattage; C_TEMP | C_VOLT
indicate calibration to be done on Temperature then Voltage.
Rev. 1.00 27
Page 28
78M6612 M-API Library User Guide UG_6612_036
Outlets Input parameter
Bit representations of outlet # to be calibrated. For example: 0x03
represents outlet #1 and 2 to be calibrated.
Purpose Run this function after a failed calibration or per io dica ll y to detect any
error/warning. Any non-zero value returned indicates some failure/w arn ing has
occurred. MPU Output Threshold levels and mask settings for the alarms can be
read, modified, and saved using the MAPI_GetSetRegister() API call.
Synopsis void MAPI_MeterStatus ( unsigned long Status);
Parameters StatusOutput parameter.
Min Temperature exceeded Bit 0 = 1 //0000 0001
Max Temperature exceeded Bit 1 = 1 //0000 0002
Min Frequency exceeded Bit 2 = 1 //0000 0004
Max Frequency exceeded Bit 3 = 1 //0000 0008
SAG A detected Bit 4 = 1 //0000 0010
Under Min VA on A Bit 5 = 1 //0000 0020
Over Max Voltage on A Bit 6 = 1 //0000 0040
Over Max I on A – narro w Band Bit 7 = 1 //0000 0080
Over Max I on A – wide Ba nd Bit 8 = 1 //0000 0100
Min Power Factor exceeded on A -NB Bit 9 = 1 //0000 0200
Max Power Factor exceeded on A-NB Bit 10 = 1 //0000 0400
Min Power Factor exceeded on A -WB Bit 11 = 1 //0000 08 00
Max Power Factor exceeded on A-WB Bit 12 = 1 //0000 1000
Max Current exceeded on B - NB Bit 1 3 = 1 //0000 2000
Max Current exceeded on B - WB Bit 14 = 1 //0000 4000
Min Power Factor exceeded on B -NB Bit 15 = 1 //0000 8000
Max Power Factor exceeded on B-NB Bit 16 = 1 //0001 0000
Min Power Factor exceeded on B -WB Bit 17 = 1 //0002 0000
Max Power Factor exceeded on B-WB Bit 18 = 1 //0004 0000
Max Current Total exceeded - NB Bit 19 = 1 //0008 0000
Max Current Total exceeded - WB Bit 20 = 1 //0010 0000
Creep on A Bit 21 = 1 //0020 0000
Creep on B Bit 22 = 1 //0040 0000
_FAULT – Neutral/Line reversal Bit 23 = 1 //0080 0000
Power Register Not Accurate Bit 27 = 1 //0800 0000
Return Codes None.
A 32-bit word status that indicates statuses as follows:
28 Rev. 1.00
Page 29
UG_6612_036 78M6612 M-API Library User Guide
Rev. 1.00 29
Page 30
78M6612 M-API Library User Guide UG_6612_036
4.4.4 MAPI_TimeToAverage()
Purpose Set/Get the time increment (in seconds) in which the power (in Watts) is to be
averaged. If a Time Interval has been set previously, it will be reset from this
point forward and the accumulator’s value will also be reset. Default value will be
10 seconds if this API is not called or if it is called with TimeInterval = 0. This
time is global time that is applicable to both channels.
Synopsis Void MAPI_TimeToAverage ( IN Bool SetTIME,
IN unsigned int TimeInterval);
Parameters SetTIME Input parameter.
TRUE (1) will set the time to TimeInterval seconds.
FALSE(0) will return the current Time Increment Query to
TimeInterval.
TRUE (1) = set operation. FALSE (0) = get operation,
Relay_Config will all be output parameter.
When Operation = TRUE:
Relay_CTLOutput parameter.
This parameter is output only. It is set via
MAPI_RelayControl().
SeqDlyTimeInput parameter.
Set the new Sequence Delay Time in 10ms
units. Delay time is time between turning
Relays ON (close circuit). Default value is 10
100ms.
DeEngergizedTimeInput parameter.
Time in mseconds + 1msecond to delay after
open circuit.
EngergizedTimeInput parameter.
Time in msecond + 1msecond to delay after
close circuit.
InvertPolarity Input parameter.
Bit 1 = Polarity (0 = non-inverted). Bit 0 =
Latch type (0 = non-latched).
Notes:
Sequence Delay Time will be used between turning relays ON.
Energized Delay Time is used as the delay time to wait
immediately after a zero-crossing before close circuit.
DeEnergized Delay Time is used as delay time to wait
immediately after a zero-crossing before open circuit.
Return Codes None.
32 Rev. 1.00
Page 33
UG_6612_036 78M6612 M-API Library User Guide
4.5.2 MAPI_RelayControl ()
Purpose Turning Relay ON/OFF (close/open circuit) on all channels.
Synopsis void MAPI_RelayControl( IN unsigned char Channels);
Parameters Channels Input parameter.
Each bit indicates turning ON(1) or OFF(0). The bit’s position
represents the specific channel/outlet number. For example:
0x01h – Turn relay ON on channel 1/A. Turn relays OFF on channel 2/B.
0x02h – Turn relay ON on channel 2/B. Turn relays OFF on channel 1/A.
Both channels can be turned ON with a single call to this API by setting 1 at the
bits representing the channels. For example:
0x03h – Turn relay ON on both channels.
Note: in the library code, channel 1 relay is mapped to DIO7 and channel 2 to
DIO19. But all other evaluation boards (6612, 6613, etc) are setup such that
DIO19 to TP4 and DIO7 is grounded. This means relay control doesn’t mean
much since only DIO19 would be suitable to be controlled in this case but since
there is only one channel, there is no point of having a control.
Return Codes None.
4.5.3 MAPI_CloseCircuit_0X()
Purpose Get zero-crossing status when positioning from open circuit to close circuit. The
value returned TRUE/FALSE indicates whether
occurred. The usage of this API is intended to be for when the circuit is
transitioning from open to close. This API uses the hardware Timer 1 in the case
when zero crossing does not take place. A delay of 12ms is set for such break.
Synopsis bool MAPI_CloseCircuit_0X( void );
Parameters None.
Return Codes TRUE – Zero crossing occurs.
FALSE – Zero crossing does not occur.
4.5.4 MAPI_OpenCircuit_0X()
Purpose Get zero-crossing status when transitioning from close circuit to open circuit.
The value returned TRUE/FALSE indicates whether
occurred for a specific channel. There is no indication of either direction
(falling/rising). The usage of this API is intended to be for when the circuit is
transitioning from close to open. This API uses the hardware Timer 1 in the case
when zero crossing does not take place. A delay of 10ms is set for such break.
Synopsis bool MAPI_OpenCircuit_0X( unsigned char Channel );
Parameters Channel Input parameter.
Channel/outlet number (1 or 2) where zero crossing will be
detected.
Return Codes TRUE – Zero crossing occurs.
FALSE – Zero crossing does not occur.
Voltage
Current
zero-crossing has
zero-crossing has
Rev. 1.00 33
Page 34
78M6612 M-API Library User Guide UG_6612_036
4.6 Soft-Timers
There are eight soft-timers in the 8051 Timer 0. Only six of these timers are available to application level
as two are used internally by the library. The timer is a fixed 10-milisecond time increment. When
TSC_Init() is called, the timer will be started and setup. It also calls MAPIstm_init() so the
application layer does NOT need to call MAPIstm_init().
When unsure, it’s best to call this API with a Get Operation (OP=1) to get current
settings prior to changing any DIO assignments.
Synopsis void MAPI_DIOConfig (struct Signals_t *Signals, uint8_t OP)
Where:
//all possible DIO signals
struct Signals_t {
uint8_t Act ive B;
uint8_t Al arm;
uint8_t FaultB;
uint8_t Rea d yB;
uint8_t Rel a y1;
uint8_t Rel a y2;
uint8_t SAG_sign;
uint8_t WPulse;
uint8_t RFU; //Customer’s specific –delete?
uint8_t RFU; //Customer’s specific –delete?
uint8_t RFU; //Customer’s specific –delete?
uint8_t RFU; //Customer’s specific –delete?
uint8_t RFU; //Customer’s specific –delete?
uint8_t Unus e d1;
uint8_t Unus e d2;
uint8_t Unus e d3;
};
Get (1) or Set DIO assignments.
Signals - Input parameter (OP = 1)/ Output parameter (OP = 0)
When OP = 1, return the current DIO pin assignments.
When OP = 0, set all DIO pin assignment according to the value assigned to
Signals..
Return Codes None.
Note: care must be taken when assigning the same DIO to be used for different functions as
there is no checking in the library for any conflict that may arise. For example, DIO6 may be used
to drive a LED and to be used as part of the I2C function. The library does NOT check for this
conflict of usage.
Rev. 1.00 35
Page 36
78M6612 M-API Library User Guide UG_6612_036
4.7.2 MAPI_DIORW()
Purpose Perform the Read/Write operation of/to the DIO.
Synopsis void MAPI_DIORW ( enum SIGNAL_TYPE Signal,
Note: To avoid accidental write to Flash, this function requires a ‘flash write’ confirmation from the
application layer. This confirmation is done such as follows: there shall be a function called
get_buff(), at application level, which returns a pointer of Xdata whose content is checked as
the following:
This selects the communication speed. Possible values are:
_RATE_3000
_RATE_600, 1
_RATE_1200, 2
_RATE_2400, 3
_RATE_4800, 4
_RATE_9600, 5
_RATE_19200, 6
_RATE_38400, 7 (default)
Return CodesNone.
4.9.2 MAPI_UARTTx()
Purpose Setup the Tx buffer before sending data to the PC UART. Subsequent call to this
API will append the buffer to the existing transmittal buffer. An application should
call this API immediately after calling MAPI_UARTInit(). This is a non-
blocking call so always call MAPI_TxLen to make sure the transmission is
completed successfully.
Synopsis enum SERIAL_RC data MAPI_UARTTx ( U08x xdata *buffer, U16 len )
Parameters buffer Input parameter.
Specifies a pointer to the data buffer containing data to send to the
PC UART.
LenInput parameter.
Specifies the current number of bytes to be sent.
Return Codes: S_EMPTY Successful transmission.
S_PENDING, Successful transmission thus far but not yet finished.
Where return code SERIAL_RC is defined as: Enum SERIAL_RC.
After calling this API, an applica tion can m ake sure all bytes were transm itted by
checking that MAPI_TxLen() returns a 0.
Rev. 1.00 39
Page 40
78M6612 M-API Library User Guide UG_6612_036
4.9.3 MAPI_TxLen()
Purpose Number of bytes transmitted thus far.
Synopsis Unsigned integer MAPI_ TxLen ( void )
Parameters None.
Return Value Unsigned integer specifying the number of bytes left in the Tx buffer, i.e. the
remaining bytes to be sent.
4.9.4 MAPI_UARTRx()
Purpose Setup the receive buffer and start receiving. Always call this function after
MAPI_UARTInit() to make sure the receive buffer is available. Subsequent
call to this API will append the data to the existing buffer queue, if data is being
received. This is a non-blocking call so always check for completion of the
Specifies a pointer to the data buffer to store the data received from
the PC UART.
lenInput parameter.
Specifies the maximum number of bytes to receive at any one time.
Return Codes Unsigned integer specifying the number of bytes fetched thus far. Use
MAPI_RxLen() to keep track of the remaining number of bytes unfetched in the
Rx buffer.
4.9.5 MAPI_RxLen()
Purpose Number of bytes received thus far.
Synopsis Unsigned Integer MAPI_ RxLen ( void )
Parameters None.
Return Value Unsigned integer specifying the number of bytes in the queued buffer.
40 Rev. 1.00
Page 41
UG_6612_036 78M6612 M-API Library User Guide
5 Default Values
The following default values are used to build the MAPI library: