|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
|||||
|
|||||
|
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++;
}
Code:
while(button is pushed) {
do stuff
}
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. |
|
#4
|
||||
|
||||
|
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? |
|
#5
|
||||
|
||||
|
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. |
|
#6
|
||||
|
||||
|
Re: While loops
Quote:
|
|
#7
|
|||
|
|||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |