106 #include "IQmathLib.h" 107 #include "QmathLib.h" 120 #define EM_PHASE_RESULT_CALC_VRMS BIT0 121 #define EM_PHASE_RESULT_CALC_IRMS BIT1 124 #define EM_PHASE_RESULT_CALC_V_PEAK BIT2 127 #define EM_PHASE_RESULT_CALC_I_PEAK BIT3 130 #define EM_PHASE_RESULT_CALC_POWER_FACTOR BIT4 133 #define EM_PHASE_RESULT_CALC_FREQ BIT5 136 #define EM_PHASE_RESULT_CALC_ACTIVE_POWER BIT6 139 #define EM_PHASE_RESULT_CALC_REACTIVE_POWER BIT7 142 #define EM_PHASE_RESULT_CALC_APPARENT_POWER BIT8 145 #define EM_PHASE_RESULT_CALC_ACTIVE_ENERGY BIT9 148 #define EM_PHASE_RESULT_CALC_REACTIVE_ENERGY BIT10 151 #define EM_PHASE_RESULT_CALC_APPARENT_ENERGY BIT11 157 #define EM_PULSE_GEN_PHASE_NONE (0x00) 158 #define EM_PULSE_GEN_PHASE_A (0x01) 161 #define EM_PULSE_GEN_PHASE_B (0x02) 164 #define EM_PULSE_GEN_PHASE_C (0x04) 167 #define EM_PULSE_GEN_PHASE_D (0x08) 170 #define EM_PULSE_GEN_PHASE_E (0x10) 173 #define EM_PULSE_GEN_PHASE_F (0x20) 176 #define EM_PULSE_GEN_PHASE_NEUTRAL (0x40) 180 #define EM_PULSE_GEN_PHASE_AGGREGATE (0x80) 525 int16_t iDCEstimate[3];
677 uint8_t *pWorkingCalibration,
678 uint8_t *pFlashCalibration);
691 uint8_t *pWorkingCalibration,
692 uint8_t *pFlashCalibration);
1254 #endif // extern "C" 1256 #endif // end of _EMSWLIB_H_ definition Contains EM SW Lib System Configuration.
Definition: emSwLib.h:345
Contains EM SW Lib Result Handle.
Definition: emSwLib.h:586
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:588
EM_Power_t reactivePower
Reactive Power for previous frame (uVAr)
Definition: emSwLib.h:552
Definition: emSwLib.h:479
Contains EM Phase Background Results.
Definition: emSwLib.h:521
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:471
EM_Power_t apparentPower
Total Apparent Power since system initialization (uVA)
Definition: emSwLib.h:574
Definition: emSwLib.h:221
int32_t * currentSamplePtr
Pointer to the current sample.
Definition: emSwLib.h:398
Contains EM SW Lib Config Handle.
Definition: emSwLib.h:469
uint8_t * meterName
Pointer to meter name string.
Definition: emSwLib.h:432
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:268
Contains EM SW Lib Algorithm Configuration.
Definition: emSwLib.h:442
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:514
Definition: emSwLib.h:195
EM_Power_t activePower
Total Active Power since system initialization (uW)
Definition: emSwLib.h:570
enum _EM_Phase_ EM_Phase
Selects appropiate phase to provide results for.
uint8_t activePulseGpioPort
Definition: emSwLib.h:287
Contains EM SW Lib System Configuration.
Definition: emSwLib.h:396
EM_Phase_BG_Results * phaseBGResults
Pointer to the EM_Phase_BG_Results struct buffer.
Definition: emSwLib.h:592
uint32_t VRMS
VRMS for previous frame (mV)
Definition: emSwLib.h:537
EM_Metrology ** phaseMetrologyPong
Pointer to EM_Metrology struct Pong buffer.
Definition: emSwLib.h:596
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:464
uint16_t totalPhasePulseDuration
Definition: emSwLib.h:361
EM_Energy_t reactiveEnergy
Reactive Energy for previous frame (uVArh)
Definition: emSwLib.h:558
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:473
Contains EM Total Results.
Definition: emSwLib.h:568
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:430
uint16_t reactiveEnergyPulseRemaining
Counter used to keep track of remaining ADC samples to keep pulse high.
Definition: emSwLib.h:339
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:387
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:285
_EM_Current_Sensor_
Selects appropriate EM Sensor for the corresponding channel.
Definition: emSwLib.h:246
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:350
int64_t EM_Power_t
Type for Power variables.
Definition: emSwLib.h:256
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:594
struct _EM_Algorithm_Configuration_ EM_Algorithm_Configuration
Contains EM SW Lib Algorithm Configuration.
Definition: emSwLib.h:276
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:444
Definition: emSwLib.h:274
Definition: emSwLib.h:266
int16_t * voltageSamplePtr
Pointer to the voltage sample.
Definition: emSwLib.h:400
int16_t sampleCount
Definition: emSwLib.h:481
_EM_message_code_
The following enumeration contain all possible EM SW Library return message codes.
Definition: emSwLib.h:192
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:335
EM_Energy_t activeEnergy
Active Energy for previous frame (uWh)
Definition: emSwLib.h:556
Definition: emSwLib.h:206
EM_Power_t totalResidualPowerCutoff
Definition: emSwLib.h:447
int16_t reactPowPrevV90
Previous V90 voltage used for the IIR filter in the reactive power calculation.
Definition: emSwLib.h:527
_EM_Phase_
Selects appropiate phase to provide results for.
Definition: emSwLib.h:264
uint64_t reactiveEnergyCounter
Ongoing Reactive Energy Sum.
Definition: emSwLib.h:337
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:272
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:505
and indPhaseMeterConstant is 0
Definition: emSwLib.h:203
uint32_t vPeak
VPeak since system initialization (mV)
Definition: emSwLib.h:541
uint8_t pulseGeneration
Definition: emSwLib.h:364
uint8_t mainNomFreq
Nominal Freq value for the system (Hz)
Definition: emSwLib.h:450
uint64_t indPhaseMeterConstant
Definition: emSwLib.h:352
uint16_t indPhasePulseDuration
Pulse duration in ADC counts for each active / reactive energy.
Definition: emSwLib.h:355
Definition: emSwLib.h:239
uint16_t cycleSampleCount
Definition: emSwLib.h:500
Definition: emSwLib.h:278
int64_t reactPowDotProd
Definition: emSwLib.h:487
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:507
uint16_t phaseResultsSupported
Definition: emSwLib.h:404
uint64_t activeEnergyCounter
Ongoing Active Energy Sum.
Definition: emSwLib.h:333
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:389
EM_Meter_Configuration * meterConfig
Pointer to EM_Meter_Configuration struct.
Definition: emSwLib.h:475
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:213
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:426
EM_Energy_t apparentEnergy
Apparent Energy for previous frame (uVAh)
Definition: emSwLib.h:560
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:229
EM_Phase_Calibration * phaseCalibPtr
Pointer to EM_Phase_Calibration struct.
Definition: emSwLib.h:420
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:224
uint16_t freqSampling
Sampling Frequency (Hz)
Definition: emSwLib.h:456
uint32_t activePowerSF
Active Power Scaling Factor.
Definition: emSwLib.h:385
EM_Power_t reactivePower
Total Reactive Power since system initialization (uVAr)
Definition: emSwLib.h:572
int64_t iDotProd
Definition: emSwLib.h:495
Contains EM Phase Result.
Definition: emSwLib.h:535
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:458
int16_t vPrevSample
Previous Voltage sample used for the IIR filter in the reactive power calculation.
Definition: emSwLib.h:529
uint32_t voltageSF
Voltage Scaling Factor - used to calculate VRMS.
Definition: emSwLib.h:381
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:576
uint64_t totalPhaseMeterConstant
Definition: emSwLib.h:357
EM_Power_t apparentPower
Apparent Power for previous frame (uVA)
Definition: emSwLib.h:554
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:454
EM_Current_Sensor currentSensor
Sensor connected to the current (I) channel.
Definition: emSwLib.h:402
Contains EM SW Lib Phase Calibration.
Definition: emSwLib.h:379
_iq30 reactPowGConst
G Constant used for the IIR filter to calculate Reactive Power.
Definition: emSwLib.h:503
int32_t vDCEstimate
DC Estimate for Voltage.
Definition: emSwLib.h:523
_iq30 oneDivSC
Constant used to calculate the VRMS,IRMS, power and energy values (1/sample_count) ...
Definition: emSwLib.h:509
uint8_t * meterPW
Definition: emSwLib.h:436
uint8_t reactivePulseGpioPort
Definition: emSwLib.h:299
Shunt.
Definition: emSwLib.h:250
uint64_t EM_Energy_t
Type for Energy variables.
Definition: emSwLib.h:260
Definition: emSwLib.h:200
Definition: emSwLib.h:209
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:462
EM_Phase_Configuration * phaseConfigPtr
Pointer to the EM_Phase_Configuration struct buffer.
Definition: emSwLib.h:428
Definition: emSwLib.h:270
_iq29 sqrtTwoConst
Square of 2 constant used for Vpeak and Ipeak calculations.
Definition: emSwLib.h:452
uint16_t activePulseGpioPin
Definition: emSwLib.h:311
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:547
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:347
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:383
uint32_t iPeak
IPeak since system initialization (uA)
Definition: emSwLib.h:543
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:590
EM_Energy_t reactiveEnergy
Total Reactive Energy consumed since system initialization (uVArh)
Definition: emSwLib.h:578
EM_Power_t activePower
Active Power for previous frame (uW)
Definition: emSwLib.h:550
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:231
EM_Phase phaseID
Present Phase ID Name.
Definition: emSwLib.h:562
struct _EM_Meter_Configuration_ EM_Meter_Configuration
Contains EM SW Lib Meter Configuration.
Current Transformer (CT)
Definition: emSwLib.h:248
uint16_t prevSampleCount
Definition: emSwLib.h:511
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:235
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:545
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:484
EM_Energy_t apparentEnergy
Total Apparent Energy consumed since system initialization (UVAh)
Definition: emSwLib.h:580
uint32_t IRMS
IRMS for previous frame (uA)
Definition: emSwLib.h:539
This error is returned if the sampling frequency is not greater than 0.
Definition: emSwLib.h:219
uint8_t reactPowIIRShift
Number of shifts required to calculated index for IIR table.
Definition: emSwLib.h:460
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:322
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:434
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:598