cancel
Showing results for 
Search instead for 
Did you mean: 

Integration over time

Nico3
Senior

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.

3 REPLIES 3
MasterT
Senior III

First of all, make sampling rate constant. Than integral is simply a sum of samples over specified period of time, 1 sec or so.

raptorhal2
Lead

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.

Johi
Senior III

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).