Teensy 3 Timer Based PWM for Servo Control

Status
Not open for further replies.

rvnash

Member
Hi All.

Perhaps I missed it, but I couldn't find any library to utilize free running internal timers of the K20 to do PWM generation to control servo motors, with no interrupts. So I wrote one myself. My goal was to make it as simple to use as possible, and to take up no RAM at all. An explanation of how to use it is in the .h file.

Testing hasn't been extensive yet, but the traces all look right on my scope, and my servo sweeps back and forth.

- Rich

<< To avoid confusion, deleted the attached files. See future post. >>
 
Last edited:
Looks very nice! What did you have in mind regarding others including your code in their projects? As I understand it, "All rights reserved" prevents anyone else from incorporating the code in a project they publish or sell.
 
Hey Rich,

First, thanks for posting this lib! Really easy to use, works great! Except for one thing...

For some reason I´m not getting anything out of pin 25 & 32 (either read or write). All of the other PWM pins work as expected. Thought it might have been a dodgy soldering job I´d done on the bottom pads, but both pins function fine when I tried with a blinky sketch.

I would post code, but I´ve boiled it down to simply defining the pins, including the lib, initializing and then doing a sweep on all PWM pins.

I will include a pic, though. This is with two of the working channels. Pin 25 & 32 nothing.
https://dl.dropboxusercontent.com/u/950996/teensy/2014-10-07%2022.05.06.jpg

From your code comments, see these pins share the same FTM2 timer. Do I need to enable this separately?

Teensy 3.1
Teensyduino 1.19
Arduino 1.0.5 (Mac)

Any tips greatly appreciated!

Daniel
 
Hey Paul,

Thanks for your speedy response! I'll try 1.20. Was waiting for the final version, but know you´re almost ready to call it done.
 
Hi Daniel,

I'm so glad it was useful. Let me know if the 1.20 fix does the trick for you. If not, I'll try to diagnose it here. I must admit my project doesn't use those pins, and it is probable I didn't test them.

Just so you know I have an update to that library for PWM input that detects when the incoming PWM signal is disappears. It, unfortunately, requires a little bit of static memory, but I found it necessary for my project. If you would like, I'll post the update.

- Rich
 
Hey Rich,

Would be extremely useful to detect lost signals! Am using this to read in 7 channels from an 8ch RC receiver. Greatly appreciated if you post the update (to github?).

Paul, congrats on releasing v1.20 today. It did indeed resolve the issue I was having, thanks!

- Daniel
 
Status
Not open for further replies.
Back
Top