Best way to read PWM input?

Status
Not open for further replies.

jwatte

Well-known member
I need to read 3 hobby servo PWM inpur signals (60 Hz, 1-2 ms duty)
I need to do this asynchronously.
I can do this with pin change interrupts and reading some timer for on/off times.
But is there an easier way to do this? Some library, or some gated timer functionality perhaps?
 
But is there an easier way to do this? Some library, or some gated timer functionality perhaps?

The answer seems to be to use the PulsePosition library, assuming the pins I have available match up.

Also: I was trying to browse to some unified list of all the libraries from the PJRC store page, but I didn't manage to find it.
Reading through the forum backlog, pointed at some links, that in turn led me to the listing of all the Teensyduino libraries.
I expected the pages on the Teensy descriptions to point me at the libraries, or the "code library" link to be the code library.
I didn't pay attention to the "Teensyduino" header because it sounded Arduino-compatible, which isn't interesting to me :-/
 
Hi jwatte,

Yep if I were you, I would try pulseposition library. However as you mentioned it is setup for specific pins. Otherwise in the past I did as you mentioned and used the Pin Change Interrupt. Used to do this to receive the signals from an RC receiver...

As for figuring out which libraries are available, Besides browsing the forums: I usually end up doing a few different things:
Check the web site: http://www.pjrc.com/teensy/td_libs.html
Check Paul's github: https://github.com/PaulStoffregen?tab=repositories
Check to see what libraries were installed by Teensyduino, in my case on my Windows machine they are stored at: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries
 
Oh. Hmm, yeah, that looks right.
Is there a better option than pin change interrupts then?
 
Is there a better option than pin change interrupts then?

Timer input capture would (probably) be the very best way. But I'm not aware of any already-written library which does this. You'd have quite a lot of work to do to implement this....
 
That looks interesting. The benefit compared to pinChange is that the time reading of the event would be captured in hardware.
The PulsePositionInput module actually is a reasonable sample in and of itself -- I want to measure something slightly different than what it does, but it seems like a good start.
That being said, I'm going to start with attachInterrupt() for now, and go from there if I need more precision (which I likely don't :)
 
I'm going to start with attachInterrupt() for now, and go from there if I need more precision (which I likely don't :)

Actually, this question has come up many times, and pretty much everyone has gone down that path and achieved good enough results that nobody (at least nobody who's shared code or even a brief followup summary) had bothered to dig into the more difficult input but more precise capture way.

If you do use timer input capture, please at least tell us how it goes?
 
Looks Interesting. I have not had the need yet on the Teensy for this as I sort of have dropped doing very much at all with RC servos and RC remotes...

I used to use the Timer Input capture on a different processor (Basic Atom Arc32), which had an H8... processor. On these processors used the timer to both control generating the servo pulses, as well capture position data back from their servos (Orion Robotics, which is no longer)... So if you need the accuracy that is a great way to go. But my guess is that this only works with specific IO pins...
 
Orion Robotics

Didn't they just change names to Ion Motion Control? (ionmc.com)
They still support their RoboClaw motor drivers, at least!
(which is good for me -- the PWM input is for the "safety" control for a rover that uses those controllers ...)
 
Didn't they just change names to Ion Motion Control? (ionmc.com)
They still support their RoboClaw motor drivers, at least!
Sort-of: It looks like Dale and Nathan, ended the two companies (Basic Micro and Orion Robotics) (website and forum) and created this new one, that mainly does the Roboclaw. They probably completely dropped making and supporting their robots and servos, although I see some sites like NoDNA saying things like new stock soon... As for their processor boards (chips), I believe the nano was taken over by Basic Micro UK (not related). The Basic Atom and Basic Atom Pro they say that companies can order in bulk...
 
Status
Not open for further replies.
Back
Top