|
|
View previous topic :: View next topic |
Author |
Message |
neurus
Joined: 31 Mar 2004 Posts: 23 Location: Switzerland
|
integration of values from ADC |
Posted: Tue Feb 01, 2005 4:07 am |
|
|
hi
I've to do an integrator from 0 to 60 sec. Every 0,5 sec I get a new value from ADC. Doe's anybody have any idea?
I'm working with CCS and Pic 18f252.
Thanks
pablo |
|
|
neurus
Joined: 31 Mar 2004 Posts: 23 Location: Switzerland
|
|
Posted: Tue Feb 01, 2005 6:31 am |
|
|
hi
how can I implement the trapezoidal rule for a Pic 18f252? Can help me anybody?
Thanks
Pablo |
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 01, 2005 6:43 am |
|
|
Do you really mean an 'integrator'?. If you feed a DC valtage into a pure integrator, you will just end up with the output eventully going over/underscale. The same will happen with a software version, unless you code relative to the mean signal level.
Probably the easiest 'averaging' algrithm, is this:
Code: |
int32 sum;
int16 adval
int16 result;
adval=read_adc();
sum=sum+adval;
result=sum/120;
sum=sum-result;
|
Note that the maths will be faster, if you use a 'binary' division (so /128), but this will give a slightly slower response.
This behaves in part like an integrator, but is only integrating the _difference_ between the current output value, and the incoming voltage. As such it avoids the excursion runaway, that a pure integrator would incur.
Best Wishes |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Feb 01, 2005 8:17 am |
|
|
I have never heard of a "trapezoidal rule." But if you want to do a "boxcar" filter you must store every reading in the sample so it can be removed when it is too old. That is RAM intensive.
Consider if you really need a FIR (finite impulse responce) filter, or can you get away with an IIR (infinite impulse responce) filter like Ttelmah suggested. IIR is much easier. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 01, 2005 9:30 am |
|
|
I was going to suggest in my original post, that you can do a 'rolling sum' filter (have done this myself in the past). With this, for the 120 sample example, you implement a buffer, using one wrapping pointers. Then when a new value arrives, you retrieve the old value which would be overwritten (120 samples ago), and subtract this from the 'sum', add the new value to the sum, and then save the new value into the buffer at the same location, then increment the pointer. Though this still means you have to hold 120 values, you don't have to regenerate the 'sum' for every moment in time. If you have your input voltage 'offset' into the ADC input range, with zero at (say) 1024 counts, then store the value as a signed int16, subtract 1024 from the incoming number, and perform this arithmetic, you generate the trapezoidal waveform, that I think you are looking for.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|