View previous topic :: View next topic |
Author |
Message |
Dargar
Joined: 12 Dec 2003 Posts: 25
|
Efficient Averaging of 10bit ADC samples on a 18F6520 |
Posted: Tue Apr 19, 2005 5:37 pm |
|
|
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
|
|
Posted: Wed Apr 20, 2005 7:20 am |
|
|
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
|
|
Posted: Wed Apr 20, 2005 9:21 am |
|
|
Keep your divides divisible by 2 and they will be simple bit shifts. |
|
|
Guest
|
Calculating number of cycles required for commands |
Posted: Wed Apr 20, 2005 9:33 am |
|
|
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
|
|
Posted: Wed Apr 20, 2005 10:31 am |
|
|
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
|
|
Posted: Wed Apr 20, 2005 10:54 am |
|
|
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? |
|
|
|