Smart Plug Software Design Reference Manual

Similar documents
i.mx 7 Dual/Solo Product Lifetime Usage

Offline Flash Programmer for Kinetis K- and L-series MCUs

Getting Started with the MCU Flashloader

i.mxrt1050 Product Lifetime Usage Estimates

i.mx 6ULL Product Usage Lifetime Estimates

Kinetis USB-KW41Z Wireless Protocol Sniffer Quick Start Guide

Three-Phase Power Meter Hardware Design Reference Manual

i.mx 6UltraLite Product Usage Lifetime Estimates

Emulating Dual SPI Using FlexIO

Power Consumption and Measurement of i.mx RT1020

How to use FlexMemory as D-Flash and EEPROM in KE1xF

MQX RTOS Release Notes for Kinetis SDK FRDM- KV10Z Freescale Freedom Development Platform

WCT1011A/WCT1013A Automotive MP-A9 V4.0 Run-Time Debugging

TWR-KV10Z32 Sample Code Guide for IAR Board configuration, software, and development tools

Getting Started with Freescale MQX RTOS for Kinetis SDK and MDK-ARM Keil

HVP-KV10Z32 User s Guide

MQX RTOS Release Notes for Kinetis SDK v1.2.0 for KL33Z64 for FRDM-KL43Z Freescale Freedom Development Platform

Getting Started with MCUXpresso SDK CMSIS Packs

TWR-KV10Z32 Sample Code Guide for CodeWarrior Board configuration, software, and development tools

Emulating I2S bus on KE06

Kinetis KE1xF512 MCUs

How to Implement USB Suspend/Resume Feature with MCUXpresso SDK USB Stack

MCUXpresso SDK USB Power Delivery

How to Enable Boot from QSPI Flash

WPR1500-LDO MP Receiver V2.1 Reference Design User s Guide

SPI topics: watchdog, serial output and parity check

AN5016. Trigonometry approximations. Document information

Building U-Boot in CodeWarrior ARMv8

Kinetis SDK Release Notes for the TWR-K24F120M Tower System Module

Configuring DDR in U-Boot using QCVS

HVP-KV31F120M User s Guide

Freedom FRDM-KV31F Development Platform User s Guide

FRDM-K64F Board Errata

Kinetis Flash Tool User's Guide

Adding a run control interface into an existing CodeWarrior for MCU v10.x project

Kinetis SDK Freescale Freedom FRDM-KL03Z Platform User s Guide

KW41Z IEEE and BLE Coexistence Performance

Kinetis SDK v Release Notes for KV5x Derivatives

Developing a simple UVC device based on i.mx RT1050

Kinetis SDK v Release Notes for the MK21DA5 and MKW24D5 Devices

Kinetis Bootloader to Update Multiple Devices in a Field Bus Network

Load Position-Independent Code (PIC) on a Kinetis Platform Using the IAR EWARM Compiler

Using FCCU on MPC5744P

Kinetis Flash Tool User's Guide

OpenSDA on TWR-KW2x. User s Guide Rev 1.1

Developing a Camera Application with i.mx RT Series

Measuring Interrupt Latency

Kinetis Bootloader v1.2.0 Release Notes

PICO-i.MX6UL Development Platform for Android Things Quick Start Guide

Processor Expert Software for i.mx Processors Version 1.0

Kinetis Updater User's Guide

Configure QSPI Bus Width and Frequency in Pre-Boot Loader Stage on QorIQ LS Series Processors

TWR-KE18F User's Guide

Getting Started with Freescale MQX RTOS for Kinetis SDK and ARM GCC

Watt Saver Software Component (WSC)

Freedom FRDM-MC-LVBLDC Development Platform User s Guide

Freescale Kinetis Software Development Kit Release Notes

FRDM-KL03Z User s Guide

Getting Started with Freescale MQX RTOS for Kinetis SDK and Kinetis Design Studio IDE

Using an FFT on the Sigma-Delta ADCs

Collect Linux Hardware Trace for ARMv8 User Space and Kernel Space Applications

Migrating Applications from MC9S12VR64 to MC9S12VR32 by: Manuel Rodríguez

Emulating I2C Bus Master by using FlexIO

S12Z MagniV LIN Bootloader

