|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Delay
is there a code for a delay command for c?
|
|
#2
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
|||
|
|||
|
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);" |
|
#5
|
|||
|
|||
|
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?
|
|
#6
|
|||
|
|||
|
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). As I recall from other places here at CD, the counter variable method isn't exact but is close enough. |
|
#7
|
||||
|
||||
|
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() */ |
|
#8
|
||||
|
||||
|
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). Last edited by wireties : 18-01-2008 at 15:14. |
|
#9
|
|||||
|
|||||
|
Re: Delay
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| pwm signal delay | 3dude_2231 | Programming | 14 | 05-10-2007 20:08 |
| Delay Function | Slick | Programming | 6 | 01-03-2007 22:56 |
| Delay Help! | waiakea2024 | Programming | 7 | 21-02-2007 12:41 |
| NERDS Delay... | Andy Grady | General Forum | 21 | 14-03-2006 21:52 |
| Delay | Gal Longin | Programming | 1 | 09-12-2004 10:37 |