Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, May 22, 2015 7:56 AM
Is there way how to do delay in microseconds ?
Now I am doing await Task.Delay(1) but I need 1uS or 50uS wait so 1ms is too much.
All replies (6)
Friday, May 22, 2015 9:08 AM âś…Answered
Hi,
Windows 10 IoT is not a real time operating system like Windows Embedded.
I think it is not possible to have such low delays with Windows 10 IoT.
Sorry for that.
Best Regards. When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer. This helps us build a healthy and positive community.
Friday, May 22, 2015 8:03 AM | 1 vote
With Windows IoT you can't have a so high resolution for your delay ..
I'm sorry but the minimum value is 1 ms.
Paolo.
Paolo Patierno
Sunday, June 14, 2015 2:58 AM | 2 votes
if you're willing to sacrifice one thread for timing, short delays are possible by spinning, I've found.
Others here will tell you that this won't work in cases of testing and VM's, and that it is expensive CPU and power-wise. Therefore, I would only recommend it if absolutely necessary to have delays less than 1mS, needed sporadically, and in cases where CPU load is not an issue.
Until more granular timers are available, or until we have access to some more of the Pi2's functions like hardware timer interrupts, you "could' use:
// really need a way to put this on a specific CPU so we can pick a one to sacrifice for timing
private int WaituS(int uS)
{
int loop_count = 0;
long start_ticks = overall_stopwatch.ElapsedTicks; // ticks are about 1.92Mhz
int ticks_needed = (int) ((double)uS * ((double)sw_frequency / 1000000.0));
while (overall_stopwatch.ElapsedTicks < (start_ticks + ticks_needed))
{
loop_count++;
}
return loop_count;
}
It is ugly, to be sure, but it could solve some very specific problems.
If you really need accurate timing, and/or you're doing a production device, you'll want to put some programmable interrupt source on the SPI, GPIO, etc and then use the GpioPin.ValueChanged event.
Actually, even in *nix it would be the case that "accurate" timing begs for a hardware timer.
Enjoy!
-- me --
Sunday, January 13, 2019 7:07 AM
Sunday, January 13, 2019 9:51 PM | 1 vote
It can be done - but it has to be done in kernel mode in a driver. I've successfully implemented a 50uS delay in a modified SPI driver between an SPI write and a following read.
However, Windows IOT isn't a true real time OS, though you can get close. If you need hard real-time it's better to go to a dedicated microcontroller piggy-backed onto the (for me) Raspberry Pi GPIOs.
Tuesday, January 15, 2019 10:13 PM
Article updated. I measure delay near 100 us delay. I hate kernel mode level 0 since win95-win98-win2k-winXP.