View Single Post
  #2   Spotlight this post!  
Unread 30-03-2004, 16:31
MikeDubreuil's Avatar
MikeDubreuil MikeDubreuil is offline
Carpe diem
FRC #0125 (Nu-Trons)
Team Role: Engineer
 
Join Date: Jan 2003
Rookie Year: 1999
Location: Boston, MA
Posts: 967
MikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond repute
Send a message via AIM to MikeDubreuil
Re: counting in seconds for the autonomous mode??

Here's some code I wrote that we never used. Basicly, you follow the table and it shows you how many ticks or loops is equal to X number of seconds. You set the timer by calling auton_timer_1_start(), pass the number of ticks (loops) it should wait. In your code you can check if the time has passed by using something like this:

Code:
if (auton_timer_1()) {
     // Time has been reached
} else {
     // Still cycling, time has not been reached
}
Let me know if you don't understand anything. Here's the code:

Code:
// Start prototypes
unsigned char auton_timer_1();
void auton_timer_1_start(unsigned int time);
// End Prototypes

// Variables needed
unsigned int auton_timer_1_current = 0;	// Is updated every 26.2ms loop when using timer 1
unsigned int auton_timer_1_limit = 0;	// Is the time limit, which gets set by auton_timer_1_start()
// Done with variables

/* ################################ Start Timer Table ########################
			1s/26.2ms =~ 38 ticks/s
I.E: If you want a 1 second timer, you must set the timer for 38 ticks.
		-= Seconds =-	-= Ticks =-
		0.25			10
		0.50			19
		0.75			29
		1.00			38
		1.25			48
		1.50			57
		1.75			67								
		2.00			76	
		2.25			86
		2.50			95
		2.75			105
		3.00			115
		3.25			124
		3.50			134
		3.75			143
		4.00			153
		4.25			162
		4.50			172
		4.75			181
		5.00			191

 ############################### End Timer Table ################ */


/* ******************************************************************************
* FUNCTION NAME: auton_timer_1_start
* PURPOSE:       Set and start timer 1
* CALLED FROM:   anywhere
* ARGUMENTS:     time limit (unsigned int)
* RETURNS:       void
****************************************************************************** */

	void auton_timer_1_start(unsigned int time) {
		auton_timer_1_current = 0;
		auton_timer_1_limit = time;
	return;
	}



/* ******************************************************************************
* FUNCTION NAME: auton_timer_1
* PURPOSE:       Checks timer 1 to see if limit has been reached.
* CALLED FROM:   anywhere
* ARGUMENTS:     none
* RETURNS:       TRUE if limit has been reached, FALSE if time has not expired
****************************************************************************** */

	unsigned char auton_timer_1(void) {
		++auton_timer_1_current;
		if (auton_timer_1_current >= auton_timer_1_limit) {
			return 1;
		} else {
			return 0;
		}
	}

Last edited by MikeDubreuil : 30-03-2004 at 16:34.