Ok, you'll need two global variables (put them in user_routines_fast.c, or something):
Code:
Code:
unsigned int delay_count = 0;
unsigned int delay_constant = 0;
enum {PROGRAM_RUNNING, PROGRAM_DELAY} program_state = PROGRAM_RUNNING;
Have a function:
Code:
Code:
void delay(unsigned int count)
{
if (!delay_constant) {
delay_constant = count;
delay_count = 0;
program_state = PROGRAM_DELAY;
}
if (delay_count >= delay_constant) {
delay_constant = delay_count = 0;
program_state = PROGRAM_RUNNING;
} else {
delay_count += 26;
}
}
This function should be called something like this: (in user_routines_fast.c)
Code:
Code:
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */
if (PROGRAM_RUNNING == program_state) {
/* Add your own autonomous code here. */
} else {
delay(0);
}
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
Now, anytime you want to set a delay, simply have a call to delay(milliseconds) somewhere in the autonomous code.
Most of this might not compile.
.. A certain programmer on my team who is unnamed is tooo shy to post this himself! ;D