2023-08-13 08:48 AM
Hello
I am receiving current from sensor continuously in while loop. I want to integrate the value with time so I can know total passed charge. Please suggest how to do it.
2023-08-13 09:47 AM
First of all, make sampling rate constant. Than integral is simply a sum of samples over specified period of time, 1 sec or so.
2023-08-13 10:13 AM
Sum of samples divided by the sampling rate. You choose the period of time.
The sensor data sheet should provide a factor to convert the signal to amps.
2023-08-13 12:20 PM
There is a HAL function: HAL_GetTick(), this function gives you the number of ticks since the mcu booted.
You can use this function to determine the time elapsed between 2 ADC readings = time interval.
Then multiply the interval with the reading you have and divide by the total number of ticks (1 ms).
This should give you what you need in essence.
Other alternatives are also possible, relative to your knowledge and specification.
This includes triggering your ADC with a timer and processing the data of the ADC with an ISR (interrupt service routine).