61 #include "IQmathLib.h" 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 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) 482 int16_t iDCEstimate[3];
638 uint8_t *pWorkingCalibration,
639 uint8_t *pFlashCalibration);
652 uint8_t *pWorkingCalibration,
653 uint8_t *pFlashCalibration);
1232 #endif // extern "C" 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
Definition: emSwLib.h:161
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.
Definition: emSwLib.h:168
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->...
Definition: emSwLib.h:179
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