TWR-KL28Z User s Guide

Kinetis Motor Suite v1.2.0 Release Notes

TWR-LS1021A Getting Started

Getting Started with Pins Tool User's Guide

General C Functions for the etpu Covers the MCF523x, MPC5500, MPC5600, MPC5700, MPX40 and all etpu-equipped Devices

How to Enable Boot from HyperFlash and SD Card

Freescale MQX USB Stack for TWR-K24F120M GA User s Guide

Generating a Quick and Controlled Waveform With the DAC

Using the i.mx RT FlexRAM

MCU Bootloader Release Notes

Getting Started with FreeRTOS BSP for i.mx 7Dual

i.mx 6Solo/6DualLite Product Lifetime Usage Estimates

TWR-LS1021A Getting Started

PMSM Field-Oriented Control Using MC56F84789 DSC With Encoders Demo Guide

Using the Asynchronous DMA features of the Kinetis L Series

Kinetis KM3x Metrology MCUs based on ARM Cortex -M0+ Core

QN9080 QN908x RF Certification Guide

Collecting Linux Trace without using CodeWarrior

How to Reduce SoC Power when Running M4 with A53 on i.mx8m

Quick Start Guide for the Freescale Freedom Development Platform FRDM-KL43Z

i.mx 6ULZ Migration Guide

Freescale MKW40Z IEEE Software Quick Start Guide

Controller Continuum. for Microcontrollers V6.3. Quick Start

i.mxrt1060 Product Lifetime Usage Estimates

Using VRC_CTL to Control an External VDD_LV Supply on the MPC5748G

Integrate TWR-EPD Software with MQX RTOS Based on the TWR-K21F120M Platform

Getting Started with MQX RTOS for Kinetis SDK

Differences Between S32K11x and S32K142

FRDM-KE02Z User s Manual

HVP-MC56F82748 User s Guide

QCVS Frame Distributor Wizard User Guide

Quick Start Guide for FRDM-KL05Z

User Manual Rev. 0. Freescale Semiconductor Inc. FRDMKL02ZUM

Quick Start Guide TRK-KEA. Kinetis EA Series MCUs for Automotive Electronics Applications. StarterTRAK

Working around ERR7026 according to application needs

UM User Manual for LPC54018 IoT Module. Rev November Document information

Transcription:

NXP Semiconductors Document Number: DRM158 Design Reference Manual Rev. 0, 03/2017 Smart Plug Software Design Reference Manual 1. Introduction This design reference manual describes a solution for a smart plug based on the MKM34Z64 microcontroller. This micro controller is part of the Kinetis-M microcontroller family. The smart plug reference design is intended for measurement of energies in single-phase, electronic power monitor, and wireless control. The solution can be extended to various areas, including lighting monitor, machine room power distribution, and so on. It can help the customer develop a competitive product by providing design documents. The Smart Plug Solution is based on the MKM14Z64 and implements measurement of grid voltage, current, frequency, and active and reactive energies. With the Wi-Fi chip, use UART, and predefined command protocol to implement status display and function setting from mobile application to socket. Contents 1. Introduction... 1 2. Features... 2 3. Software module... 2 3.1 Software environment introduction... 2 3.2. Packet communication... 10 3.3 Communication protocol... 10 3.4 Power metering... 28 3.5 Others... 32 4. Revision history... 32 2017 NXP B.V.

2. Features NXP Smart Plug Solution Software functions: Socket on/off status display and setting up Display of current active and reactive power, apparent power, and power consumption history Display of historic running time Time and timer setting up 3. Software module The software module consists of three main parts. These are command communication, communication protocol, and power measurement. 3.1 Software environment introduction 3.1.1. Development Tool Compiling: IAR 7.2 Debug: JTag SWD 3.1.2. Source code structure Root directory description: Figure 1. Root directory Table 1. Root directory description Root directory Projects Src Description IAR project files of Smart Plug project Source code of drivers and smart plug for MKM14Z64 2 NXP Semiconductors

