Greater time resolution using .NET Micro Framework on Netduino board (for dimming an LED)?

John K picture John K · Dec 1, 2010 · Viewed 7.3k times · Source

I'm programming a Netduino board using the .NET Micro Framework 4.1 and want to get a higher time resolution than milliseconds. This is because I'm attempting to dim an LED by blinking it really fast.

The issue is that the sample code uses Thread.Sleep(..) which takes a number of milliseconds.

Sample code from http://netduino.com/projects/ showing the issue in question:

OutputPort ledOnboard = new OutputPort(Pins.ONBOARD_LED, false);
while (true)
{
    ledOnboard.Write(true);
    Thread.Sleep(1); // << PROBLEM: Can only get as low as 1 millisecond

Even if there's another way to accomplish dimming by not using a greater time resolution, I'm game.

Answer

superfro picture superfro · Dec 1, 2010

This doesn't answer your question about getting a better time resolution, but it does solve your problem with changing the brightness on an LED. You should be using the PWM module for the Netduino.

Netduino Basics: Using Pulse Width Modulation (PWM) is a great article on how to use it.