View previous topic :: View next topic |
Author |
Message |
Richi
Joined: 15 Dec 2006 Posts: 6
|
Faster Division |
Posted: Thu Dec 21, 2006 3:40 pm |
|
|
Hi Guys,
anyone an idea how I can do that faster:
output_high(OUTPUT_2);
MERKER_16_2 = MERKER_32 / MERKER_16_1;
output_low(OUTPUT_2);
I measured the time between with the Oscilloscope
16 and 32 are for long and double and this operation takes 1,1ms with a 4MHz clock!!!
Is it possible to do this faster? Some special algorytm?
I think with a the method subtraction it is not faster
Thanks |
|
|
Moldy Green Bread Guest
|
Re: Faster Division |
Posted: Thu Dec 21, 2006 4:50 pm |
|
|
Richi wrote: | Hi Guys,
anyone an idea how I can do that faster:
output_high(OUTPUT_2);
MERKER_16_2 = MERKER_32 / MERKER_16_1;
output_low(OUTPUT_2);
I measured the time between with the Oscilloscope
16 and 32 are for long and double and this operation takes 1,1ms with a 4MHz clock!!!
Is it possible to do this faster? Some special algorytm?
I think with a the method subtraction it is not faster
Thanks |
Well, 4 Mhz only gives you 1MIPS and 32 bit math on an a 8 bit MCU with no hardware multiplier is poor. If your not into writing asm
you could change your crystal to 20Mhz providing you with 5MIPS.
I assume your using a 16f series pic. |
|
|
Richi
Joined: 15 Dec 2006 Posts: 6
|
|
Posted: Thu Dec 21, 2006 5:27 pm |
|
|
... I�m still using a PIC16F819 you meant: use a PIC18F...?
I would, but no space. Now I try to use the internal clock - 8MHz
What about the assembler? I can implement assembler code- so do you have a programm for me? I not good in assembler. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Dec 21, 2006 5:39 pm |
|
|
I'm not sure, but it is possible that CCS implements the division as int32/int32. Faster would be to do it as int32/int16 but it sounds logical for CCS not to provide seperate functions for all possible bit combinations (optimizing memory usage over speed).
Have a look at http://www.piclist.com/techref/microchip/math/div/index.htm for several (assembly) math routines.
Maybe a further optimization is possible for your application by using the int24/int16 routine from that same website? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Dec 21, 2006 9:02 pm |
|
|
Maybe you can calculate
X = 1/MERKER_16_1;
at some non-time critical point in the code. Then using this may be faster.
MERKER_16_2 = MERKER_32 * X; _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|