Project source code directory description: Figure 2. Project source code directory Table 2. Project source code directory description Project source code Description Common Initialization and common code for MKM14Z64 Drivers Driver code for MKM14Z64 Fraclib Float mathematics library Meterlib Metering library Projects Source code of smart plug project Source code description of smart plug project: Figure 3. Source code Table 3. Source code description Source code Local Appconfig.h Config.c, config.h Fsl_smart_plug_cmd.h Mk141ph.h Nvm.c nvm.h Smart_plug.c Smart_plug.h Description Driver code for SPI and UART Macro and interrupt settings for ADC, SIM, CMP, TMR Global structure processing for metering Smart Plug serial communication protocol header file Metering parameter configurations Driver for writing nvm flash Smart plug main file for metering and socket control Smart plug software configurations NXP Semiconductors 3

3.1.3 Using Alljoyn APP Smart Plug uses Alljoyn APP in mobile devices to communicate with the smart plug. The current version of the Alljoyn APP apk is 1.3.2. 3.1.3.1 APP Installation Copy AllJoynOn-1.3.2.apk to your Android mobile device and install it. 3.1.3.2 APP Usage 1. Plug the smart plug to a power supply. 2. Open the Alljoyn application by clicking on the icon in the following figure: Figure 4. ALLJoyn ON icon 3. Click the Configure button at the top right hand corner of the device list page: Figure 5. Configure button on device list page 4 NXP Semiconductors

4. Configure WIFI router and password. Figure 6. Application settings Figure 7. Setup home Wi-Fi network NXP Semiconductors 5

5. Return to the device list page and check if any of the devices have a yellow icon next to them, this indicates that they are unconfigured. Figure 8. Unconfigured devices 6 NXP Semiconductors

6. Click the yellow unconfigured device and enter the device configuration page. 7. Click on Next. Figure 9. Setup device step 1 8. Wait for connection. Figure 10. Setup device step 2 - configuration Figure 11. Setup device step 3 - connection 9. If you are prompted to enter the phrase password, enter 123456 (the password can be changed in the options section of the device control page). NXP Semiconductors 7

10. Enter the device name, then click on finish. Figure 12. Setup device step 3 - enter device name 11. Configuration is now complete and you will see the available device with a green icon next to it indicating that it is available. The configured but not unavailable devices have grey icons. Figure 13. Nearby devices list 8 NXP Semiconductors

12. Click the device and open the device control page. The device has the following features: 1. Current active power Figure 14. Device control page 2. Current reactive power 3. Current apparent power 4. History active energy consumption until now 5. Current grid frequency 6. History running time 7. Current on/off status of plug and on/off control 8. Wi-Fi power save mode 9. Timer control 10. Smart plug current time set-up. NXP Semiconductors 9

3.2. Packet communication 3.2.1 Communication hardware settings MKM14Z64 uses UART1 as the communication port to connect with the external Wi-Fi chip. The uart settings are: Bit width 9-bit (1 start bit, 8 data bit) Baud rate: 9600 No parity check Full duplex 3.2.2 Communication port parameters configuration Port parameters can be configured in smart_plug.h. Macros that can be configured are: SMTPLUG_SYS_CLK_FREQ KM Current system clock setting. By default the system clock is set to 24M. SMTPLUG_COMM_BAUDRATE Port baud rate setting. By default this is set to 9600. SMTPLUG_COMM_IRQ_MODE Use IRQ mode for UART communication. This macro cannot be set simultaneously with SMTPLUG_COMM_USE_DMA. SMTPLUG_COMM_USE_DMA Use DMA mode for UART communication. This macro cannot be set simultaneously with SMTPLUG_COMM_IRQ_MODE. 3.3 Communication protocol 3.3.1 Command and response structure A command is composed of a command header and a data body, sent from the KM to the Wi-Fi chip, or vice versa. As the communicated data packages are not too large, the current design uses a fixed 8 bytes data transfer, therefore every message header and data body are 8 bytes. The application can cut out data from the data body according to the data length in the command header. Command Magic Num 1 Magic Num 2 Op Code Parameter 1 Parameter 3 LC Class 1 Byte 1 Byte 1 Byte 1 Byte 1 Byte 1 Byte 1 Byte 1 Byte Figure 15. Command header 10 NXP Semiconductors

