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

Time resolution


  • Please log in to reply
3 replies to this topic

#1 BenT

BenT

    New Member

  • Members
  • Pip
  • 1 posts

Posted 01 November 2012 - 06:24 AM

I have developed a new programming using .NET Micro Framework 4.1 and I need to obtain a higher time resolution than a millisecond. As I'm going to make the LED by blinking it really fast. When I use Thread.Sleep(), it takes a number of milliseconds. OutputPort ledOnboard = new OutputPort(Pins.ONBOARD_LED, false); while (true) { ledOnboard.Write(true); Thread.Sleep(1); The problem is I can only get as low as 1 millisecond  



#2 MedfordChris

MedfordChris

    New Member

  • Members
  • Pip
  • 7 posts
  • LocationMedford MA

Posted 01 November 2012 - 01:11 PM

You may want to use PWM for that. That's a hardware function, so you don't have to worry about the timing in software.

#3 Dan Kowalczyk

Dan Kowalczyk

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationSeattle

Posted 01 November 2012 - 06:06 PM

Are you familiar with PWM (Pulse width modulation)? It will give you a lot more control over how long the LED is on and how long it is off. Why do you want the LED to blink quickly? That would give us a better grasp of what technique to lead you to.
If you want a treat and don't mind the treatment...

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 November 2012 - 07:37 PM

Another potential option is to create a "SleepMicroseconds" function which simply loops dummy functions for a certain # of loops. You'd have to calibrate it to the speed of your particular board, and it would waste a lot of MCU cycles--but it would let you wait for shorter periods of time.

Something like:
const LOOPS_PER_MICROSECOND = ###; // insert calibration value here

void SleepMicroseconds(int microseconds)
{
    int dummyValue = 0;

    for (int i = 0; i < microseconds * LOOPS_PER_MICROSECOND; i++)
    {
        dummyValue++;
    }
}
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.