Thread: Delay Function
View Single Post
  #3   Spotlight this post!  
Unread 21-02-2007, 12:38
tdlrali tdlrali is offline
Registered User
FRC #0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Sep 2006
Rookie Year: 2006
Location: MI
Posts: 377
tdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud of
Re: Delay Function

"Stalling" execution is generally a bad idea. I would make a "loopcounter" variable, and increase the counter every time the function runs. After a certain number of loops, make it do the next thing.

For example, here's our pump code:
Code:
void pump_routine(void) {

	static unsigned int loops = 0;   <--- Loop Counter

	if(BTN_PUMP_DISABLE) {

		if(DIGIN_PUMP_PRESSURE_SWITCH && loops>10) { <-- If more than ten loops have passed

			RLY_PUMP_ON = 0;

		}

		else if(DIGIN_PUMP_PRESSURE_SWITCH) {

			loops++; <-- Increase loop counter

			RLY_PUMP_ON = 1;

		}

		else {

			loops = 0;

			RLY_PUMP_ON = 1;

		}

	}

	else {

		RLY_PUMP_ON = 0;

		loops = 0;

	}

	RLY_PUMP_NUL = 0;

}