CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

integration of values from ADC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
neurus



Joined: 31 Mar 2004
Posts: 23
Location: Switzerland

View user's profile Send private message

integration of values from ADC
PostPosted: Tue Feb 01, 2005 4:07 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 01, 2005 6:31 am     Reply with quote

hi

how can I implement the trapezoidal rule for a Pic 18f252? Can help me anybody?
Thanks

Pablo
Ttelmah
Guest







PostPosted: Tue Feb 01, 2005 6:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 01, 2005 8:17 am     Reply with quote

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







PostPosted: Tue Feb 01, 2005 9:30 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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