Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Floating point calculation in 8051

Status
Not open for further replies.

neoandrewson

New Member
Hi ppl,

I'm using an 8 bit microcontroller VRX51L3074 processor, an enhanced 8 bit controller, in a project to estimate the orbit of a satellite. Thanks to my friend, who gave me formulae to calcuate the orbit of satellite (attached).

My task is to write program for computation. all the variables( well most of them) are signed floating point. so i guess ieee 754 format would do. well the issue is how to implement functions such as sin, cos, square root in assembly. any suggestions and ideas? :confused:
 

Attachments

  • Orbit.pdf
    1.4 MB · Views: 958
Last edited:
two

First, there are probably libraries available if you have enough time to do it.

Second, use fixed point. Either way it is common to use lookup tables of what ever accuracy you need when doing fast trig functions on underpowered processors.

Dan
 
Thanks a lot Ubergeek63,

1. time is an important factor in computation, so i thought of using enhanced arithmetic unit (16 bit x 16 bit MAC) for fast arithmetic processing. I guess there is no library for utilizing these functions.
2. Fixed point? did u mean Q point notation? Can u explain little bit in detail?

Thanks a lot for reply..
 
fixed point takes advantage of what you know about the data.

For instance you know your numbers are between 0 and 180 degrees, and if you only need 1 degree of accuracy you are don't need more than 8 bits of resolution in your answer.

trig tables might only need to be 90 entries long since all the SIN values can be extrapolated from a quarter wave. you also know that all the numbers are between 0 and 1.

Think of money. Cash is normally measured in fixed point in two decimal place accuracy. I suspect a 16 bit table of 90 entries will be enough for you. you could even get clever and only use 30 or less since you also know where the functions are fairly linear. you could use less entries in the linear portions and interpolate between points over the whole thing.

Dan
 
Thanks a lot Ubergeek63,

I got your idea. I forgot to mention the key point in this discussion. The accuracy for all (except the one in Kms) variables should be 8 digits from decimal point!!!! Implementing these kind of floating point arithmetic in a 16 bit hardware is my concern. Any help?
 
that does not change things... you should still use fixed point lookup tables. Is this your project, or do you need to talk to something else in FP?

Is there some reason you are not using a C compiler and it's FP library?
 
Thanks a lot Ubergeek63,

So irrespective of floating point accuracies, i need to use table for trigonometric values. right?
Also, my aim is to perform these calculations five times a second. Correct me if i'm wrong, isn't it too fast for a 8051 to carry out such calculations in such less time? I have not yet simulated these calculations with floating point libraries, but my gut feeling says so. So i thought of performing these calculations in Hardware MAC.
No, my micro controller is not interfaced with any other FP calculating device. I'm planning to use 16 bit MAC unit on the chip.
I'm not using library because, it uses hell lot of time in calculating these formulas than 16 bit hardware unit (its an 8 bit controller).
I have few ideas on arithmetic of 16 bit on 8 bit controller, like breaking the 16 bit number into two chunks of 8 bit numbers and multiplying them. Can i use the same here?
Any references to arithmetic(including addition, subtraction, multiplication and division) for 32 bit floating point carried out on 16 bit hardware? :confused:
 
co -processor for floating point

Thanks a lot Ubergeek63,

I went through the article. It proved to be much useful. Now, i'm wondering whether it will be possible to execute such equations of high precision in this processor. Its too late to change the processor, can i use any co-processor for such arithmetic? Can u suggest me co-processors for such app? 8087 seems to be outdated. Any new co-processor? Or a DSP processor? Thanks in advance
 
:) I checked that one out. Not available locally. There is one more
**broken link removed**
bad thing that they are not available in INDIA. So searching for low power easy implementation of such equations. Wondering DSP or FPGA (low gate count) could do?
 
Also, my aim is to perform these calculations five times a second. Correct me if i'm wrong, isn't it too fast for a 8051 to carry out such calculations in such less time? I have not yet simulated these calculations with floating point libraries, but my gut feeling says so. So i thought of performing these calculations in Hardware MAC.

Five times a second is incredibly slow, even a lowly 8051 should be able to greatly exceed that requirement easily.

I would imagine adding a co-processor is going to be more difficult than using freely available floating point routines, assuming you can even source a suitable device.

There are various things you can do to make life simpler, first off try and simplify the formula, for example you may be able to reduce some calculations to constants. Next, as already suggested, use fixed point whenever possible - for example, if doing currency calculations, don't use $15.35 - convert everytihing to cents, so use 1535 cents instead. As has also been previously suggested, use lookup tables for sine, cosine etc.
 
Thanks

Thanks a lot Nigel Goodwin and Ubergeek63. I'll perform these operations on processor and then get back to u. Thanks a lot for your support.
 
If the 8051 is just doing this one task, the Lookup table route ought to be loafing at 5 Hz. Coprocessor = the old nut/sledghammer method.
 
Simulated results

Hi ppl,

I'm back with the simulated results.
As Nigel Goodwin had pointed out, the time which the processor took to execute was very little. It took 5ms at 40 Mhz speed with floating point. The speed is more than what we needed!! :D Thanks Nigel!!
But at the same time, the accuracy is only 6 bits after decimal point. i wanted an accuracy of 8 bits atleast. Any ideas or suggestions on these? i tried with double, but no luck with it. btw i use keil as c compiler and whole orbit propagator in C using float.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top