Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Sleep In Microseconds


  • Please log in to reply
6 replies to this topic

#1 bryce007

bryce007

    New Member

  • Members
  • Pip
  • 5 posts

Posted 08 May 2011 - 10:40 PM

HI guys, I'm relatively new to coding the netduino, and im stuck trying to find a way to get the netduino to wait or sleep a thread in microsecond timing.. best you can do with thread.sleep is milliseconds. Is there a way to perform this task? I dont need it to be super accurate +-50 microseconds is ok. The lowest time i would need is 500 microseconds. (0.5ms). Is this possible with the netduino? As some threads i've read state that it is not possible with the current .net MF?

#2 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 09 May 2011 - 12:42 AM

Welcome to the community :) Yes try this Thread.Sleep(500); for 500ms or Thread.Sleep(Timeout.Infinite); for a tad longer :) And the main problem is with the garbage collector that kicks in ... I don't remember how long it can take in some instance.
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#3 bryce007

bryce007

    New Member

  • Members
  • Pip
  • 5 posts

Posted 09 May 2011 - 01:03 AM

Thanks Michel, However, my problem is trying to get it to microsecond accuracy, ie i need to be able to sleep for 500us = 0.5milliseconds, and the sleep function rounds to the whole integer. (you cannot do thread.sleep(0.5))

#4 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 09 May 2011 - 01:19 AM

my problem is trying to get it to microsecond accuracy

Sorry, I missread it ...
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 09 May 2011 - 03:50 AM

Bryce, the delay that you are looking for is on the mining-area, because the MF+Netduino are pretty slow, even to perform simple operations.
Anyway, you may try this trick:

class Program
{
  private static readonly long DelayTicks = 500*10; //#ticks for 500us

  private void MyWork()
  {

    // ... your stuffs ...

    long ticks = Utility.GetMachineTime().Ticks;
    while ((Utility.GetMachineTime().Ticks - ticks) < DelayTicks);

    // ... your stuffs ...

}

NOTE: I am *NOT* sure that is working fine for a so small delay, but I ma sure is working fine for longer delays (>10ms). In my case I have added a Thread.Sleep(1) within the "while"-loop.

Anyway, you should expect a considerable jitter on the nominal delay, that could be even +200%: that is unpredictable.

Tips:
avoid placing the delay procedure on a separate function, because the method calling is taking a
  • lot of time (relatively to a so short delay);
  • I have declared the delay as static, to avoid re-instantiation every time;
  • I am not sure that using "long" instead of "TimeSpan" would be faster: you may try using it instead.
Cheers
Biggest fault of Netduino? It runs by electricity.

#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 09 May 2011 - 07:27 AM

I dont need it to be super accurate +-50 microseconds is ok. The lowest time i would need is 500 microseconds. (0.5ms).

Could you please share more details on what exactly you are trying to do? In addition to what Mario mentioned, there are some tricks that could be used in certain cases...

#7 georgejh

georgejh

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts
  • LocationGlasgow, UK

Posted 09 May 2011 - 11:34 AM

I have the same problem. Last update on the subject I had is:


Posted 12 January 2011 - 09:02 PM
public/style_images/master/snapback.pnggeorgejh, on 12 January 2011 - 04:20 PM, said:
Is it possible and how can PWM be generated at 1 microsecond or less (1MHz+)?


Possible with a firmware update. We're working with Microsoft on a new "unified" PWM design for .NET MF, and will be trying to bring this ".NET MF 4.2" feature to Netduino early. Hopefully soon, but not yet.

Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.