Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: complimentary pwm with teensy 3 ?

  1. #1
    Member
    Join Date
    Jun 2013
    Location
    Southern Colorado
    Posts
    66

    complimentary pwm with teensy 3 ?

    Is complimentary pwm with adjustable dead time possible using teensy 3's hardware ?

  2. #2
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    This LINK should answer some questions.

  3. #3
    Member
    Join Date
    Jun 2013
    Location
    Southern Colorado
    Posts
    66
    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

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,001
    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.

  5. #5
    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);
    }

  6. #6
    Working complementary source code found here....http://forum.pjrc.com/threads/24992-phase-correct-PWM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •