Home/Support/Support Forum/DELAY uS RCM6700
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

DELAY uS RCM6700

0 votes
Hi, how I can make delays about milliseconds (us)? I am using an RCM6700 with Dynamic C 10.72
asked Jan 20, 2015 in Rabbit Software by jcg_perulero New to the Community (2 points)

Please log in or register to answer this question.

4 Answers

+1 vote
I use a small, blocking function for microsecond (us) delays. I specify root so it doesn't get bumped to extended memory where it might run more slowly. Spin(15); gives me about 10 microseconds on an RCM6750.
Code:
/* START FUNCTION DESCRIPTION ************************************************** spin <DCS2_IO.LIB> SYNTAX: void spin (int revs); DESCRIPTION: Variable delay nop loop PARAMETER1: revs, number of times through the loop RETURN VALUE: None SEE ALSO: KEYWORDS: END DESCRIPTION ***************************************************************/ nodebug root void spin (int revs) { int i; for (i=0; i<revs; i++){ #asm nop nop nop #endasm } }
answered Feb 3, 2015 by RonBeck62a New to the Community (19 points)
edited May 8, 2015 by RonBeck62a
+1 vote
You don't have to use costates just to use the DelayMS() function. There is a similar function that can be used outside of costates that is based on the MS_TIMER macro:

void msDelay(unsigned int delay)
{
auto unsigned long done_time;

done_time = MS_TIMER + delay;
while( (long) (MS_TIMER - done_time) < 0 );
}
answered Feb 23, 2015 by trooper2 Veteran of the Digi Community (591 points)
0 votes
I use either a costate or a blocking function, depending on the circumstance, for millisecond (ms) delays. Preferably the multitasking costate so that other processing can happen during the wait:
Code:
costate progress_Task always_on { while (updating) { // update the bar graph until the update reboots waitfor (DelayMs(100)); hBar (3, 0, 159, 0.0, 10000.0, (float) progress); } }

Code:
/* START FUNCTION DESCRIPTION ************************************************** delay_ms <DCS2_IO.LIB> SYNTAX: void delay_ms (long dur); DESCRIPTION: Delay loop PARAMETER1: long dur - number of milliseconds to delay RETURN VALUE: None END DESCRIPTION ***************************************************************/ __nodebug void delay_ms (long dur) { int i; int n =0; while (dur--) for (i=0; i<200; i++) n ^= i; }

The loop length is already tuned for the clock speed of an RCM6750.
answered Feb 3, 2015 by RonBeck62a New to the Community (19 points)
edited May 8, 2015 by RonBeck62a
0 votes
And to delays in microseconds? (us)
answered Nov 29, 2015 by jcg_perulero New to the Community (2 points)
...