I am working on a project which involves metering. For this purpose I am using single phase energy metering chip STPM10 from STMicroelectronics. I have successfully interfaced it with the microcontroller via SPI interface and I can read the Vrms Irms and Line Frequency by reading the internal registers of STPM10. There are four internal registers which contain 20bits energy up/down counters. I want to ask here if someone has experience with working with this device and can help me in obtaining the energy values from the device by using a sample code if possible it would be very helpful to me.
#define STEP 0.00000763
uint32_t energy = 0;
uint32_t integral = 0;
int32_t fractional = 0;
energy = integral + (fractional * STEP);
How can I make sure that I also save the fractional part of the calculation in the energy variable without using float type?
The reason is the speed.
reactive power will not result in energy flow (averaged over integers of mains period time, 1s surely is. )a signed integer since energy direction could be negative for reactive energy as well
uint32_t energy = 0;
uint32_t integral = 0;
int32_t fractional = 0;
energy = integral + (fractional / 131);
You shouldn´t put the whole formula into you"C" program. Just use 500.While doing a 16x16 multiplication you have used 32765.5 which is a float value would this cause undefined behaviour while calculating?
#define MW_MUL (1000 * 32765 / 65536)
uint32_t energy = 0;
uint32_t integral = 0;
int32_t fractional = 0;
energy = (integral * 1000) + ((fractional * MW_MUL) >> 16);
#define MW_MUL 500 ; // (1000 * 32765 / 65536)
uint32_t energy_mWh = 0;
uint32_t integral_Wh = 0;
int32_t fractional_LSB = 0;
energy_mWh = (integralintegral_Wh * 1000) + ((fractional_LSB * MW_MUL) >> 16);
in other words: 65790 steps make 1000 mVAR.in this case since 65790 steps make up 1VAR
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?