Integrator implementation on Arduino

Hello Arduino forum,

I am trying to use an arduino to measure a input voltage and integrate it with respect to time to get the behavior of an integrator. I would like to specify a RC time constant that would mimic the behavior as it charges. Eventually I would also like to have it decay as well, but this is for later.

I am having trouble figuring out an intelligent way to keep track of the voltage at a specific time. The arduino I am using has a maximum resolution of 1 kilo-Samples per second. My first thought was that after each voltage measurement there is some sort of counter that adds to a time variable, however I am not sure how to couple the voltage sampling rate with updating some time variable. Once I have the voltage associated with a specific time, I then have to find an intelligent way to integrate it with respect to said time.

Any suggestions and/or sample code would be greatly appreciated!

I am using: Arduino nano input voltage to analog pin A0 Windows 7

Do you have an Integration function to use ?

It is easy to sample the ADC at a specific rate. It takes the ADC about 100 microseconds to convert one sample, then you wait for a while (by either using delay() or, following the Blink Without Delay example, do something else for a while).

In the case of constant intervals, the simplest integration is to sum the series (measured ADC value)*DT, where DT is the time between samples. Since DT is a constant, you can take it out of the sum and multiply it by the total, which saves some computing.