Send Data 8 Bytes Figure 16. Data body NOTE 1. Two magic numbers (0x73 and 0x70) are added at the top of the command header. These two magic numbers will be ignored in the below command explanation. 2. Command response structure also uses this structure. 3.3.2 Wi-Fi control command The Wi-Fi control command is used by the KM to control the Wi-Fi chip. The Wi-Fi chip need to parse the command and execute accordingly the command. The following figure uses the K20 QCA board as an example. Command KM Board K20 WIFI QCA Board Response 3.3.2.1 SMTPLG_CMD_OP_WIFI_INIT Figure 17. Wi-Fi control command This command initializes the Wi-Fi board and get the initialization status. NOTE The execution of this command is decided by the Wi-Fi board. If the Wi-Fi board needs the KM to control initialization, it can do initialization after getting this command; if the Wi-Fi board will initialize itself at power up, this command can just get the initialization status. 0 SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_INIT NXP Semiconductors 11

SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_INIT Parameter 1 1 - Initialization is done 0 - Initializing 3.3.2.2 SMTPLG_CMD_OP_WIFI_RESET This command resets the Wi-Fi board. 0 SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_RESET SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_RESET 3.3.2.3 SMTPLG_CMD_OP_WIFI_LP_MODE This command sets the Wi-Fi board to low power mode. In low power mode, Wi-Fi will be disconnected and the mobile APP cannot control the smart plug. 12 NXP Semiconductors

0 SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_LP_MODE SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_LP_MODE 3.3.2.4 SMTPLG_CMD_OP_WIFI_PWR_SAVE_MODE This command sets the Wi-Fi board to power saving mode. SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_PWR_SAVE_MODE 0 SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_PWR_SAVE_MODE 3.3.2.5 SMTPLG_CMD_OP_WIFI_NORMAL_MODE This command sets the Wi-Fi board to normal mode. NXP Semiconductors 13

0 SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_NORMAL_MODE SMTPLG_CMD_CLS_WIFI_CTL SMTPLG_CMD_OP_WIFI_NORMAL_MODE 3.3.2.6 Application command APP commands send procedure (For instance the example below uses K20 QCA Wi-Fi board as an example): KM Board K20 WIFI QCA Board Phone APP Figure 1 Mobile APP command APP commands are sent from APP. The Wi-Fi board will forward the command to KM directly without any parsing. KM will parse and execute the command and send the response back to the APP. The Wi-Fi board needs to decide whether to do parsing according to the command class in the command header. For the APP command, no parsing is needed, otherwise, Wi-Fi control commands, parsing is needed and executes the command. 3.3.2.7 SMTPLG_CMD_OP_SET_PWR_ONOFF This command turns On/Off the smart plug power supply. 14 NXP Semiconductors

Parameter 1 0 SMTPLG_CMD_SET_PWR_ONOFF 0 1 - On 0 0 - Off SMTPLG_CMD_CLS_WIFI_APP SMTPLG_CMD_OP_SET_PWR_ONOFF 3.3.2.8 SMTPLG_CMD_OP_SET_WIFI_RESET This command resets the Wi-Fi. 0 SMTPLG_CMD_OP_SET_WIFI_RESET SMTPLG_CMD_OP_SET_WIFI_RESET NXP Semiconductors 15

3.3.2.9 SMTPLG_CMD_OP_GET_PWR_STS This command gets the current On/Off status of the smart plug. SMTPLG_CMD_OP_GET_PWR_STS 0 SMTPLG_CMD_OP_GET_PWR_STS Data Data body: On/Off status 1 - On 0 - Off 3.3.2.10 SMTPLG_CMD_OP_SET_PWRSAVE_MODE This command turns On/Off the power saving mode of the smart plug. This command sets the smart plug to power saving mode when idle. SMTPLG_CMD_OP_SET_PWRSAVE_MODE Parameter 1 1 - On 0 - Off 0 16 NXP Semiconductors

SMTPLG_CMD_OP_WIFI_SET_PWRSAVE_MODE 3.3.2.11 SMTPLG_CMD_OP_GET_PWRSAVE_MODE This command gets the power saving setting status of the smart plug. SMTPLG_CMD_OP_GET_PWRSAVE_MODE 0 SMTPLG_CMD_OP_GET_PWRSAVE_MODE Data Data body: Power saving status 1 - On 0 - Off NXP Semiconductors 17

