The fixedpoint library at http://code.google.com/p/fixpointlib/ looks less than ideal. There is no source code available :-(
So I'm not interested in it. Back to understanding gcc's _Fract, _Sat, _Accum etc. support.
The fixedpoint library at http://code.google.com/p/fixpointlib/ looks less than ideal. There is no source code available :-(
So I'm not interested in it. Back to understanding gcc's _Fract, _Sat, _Accum etc. support.
thats too bad. Hopefully Ill find some time for this soon, right now its all about serialusb
What about http://code.google.com/p/libfixmath/ ? Still GCC support would be optimal.
mabl --
Thanks for the link!
This page seems to indicate that libfixmath is compatible with GCC:
http://en.wikipedia.org/wiki/Libfixmath
Or did you mean something different?
It is compatible with gcc and I already use it on an STM32P107 with ChibiOS. It recently even got smull support on ARMs.
What I was referring to was the build-in gcc support for fixed point.
mabl are you using ChibiOS wow :) How fast is this lib respect of standard math ? I'm very interest to use it in our project but you use it on your quad ?
Best
Roberto
Hello redfox,
yes I'm using ChibiOs, it is really nice. The build system is super simple and there is a quite extensive set of documentation. In addition, the core developer Giovanni answers all questions in the forum quickly. (Hey leaflabs, give him one free Maple sample, I'm sure he will hack some demo for the board - great advertisement!)
As for the speed of the lib - I have no idea actually. (I always meant to test, but haven't made it yet.) Still there are some benchmarks [1] available. Judging from the code, I could imagine that there is still quite a possibility to improve performance. But those 32/64 bit integers are just so efficient on the Cortex M3. (I would not attempt to use this lib on an AVR...)
[1] http://code.google.com/p/libfixmath/wiki/Microcontroller_Usage
Well, I'm attempting to get fixed point working with IDE v0.0.10b however I've got some problems, I probably would have better luck compiling from command line, but I don't have much experience in this matter.
Errors:
http://www.crennsmind.com/Code/Maple/FixedPoint/compiling_errors.txt
Code trying to compile:
http://www.crennsmind.com/Code/Maple/FixedPoint/fixed_point_code.txt
Help would be appreciated.
Thanks,
crenn
Hi crenn,
this looks like the libfixmath library does not get built, so the linker does not know wher to link you fix16_xxx calls to. I have never used the maple so you are on you own here, but I'd have a look into the build system. You should be able to specify other sources you want to build as well.
Well, it seems it was a case of how I was including the file. I was doing
#include "./fixmath.h"
but I only needed:
#include "fixmath.h"
After doing that, it's working fine! So now I need to test it on hardware to ensure it's working, and then use it in my hacked up Razer/Maple code to see what the speed increase is.
adding a library to your libraries directory and then selecting from the dropdown menu will cause the IDE to compile and link against it (and auto-add the #include) if you are using the IDE. I am psyched to see the result!
Well, I'll have access to the hardware today, and run the tests later this afternoon after I finish up a write up on a VHDL project. mbolivar suggested using the drop down menu, and that's how I made the above discovery.
Well, I'm half there.... there are some problems though:
http://www.crennsmind.com/Code/Maple/FixedPoint/compiling_errors_v2.txt
http://www.crennsmind.com/Code/Maple/FixedPoint/fixed_point_code_v2.txt
But I've also run it with the complex_karctan2, it takes 14uS to process, but only takes the floating point atan2 0-1uS to process.... But I'm also wonder if that's because I previously didn't add math.h. Tests will be run this morning. But anyway, the included fixed point atan2 doesn't allow the program to be uploaded.
Well, with the help of mbolivar, we've found that it really was trying to use over 32kB of RAM. But there is an option to fix this, usually it requires adding a compiler options, but adding some #define works just as well for this purpose.
To allow fix16.h to be used, add the following defines at line 9:
#define FIXMATH_NO_CACHE
#define FIXMATH_NO_64BIT
This will allow libfixmath to compile and also makes some functions quicker to process. Now onto the next part, why was floating point operations quicker than fixed point?
The answer is, it wasn't! The complier was running an optimisation because of the static and constant variables, a little bit of a code change later:
http://www.crennsmind.com/Code/Maple/FixedPoint/fixed_point_code_v3.txt
Output:
Fixed conversion Took 14
Got 11326.75
Floating conversion Took 71
Got 11339.42
The times are in uS (because of calls to micros() ). It took a while to realise what what happening, but there you go, I'm getting a 5.5x speed-up at the cost of some accuracy. Remember that you need to decide which you need more, more accuracy, or more speed. I'm going to be running one more test for today then working on uni stuff (lot of work over the next 2 weeks, so I might not be on the forums a lot for the next week or so) but I'll be sure to let you know of the results.
EDIT: Just to let you know, I'm having problems currently with the conversion, but it's probably a mistake somewhere, so I'll need to fix that up, however I can't work on it until after next friday.
That's a really nice performance increase! I'll surely be using this in a project.
Unless one plans to mostly stay in fix16 and rarely convert to float, I think it would be a good idea to count the conversation time from fix16 to float within the time it takes to do the fixpoint math. At the end of the day, we care about the floating point value, unless the code is written to specifically use only fixed point numbers.
You must log in to post.