View previous topic :: View next topic |
Author |
Message |
mizi_suichiro
Joined: 23 Mar 2004 Posts: 7
|
PIC16F877 support floating point? |
Posted: Mon Mar 29, 2004 9:12 am |
|
|
does the PIC16F877 support floating point? how to determine either the microcontroller support the floating point or not?
if the microcontroller support the folating point, is it makes the microcontroller slow when the microcontroller do a calculation?
thanks. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
Re: PIC16F877 support floating point? |
Posted: Mon Mar 29, 2004 9:55 am |
|
|
Any PIC can in principle use floating point, but it may not be pratical.
First look at the amount of RAM available. Each floating point variable, including scratch variables, will consume 4 bytes of RAM. On a 16C54 there are only 24 bytes of general purpose RAM available, so six is the theoretical max number of floating point variables for the 16C54, not very practical.
Second is ROM size. I don't use floating point so I only know floating point functions use lots of ROM. It is probably best to write some simple test code and see for yourself how big it really is.
Third is execution speed. Again I only know it is slow. I think someone on this forum has posted some executions times, but I don't know where. You can allways do some tests yourself.
Last consider do you REALLY REALLY need floating point? Usually the answer is No. Many beginning programmers think they need floating point when fixed point will do fine. Say you want to display temperatures such as -0.12, +12.34, -123.45, +234.56 degrees. These all fit in a signed long int number with a decimal point crammed in the third to last character. Calculate the temperature in signed long int centi-degrees and then use mod or string functions to put a decimal point where you need it. It saves a lot of time and space over using floating point for the whole calculation.
(See guys, I didn't even mention measuring a supertanker in 24 bit millimeters!) _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
mizi_suichiro
Joined: 23 Mar 2004 Posts: 7
|
|
Posted: Mon Mar 29, 2004 11:31 am |
|
|
in my application, i'll measure a distance between an image blob with the center of the image sensor on the image sensor plane. this will give me an error. the microcontroller with do some control algorithm (PID, phase lead) to give an adequate input to the motor so i can achieve the desired specification (involve with time). when i discuss with my SV, to get precise and good response of the controller for control algorithm, it is a best way to have a floating point microcontroller.
i'm quite blur about the fixed point and floating point actually. as i know, the fixed point involve with integer and floating point have a point number.
hope anyone can give me an idea. thanks. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Mar 29, 2004 12:19 pm |
|
|
Hmm... Sounds like either a star tracker for a telescope or a tracking gunsight. There are probably people on this BBS that have done both. If it is a star tracker things are probably going slow enough that you can use floating point if you have ROM & RAM for it. If it is a gunsight then speed may be an issue. Hopefully someone who has done more with floating point on a PIC will have more relevent experience than I.
Also try to keep your algorithm simple. PID is pretty easy but anything involving SIN(), COS(), or other trig functions may be slow. You may have to use a look-up table. Try to avoid trig on a PIC.
Try looking at the application notes on the Microchip web site. They have a few about PID controllers. The code will likely be in assembly but you can learn a lot from the flow charts. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|