3.3.2.12 SMTPLG_CMD_OP_GET_TOTAL_ACT_PWR_SUM This command gets the history energy consumption. In the current design, the value of this history energy consumption indicates energy consumption from the moment that smart plug is plugged to the socket. When the smart plug is removed, this value will be reset to 0. SMTPLG_CMD_GET_TOTAL_ACT_PWR_SUM 0 SMTPLG_CMD_CLS_WIFI_APP SMTPLG_CMD_GET_TOTAL_ACT_PWR_SUM Parameter 3 1 Negative 0 Positive Data length 8 Data Data body: Data format: History active power energy consumption. The value of history energy consumption is a float data, which is stored as 8 bytes, big endian. The first 4 bytes indicate the integer part, the latter 4 bytes indicate the fractional part. The sign byte indicates whether it is a positive value or not. Integer Part Fractional Part 4 Bytes 4 Bytes 3.3.2.13 SMTPLG_CMD_OP_GET_HIST_TIME This command gets the history running time of the smart plug. In the current design, the value of this time is the duration from the moment that the smart plug is plugged to the socket. When the smart plug is removed, this value will be reset to 0. 18 NXP Semiconductors

The time value uses a 32-bit integer to indicate total minutes. This data is stored in big endian mode. SMTPLG_CMD_OP_GET_HIST_TIME 0 Command header: SMTPLG_CMD_OP_SET_WIFI_RESET Data length 4 Data Data body: History running time, 32-bit integer, big integer. 3.3.2.14 SMTPLG_CMD_OP_GET_ACT_PWR This command gets the current active power of the smart plug. SMTPLG_CMD_OP_GET_ACT_PWR 0 NXP Semiconductors 19

SMTPLG_CMD_OP_GET_ACT_PWR Parameter 3 1 Negative 0 Positive Data length 8 Data Data body: Data format: Value of active power The value of history energy consumption is a float data, which is stored as 8 bytes, big endian. The first 4 bytes indicate the integer part, the latter 4 bytes indicates the fractional part. The sign byte indicates whether it is a positive value or not. Integer Part Fractional Part 4 Bytes 4 Bytes 3.3.2.15 SMTPLG_CMD_OP_GET_REACT_PWR This command gets the current reactive power of the smart plug. SMTPLG_CMD_OP_GET_REACT_PWR _MODE 0 SMTPLG_CMD_OP_WIFI_GET_REACT_PWR Parameter 3 1 Negative 0 Positive 20 NXP Semiconductors

Data Data body: Data format: Value of reactive power The value of history energy consumption is a float data, which is stored as 8 bytes, big endian. The first 4 bytes indicate the integer part, the latter 4 bytes indicate the fractional part. The sign byte indicates whether it is a positive value or not. Integer Part Fractional Part 4 Bytes 4 Bytes 3.3.2.16 SMTPLG_CMD_OP_GET_TOTAL_PWR This command gets the current apparent power of smart plug. SMTPLG_CMD_OP_GET_TOTAL_PWR 0 SMTPLG_CMD_OP_GET_TOTAL_PWR Parameter 3 1 Negative 0 Positive Data Data body: Data format: Value of apparent power NXP Semiconductors 21

The value of history energy consumption is a float data, which is stored as 8 bytes, big endian. The first 4 bytes indicate the integer part, latter 4 bytes indicates the fractional part. The sign byte indicates whether it is a positive value or not. Integer Part Fractional Part 4 Bytes 4 Bytes 3.3.2.17 SMTPLG_CMD_OP_GET_GRID_FREQ This command gets the current grid frequency. SMTPLG_CMD_GET_GRID_FREQ 0 SMTPLG_CMD_CLS_WIFI_APP SMTPLG_CMD_GET_GRID_FREQ Data length 8 Data Data body: Data format: Grid frequency value The value of history energy consumption is a float data, which is stored as 8 bytes, big endian. The first 4 bytes indicate the integer part, latter 4 bytes indicates the fractional part. The sign byte indicates whether it is a positive value or not. 22 NXP Semiconductors

