Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

How to read from a pin that gets a PWM signal


  • Please log in to reply
9 replies to this topic

#1 Daniel Stritt

Daniel Stritt

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationNorman, OK, USA

Posted 09 September 2012 - 01:38 AM

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
To perform the same action over and over, and expect a variant reaction, is surely a sign that you use computers.

#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

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 Daniel Stritt

Daniel Stritt

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationNorman, OK, USA

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 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

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 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

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.

#6 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

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 Geancarlo2

Geancarlo2

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

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 :)

#8 Daniel Stritt

Daniel Stritt

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationNorman, OK, USA

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 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

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 patduino

patduino

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationIndiana, USA

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

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.