2021-07-11 12:57 PM
Please advise on the below issue in STPM32 Active Energy Register.
All other parameters are reading correctly. Voltage, Current, Frequent, PF, and Active Power.
Voltage resistor divider - 470E and 270K X 4.
CT - 1:2500 ration Class 0.5,
STPM interface to the controller through the UART interface. An additional signal is "EN".
Attached the Schematic of the STPM34 section.
The load connected - 3200W resistive load,
int32_t PH1_REG1=0;
SEND_DATA_TO_STPM34(0x58,0xFF,0xFFFF);
memcpy(&PH1_REG1,U2_STPM34_RX,4);
buffer1 = PH1_REG1;
DATA.ACTIVE_ENERGY1=ENERGY_CALCULATION(PH1_REG1,ACTIVE);
------------------------------------------------
int32_t ENERGY_CALCULATION(uint32_t raw_nrj,TYPE_ENERGY type)
{
int64_t calc_nrj = 0;
/* manage the 2 U32 to have enougth place to save energy cumulated */
/* Make sure between two reads inside hardware registers if we have to add carry inside ext U32 */
if (((uint32_t)energy[type]>0xA0000000) && ((uint32_t)raw_nrj<0x60000000))
{
energy_extension[type]++;
}
if (((uint32_t)energy[type]<0x60000000) && ((uint32_t)raw_nrj>0xA0000000))
{
energy_extension[type]--;
}
/* save the new result cumulated come from register inside internal structure */
energy[type] = raw_nrj;
/* calculate the nrj value and add the 32 bits extension */
calc_nrj = (uint64_t)raw_nrj + ((int64_t)energy_extension[type] << 32);
calc_nrj *= (int64_t)35145;
/* multiply by 10 to have in milli- */
calc_nrj *= 10;
/* Put the result in 32 bits format */
calc_nrj >>= 32;
/* return the nrj value */
return((int32_t)calc_nrj);
}
2023-05-18 04:25 AM
Hi Aneesh, I am facing same issue. Can you please help.
Energy values overflow after 230W.
Mobile - 8888883467
2023-06-12 05:11 AM
hi, did u got the solution,
2023-07-27 12:41 PM
Hi... No still looking for solution... What about you ?