emSwLib.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2020, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 
33 #ifndef _EMSWLIB_H_
34 #define _EMSWLIB_H_
35 
36 //#############################################################################
37 //
43 //
44 // Group: MSP
45 // Target Device: MSP430F677x1A, MSP430F673xA and MSP430i20xx
46 //
47 // (C) Copyright 2017, Texas Instruments, Inc.
48 //#############################################################################
49 // TI Release: MSP430_ENERGY_MEASUREMENT
50 // Release Date: 29Jul2020
51 //#############################################################################
52 
53 
54 //*****************************************************************************
55 // includes
56 //*****************************************************************************
57 #include <msp430.h>
58 
59 #include <stdint.h>
60 #include <stdbool.h>
61 #include "IQmathLib.h"
62 #include "QmathLib.h"
63 
64 #ifdef __cplusplus
65 
66 extern "C" {
67 #endif
68 
69 //*****************************************************************************
70 // defines
71 //*****************************************************************************
72 
75  #define EM_PHASE_RESULT_CALC_VRMS BIT0
76  #define EM_PHASE_RESULT_CALC_IRMS BIT1
79  #define EM_PHASE_RESULT_CALC_V_PEAK BIT2
82  #define EM_PHASE_RESULT_CALC_I_PEAK BIT3
85  #define EM_PHASE_RESULT_CALC_POWER_FACTOR BIT4
88  #define EM_PHASE_RESULT_CALC_FREQ BIT5
91 #define EM_PHASE_RESULT_CALC_ACTIVE_POWER BIT6
94 #define EM_PHASE_RESULT_CALC_REACTIVE_POWER BIT7
97 #define EM_PHASE_RESULT_CALC_APPARENT_POWER BIT8
100 #define EM_PHASE_RESULT_CALC_ACTIVE_ENERGY BIT9
103 #define EM_PHASE_RESULT_CALC_REACTIVE_ENERGY BIT10
106 #define EM_PHASE_RESULT_CALC_APPARENT_ENERGY BIT11
109 
112 #define EM_PULSE_GEN_PHASE_NONE (0x00)
113 #define EM_PULSE_GEN_PHASE_A (0x01)
116 #define EM_PULSE_GEN_PHASE_B (0x02)
119 #define EM_PULSE_GEN_PHASE_C (0x04)
122 #define EM_PULSE_GEN_PHASE_D (0x08)
125 #define EM_PULSE_GEN_PHASE_E (0x10)
128 #define EM_PULSE_GEN_PHASE_F (0x20)
131 #define EM_PULSE_GEN_PHASE_NEUTRAL (0x40)
135 #define EM_PULSE_GEN_PHASE_AGGREGATE (0x80)
139 
140 //*****************************************************************************
141 // typedefs
142 //*****************************************************************************
143 
147 typedef enum _EM_message_code_
148 {
149 
153 
154  // 1-20 reserved for system configuration messages
172 
173  // 21-40 reserved for algorithm configuration messages
182 
183  // 41-59 reserved for meter configuration messages
188 
189  // 60-249 reserved for calibration messages
192 
193  //240-255 error
198 
202 {
210 
213 typedef int64_t EM_Power_t;
214 
217 typedef uint64_t EM_Energy_t;
218 
221 typedef enum _EM_Phase_
222 {
237 } EM_Phase;
238 
239 
242 typedef struct _EM_Pulse_Settings_
243 {
299 
303 {
332 
333 
337 {
338  uint32_t voltageSF;
340  uint32_t currentSF;
342  uint32_t activePowerSF;
344  uint32_t reactivePowerSF;
348 
350 
354 {
380 
384 {
387  uint8_t phaseLength;
389  uint8_t *meterName;
393  uint8_t *meterPW;
394  //~< Pointer to meter password string
396 
400 {
407  uint8_t mainNomFreq;
413  uint16_t freqSampling;
423 
427 {
435 
436 typedef struct _EM_Metrology_
437 {
438  int16_t sampleCount;
441  int64_t actPowDotProd;
447  int16_t vDotProd[3];
452  int64_t iDotProd;
462  uint32_t mainPeriod;
464  uint32_t prevMainPeriod;
466  _iq30 oneDivSC;
468  uint16_t prevSampleCount;
471  uint8_t cycleCount;
474 } EM_Metrology;
475 
478 typedef struct _EM_Phase_BG_Results_
479 {
480  int32_t vDCEstimate;
482  int16_t iDCEstimate[3];
486  int16_t vPrevSample;
490  int32_t iPrevSample;
493 
496 typedef struct _EM_Phase_Results_
497 {
498  uint32_t VRMS;
500  uint32_t IRMS;
502  uint32_t vPeak;
504  uint32_t iPeak;
506  int32_t powerFactor;
508  uint16_t frequency;
511  EM_Power_t activePower;
513  EM_Power_t reactivePower;
515  EM_Power_t apparentPower;
517  EM_Energy_t activeEnergy;
519  EM_Energy_t reactiveEnergy;
521  EM_Energy_t apparentEnergy;
526 
529 typedef struct _EM_Total_Results_
530 {
531  EM_Power_t activePower;
533  EM_Power_t reactivePower;
535  EM_Power_t apparentPower;
537  EM_Energy_t activeEnergy;
539  EM_Energy_t reactiveEnergy;
541  EM_Energy_t apparentEnergy;
544 
548 {
562 
563 //*****************************************************************************
564 // globals
565 //*****************************************************************************
567 extern uint16_t * EMSWLIB_EM_HAL_ADC_maxFreqCount;
568 
570 extern uint16_t * EMSWLIB_EM_HAL_ADC_minFreqCount;
571 
572 //*****************************************************************************
573 // the function prototypes
574 //*****************************************************************************
575 
576 /*******************************************************************************
577  * EM SW LIBRARY CONFIGURATION APIS
578  ******************************************************************************/
579 //*****************************************************************************
580 //
583 //
584 //******************************************************************************
596  EM_SW_Lib_Config_Handle *config,
597  EM_SW_Lib_Result_Handle *result);
598 
606 extern void EM_initDCFilters(
607  EM_SW_Lib_Config_Handle *config,
608  EM_SW_Lib_Result_Handle *result);
609 
610 //******************************************************************************
611 //
612 // Close the Doxygen group.
614 //
615 //******************************************************************************
616 
617 /*******************************************************************************
618  * EM SW LIBRARY CALIBRATION APIS
619  ******************************************************************************/
620 //*****************************************************************************
621 //
624 //
625 //******************************************************************************
638  uint8_t *pWorkingCalibration,
639  uint8_t *pFlashCalibration);
640 
652  uint8_t *pWorkingCalibration,
653  uint8_t *pFlashCalibration);
654 
655 //******************************************************************************
656 //
657 // Close the Doxygen group.
659 //
660 //******************************************************************************
661 
662 /*******************************************************************************
663  * EM SW LIBRARY RESULT APIS
664  ******************************************************************************/
665 //*****************************************************************************
666 //
669 //
670 //******************************************************************************
684 extern int16_t EM_voltageDCFilter(
685  int32_t *p,
686  int16_t x);
687 
701 extern int32_t EM_currentDCFilter(
702  int16_t p[3],
703  int32_t x);
704 
716 extern void EM_perSample(
717  EM_Metrology *metro,
718  EM_Phase_Configuration *phase,
719  EM_Phase_BG_Results *bgData);
720 
733 extern void EM_perDataChunk(
734  EM_SW_Lib_Config_Handle *config,
735  EM_SW_Lib_Result_Handle *result,
736  uint16_t phaseIdx);
737 
751 extern void EM_delayCurrent90Degrees(EM_Metrology *metro,
752  EM_Phase_Configuration *phase,
753  EM_Phase_BG_Results *bgData);
754 
767 extern void EM_genPulseIndPhase(
768  EM_System_Configuration *config,
769  EM_Pulse_Settings *pulse,
770  EM_Phase_Results *result);
771 
784 extern void EM_genPulseTotalPhases(
785  EM_System_Configuration *config,
786  EM_Pulse_Settings *pulse,
787  EM_Total_Results *result);
788 
798 extern void EM_updateOneDivSC(
799  EM_Metrology *metro);
800 
809 extern void EM_clearMetrology(
810  EM_Metrology *metro);
811 
824 extern void EM_updateReactPowConst(EM_Metrology *metro,
825  EM_Phase_Results *result,
827 
837  EM_SW_Lib_Config_Handle *config);
838 
850 extern void EM_calcActivePowerMultAcc(
851  EM_Metrology *metro,
852  EM_Phase_Configuration *phase);
853 
867 extern void EM_calcActivePowerDiv(
868  EM_Metrology *metro,
869  EM_Phase_Configuration *phase,
870  EM_Phase_Results *result,
872 
885 extern void EM_calcActiveEnergy(
886  EM_Metrology *metro,
888  EM_Phase_Results *result);
889 
907 extern void EM_calcReactivePowerMultAcc(
908  EM_Metrology *metro,
909  EM_Phase_Configuration *phase,
910  EM_Phase_BG_Results *bgData);
911 
925 extern void EM_calcReactivePowerDiv(
926  EM_Metrology *metro,
927  EM_Phase_Configuration *phase,
928  EM_Phase_Results *result,
930 
943 extern void EM_calcReactiveEnergy(
944  EM_Metrology *metro,
946  EM_Phase_Results *result);
947 
958 extern void EM_calcApparentPower(
959  EM_Phase_Results *result);
960 
973 extern void EM_calcApparentEnergy(
974  EM_Metrology *metro,
976  EM_Phase_Results *result);
977 
988 extern void EM_calcPowerFactor(
989  EM_Phase_Results *result);
990 
1002 extern void EM_calcVRMSMultAcc(
1003  EM_Metrology *metro,
1004  EM_Phase_Configuration *phase);
1005 
1017 extern void EM_calcVRMSDivSqrt(
1018  EM_Metrology *metro,
1019  EM_Phase_Configuration *phase,
1020  EM_Phase_Results *result);
1021 
1033 extern void EM_calcIRMSMultAcc(EM_Metrology *metro,
1034  EM_Phase_Configuration *phase);
1035 
1047 extern void EM_calcIRMSDivSqrt(
1048  EM_Metrology *metro,
1049  EM_Phase_Configuration *phase,
1050  EM_Phase_Results *result);
1051 
1063 extern void EM_calcIPeak(
1064  EM_Phase_Results *result,
1066 
1078 extern void EM_calcVPeak(
1079  EM_Phase_Results *result,
1081 
1111 extern void EM_calcFreqPeriod(
1112  EM_Metrology *metro,
1113  EM_Phase_Configuration *phase,
1114  EM_Phase_BG_Results *bgData);
1115 
1127 extern void EM_calcFreq(
1128  EM_Metrology *metro,
1129  EM_Phase_Results *result,
1131 
1142 extern void EM_calcTotalActivePower(
1143  uint8_t *phaseIdx,
1144  uint8_t length,
1145  EM_SW_Lib_Result_Handle *result);
1146 
1157 extern void EM_calcTotalReactivePower(
1158  uint8_t *phaseIdx,
1159  uint8_t length,
1160  EM_SW_Lib_Result_Handle *result);
1161 
1172 extern void EM_calcTotalApparentPower(
1173  uint8_t *phaseIdx,
1174  uint8_t length,
1175  EM_SW_Lib_Result_Handle *result);
1176 
1177 
1188 extern void EM_calcTotalActiveEnergy(
1189  uint8_t *phaseIdx,
1190  uint8_t length,
1191  EM_SW_Lib_Result_Handle *result);
1192 
1203 extern void EM_calcTotalReactiveEnergy(
1204  uint8_t *phaseIdx,
1205  uint8_t length,
1206  EM_SW_Lib_Result_Handle *result);
1207 
1218 extern void EM_calcTotalApparentEnergy(
1219  uint8_t *phaseIdx,
1220  uint8_t length,
1221  EM_SW_Lib_Result_Handle *result);
1222 
1223 //******************************************************************************
1224 //
1225 // Close the Doxygen group.
1227 //
1228 //******************************************************************************
1229 
1230 #ifdef __cplusplus
1231 }
1232 #endif // extern "C"
1233 
1234 #endif // end of _EMSWLIB_H_ definition
Contains EM SW Lib System Configuration.
Definition: emSwLib.h:302
Contains EM SW Lib Result Handle.
Definition: emSwLib.h:547
struct _EM_Phase_BG_Results_ EM_Phase_BG_Results
Contains EM Phase Background Results.
EM_Total_Results * emTotalResult
Pointer to EM_Total_Results struct.
Definition: emSwLib.h:549
EM_Power_t reactivePower
Reactive Power for previous frame (uVAr)
Definition: emSwLib.h:513
Definition: emSwLib.h:436
Contains EM Phase Background Results.
Definition: emSwLib.h:478
void EM_calcVPeak(EM_Phase_Results *result, EM_Algorithm_Configuration *algo)
The following API is used to calculate V Peak. This API updates the global Phase Result structure...
EM_System_Configuration * systemConfig
Pointer to EM_System_Configuration struct.
Definition: emSwLib.h:428
EM_Power_t apparentPower
Total Apparent Power since system initialization (uVA)
Definition: emSwLib.h:535
Definition: emSwLib.h:176
int32_t * currentSamplePtr
Pointer to the current sample.
Definition: emSwLib.h:355
Contains EM SW Lib Config Handle.
Definition: emSwLib.h:426
uint8_t * meterName
Pointer to meter name string.
Definition: emSwLib.h:389
void EM_calcVRMSDivSqrt(EM_Metrology *metro, EM_Phase_Configuration *phase, EM_Phase_Results *result)
The following API is used to calculate the division and square root for VRMS. This API uses the dot p...
Definition: emSwLib.h:225
Contains EM SW Lib Algorithm Configuration.
Definition: emSwLib.h:399
int32_t iPrevSample
Previous Current sample used for the IIR filter in the Rogowski ADC current calculation.
Definition: emSwLib.h:490
int32_t rogowskiPrevI90
Previous I90 current used for the IIR filter in the Rogowski ADC current calculation.
Definition: emSwLib.h:488
void EM_calcTotalActivePower(uint8_t *phaseIdx, uint8_t length, EM_SW_Lib_Result_Handle *result)
The following API is used to calculate total active power. This API will aggregate the total power of...
struct _EM_Metrology_ EM_Metrology
uint8_t cycleCount
Definition: emSwLib.h:471
Definition: emSwLib.h:150
EM_Power_t activePower
Total Active Power since system initialization (uW)
Definition: emSwLib.h:531
enum _EM_Phase_ EM_Phase
Selects appropiate phase to provide results for.
uint8_t activePulseGpioPort
Definition: emSwLib.h:244
Contains EM SW Lib System Configuration.
Definition: emSwLib.h:353
EM_Phase_BG_Results * phaseBGResults
Pointer to the EM_Phase_BG_Results struct buffer.
Definition: emSwLib.h:553
uint32_t VRMS
VRMS for previous frame (mV)
Definition: emSwLib.h:498
EM_Metrology ** phaseMetrologyPong
Pointer to EM_Metrology struct Pong buffer.
Definition: emSwLib.h:557
void EM_genPulseTotalPhases(EM_System_Configuration *config, EM_Pulse_Settings *pulse, EM_Total_Results *result)
The following API is used to generate pulses for the total phase. This API checks if the config->puls...
void EM_calcIRMSDivSqrt(EM_Metrology *metro, EM_Phase_Configuration *phase, EM_Phase_Results *result)
The following API is used to calculate the division and square root for IRMS. This API uses the dot p...
_iq30 * reactPowIIRTable
Definition: emSwLib.h:421
uint16_t totalPhasePulseDuration
Definition: emSwLib.h:318
EM_Energy_t reactiveEnergy
Reactive Energy for previous frame (uVArh)
Definition: emSwLib.h:519
void EM_updateFlashCalibrationValues(uint8_t *pWorkingCalibration, uint8_t *pFlashCalibration)
The following API is used store working (RAM) pWorkingCalibration values to the pFlashCalibration str...
void EM_initalizeCalibrationValues(uint8_t *pWorkingCalibration, uint8_t *pFlashCalibration)
The following API is used to copies calibration values from flapFlashCalibration to pWorkingCalibrati...
void EM_calcTotalApparentPower(uint8_t *phaseIdx, uint8_t length, EM_SW_Lib_Result_Handle *result)
The following API is used to calculate total apparent power. This API will aggregate the total power ...
EM_Algorithm_Configuration * algorithmConfig
Pointer to EM_Algorithm_Configuration struct.
Definition: emSwLib.h:430
Contains EM Total Results.
Definition: emSwLib.h:529
void EM_calcPowerFactor(EM_Phase_Results *result)
The following API is used to calculate power factor. The formula used to calculate it: activePower / ...
uint8_t phaseLength
Length of the emPhasePtr buffer.
Definition: emSwLib.h:387
uint16_t reactiveEnergyPulseRemaining
Counter used to keep track of remaining ADC samples to keep pulse high.
Definition: emSwLib.h:296
uint16_t * EMSWLIB_EM_HAL_ADC_maxFreqCount
The following variable is used as a maximum ADC count to detect frequency.
struct _EM_SW_Lib_Result_Handle_ EM_SW_Lib_Result_Handle
Contains EM SW Lib Result Handle.
uint32_t reactivePowerSF
Active Power Scaling Factor.
Definition: emSwLib.h:344
struct _EM_Total_Results_ EM_Total_Results
Contains EM Total Results.
struct _EM_Phase_Configuration_ EM_Phase_Configuration
Contains EM SW Lib System Configuration.
Contains EM SW Lib Phase Calibration.
Definition: emSwLib.h:242
_EM_Current_Sensor_
Selects appropriate EM Sensor for the corresponding channel.
Definition: emSwLib.h:201
EM_message_code EM_processSample(EM_SW_Lib_Config_Handle *config)
The following API is used process the samples. It is used to calculate intermediate dot product resul...
void EM_calcTotalReactiveEnergy(uint8_t *phaseIdx, uint8_t length, EM_SW_Lib_Result_Handle *result)
The following API is used to calculate total reactive energy. This API will aggregate the total energ...
uint8_t pulseArrayLength
Length of the pulseArray configuration.
Definition: emSwLib.h:307
int64_t EM_Power_t
Type for Power variables.
Definition: emSwLib.h:213
void EM_delayCurrent90Degrees(EM_Metrology *metro, EM_Phase_Configuration *phase, EM_Phase_BG_Results *bgData)
The following API is used to delay the current degree by 90 degrees. It uses an IIR filter with 1 pol...
void EM_updateReactPowConst(EM_Metrology *metro, EM_Phase_Results *result, EM_Algorithm_Configuration *algo)
The following API is used to look up the IIR G constant used to calculate the Reactive Power using th...
EM_Metrology ** phaseMetrologyPing
Pointer to EM_Metrology struct Ping buffer.
Definition: emSwLib.h:555
struct _EM_Algorithm_Configuration_ EM_Algorithm_Configuration
Contains EM SW Lib Algorithm Configuration.
Definition: emSwLib.h:233
void EM_calcFreq(EM_Metrology *metro, EM_Phase_Results *result, EM_Algorithm_Configuration *algo)
The following API is used to calculate frequency. This API updates the global Phase Result structure...
EM_Power_t residualPowerCutoff
Definition: emSwLib.h:401
Definition: emSwLib.h:231
Definition: emSwLib.h:223
int16_t * voltageSamplePtr
Pointer to the voltage sample.
Definition: emSwLib.h:357
int16_t sampleCount
Definition: emSwLib.h:438
_EM_message_code_
The following enumeration contain all possible EM SW Library return message codes.
Definition: emSwLib.h:147
void EM_calcTotalReactivePower(uint8_t *phaseIdx, uint8_t length, EM_SW_Lib_Result_Handle *result)
The following API is used to calculate total reactive power. This API will aggregate the total power ...
void EM_updateOneDivSC(EM_Metrology *metro)
The following API is used to calculate the 1/sample_count constant. This function must be executed af...
uint16_t activeEnergyPulseRemaining
Counter used to keep track of remaining ADC samples to keep pulse high.
Definition: emSwLib.h:292
EM_Energy_t activeEnergy
Active Energy for previous frame (uWh)
Definition: emSwLib.h:517
EM_Power_t totalResidualPowerCutoff
Definition: emSwLib.h:404
int16_t reactPowPrevV90
Previous V90 voltage used for the IIR filter in the reactive power calculation.
Definition: emSwLib.h:484
_EM_Phase_
Selects appropiate phase to provide results for.
Definition: emSwLib.h:221
uint64_t reactiveEnergyCounter
Ongoing Reactive Energy Sum.
Definition: emSwLib.h:294
void EM_calcTotalApparentEnergy(uint8_t *phaseIdx, uint8_t length, EM_SW_Lib_Result_Handle *result)
The following API is used to calculate total apparent energy. This API will aggregate the total energ...
Definition: emSwLib.h:229
EM_message_code EM_configureEnergyMeasurement(EM_SW_Lib_Config_Handle *config, EM_SW_Lib_Result_Handle *result)
The following API initializes the variables needed by the library at run time. This includes the G co...
uint32_t mainPeriod
This a running average of the length of a mains cycle. (samples/cycle * 256)
Definition: emSwLib.h:462
and indPhaseMeterConstant is 0
Definition: emSwLib.h:158
uint32_t vPeak
VPeak since system initialization (mV)
Definition: emSwLib.h:502
uint8_t pulseGeneration
Definition: emSwLib.h:321
uint8_t mainNomFreq
Nominal Freq value for the system (Hz)
Definition: emSwLib.h:407
uint64_t indPhaseMeterConstant
Definition: emSwLib.h:309
uint16_t indPhasePulseDuration
Pulse duration in ADC counts for each active / reactive energy.
Definition: emSwLib.h:312
Definition: emSwLib.h:194
uint16_t cycleSampleCount
Definition: emSwLib.h:457
Definition: emSwLib.h:235
int64_t reactPowDotProd
Definition: emSwLib.h:444
void EM_calcVRMSMultAcc(EM_Metrology *metro, EM_Phase_Configuration *phase)
The following API is used to calculate the dot product and accumulation for VRMS. This API reads the ...
uint32_t prevMainPeriod
This a running average of the length of a mains cycle. (samples/cycle * 256)
Definition: emSwLib.h:464
uint16_t phaseResultsSupported
Definition: emSwLib.h:361
uint64_t activeEnergyCounter
Ongoing Active Energy Sum.
Definition: emSwLib.h:290
struct _EM_SW_Lib_Config_Handle_ EM_SW_Lib_Config_Handle
Contains EM SW Lib Config Handle.
int16_t phaseCorrection
Phase Correction between voltage and current (register units)
Definition: emSwLib.h:346
EM_Meter_Configuration * meterConfig
Pointer to EM_Meter_Configuration struct.
Definition: emSwLib.h:432
void EM_calcIPeak(EM_Phase_Results *result, EM_Algorithm_Configuration *algo)
The following API is used to calculate I Peak. This API updates the global Phase Result structure...
struct _EM_Pulse_Settings_ EM_Pulse_Settings
Contains EM SW Lib Phase Calibration.
void EM_calcFreqPeriod(EM_Metrology *metro, EM_Phase_Configuration *phase, EM_Phase_BG_Results *bgData)
The following API is used to calculate the period of the voltage signal. For systems with 2 voltages...
enum _EM_message_code_ EM_message_code
The following enumeration contain all possible EM SW Library return message codes.
void EM_calcActiveEnergy(EM_Metrology *metro, EM_Algorithm_Configuration *algo, EM_Phase_Results *result)
The following API is used to calculate the active energy result. The formula used to calculate active...
Contains EM SW Lib Meter Configuration.
Definition: emSwLib.h:383
EM_Energy_t apparentEnergy
Apparent Energy for previous frame (uVAh)
Definition: emSwLib.h:521
void EM_calcActivePowerMultAcc(EM_Metrology *metro, EM_Phase_Configuration *phase)
The following API is used to calculate the dot product and accumulation of Voltage and Current...
This error is returned if the phaseLength is equal to 0.
Definition: emSwLib.h:184
EM_Phase_Calibration * phaseCalibPtr
Pointer to EM_Phase_Calibration struct.
Definition: emSwLib.h:377
void EM_genPulseIndPhase(EM_System_Configuration *config, EM_Pulse_Settings *pulse, EM_Phase_Results *result)
The following API is used to generate pulses for an individual phase. This API checks if the config->...
uint16_t freqSampling
Sampling Frequency (Hz)
Definition: emSwLib.h:413
uint32_t activePowerSF
Active Power Scaling Factor.
Definition: emSwLib.h:342
EM_Power_t reactivePower
Total Reactive Power since system initialization (uVAr)
Definition: emSwLib.h:533
int64_t iDotProd
Definition: emSwLib.h:452
Contains EM Phase Result.
Definition: emSwLib.h:496
void EM_calcReactiveEnergy(EM_Metrology *metro, EM_Algorithm_Configuration *algo, EM_Phase_Results *result)
The following API is used to calculate the reactive energy result. The formula used to calculate reac...
int32_t EM_currentDCFilter(int16_t p[3], int32_t x)
The following API is intended for the removal of the DC content from 24 bit 50Hz/60Hz mains signals...
uint16_t reactPowIIRMinFreq
Min Frequency for the IIR coefficient table.
Definition: emSwLib.h:415
int16_t vPrevSample
Previous Voltage sample used for the IIR filter in the reactive power calculation.
Definition: emSwLib.h:486
uint32_t voltageSF
Voltage Scaling Factor - used to calculate VRMS.
Definition: emSwLib.h:338
struct _EM_System_Configuration_ EM_System_Configuration
Contains EM SW Lib System Configuration.
void EM_perSample(EM_Metrology *metro, EM_Phase_Configuration *phase, EM_Phase_BG_Results *bgData)
The following API is used update the previous voltage value for a phase and to increment the number o...
EM_Energy_t activeEnergy
Total Active Energy consumed since system initialization (uWh)
Definition: emSwLib.h:537
uint64_t totalPhaseMeterConstant
Definition: emSwLib.h:314
EM_Power_t apparentPower
Apparent Power for previous frame (uVA)
Definition: emSwLib.h:515
enum _EM_Current_Sensor_ EM_Current_Sensor
Selects appropriate EM Sensor for the corresponding channel.
_iq30 energyCalcConst
One dividing by (3600 x sampling frequency)
Definition: emSwLib.h:411
EM_Current_Sensor currentSensor
Sensor connected to the current (I) channel.
Definition: emSwLib.h:359
Contains EM SW Lib Phase Calibration.
Definition: emSwLib.h:336
_iq30 reactPowGConst
G Constant used for the IIR filter to calculate Reactive Power.
Definition: emSwLib.h:460
int32_t vDCEstimate
DC Estimate for Voltage.
Definition: emSwLib.h:480
_iq30 oneDivSC
Constant used to calculate the VRMS,IRMS, power and energy values (1/sample_count) ...
Definition: emSwLib.h:466
uint8_t * meterPW
Definition: emSwLib.h:393
uint8_t reactivePulseGpioPort
Definition: emSwLib.h:256
Shunt.
Definition: emSwLib.h:205
uint64_t EM_Energy_t
Type for Energy variables.
Definition: emSwLib.h:217
Definition: emSwLib.h:155
Definition: emSwLib.h:164
Rogowski Coil (RC)
Definition: emSwLib.h:207
void EM_calcApparentPower(EM_Phase_Results *result)
The following API is used to calculate apparent power. The formula used to calculate apparentPower (u...
uint16_t reactPowIIRLength
Length of the IIR coefficient table.
Definition: emSwLib.h:419
EM_Phase_Configuration * phaseConfigPtr
Pointer to the EM_Phase_Configuration struct buffer.
Definition: emSwLib.h:385
Definition: emSwLib.h:227
_iq29 sqrtTwoConst
Square of 2 constant used for Vpeak and Ipeak calculations.
Definition: emSwLib.h:409
uint16_t activePulseGpioPin
Definition: emSwLib.h:268
void EM_calcIRMSMultAcc(EM_Metrology *metro, EM_Phase_Configuration *phase)
The following API is used to calculate the dot product and accumulation for IRMS. This API reads the ...
uint16_t frequency
Definition: emSwLib.h:508
void EM_calcTotalActiveEnergy(uint8_t *phaseIdx, uint8_t length, EM_SW_Lib_Result_Handle *result)
The following API is used to calculate total active energy. This API will aggregate the total energy ...
EM_Pulse_Settings * pulseArray
Definition: emSwLib.h:304
void EM_initDCFilters(EM_SW_Lib_Config_Handle *config, EM_SW_Lib_Result_Handle *result)
The following API initializes the voltage / current DC filters to 0.
uint32_t currentSF
Current Scaling Factor - used to calculate IRMS.
Definition: emSwLib.h:340
uint32_t iPeak
IPeak since system initialization (uA)
Definition: emSwLib.h:504
void EM_calcReactivePowerMultAcc(EM_Metrology *metro, EM_Phase_Configuration *phase, EM_Phase_BG_Results *bgData)
The following API is used to calculate the dot product and accumulation of Voltage_90 and Current...
EM_Phase_Results * phaseResults
Pointer to EM_Phase_Result struct buffer.
Definition: emSwLib.h:551
EM_Energy_t reactiveEnergy
Total Reactive Energy consumed since system initialization (uVArh)
Definition: emSwLib.h:539
EM_Power_t activePower
Active Power for previous frame (uW)
Definition: emSwLib.h:511
void EM_perDataChunk(EM_SW_Lib_Config_Handle *config, EM_SW_Lib_Result_Handle *result, uint16_t phaseIdx)
The following API is used to swap the metrology ping and pong pointers. This API must be executed aft...
This error is returned if the phaseConfigPtr is equal to 0.
Definition: emSwLib.h:186
EM_Phase phaseID
Present Phase ID Name.
Definition: emSwLib.h:523
struct _EM_Meter_Configuration_ EM_Meter_Configuration
Contains EM SW Lib Meter Configuration.
Current Transformer (CT)
Definition: emSwLib.h:203
uint16_t prevSampleCount
Definition: emSwLib.h:468
struct _EM_Phase_Calibration_ EM_Phase_Calibration
Contains EM SW Lib Phase Calibration.
This error is returned if the phase number is invalid.
Definition: emSwLib.h:190
void EM_calcActivePowerDiv(EM_Metrology *metro, EM_Phase_Configuration *phase, EM_Phase_Results *result, EM_Algorithm_Configuration *algo)
The following API is used to calculate the active power in the foreground code and store activePower ...
int32_t powerFactor
Power Factor calculated when the EM_powerFactor.
Definition: emSwLib.h:506
int16_t EM_voltageDCFilter(int32_t *p, int16_t x)
The following API is intended for the removal of the DC content from 16 bit 50Hz/60Hz mains signals...
void EM_calcApparentEnergy(EM_Metrology *metro, EM_Algorithm_Configuration *algo, EM_Phase_Results *result)
The following API is used to calculate the apparent energy result. The formula used to calculate appa...
int64_t actPowDotProd
Definition: emSwLib.h:441
EM_Energy_t apparentEnergy
Total Apparent Energy consumed since system initialization (UVAh)
Definition: emSwLib.h:541
uint32_t IRMS
IRMS for previous frame (uA)
Definition: emSwLib.h:500
This error is returned if the sampling frequency is not greater than 0.
Definition: emSwLib.h:174
uint8_t reactPowIIRShift
Number of shifts required to calculated index for IIR table.
Definition: emSwLib.h:417
uint16_t * EMSWLIB_EM_HAL_ADC_minFreqCount
The following variable is used as a minimum ADC count to detect frequency.
uint16_t reactivePulseGpioPin
Definition: emSwLib.h:279
void EM_calcReactivePowerDiv(EM_Metrology *metro, EM_Phase_Configuration *phase, EM_Phase_Results *result, EM_Algorithm_Configuration *algo)
The following API is used to calculate the reactive power in the foreground code and store reactivePo...
struct _EM_Phase_Results_ EM_Phase_Results
Contains EM Phase Result.
uint8_t * libVersionNumber
Pointer to library version number string.
Definition: emSwLib.h:391
void EM_clearMetrology(EM_Metrology *metro)
The following API is used to clear the temporary variables inside the metro structure. This API must be called as the last API in the foreground code.
uint8_t phaseResultsSupportedLen
Length of the phaseResultsSupportedPtr buffer.
Definition: emSwLib.h:559
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale