| By Anonymous on Tuesday, July 01, 2003 - 7:54 am: Edit |
I have been trying some of the examples from the forums here on Microsecond timing. I still don't have anything satisfactory working. I just need a simple and accurate microsecond delay function.
ie MicroSecDelay(100)
I'll take what I can get as long as it is accurate for a range of values.
The below code was ripped from another programmers code here at work based off a RCM2020
but when I scoped the signal it was only accurate around 100 microsecond, and way off below and above. Anyone have a better way to do this?
/*void MyUsDelay(unsigned int uiDelay)
{
unsigned int i;
uiDelay /= 11;
for(i=0; i<uiDelay; i++);
}*/
| By Anonymous on Tuesday, July 01, 2003 - 9:30 am: Edit |
Hi.
This is the function I use to do very small waits.
The argument of the function is in units of 550 ns. It uses a simple loop of 11 cycles of clock.
#asm root
mwait::
loop:
dec hl ; (2 cycles)
ld a, h ; 2 "
or l ; 2
jr nz, loop; 5
ret ; (8 cycles)
#endasm
| By Anonymous on Tuesday, July 01, 2003 - 12:18 pm: Edit |
Is this fixed time?
Sorry for my assembly ignorance...how do I call this code from Dynamic C as a function with a time argument? Thx, G
| By Moderator2 (Moderator2) on Tuesday, July 01, 2003 - 2:20 pm: Edit |
Hi,
You may also look at the post below. It uses timer b to generate a periodic interrupt.
http://www.rabbit.com/support/bb/messages/14/1913.html?1010690060
| By Anonymous on Tuesday, July 01, 2003 - 11:40 pm: Edit |
Sorry, I forgot to add the declaration:
extern void mwait(int u550);
Perhaps it is now a little bit clear?
You can use mwait() directly:
- Add the declaration and the #asm / #endasm block to your source
- call mwait() like any other C function, with a int (16 bit) argument, like any other C function.
Sample:
for a 55 microsecond pause:
mwait(100); // 100 * 550 ns = 55 us
Remember, the units of the arguments are "550 ns".