View Single Post
  #1   Spotlight this post!  
Unread 04-01-2005, 13:52
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Rewriting main loop

I want to rewrite the main loop so that the program enters one of the two possible 26.2ms loop functions (User_Autonomous_Code() and Process_Data_From_Master_uP()) from the same place in the code. As it is, when the code enters autonomous mode, it stays in User_Autonomous_Code() until autonomous mode is unset. The main reason I'd like to change this is so that I can have a single counter counting 26.2ms cycles, rather than one in each function. Secondly, its much more logical to do it this way.

I tried to implement my method, but I get some inexplicable problem where User_Initialization() (which should be called prior to any of my changes) is not getting called, and consequently, the rest of the program cannot run. Does the master processor detect my changes and decide they are illegal or something? Why is the code written like this in the first place?

The changes I made:

in main.c replace

Code:
    while (1)   /* This loop will repeat indefinitely. */
    {
  #ifdef _SIMULATOR
  	statusflag.NEW_SPI_DATA = 1;
  #endif
  
  	if (statusflag.NEW_SPI_DATA)	  /* 26.2ms loop area */
 {								 /* I'm slow! I only execute every 26.2ms because */
 									 /* that's how fast the Master uP gives me data. */
  	  Process_Data_From_Master_uP();  /* You edit this in user_routines.c */
  
  	  if (autonomous_mode)		    /* DO NOT CHANGE! */
  	  {
 	 User_Autonomous_Code();		/* You edit this in user_routines_fast.c */
  	  }
  	}
  	Process_Data_From_Local_IO();	 /* You edit this in user_routines_fast.c */
 									 /* I'm fast! I execute during every loop.*/
    } /* while (1) */
  }  /* END of Main */
with

Code:
     while (1)   /* This loop will repeat indefinitely. */
     {
   #ifdef _SIMULATOR
   	statusflag.NEW_SPI_DATA = 1;
   #endif
   
   	if (statusflag.NEW_SPI_DATA)	  /* 26.2ms loop area */
 {								 /* I'm slow! I only execute every 26.2ms because */
 									 /* that's how fast the Master uP gives me data. */
   		/* You edit this in user_routines.c */
   
   	  if (autonomous_mode)		    /* DO NOT CHANGE! */
   	  {
 	 User_Autonomous_Code();		/* You edit this in user_routines_fast.c */
   	  }
   	  else
   	  {
   		Process_Data_From_Master_uP();
   	  }
   /*counter++; can go here*/
   	}
   	Process_Data_From_Local_IO();	 /* You edit this in user_routines_fast.c */
 									 /* I'm fast! I execute during every loop.*/
     } /* while (1) */
   }  /* END of Main */
In user_routines_fast.c replace

Code:
  while (autonomous_mode)   /* DO NOT CHANGE! */
     {
   	if (statusflag.NEW_SPI_DATA)	  /* 26.2ms loop area */
   	{
   	    Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */
   
   		/* Add your own autonomous code here. */
   
   
   
   		Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
   
   	    Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
   	}
     }
with

Code:
   	    Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */
   	    Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award

Last edited by Max Lobovsky : 04-01-2005 at 13:55.