Thread: loop problems
View Single Post
  #6   Spotlight this post!  
Unread 09-02-2006, 14:36
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: loop problems

Quote:
Originally Posted by Dave Scheck
Max

You can try something like this to set the pwm value to 127 after 30 loops:
Code:
void pulse(void)
{
  static int loop_count = 0;
  if(loop_count < 30)
  {
    pwm06 = 254;
  }
  else
  {
    pwm06 = 127;
  }
  loop_count++;
}
Then, you would want to call this in your main loop. Note that this method never resets loop_count, so this would run for 30 loops at 254 and then stop.
As Dave said.. when you want to keep track of how many times something has looped, use a counter variable. You should try to stay away from while and for loops in your code. Even when you are in your Default Routine, you are still nested within a while loop that will execute the default routine 39 times per second.