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

Efficient Averaging of 10bit ADC samples on a 18F6520

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



Joined: 12 Dec 2003
Posts: 25

View user's profile Send private message

Efficient Averaging of 10bit ADC samples on a 18F6520
PostPosted: Tue Apr 19, 2005 5:37 pm     Reply with quote

Hi!

PCB/PCM/PCH v. 3.174

I am rather new to "firm" timing constraints, and as such I have only loosely tried to play with CCS compiler generated statistics. I do not yet know of all the capabilities and options available to me to document timings of my code.

I am slightly familiar with assembler coding, enough to know that I dont want to do it, but not enough to write code that would be faster than the CCS generated code.

The task:
Sample Channel A Y-times and return the averaged value as an integer, I dont need the decimal values.(?)

This must be completed as fast as possible so I can move on to the next channel and repeat the process.

Since the 18F6520 has a built in 8x8 multiplier, will I gain from doing the averaging such as this (for a 4 sample situation):

int16 Sum; //sum of 4 samples
float Factor = 0.25;
int16 FilteredData;

FilteredData = Sum * Factor;

Or will it be faster/just as fast to just immidiately do:

FilteredData = Sum/4;

Be aware that I might change my mind as the project progresses as to how many samples to average over.

Thank you for your time.
Also, I would like to point some attention to the soon to be posted question about mixing digital and analog filtering in a project.
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Wed Apr 20, 2005 7:20 am     Reply with quote

Quote:
The task:
Sample Channel A Y-times and return the averaged value as an integer, I dont need the decimal values.(?)

This must be completed as fast as possible so I can move on to the next channel and repeat the process.

Since the 18F6520 has a built in 8x8 multiplier, will I gain from doing the averaging such as this (for a 4 sample situation):

int16 Sum; //sum of 4 samples
float Factor = 0.25;
int16 FilteredData;

FilteredData = Sum * Factor;

Or will it be faster/just as fast to just immidiately do:

FilteredData = Sum/4;




The hardware multplier is not a floating point multiplier. The latter would be MUCH faster. Avoid using floats when you care about speed

Scott
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Apr 20, 2005 9:21 am     Reply with quote

Keep your divides divisible by 2 and they will be simple bit shifts.
Guest








Calculating number of cycles required for commands
PostPosted: Wed Apr 20, 2005 9:33 am     Reply with quote

Thanks for the insight and tips so far.

Is there a way for CCS to genereate automatic "timing" reports? Right now I'm looking at the generated asembler code for certain key-operations and then calculating the cycles myself.. I thought that was fairly reliable until I noticed this: (all variables are int16)

a=16;
a=a+8;

the above takes 4 cycles to complete

a=1024;
a=a+1024;

the above takes 1 cycle to complete.. Makes me wonder if 4 cycles is worst case or if some combination can make it even worse.. Is there an "easy" way to get this type of worst execution time information for "simple" commands, like addition, multiplications, divisions etc.?

Also, if anyone could glance quickly over my other thread "Analog (anti-aliasing) and digital filtering mixed together" http://www.ccsinfo.com/forum/viewtopic.php?t=22606 especially concerning if i need/should do digital averaging in my project! Thanks!!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Apr 20, 2005 10:31 am     Reply with quote

There is or was a stop watch window in MPLAB. You can set a break point at the begining and end to determine the time.
Dargar



Joined: 12 Dec 2003
Posts: 25

View user's profile Send private message

PostPosted: Wed Apr 20, 2005 10:54 am     Reply with quote

oh, I'm (one of the few) that uses the CCS IDE
PCB/PCM/PCH v. 3.174

Does it have any report generating feature (except the asm/c report) that would be useful to do this?
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