I am trying ADE7758 for energy metering. I have made quite a progress in my code. I could now read VRMS,IRMS and FREQ register properly. I could set VRMS , IRMS offsets for calibration and get perfect value. But i am stuck with a weird kind of problem while reading VRMS, IRMS and FREQ values together. I could get those values correctly while calculating individually but when i calculate those values together somehow my VRMS values get reduced to <2V. What i am doing is while the interrupt occurs for zero crossing, first i disable all interrupts. Then i check for which phase the interrupt has occured. Then i take a VRMS and IRMS sample and save it. Then i clear the interrupt status register(reset). Then i enable the global interrupts. I repeat this process for 20 interrupt calls and take an average value. Thats it. I am doing this but if i do this individually for VRMS and IRMS. I get the proper calibrated value. But when i join it together something goes wrong with the voltage.
I am using STM32F411.
Here is the sample code for ISR for phase A
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
if (HAL_GPIO_ReadPin(ADE7758_INT_GPIO_Port, ADE7758_INT_Pin) == GPIO_PIN_RESET) //Checking the interrupt pin
__disable_irq(); //disable global interrupt
if (count == 0) //if first data (ignore it)
if (ADE7758_getInterruptStatus() & PHASE_A_STAT) //if interrupt caused by phase A
IRMS_A_ORG = ADE7758_getIRMS(PHASE_A); //get raw register values
IRMS_A += IRMS_A_ORG;
VRMS_A_ORG = ADE7758_getVRMS(PHASE_A); //get raw register values
VRMS_A += VRMS_A_ORG;
Frequency_A = ADE7758_GetLineFreq(PHASE_A) * 0.0625 ;
if (count >= 20)
AVG_VRMS_A = VRMS_A / 20; //take the average after 20 counts
AVG_VRMS_A *= 0.00021275; //for calibration
VRMS_A = 0.0;
AVG_IRMS_A = IRMS_A / 20; //take the average after 20 counts
AVG_IRMS_A *= 0.0218160398797; //for calibration
IRMS_A = 0.0;
count = 0;
ADE7758_getResetInterruptStatus(); //Reset interrupt status register
__enable_irq(); //enable global interrupt
HAL_GPIO_TogglePin(GREEN_GPIO_Port, GREEN_Pin); //toggle led
Sorry for the slow response. Here are a few troubleshooting suggestions:
Please ensure you are reading the correct number of bits in the FREQ register
Does FREQ register reading work when you do this by itself?
It could be an error with the math/variable type used. Is each individual VRMS_A, IRMS_A reading correct and just the average is wrong?
If you are having trouble with the raw VRMS_A, IRMS_A and FREQ readings, please use an oscilloscope to show this transaction using the IRQ and SPI bus and we can verify what is going on that way.
I have already solved above problem but i am stuck with Watt gain calibration.
Hi, we have done the voltage and current calibration and its working as expected. However we are facing difficulties while doing Watt calibration.
Have you solved this error ..Im too facing the same problem Aphase Watt register is not properly calibrated .
Can I see your register initializations.And if you have solved the error Please let me know which may help a lot.
Hi devjeetmandal09 and fautomation436,
From what you describe it would seem that you have a reverse current situation. The energy register is a 16 bit signed register. This means that the value of 63221 is actually -2315 in terms of accumulated energy. Then when you increase the current to 5.3A, the value increases to 53241 which is -12295 (this is about 5x larger than the original value with 1.1A).
Check your hardware to make sure everything is connected correctly unless you actually do expect negative power. If you don't then you have to swap either the current channel connections to measure the current with the correct sign. RMS doesn't care about direction.