PDA

View Full Version : Help! How to get a greater resolution with brads???


Tophinater
Dec 31, 2006, 12:53 AM
For my senior project for school I require very accurate angle measurement which will probably be achieved with a magnetometer. The problem is that I am going to be using these angles to calculate distances using an ARMmite micro that only likes brads. Since this controller, like many others, does not support floating point calculations this leaves me with a very large error when calculating distances from these angles. So to get around this floating point problem, is there a way to increase the resolution of brads in a circle? Maybe in some way sort of fake having a full circle be 2550 brads purhaps? Any help would be greatly appreciated.

Tom Harper
Dec 31, 2006, 07:44 AM
You can simply treat the fractions as integers by consistently multiplying everything by 1000. I think that is what you are referring to as '2550 brads'. Of course you have to treat the integers the same way. 1/.5 becomes 1000/500.

Another technique is to store constants and tables as reciprocals. Then you multiply instead of dividing. .5 is stored as 2. 1/.5 becomes 1*2, an easier operation to handle.

The only problem I have found is that the integers will get very large. Be prepared to handle 32 and even 64 bit numbers.

Tophinater
Dec 31, 2006, 11:49 AM
Sorry Tom, but I don't really see how assuming integers and fractions is really going to help me. Perhaps you could post an example so I understand better? Changing the magnitude of a number isn't really going to make a difference. My error is going to come from everything right of the decimal being truncated. Even if I programmed it to give me the cos(455 or 1*2) its just going to give me the cos of the angle of 200 regardless. And if I'm going to be dealing with 64bit numbers Id much rather just use taylor series.

Tom Harper
Dec 31, 2006, 12:10 PM
Perhaps I do not understand your problem. The issue you posted was how to deal with a lack of floating point in the small microcontroller.

What is causing truncation of your data to the right of the decimal?

I agree that if the data is not there you are not going to reconstruct it. But if a sensor or other device gives you the value 2.4769, you can simply treat it as the integer 24769 as long as you multiply everything else by 10,000.

If you set up your tables as reciprocals then .6886 would be stored as ((1/.6886)*10000)=14522. To multiply 24769 by .6886 you would: 24769/14522. If you make the integers large enough no accuracy is lost.

Sorry if I am working on the wrong problem.

Are you using the Honeywell sensor that has a pulse width as it's output?

Unterhausen
Dec 31, 2006, 08:05 PM
What is a brad? I'm assuming it's some representation of a radian. Does the processor do native trig?

sensor reading in floating point are very rare, they almost all start out as integers. Go look at Embedded Systems Magazine archives for information about how to represent floating point on a fixed point machine. There is also plenty of information available for fixed point DSPs. Generalize your problem a little, and lots of people have solved it before you.

Tophinater
Jan 01, 2007, 04:23 PM
I think Im starting to understand what you are saying tom. I just didn't understand the part about reciprocal as being the inverse. However, I'm assuming that by doing it the way you are describing I'm going to need to develop a look up table like one that is already programmed into the processor. While I could do this, it might take up to much memory but Ill keep it an option. I have thought about using hyperbolic interpolation with a table with few points.

About the sensor, I haven't really decided on which one to use yet. Iv been looking at the Vector 2Xe (http://www.sparkfun.com/commerce/product_info.php?products_id=236) which as a resolution of 0.01 degrees.

A brad is a binary radian. Instead of having a value of -1 to 1, an angles value goes from -127 to 127 in order to be more easily represented in a chip.

Tom Harper
Jan 01, 2007, 05:02 PM
Are you using standard code? Is that why there is a table already in the processor?

It's not necessary to store the table. You can reconstruct it from straight line chords, especially if you blow it up into big integers. You can do arbitrary functions this way:

http://www.rcgroups.com/forums/showpost.php?p=6606817&postcount=54

Interesting project - keep us informed.

Tom

Tophinater
Jan 02, 2007, 12:21 PM
Im usng ARMbasic to program the microcontroller. Its a proprietary code similar to Pbasic but modified. I don't know for sure but the processor probably calculates trig values by using a referance table and interpolation since that is usually faster then other methods. I read through your post that you linked and it looks like a good idea. However to get a table with more then 1 degree of resolution is going to be a little bit complicated. I think if I use modified taylor series to the 7th degree I will be able to get the accuracy I desire. Its a 10Mips controller with 12k of memory. Im going to be doing a lot of calculations with large matricies so processor power I can spare, memory I don't think I can. I really wish I knew assembly code.

Tom Harper
Jan 04, 2007, 08:53 AM
Tophinator,

Assembly code is not difficult. All processors load, store, add and subtract with a few addressing modes.

A good approach to a product is to reduce your application to practice using 'C' on a PC with an I/O card and then convert it to assembly for the microcontroller. That way you have lot's of resources for proof of concept and an econimical end product. Best of both worlds. Since you have serious time constraints you could prove concept in the PC and then show on paper how it could be done in an Arm.

Tophinater
Jan 04, 2007, 12:19 PM
Thanks for the advice Tom. In the future, as in when Im a graduat student, I plan on learning C++ and assembly. Looking back on, I should have started that way but basic will serve my well none the less. For my senior project proposal I plan on doing all my calculation in excel first. Then if and when my project gets approved I will be doing what you suggested and impliment it with the ARMs. I found out that MS's Visual Basic Express also has a similar version C#, C++, and even java all free. That should hopefully make the learning curve a little easier when the time comes.

Tom Harper
Jan 04, 2007, 12:33 PM
Sounds like a good plan! Visual Basic and Excel do almost everything.