Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Delay (http://www.chiefdelphi.com/forums/showthread.php?t=61911)

jasonpeinko 17-01-2008 18:38

Delay
 
is there a code for a delay command for c?

i_am_samus 17-01-2008 18:41

Re: Delay
 
You could start up a counter and use the counter to tell the robot to do certain things at a certain time (remember the code loops every 26. something milliseconds).

Unfortunately, as far as I know, there is no delay function.

whitetiger0990 17-01-2008 21:59

Re: Delay
 
There are timer interrupts (which, sorry, I'm unsure how to use). But for most applications you rarely need any more resolution than 26.2ms. It's pretty much constant from loop to loop.

taggartbg 18-01-2008 01:06

Re: Delay
 
Wait(x);

x being the number of milliseconds. Thus, if you want the code to pause for 3 seconds, you type "Wait(3000);"

windell747 18-01-2008 06:17

Re: Delay
 
Where did you find reference to the "Wait" command? Did you find it in a manual. I'm trying to find a reference to all these kinds of functions?

Roger 18-01-2008 07:49

Re: Delay
 
I believe Wait(n) is in EasyC, not in mplab. The two operate much differently in this respect.

In mplab you don't want a command like wait 3 seconds inside your code. The code needs to do it's own paperwork every loop. You can use a counter variable like i_am_samus suggests. Here's my note to myself in the code:
Code:

//  timer notes:
//
//  The autonomous code functions are called by the controller
//  every 26.2 mS (milliseconds), or 38.17 times each second.
//  For calculations we will use 38 times per second.
//  The total length of Autonomous Mode is 15 seconds,
//  or  570 counts total (or exactly 572.55 counts).

(I'm willing to be corrected if this isn't right.)

As I recall from other places here at CD, the counter variable method isn't exact but is close enough.

ay2b 18-01-2008 11:48

Re: Delay
 
If you're using MPLAB and last year's code, you should have a "delay.h" file (partially copied here). If you're using this year's code, some of these functions appear to be
called, but from an unused code block, and the file "delay.h" is gone. Perhaps Kevin can shed more light on this?

Code:

/* PIC 17Cxxx and 18Cxxx cycle-count delay routines.
 *
 *  Functions:
 *              Delay1TCY()
 *              Delay10TCY()  // 17Cxx only
 *              Delay10TCYx()
 *              Delay100TCYx()
 *              Delay1KTCYx()
 *              Delay10KTCYx()
 */


wireties 18-01-2008 15:11

Re: Delay
 
You can setup one of the timers and increment an integer in the interrupt routine (more accurate and adjustable period) or increment a counter variable in the default functions (fixed period but easier to implement and only works when OI is talking to the robot). Spinning a loop to get a delay is a bad idea in this application. The "paperwork" referred to in this post is the processing of messages to and from the operator interface controller. If you start missing those messages or not replying in a timely manner, the master game controller will disable your robot for the duration of the match.

Update: A simple spin to create usec type delays is OK but don't spin for a long time relative to the cycle of the main loop (~23ms).

Alan Anderson 18-01-2008 15:56

Re: Delay
 
Quote:

Originally Posted by jasonpeinko (Post 680355)
is there a code for a delay command for c?

There are several ways to implement delays in software for FRC robots. The best advice for how to do it in your case will depend on why you want a delay. What do you intend to use it for? The more specific you can be, the more helpful an answer you will get.


All times are GMT -5. The time now is 13:45.

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