You are here
Home > embedded >

Calibrate STPM32/33 For Smart Energy Meter

In this tutorial, we will see how to calibrate STPM32/33. STPM32 is an ASSP (Application Specific Standard Product) for metering applications. It is designed for measurement of power and energies in a power line with high accuracy. It provides instantaneous voltage and currents, active, reactive and apparent powers, and energies. Lets start with how to Calibrate STPM32/33 For Digital Smart Energy Meter.

Introduction To Energy Calibration

Calibration is the process of comparing reading on one piece of equipment or system, with another piece of equipment. The other piece of equipment that has been calibrated and referenced to a known set of parameters. After the design phase, any tolerance of the real components from these values or device internal parameter drift can be compensated through calibration.

Any energy measure performed by the device (active wideband and active fundamental, reactive or apparent power and energy) is calculated digitally (without error) from current and voltage signals. This means that every measure is automatically calibrated if current and voltage channels are calibrated.

Design the application as stated in Section 3: “System calibration” in stpm32 datasheet ,for our STPM32 board, designed parameters are:

Reference voltage in v V_REF = 1.2 Voltage divider resistor 1 R1 = 810000 Ohm //user manual Voltage divider resistor 2 R2 = 470Ohm //user manual Voltage calibrator CALIB_V = 0.875 //STPM datasheet Voltage gain AV = 2 //calibration process doc Current calibrator CALIB_I = 0.875 //STPM datasheet Current gain AI = 16 //calibration process doc Current sensor Sensitivity KS = 0.3mV/A //user manual Integrator gain KINT = 1 //calibration process doc Sampling freq DCLK = 7812.5 //calibration process doc

Step 1. Reading RMS voltage and current values for no of samples time.

After applying voltage VN and current IN to the meter, a certain number of voltage and current RMS samples must be read and averaged(averaged values for voltage and current will be stored in Vav and Iav respectively). To find Vav and Iav do following steps:

maxSampleCount is the maximum number of samples to take for calibration. We are taking 20 samples for average values of RMS voltage and RMS current i.e. reading voltage and current value for each second . In datasheet it is given that “RMS updated values are available in DSP_REG14 and DSP_REG15 registers every 128 μs.” We will read voltage and current values using method given in another blog. Please refer “Measuring voltage, current, energy and power from STPM32/33”.

Read RMS voltage and RMS current. Here note that we have to read raw voltage and current register values, no need to multiply it by LSB value.
Add RMS voltage to one variable till maxSampleCount is not reached. Add RMS current to one variable till maxSampleCount is not reached.

2.Calculating average voltage and average current values for number of samples.

Once maxSampleCount is reached, calculate average of voltage and current value.

vAverage = getVavg(device_index, channel);                                                                                                                               iAverage = getIavg(device_index, channel);

3.Calculating target values for voltage and current using nominal voltage and current values.

The target values of voltage and current RMS registers, XV and XIrespectively are calculated as follows:

XV = (V_NOMINAL/VLSB_RMS)

where, VLSB_RMS = (V_REF(1+(R1/R2)))/(CALIB_VAV*32768) calculate from above parameters.

XI = (I_NOMINAL/ILSB_RMS)

where, ILSB_RMS = (V_REF)/(CALIB_IAI131072KSKINT) calculate from above parameters.

4.Calculating voltage and current calibrator values using average and target voltage and current values.

CHV is voltage calibrator value , CHC is current calibrator value calculated using formulae as:

CHV = (CALIB_MULTIPLY_FACTOR*vTarget)/vAverage)-CALIB_SUBTRACT_FACTOR
CHC = (CALIB_MULTIPLY_FACTOR*iTarget)/iAverage)-CALIB_SUBTRACT_FACTOR
where,
CALIB_MULTIPLY_FACTOR = 14336
CALIB_SUBTRACT_FACTOR = 12288

5.Writing voltage calibrator values to DSP control register .

For writing voltage calibrator value of channel 1, we have to write bits[11:0] in DSP control register 5(DSP_CR5).For writing voltage calibrator value of channel 2, we have to write bits[11:0] in DSP control register 7(DSP_CR7).

#define PRIMARY_V_CALIB_REG 0x08
#define SECONDARY_V_CALIB_REG 0x0C
/*We have to write [11:0]12 bits Calibrator value to register. Take calibrator value as 16 bit value.*/
/*Split CHV into data1 and data2*/
uint16_t CHV_Integer = (uint16_t)CHV;
/*Split CHV value into two 8 bit values for writing using SPI communication. Data1 as LSB and data2 as MSB value.*/
uint8_t data1 ,data2 =0;
data1 =((CHV_Integer)&(0x00FF));
data2 =((CHV_Integer>>8)&(0x000F));
/*Corresponding to channel no, call measure_writeRegister function with LSB and RSB data.*/
if(channel == CHANNEL_1)
{
measure_writeRegister(PRIMARY_V_CALIB_REG,device_index,data1,data2);
delay_us(5);
}
else if(channel == CHANNEL_2)
{
measure_writeRegister(SECONDARY_V_CALIB_REG,device_index,data1,data2);
delay_us(5);
}
where, data1 is LSB and data2 is MSB.

Writing current calibrator values to DSP control register .

For writing current calibrator value of channel 1, we have to write bits[11:0] in DSP control register 6(DSP_CR6).For writing current calibrator value of channel 2, we have to write bits[11:0] in DSP control register 8(DSP_CR8).

V_NOMINAL#define PRIMARY_I_CALIB_REG 0x0A
#define SECONDARY_I_CALIB_REG 0x0E
We have to write 12 bits Calibrator value to register. Take calibrator value as 16 bit value.
uint16_t CHC_Integer = (uint16_t)CHC;
Split CHV value into two 8 bit values for writing using SPI communication. Data1 as LSB and data2 as MSB value.
uint8_t data1 ,data2 =0;
data1 =((CHC_Integer)&(0x00FF));
data2 =((CHC_Integer>>8)&(0x000F));
/*Corresponding to channel no, call measure_writeRegister function with LSB and MSB data*/
if(channel == CHANNEL_1)
{
measure_writeRegister(PRIMARY_I_CALIB_REG ,device_index,data1,data2);
delay_us(5);
}
else if(channel == CHANNEL_2)
{
measure_writeRegister(SECONDARY_I_CALIB_REG,device_index,data1,data2);
delay_us(5);
}
where, data1 is LSB and data2 is MSB.

We are writing these Voltage and current calibrator values to storage and then for each time on controller reset, Get the values from storage and writing these values to calibrator registers. Hope you have enjoyed reading on how to Calibrate STPM32/33 For Digital Smart Energy Meter.

Top
%d bloggers like this: