View Single Post
  #5   Spotlight this post!  
Unread 04-08-2010, 16:44
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,795
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Delay10KTCYx in C18

That looks good.
Yes, I was just showing an elaboration on what Foster told you. Instead of the Case statement you can use If statements like you did.

The only way the loop will take longer than 18.5ms is if the code you add takes more than 18.5ms to execute and slows everything down so you don't get to the "if (statusflag.NEW_SPI_DATA)" statement in time. That would take an intense time-consuming internal loop, not the sets and checks you're doing.

For a simple Wait just duplicate the structure you already recognize. You want to repeat all the work that routine does, so the system doesn't lockup while you wait.
I just dashed this off and haven't checked it, but this is the general idea using what you've already learned. You'd add something like this before User_Autonomous_Code.
Code:
void My_Wait(int milliseconds)
{
  int elapsedtime=0;  // in increments of 18.5ms
  int elapsedcount=0;  // in units of 18.5ms
 
  while((elapsedtime < milliseconds) & autonomous_mode)  // also quit if Auto mode happens to end
  {
    if (statusflag.NEW_SPI_DATA)      /* 18.5ms loop area */
    {
      elapsedcount++;
      elapsedtime = elapsedcount * 185 / 10; //the Vex PIC processor doesn't have floating point
      Getdata(&rxdata); // tells us when Auto Mode is over
      Putdata(&txdata); // Lets the master controller know we're alive and well
    }
  }
}
And then in User_Autonomous_Code you can do something like this:
pwm02 = 100;
pwm03 = 155;
My_Wait(5000);
pwm02 = 127;
pwm03 = 127;
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 04-08-2010 at 20:17.