Go to Post Mastering simple skills can be a complex challenge. - Petey [more]
Home
Go Back   Chief Delphi > Other > VEX
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-11-2006, 04:24
Guy_E Guy_E is offline
Registered User
FRC #1574 (MisCar)
Team Role: Leadership
 
Join Date: Mar 2006
Rookie Year: 2006
Location: ISRAEL
Posts: 81
Guy_E has a spectacular aura aboutGuy_E has a spectacular aura about
Send a message via MSN to Guy_E
While loops

Hi,
I tried today to use while loops in my program. The code was compiled noramlly, but after I downloaded the program the program state LED was blinking and the controller seemed to be stuck. the problem is the while loop for sure.

I know that a while loop is included in the main function, but can it be used somewhere else?

thanks,

Guy

P.S.

Im programming using MPLAB
__________________
Team #1574 Misgav High School - Israel

Winner of the 2007 Israeli Regional

Winner of the 2007 Motorola Quality in Design Award

Visit our website:
www.miscar1574.com
Reply With Quote
  #2   Spotlight this post!  
Unread 01-11-2006, 06:46
Imajie Imajie is offline
Registered User
AKA: James Letendre
FRC #0195 (Cyber Knights)
Team Role: Electrical
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Southington
Posts: 114
Imajie has much to be proud ofImajie has much to be proud ofImajie has much to be proud ofImajie has much to be proud ofImajie has much to be proud ofImajie has much to be proud ofImajie has much to be proud ofImajie has much to be proud of
Send a message via AIM to Imajie
Re: While loops

I don't know if this applies to the vex controller too, but the RC gives an error if the code loop takes too long to finish, this may be your problem.
__________________
2007 UTC Champions Thanks 1124 and 558
2007 UTC GM Industrial Design Award

2006 Newton Divisional Winners
2006 Championship finalists
(Thanks 25 and 968 for picking us!)
2006 National Innovation in Control
Reply With Quote
  #3   Spotlight this post!  
Unread 01-11-2006, 06:55
Timothy D. Ginn's Avatar
Timothy D. Ginn Timothy D. Ginn is offline
I check here maybe once a year.
no team
 
Join Date: Apr 2003
Rookie Year: 2002
Location: Port Perry, ON. Canada
Posts: 247
Timothy D. Ginn is a name known to allTimothy D. Ginn is a name known to allTimothy D. Ginn is a name known to allTimothy D. Ginn is a name known to allTimothy D. Ginn is a name known to allTimothy D. Ginn is a name known to all
Send a message via ICQ to Timothy D. Ginn Send a message via AIM to Timothy D. Ginn Send a message via MSN to Timothy D. Ginn Send a message via Yahoo to Timothy D. Ginn
Re: While loops

This really depends on what the while loop does. If it's say, something to the effect of:

Code:
int i = 0;
while(i < 10) {
  i++;
}
then certainly you can do it. If, instead you're doing something relying on external sensors/states. For example, in pseudo code:

Code:
while(button is pushed) {
  do stuff
}
then you won't get anywhere because whether or not the button is pushed isn't going to be updated within your function (that updating in some of the FIRST-provided code which you don't need to and shouldn't modify; but, if you're curious you can look). If your code doesn't let the program flow continue to the FIRST-code which updates buttons you just won't have the new status of the button being pushed (and as a result you'll be stuck).

It's probably worth noting that your user code is already in a big while loop (the one you rightly pointed out is in the main function) and as a result already will be called repetitively.
__________________
Alumni of FRC Team 1006
Former mentor of Full Lego Alchemist (FLL 5621) - Sempar School / Computing Students' Association of Queen's University
Reply With Quote
  #4   Spotlight this post!  
Unread 01-11-2006, 11:28
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: While loops

Something else to note:

The RC does some processing each loop that lets it know that it's still alive. If it doesn't get to that processing in a timely manner (i.e. if you're in a tight loop), the master processor in the RC generate a code error. If you're not familiar with this process, it's referred to as a watchdog timeout.

I would suggest reevaluating why you're using a while loop in your RC code. If you're looping over a small amount of data (like a lookup table) you should be fine, but if you're doing serious data processing in the loop you may want to find an alternate way to perform the same task. As Timothy mentioned, there's already a loop within the RC code. Can you leverage that?
Reply With Quote
  #5   Spotlight this post!  
Unread 01-11-2006, 13:04
Guy_E Guy_E is offline
Registered User
FRC #1574 (MisCar)
Team Role: Leadership
 
Join Date: Mar 2006
Rookie Year: 2006
Location: ISRAEL
Posts: 81
Guy_E has a spectacular aura aboutGuy_E has a spectacular aura about
Send a message via MSN to Guy_E
Re: While loops

How come that while loops are a possible option in EasyC but not in MPLAB?
The while loops I had was quiet basic. I wanted to do some heavy calculation in the while loop, but I guess I'll have to change it with SWITCH and IF statements.
__________________
Team #1574 Misgav High School - Israel

Winner of the 2007 Israeli Regional

Winner of the 2007 Motorola Quality in Design Award

Visit our website:
www.miscar1574.com
Reply With Quote
  #6   Spotlight this post!  
Unread 01-11-2006, 15:35
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: While loops

Quote:
Originally Posted by Guy_E
How come that while loops are a possible option in EasyC but not in MPLAB?
It all depends on the complexity of the program. If you're not doing much, while loops can work. It's when you start hogging the processesor that you run into problems. My guess is that you had a relatively small program with your EasyC, but somthing that's a little more complex now.
Reply With Quote
  #7   Spotlight this post!  
Unread 01-11-2006, 22:04
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: While loops

Easy C uses a timer interrupt to do getData and putData.

In MPLAB getData and putData are called from the "main" while loop. If you code an inner while loop which does not call getData and putData, the error light will flash.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
POLL: control loops Rickertsen2 Programming 2 28-10-2004 20:32
loops inside of subs??? manodrum Programming 4 19-02-2003 20:05
Solution to Timing Loops Steven Carmain Programming 39 10-02-2003 13:33
PID Control Loops ttedrow Programming 7 05-12-2002 12:03
Programming Loops Mike o. Programming 5 26-03-2002 11:24


All times are GMT -5. The time now is 03:59.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi