English
Language : 

AN2512 Datasheet, PDF (30/38 Pages) STMicroelectronics – This application note describes how to design
Example of source code
AN2512
long int frac[4];
long int integ[4];
} ENERG;
/* fraction part of energy integrator */
/* integer part of energy integrator */
/* definition of variables for internal registers values */
char status[3];
char mode[3];
int freq[3];
int uRMS[3];
int iRMS[3];
int uMOM[3];
int iMOM[3];
long int active0[4];
long int active1[4];
long int reactive[4];
long int apparent[4];
/* allocation for all types of energies */
long int new;
/* energy value to be handled */
ENERG *e;
/* -> energy integrator */
ENERG ActWB;
/* Active wide band energy */
ENERG Reactive;
/* Reactive energy */
ENERG ActFund;
/* Active fundamental energy */
ENERG Apparent;
/* Apparent energy */
/* definition of constant */
#define ELIMIT 0x140000 /* produces 0.01 kWh resolution in case of 128000 pulses per
kWh */
/*----------------------------------------------------------------------------------
ROUTINE NAME : EnergyQuant
INPUT/OUTPUT : None/None
DESCRIPTION : Energy quant computing function (version for signed energy
integration). Checks for rollovers and compute quant as difference between new and
old value. Returns a negative sign of quant.
----------------------------------------------------------------------------------*/
30/38
int EnergyQuant(Long int *new)
{
long int NewTemp;
char i,Temp;