View Single Post
  #41   Spotlight this post!  
Unread 01-01-2005, 11:24
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

I was reading about extern and static variables. I realize that it's considered bad coding technique to declare extern variables, because they are declared outside functions. however, I need this variable available to interrupts.c and user_routines_fast.c. however, I only want this variable to have its value assigned once. where should I place a variable that can be used in both these files, and have the variables value (unsigned int phase = 1000) assigned only once. I did search on google, but it doesn't exactly tell me about how the structure of the default code is set up to work with and where to put such a variable so it will be available to these particular files.
by the way, the purpose of the variable, is so when interrupt #1 fires, 1 is added to its value, and when interrupt #2 fires, 1 is subtracted from its value. the reason it needs to be available to user_routines_fast.c, is because that is where I want to place my functions, as it would be confusing to have the interrupts.c file running a function controlling the robot and a function in user_routines_fast.c controlling the robot as well.
thanks a lot,
Stephen.