Quote:
|
Originally Posted by Pattyta
does any one knows how to convert the cycles of the autonomous mode 26.2ms to like actual seconds to keep a counter in seconds???
|
Here's the simple solution I used to keep track of milliseconds.
Code:
#define MS *4
void User_Autonomous_Code(void)
{
unsigned int clicks; /* 4000 clicks per second theoretical, 4007.63358779 clicks actual :-) */
clicks = 0;
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! */
if (clicks < 16000 MS)
clicks += 105; /* 26.2 more milliseconds have elapsed, this count will be fast by just over 0.19% */
else
clicks = 16000 MS; /* peg at 16 seconds */
/* Add your own autonomous code here. */
User_Mode_byte = clicks/400;
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}
I complicated things slightly by using four "clicks" per millisecond. In the normal case of autonomous operation, the unsigned int will not overflow, but I limited it to 16 seconds anyway. Defining
MS as a modifier was just a convenience so the other programmer could use "real" times while deciding when the program should take action.
The User_Mode_byte on the OI counts in tenths of a second while the autonomous function is running.