Integer Part Fractional Part 4 Bytes 4 Bytes 3.3.2.18 SMTPLG_CMD_OP_GET_TIMER_BEGIN This command gets the begin time of a timer by timer index. SMTPLG_CMD_OP_GET_TIMER_BEGIN Timer index (value is 0 when there is only one timer) Parameter 1 SMTPLG_CMD_OP_GET_TIMER_BEGIN Timer index (value is 0 when there is only one timer) Data length 3 Data Data body: Data format: Time value Follow hour, min and sec variable in SMTPLUG_TM structure in fsl_smart_plug_cmd.h. 3.3.2.19 SMTPLG_CMD_OP_GET_TIMER_END This command gets the end time of a timer by timer index. SMTPLG_CMD_OP_GET_TIMER_END NXP Semiconductors 23

Timer index (value is 0 when there is only one timer) Response: Parameter 1 SMTPLG_CMD_OP_GET_TIMER_END Timer index (value is 0 when there is only one timer) Data length 3 Data Data body: Data format: Time value Follow the hour, min and sec variable in SMTPLUG_TM structure in fsl_smart_plug_cmd.h. 3.3.2.20 SMTPLG_CMD_OP_SET_TIMER_BEGIN This command sets the begin time of a timer by timer index. SMTPLG_CMD_OP_SET_TIMER_BEGIN Timer index (value is 0 when there is only one timer) Data length 3 Data Data body: Data format: Time value Follow the hour, min and sec variable in SMTPLUG_TM structure in fsl_smart_plug_cmd.h. Response: 24 NXP Semiconductors

Parameter 1 SMTPLG_CMD_OP_SET_TIMER_BEGIN Timer index (value is 0 when there is only one timer) 3.3.2.21 SMTPLG_CMD_OP_SET_TIMER_END This command sets the end time of a timer by timer index. SMTPLG_CMD_OP_SET_TIMER_END Timer index (value is 0 when there is only one timer) Data length 3 Data Data body: Data format: Time value Follow the hour, min and sec variable in SMTPLUG_TM structure in fsl_smart_plug_cmd.h. Response: Parameter 1 SMTPLG_CMD_OP_SET_TIMER_END Timer index (value is 0 when there is only one timer) 3.3.2.22 SMTPLG_CMD_OP_SET_TIMER_ONOFF This command turns On/Off a timer by timer index. NXP Semiconductors 25

Parameter 1 SMTPLG_CMD_OP_SET_TIMER_ONOFF Timer status 1 - On 0 - Off Timer index (value is 0 when there is only one timer) Data format: Follow the hour, min and sec variable in SMTPLUG_TM structure in fsl_smart_plug_cmd.h. Response: SMTPLG_CMD_CLS_WIFI_APP Parameter 1 SMTPLG_CMD_GET_TOTAL_ACT_PWR_SUM Timer index (value is 0 when there is only one timer) 3.3.2.23 SMTPLG_CMD_OP_SET_CONN_PASSWD This command sets the connection password of the smart plug. SMTPLG_CMD_OP_SET_CONN_PASSWD 0 Data length Data Data body: Password length (within 8 bytes) Connection password string. Response: 26 NXP Semiconductors

SMTPLG_CMD_OP_SET_CONN_PASSWD 3.3.2.24 SMTPLG_CMD_OP_SET_CUR_TIME This command sets the current time of the smart plug. SMTPLG_CMD_OP_SET_CUR_TIME 0 Data length 7 Data Data body: Data format: Current time value. Follow the SMTPLUG_Date_Time structure in fsl_smart_plug_cmd.h. NOTE In the current design, variable year is stored in little endian mode. SMTPLG_CMD_OP_SET_CUR_TIME NXP Semiconductors 27

3.3.2.25 SMTPLG_CMD_OP_GET_CUR_TIME This command gets the current time of the smart plug. SMTPLG_CMD_OP_GET_CUR_TIME 0 SMTPLG_CMD_OP_SET_CUR_TIME Data length 7 Data Data body: Data format:: Current time value Follow the SMTPLUG_Date_Time structure in fsl_smart_plug_cmd.h. NOTE In the current design, the variable year is stored in little endian mode. 3.4 Power metering 3.4.1 Metering settings Smart Plug project provide two metering library, filter library and fft library. The metering algorithms perform computation in either the time or frequency domain. Filter lib calculates all billing and non-billing quantities in the time domain and FFT lib in the frequency domain. 28 NXP Semiconductors

