View Single Post
  #32   Spotlight this post!  
Unread 04-01-2005, 10:17
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
I've been using Kevin Watson's interrupt template code. I want to have a variable increment every time the interrupt fires. that's not a problem. however, is there a static variable type available that I can use between files? I'm not aware of such a thing. also, does the code in interrupts.c execute first, or the code in user_routines_fast.c go first? this affects whether I use the interrupts.c file to handle the motor speed or the user_routines_fast.c file to handle the speed of the motor. if the user routines file comes second, that would be the case where I need the variable. I'm willing to bet there's an easier way, but this is what I've come up with so far. I would use Kevin's template for encoders but it supports two encoders for the wheels, when I want to use the one we already have set up on digitals 1 and 2 with one motor. we'll probably have to use his eventually on the wheels in addition to this encoder.
thanks,
Stephen.
Declare the variable you want to share between files in a header file with the "extern" storage specifier. For example:

extern unsigned char MyVar;

In a source file that includes the header, define the actual variable:

unsigned char MyVar;

Any source files that use the header now have access to MyVar. I would declare all of your shared variables in one header file and define them all in one source file. To use them you just include the header in the source files where needed. Something like "sharedvars.h" and "sharedvars.c".