complimentary pwm with teensy 3 ?

Status
Not open for further replies.
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
 
Yes, the PWM in Teensy3 has this capability. But you'll need to access the FTM timers directly to use it.

http://www.pjrc.com/teensy/K20P64M50SF0RM.pdf

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.
 
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?

Code:
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()                     
{
  digitalWrite(ledPin,!digitalRead(ledPin));
  delay(500);
}
 
Status
Not open for further replies.
Back
Top