This may sound silly, but is there a command that I can use in C-Prog on CCS to introduce delay in Cycles or Secs?
I tried finding it through CCS help but could not find it.
-Rgds
Vallabha
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
This may sound silly, but is there a command that I can use in C-Prog on CCS to introduce delay in Cycles or Secs?
I tried finding it through CCS help but could not find it.
-Rgds
Vallabha
Are you looking for something like a sleep() function? I do not believe there is anything like this built into the run-time support libary, it is easy to create your own. Try something like this:
void sleepFunc(int delay){
int count;
for(count = 0; count < delay; count++);
}
void sleepFunc(int delay){
int count;
for(count = 0; count < delay; count++);
}
Regards,
Venu
TimHarron said:Are you looking for something like a sleep() function? I do not believe there is anything like this built into the run-time support libary, it is easy to create your own. Try something like this:
void sleepFunc(int delay){
int count;
for(count = 0; count < delay; count++);
}
If you wanted to you could tweak this function and figure out how many iterations equals a standard unit of time (for example, maybe 10000 iterations is equal to 1ms). This would mean the number passed in the argument equals the amount of time that would pass before exiting.
NOTE that some of the EVMs may include some sort of wait function in the Board Support Library (BSL). For example, the DM6437 BSL includes a wait function inside the evmdm6437.c file. [/quote]As Venu suggested with full compiler optimization the said piece of code may not work. I have tried using similar dummy code to introduce delay but the delay produced is not consistent.
If you want consistent code then create a small library with just this function in it. That way it is not recompiled every time you build your code and it can have its own static build options (probably with optimization turned off). Alternately you could put this function in its own C file and simply specify file-specific options instead, but this will also leave it open to recompilation everytime you build.Vallabha said:As Venu suggested with full compiler optimization the said piece of code may not work. I have tried using similar dummy code to introduce delay but the delay produced is not consistent.
I believe if you define count as volatile you will avoid the optimizing out of the loop code.
As a side note if you use DSP/BIOS within CCS there is a TSK_sleep function that you can use to delay a task for a specified amount of time in system ticks, allowing other tasks to run while your delayed task is sleeping. This is shown on page 541 of SPRU403.