|
#2
|
||||
|
||||
|
Re: Timers and Such
Quote:
You have full control over the code that gets installed in the user processor. The good news is that you can do pretty much whatever you want. The bad news is, you can do pretty much whatever you want. It appears that you are probably wanting to do this for autonomous mode, but the same thing will work for both. Structure your code so that it is state driven and always exits. Whether in autonomous or teleoperated, setup your statemachine code to run every SPIData receive event (~38Hz). You can then setup timer's like this: Code:
if (TimerDrive) { // if timer running
if (!(--TimerDrive)) { // decrement one tick, and when it hits zero
// do whatever you need to do to advance to the next step in your state machine
}
}
if (TimerSomethingElse) { // if timer running
if (!(TimerSomethingElse)) { // decrement one tick, and when it hits zero
// do something else
}
}
If you really do want to impliment a sleep function, and if this is for autonomous, keep in mind how the default autonomous mode software is structured, and make sure you'll exit at the proper time... in other words, you'll probably need to sprinkle tests at each step along the way. That said, to impliment a sleep function, I'd suggest setting up one of the unused hardware timers to interrupt and reload at rate equal to whatever you need your timer resolution to be, say 100ms. In the interrupt service routine, in addition to servicing the interrupt, do this: Code:
if (TimerSleep) {
--TimerSleep;
}
Then your sleep function can be setup like this: Code:
volatile unsigned char TimerSleep;
void Sleep(unsigned char timer) {
TimerSleep = timer;
while (TimerSleep);
}
If you need more than 8 bits of dynamic range for your timer and move up to a 16 or 32 bit value, then you should disable interrupts, move the TimerSleep variable into a local temp, re-enable interrupts, test the local variable, and loop until it times out. The protection is necessary because the interrupt routine would update one byte of the variable at a time, and it creates a critical region for your foreground test. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Descriptions and such in image threads? | Billfred | CD Forum Support | 5 | 06-06-2005 10:01 |
| Inventor skins and such | Pat Roche | Inventor | 0 | 18-05-2004 22:46 |
| Careers related to Animation and such.. | Ryan Dognaux | Career | 8 | 04-02-2003 21:44 |
| Careers related to Animation and such.. | Ryan Dognaux | Computer Graphics | 0 | 03-02-2003 15:54 |
| Thank You's and such | Chris Hibner | Thanks and/or Congrats | 0 | 01-05-2002 08:54 |