|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Floats
Quote:
That kind of deflates my entire argument. Never mind... ![]() |
|
#2
|
||||
|
||||
|
Re: Floats
Steven,
To expand for the benefit of other interested viewers, I thought I'd chime in... I am entirely in agreement with Dave, Dave and Tristan on this issue. Never use floating point... Let’s look at a sin function. According to Microchip application note AN660, the math library “sin” function has a performance of 4030 (minimum) to 6121 (maximum) machine cycles. Note: This data is for the PIC16 family. I could not find PIC18 data but I expect it is similar. As my fixed point integer representation, I choose 0x0400 = 360 degrees for my integer variable “theta”. This is a granularity of about 1/3 of a degree (I dare you to argue that you need more. A table of integers (0x4000 = 1.000) is generated in Excel for the 1024 data points required and included into the code as a rom const int array named sine_table (2K of program memory used). The statement sine = sine_table [theta]; executes in 15 machine cycles. Note that you get cos just as easy from the same array: cosine = sine_table [(theta + 0x0100) % 0x0400]; If using 2K of program space bothers you, you can use various math techniques such as a Taylor series expansion (see this thread for a discussion). Regards, Mike Post Script: I never saw Seth's last question in the above link until just now... Code:
// sine_table is an array of 1024 2FX14 integers where 0x4000 = 1.0 and 0xC000 = -1.0
// sine.csv is a slightly modified "comma separated variable" file created by Excel.
// The declaration "rom const" causes this array to exist in the PIC program space.
rom const int sine_table[DEG_360] =
{
#include "sine.csv"
};
Sorry for not responding sooner Seth... - Mike |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Favorite Monty Python Sketch/Movie | Joe Matt | Chit-Chat | 47 | 30-03-2004 21:45 |
| EduCAD and Arrays!!!!! | Sachiel7 | Programming | 14 | 03-11-2003 03:21 |
| Exponenets and floats | Jonbca | Programming | 4 | 31-01-2003 08:28 |