2024-04-03 11:33 PM - edited 2024-04-03 11:40 PM
Hi,
I am working with STM32G491RE.I communicating ATM90E26 single phase energy meter with STM32 through SPI communication.
I can able to read voltage ,current values correctly from the meter.
For KWH calculation, I am reading Absolute active energy register for kwh values. In the datasheet they mentioned the values I receive from the energy register are pulses.
how can I convert pulses to kwh. can anyone suggest?
my pulse constant value is 1000 imp/kwh.
From the datasheet they mentioned register will be cleared after read.
For that I am following below process
uint16_t Em_kwh=0;
uint16_t Em_kwhcharging=0;
uint8_t kwh_power[2]={0x00,0x00,0x00};
Em_kwh=GetAbsoluteActiveEnergy(); //to read the register its working properly
Em_kwhcharging=Em_kwhcharging+Em_kwh;
// I am converting above decimal value in to hex values
void ConvertDecimalToHex(int decimalValue, uint8_t* res) {
res[0] = (uint8_t)((decimalValue >> & 0xFF); // High byte
res[1] = (uint8_t)(decimalValue & 0xFF); // Low byte
}
ConvertDecimalToHex(Em_kwhcharging,kwh_power);
I am sending the hex value to other mcu using uart.
Is above way of handling the reset of register is correct. Can anyone suggest.
Is there any possibility Em_kwhcharging overflows. Is it better to take Em_kwhcharging as uint32_t.
Please suggest
Thanks
Solved! Go to Solution.
2024-04-04 01:31 AM
@sireevenkat1 wrote:
how can I convert pulses to kwh. can anyone suggest?
my pulse constant value is 1000 imp/kwh.
That's just basic arithmetic, surely?
"imp/kWh" is, presumably, short for "impulses per kWh" - in other words, "pulses per kWh"
So "1000 imp/kWh" means that you get 1000 pulses for each kWh
So 1 pulse is 1/1000 kWh - ie, 1 Wh
@sireevenkat1 wrote:
So that's telling you that the number in the register is in units of 0.1 pulse;
eg, if the register value is 65535, that represent 65535 * 0.1 pulses = 6553.5 pulses.
As we've already established, 1 pulse represents 1 kWh - so 6553.5 pulses represent 6553.5 kWh.
As the others have said, none of this has anything specifically to do with the STM32.
2024-04-04 01:12 AM
Well, these are all questions that have little to do with an STM32 as already mentioned before. Only the reading of the ATenergy register, which you read with 8-bit accesses, should be done with a 16-bit access.
The manufacturer of this component or its forum can (perhaps) help you with the other questions, as already mentioned too.
Regards
/Peter
2024-04-04 01:31 AM
@sireevenkat1 wrote:
how can I convert pulses to kwh. can anyone suggest?
my pulse constant value is 1000 imp/kwh.
That's just basic arithmetic, surely?
"imp/kWh" is, presumably, short for "impulses per kWh" - in other words, "pulses per kWh"
So "1000 imp/kWh" means that you get 1000 pulses for each kWh
So 1 pulse is 1/1000 kWh - ie, 1 Wh
@sireevenkat1 wrote:
So that's telling you that the number in the register is in units of 0.1 pulse;
eg, if the register value is 65535, that represent 65535 * 0.1 pulses = 6553.5 pulses.
As we've already established, 1 pulse represents 1 kWh - so 6553.5 pulses represent 6553.5 kWh.
As the others have said, none of this has anything specifically to do with the STM32.