Hi Netduino Users,
I have a problem. I want to get analog input (in my case this is a potentiometer) in a specific period. Like 100 Hz. At the end an infinite loop will be perform. Under that there may be a thread which triggers analog input 100 times in a second.
How can I do that ? Thanks for your answer.
NOTE: After finishing my project, i will share with you.
Triggering Thread
Started by KODOZANI, Apr 28 2012 03:37 PM
2 replies to this topic
#1
Posted 28 April 2012 - 03:37 PM
#2
Posted 28 April 2012 - 04:30 PM
Hello Kodozani.
You can do a dedicate thread running endlessly a loop, but it's an overkill, I think.
I'd use a Timer which is also the most accurate way to perform a certain task.
Try this:
Note: I written the above code by mind...it could contain some error, but it should be pretty near to a working program.
Cheers
You can do a dedicate thread running endlessly a loop, but it's an overkill, I think.
I'd use a Timer which is also the most accurate way to perform a certain task.
Try this:
class Program { private static Timer _clock; private static AnalogInput _pot = new AnalogInput(Pins.GPIO_PIN_A0); public static void Main() { _clock = new Timer(Tick, null, 10, 10); Thread.Sleep(Timeout.Infinite); } private static void Tick(object state) { int read = _pot.Read(); // do whatever ... } }
Note: I written the above code by mind...it could contain some error, but it should be pretty near to a working program.
Cheers
Biggest fault of Netduino? It runs by electricity.
#3
Posted 29 April 2012 - 06:17 AM
There may also be a problem with timing as threads execute for 20ms at a time on NETMF. If you are interested on how threading works then you can find out more in the article Threads and Thread Priorities in NETMF.You can do a dedicate thread running endlessly a loop, but it's an overkill, I think.
Regards,
Mark
To be or not to be = 0xFF
Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life
Follow @nevynuk on Twitter
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users