View Single Post
  #3   Spotlight this post!  
Unread 17-02-2005, 18:28
Orborde Orborde is offline
Registered User
FRC #1747
Team Role: Mentor
 
Join Date: Apr 2004
Rookie Year: 2003
Location: Indianapolis, IN
Posts: 44
Orborde has a spectacular aura aboutOrborde has a spectacular aura about
Send a message via AIM to Orborde
Re: Global Struct Arrays and Interrupts

First of all, thanks for taking the time to sort out my twisted English syntax.

Quote:
Originally Posted by Astronouth7303
That's 5 questions.

In order: Yes. The former. Not necessary. No.
Um...you contradicted yourself.
Question 1: My question, then, is whether I need to disable interrupts when I want to write to goal_velocity?
Your Answer: "Yes"
Question 4 (or 5?): Or is it imperative that I disable interrupts before reading/writing goal_velocity?
Your Answer: "No."

Quote:
Volatile only means that the value cannot be "cached" by the processor. The compiler will assume that the value will change every time you use it.
So I assume that this applies to the components of the array pointed to by "motors" and not merely the value of the pointer variable "motors"?







Quote:
Easy. You make a header that contains the macros. In the same header, add the following code:
-blah-
I moved the following to the header file (which is #included in the C file that the code is in...)
Code:
extern volatile drivemotor motors[NUM_MOTORS] = {
  {&drive1, 0, 0, 0, 0, 0},
  {&drive2, 0, 0, 0, 0, 0},
  {&drive3, 0, 0, 0, 0, 0},
  {&drive4, 0, 0, 0, 0, 0}
};
and got this:
Code:
C:\mcc18\pidexp\drivereg.c:140:Fatal [151] -internal- populateExternalReferences() - symbol 'motors' is not an external reference.
The line it refers to is:
Code:
void set_motor(int motor, int goal) {
      motors[motor].goal_velocity = goal; // this line
}
Theoretically this function shouldn't exist, but when it is commented out, I get the same thing on
Code:
Motor_Ints_Enable();
(huh?)
and, when I comment that out, I get it here:
Code:
motor_gains[a].kd * (motors[a].error_current - motors[a].error_last));
and so I have stopped commenting things out like that.
Help?



To clarify the functionality of the original motors struct and array: Only the element "ticks" of the struct is touched at all by the interrupt routine (the interrupt uses "motors[0].ticks++;" or similar). No other variable in the struct is explicitly accessed. As stated, the question was whether I need to shut off interrupts if I want to assign goal_velocity a value.

Thanks again for the help. Maybe if I'm lucky this will work someday...

Last edited by Orborde : 17-02-2005 at 18:32.