Figure 18. Summary of library 3.4.2 Filter library Figure 19. Filter library framework NXP Semiconductors 29

For further information, see the following link: Filter-Based Algorithm for Metering Applications (document AN4265). The filter library is located in Meterlib directory,meterlib.a meterlib.h. The fraction library is located in the Fraclib directory, fraclib.a fraclib.h. 3.4.2 FFT library For further information, see the following link: Figure 20. FFT library framework http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/kinetis-cortex-mmcus/m-series-metrology-m0-plus/kinetis-km3x-5075-mhz-precision-metrology-with-segment-lcdmcus-based-on-arm-cortex-m0-plus:km3x?fpsp=1&tab=documentation_tab&lang_cd=en http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/kinetis-cortex-mmcus/m-series-metrology-m0-plus/kinetis-km3x-5075-mhz-precision-metrology-with-segment-lcdmcus-based-on-arm-cortex-m0-plus:km3x?fpsp=1&tab=documentation_tab&lang_cd=en FFT-Based Algorithm for Metering Applications (document AN4255). Using an FFT on the Sigma-Delta ADCs (document AN4847). The FFT library is located in the fftlib directory, meterlibfft2.a metering2.h. The fraction library is located in the Fraclib directory, fraclib.a fraclib.h. 30 NXP Semiconductors

3.4.3 Metering library comparison 1. FFT library performance Number of FFT samples Computing time [ms] MCU execution cycles 8 0.24 11513 16 0.55 26384 32 1.13 54208 64 2.42 116093 128 5.36 257131 CPU Clock = 47.972352 MHz Compiler optimization = high speed Grid frequency = 50 Hz ARM Cortex -M0+ core 2. Filter library performance Phase number Computing time [ms] MCU execution cycles 1PH 0.20 9586 2PH 0.38 18130 3PH 0.63 30218 CPU Clock = 47.972352 MHz Compiler optimization = high speed Grid frequency = 50 Hz ARM Cortex-M0+ core 3. Resource usage As a typical 3PH power meter design, resource usage: Resource usage (3PH) Flash RAM CPU loading CAL period Filter 34 KB 4.3 KB 75% 1200 Hz FFT (interpolation) N=64 FFT (synchronous) N=64 29 KB 8 KB 70% 50 Hz 22 KB 5 KB 51% 50 Hz NOTE: The Flash resource includes application and meter lib code size only. NXP Semiconductors 31

Revision history 3.5 Others 3.5.1 Cross zero detection The smart plug will switch the relay when cross zero is detected to reduce spark and increase life of relay. Procedure: 1. Enable cross zero detection when CMP module is initialized. 2. When you need to switch to the relay, the plug will check the variable cmp_czd_detected first. 3.5.2 Key behavior By default, pressing the key on the smart plug will switch the relay and send an Init command to the Wi- Fi board (please check pulse_output() function for implementation). This behavior can be changed as per requirements. 4. Revision history Table 4. Revision history Revision number Date Substantive changes 0 03/2017 Initial release 32 NXP Semiconductors

How to Reach Us: Home Page: nxp.com Web Support: nxp.com/support Information in this document is provided solely to enable system and software implementers to use NXP products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits based on the information in this document. NXP reserves the right to make changes without further notice to any products herein. NXP makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does NXP assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. Typical parameters that may be provided in NXP data sheets and/or specifications can and do vary in different applications, and actual performance may vary over time. All operating parameters, including typicals, must be validated for each customer application by customer s technical experts. NXP does not convey any license under its patent rights nor the rights of others. NXP sells products pursuant to standard terms and conditions of sale, which can be found at the following address: nxp.com/salestermsandconditions. NXP, the NXP logo, Freescale, and Kinetis are trademarks of NXP B.V. All other product or service names are the property of their respective owners. ARM, the ARM Powered logo, and Cortex are registered trademarks of ARM Limited (or its subsidiaries) in the EU and/or elsewhere. All rights reserved. 2017 NXP B.V. Document Number: DRM158 Rev. 0 03/2017