Ok, I have a Memsic accelerometer that outputs it's data using PWM. In Arduino it is read using pulseIn() to count how long each pulse is. I am new to .NET, and wondering if there was any easy way to read PWM signals? Or a PWM class, but for inputs, not outputs.
Thanks
Daniel
How to read from a pin that gets a PWM signal
Started by Daniel Stritt, Sep 09 2012 01:38 AM
9 replies to this topic
#1
Posted 09 September 2012 - 01:38 AM
To perform the same action over and over, and expect a variant reaction, is surely a sign that you use computers.
#2
Posted 09 September 2012 - 06:43 AM
Hi Daniel,
I don't think the Netduino has an equivelant way to read PWM.
I think some people use interrupts to measure the pulse width, but since this is software controled, it can't be as accurate as using a timer.
Paul
#3
Posted 09 September 2012 - 08:50 AM
Do I have access to the timers of the microcontroller through the .NET runtimes?
To perform the same action over and over, and expect a variant reaction, is surely a sign that you use computers.
#4
Posted 09 September 2012 - 01:03 PM
I think the best you can do is store the current time when an interrupt goes off.
I'm not an expert on this - someone else want to jump in.......
#5
Posted 09 September 2012 - 01:15 PM
afaik you can't directly access the timers as they are being used by the netmf runtime.
Paul's suggestion of sampling the time would probably work, however the accuracy may be questionable, could you use the adc to derrive the average voltage I.e. 100% duty would be 3.3v etc.
Nak.
- Paul Newton likes this
#6
Posted 09 September 2012 - 01:28 PM
Is there a shield for reading PWMs?
There must be lots of people who would like to place a Netduino between a radio control receiver and some servos.
#7
Posted 09 September 2012 - 07:03 PM
Although not ideal, an RC low pass filter should work. For more info on this matter look at http://www.thebox.my...torial/PWM.html specially the last part
- Paul Newton likes this
#8
Posted 09 September 2012 - 09:53 PM
Whew, I guess I was spoiled by Arduino . The solution that will work for me seems to be getting the current tine with a DateTime object, then getting the current time after the pulse, and compare the result. I am still not sure whether to put the code in a thread or use interrupts, because the data should always be sampling, but I want to interfere with the main code the least. Any ideas?
Daniel
To perform the same action over and over, and expect a variant reaction, is surely a sign that you use computers.
#9
Posted 10 September 2012 - 05:48 AM
You will have to use interupts, one to store the time on the rising edge, and one to calculate the diference on the falling edge.
Doing it in a task wil be too unpredictable.
Paul
#10
Posted 03 October 2012 - 12:37 AM
One possible problem I see with using interrupts is that if your main task is busy, the interrupt handling routine won't run until the main task's 20ms time slice is up. Interrupts don't preempt in .NETMF so you could have up to a 20 ms error in your measurement. You'll need to make sure that none of your other tasks are running.
There are 10 types of people in the world... Those that can understand binary and those who can't.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users