Monday, September 6, 2010

Controlling a DC Motor and Handling Threading with .NET MF

I found a new article on how to control a DC motor and why Thread.Sleep doesn’t really sleep.

A big highlight of NETMF is the using of threads. Which means you can run many functions quasi in parallel. You only need to pack your single programs into a function. Declare the function as a thread and start the thread. Thats all. The secret behind is the use of the 'thread.Sleep' function. This is the NETMF function for 'delay' in Arduino speech. But NETMF will not simply wait, it will bring another thread into foreground to run on the processor. The other thread will sleep in the background, until the sleep time is finished.

I am running into my first big problem with NETMF when I use the thread functionality. As you can see in the first video, the servo will not do his sweep, as he do when running as a single program. It costs me some hours to find out that this is not a thread problem. After changing the servo lib to the GHI components lib, everything works fine, as you can see in the 2nd video.

Check the full blog post (ported the Arduino RTTTL sketch to .NET MF) and download the source code at

No comments: