View Full Version : complimentary pwm with teensy 3 ?

08-11-2013, 04:55 PM
Is complimentary pwm with adjustable dead time possible using teensy 3's hardware ?

08-11-2013, 05:56 PM
This LINK (http://www.pjrc.com/teensy/td_pulse.html) should answer some questions.

08-11-2013, 06:42 PM
Thanks for the tip but I had previously looked at that page and didn't detect any clues
on how to do complementary pwm with teensy 3. Here is perhaps a better example of what
I was wondering .....say for instance pwm on pins 3 and 4 where they would be running at
the same frequency and duty cycle but would have a 180 degree phase difference. Between
each state change both pins would be low for an adjustable time in nano or microseconds.
I know this is easily accomplished with an external half bridge driver but if the T3 can do it
that would eliminate the need for an external driver. The T3 could easily drive a discrete
bipolar transistor totem pole circuit

08-11-2013, 08:18 PM
Yes, the PWM in Teensy3 has this capability. But you'll need to access the FTM timers directly to use it.


The info is in chapter 35 "Flextimer Module (FTM)" starting on page 687. You'll see it actually has a tremendous number of features for creating complementary pulse pairs for totem pole drivers. Because it there are so many features, that chapter is pretty long and complex. The key is ignoring the parts you don't need.

03-23-2014, 07:41 PM
I'm trying to setup a complementary output on channels 2 and 3 of FlexTimer0. This is my first try dabbling with the K20 hardware directly, so maybe I've missed something completely.

From what I can tell, I only need to enable the FlexTimer features with FTMEN = 1, combine channels 2 & 3 with COMBINE1 = 1, and set CH3 as the compliment of CH2 with COMP1 = 1.

The problem I'm having is when I set FTMEN=1, the PWM output stops completely. Even after initializing the COMBINE register, I get no output after setting FTMEN = 1. Has anyone done this and could give me some pointers?

const int ledPin = 13;
const int PWM_H = 9; // FTM0 - CH2
const int PWM_L = 10; // FTM0 - CH3

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(PWM_H, OUTPUT);
pinMode(PWM_L, OUTPUT);

analogWriteFrequency(PWM_H, 6000); // PWM frequency is 6kHz
analogWriteResolution(10); // 10-bits of PWM resolution

FTM0_MODE = 0x5; // FTMEN = 1, enables FlexTimer features/registers
// FTM0_COMBINE = 0x0030; // COMP1 = 1, ch3 is the inverse of ch2
// COMBINE1 = 1, combines ch2 & ch3

analogWrite(PWM_H, 500);

void loop()

03-26-2014, 07:49 PM
Working complementary source code found here....http://forum.pjrc.com/threads/24992-phase-correct-PWM