|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Global Constants
I was wondering how I could make a global constant for a trig lookup table.
|
|
#2
|
|||||
|
|||||
|
Re: Global Constants
You can use a #define statement in a globally-included header file to create global constants. You can also use extern to define global variables.
|
|
#3
|
|||
|
|||
|
Re: Global Constants
Quote:
For example: Code:
user_routines.c
#define axelWidth 1234
...
void fn(void)
{
...
x*=axelWidth; //Can it be this?
x*=(int)axelWidth; //Or must it be this?
x=x*(axelWidth); //This seems to be the only form that the compiler likes
...
}
...
Please clarify!!! |
|
#4
|
||||
|
||||
|
Re: Global Constants
Quote:
Beware comparing C++ with C. C has been around since 1974 and has changed very little in all these years. ANSI complient C is a standard and C++ is a different animal. |
|
#5
|
|||||
|
|||||
|
Re: Global Constants
Quote:
Quote:
Last edited by Adam Shapiro : 08-02-2004 at 11:38. |
|
#6
|
|||||
|
|||||
|
Re: Global Constants
If it is in a header, then you can is a const in any file that includes the header
|
|
#7
|
||||
|
||||
|
Re: Global Constants
When I use extern would the variable be placed in user memory? I have 2k of data for the lookup tables in the trig (this is very little for the 32k of rom space available) and don't want to put these non changing variables in the ram. A define doesn't help because this is an actual table containing data not just one macro that can be quickly changed.
|
|
#8
|
|||||
|
|||||
|
Re: Global Constants
Unfortunately the extern will be placed in the user memory so, if there is no other way, you might have to try to minimize your table
. |
|
#9
|
||||
|
||||
|
Re: Global Constants
couldnt you declare the table rom? look in the c18 compiler reference guide, i think you could just declare
Code:
const rom int trig_lookup[] = {/*info here*/}
|
|
#10
|
||||
|
||||
|
Re: Global Constants
Ahhh thank you, it appears that should work out well, now the table won't have to be minimized. Seeings as how I don't have the C Reference available and am not able to attend meetings for now due to Academic problems, would you declare this in the header or the C file?
|
|
#11
|
||||
|
||||
|
Re: Global Constants
you would declare it and define it without extern in one .c file, and declare it extern in all other .c files that you want to use it in.
|
|
#12
|
||||
|
||||
|
Re: Global Constants
Thank you for your time.
|
|
#13
|
|||
|
|||
|
Re: Global Constants
deltacoder already wrote some excellent trig lookup code:
Check the repository: http://nrg.chaosnet.org/repository/i...ral%20C%20Code |
|
#14
|
||||
|
||||
|
Re: Global Constants
note - the code in the repository does not currently utilize the "rom" keyword - it's meant to be compiler/platform independent. I would recommend the addition of the rom and const keywords to the definition of the table array, like so:
const rom unsigned char SIN_LOOKUP[90] |
|
#15
|
||||
|
||||
|
Re: Global Constants
I think my trig code will run fine,
It has a lookup table with 1440 16-bit values and my sine and cosine functions take very little hit to performance. The angle I use is also in 16-bit straight from the gyro which makes this whole thing very high precision which will be increadably useful for the new drive style (Arcade) I developed and hopefully will get to test Wednesday. The reason for so many values is that we have 32k of rom sitting there doing nothing. Infact it would be a much more efficient way to calculate out 8-bit values for your angles and multiply it by a 8-bit number for your hypontenuse then shift right by 8. That essentially does floating point for you without the performance hit. Doing it with 16-bits can be a bit trickier but the same principle applies. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Slightly humorous story about global warming & space explor. | archiver | 2001 | 3 | 24-06-2002 04:01 |
| 'IT' info... | archiver | 2001 | 19 | 24-06-2002 01:58 |