Afuevu
Afuevu
DIIDevHeads IoT Integration Server
Created by Afuevu on 12/20/2024 in #firmware-and-baremetal
How to Optimize Energy Calculations for STM32 Energy Meter Without Overloading Interrupts?
I am using DMA for the ADC. The timer 2 interrupt is called every 50uS. Line 20 and 23, i am updating the variable to store the values of ADC read using DMA. There is a counter variable that increments every time the interrupt is called which is on line 3, the counter variable is value1. On line 23 the when value1 counter gets to 400, the counter is true at that point and i have gotten 20ms( 50uS*400= 20ms) = 50hz, meaning every 50hz or 20ms, i would have gotten 400 samples. From line 30 to 41, is where i get the main calculation for my voltage and current after taking many samples. For a detailed breakdown and understanding of how i came up with the voltage reading, this link explains more on how to use op-amp to measure ac voltagehttps://microcontrollerslab.com/ac-voltage-measurement-using-microcontroller/. For the measurement of the current, this link explains how to go about it https://microcontrollerslab.com/alternating-current-measurement-using-pic-micocontroller/#:~:text=To%20measure%20AC%20current%20with,drop%20across%20the%20shunt%20resistor. Then on line 47 there is a variable timer2_count that increments every 20ms. Then on line 51, when the timer2_count variable gets up to 50, the condition is true and that block of code is called, inside the block i calculate my energy consumed every second.
23 replies