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
Time resolution
Started by BenT, Nov 01 2012 06:24 AM
3 replies to this topic
#1
Posted 01 November 2012 - 06:24 AM
#2
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
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
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:
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