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

Thread: Teensy 4.0 - some PMW pins are not working

  1. #1

    Teensy 4.0 - some PMW pins are not working

    Hi Everybody,

    I have a project where I need to operate 9 LRA's with high frequency PWM (10K hz). According to the chart from pjrc, the 4.0 has 20 pins which are PWM capable: 0-12, 13-15, 18-19, and 22-23. I am using the USB serial, which I think eliminates pins 0 and 1. I am also using two I2C buses, and this should also eliminate pins 18-19. That leaves me with 16 possible pins. However, I can only get 8 to work: 2, 4-9, and 22. I've read that 10 - 15 are QaudTimers, and I can't get those to work at all. That leaves only two problem pins that run with FlexPWM modules, pins 3 and 23.

    Pin 23 locks logic high and stays there no matter what the code tells it to do.

    Pin 3 operates at the correct frequency but has ghosting and the voltage is much lower (5 mv) than the pins that do work (400 mV). I hooked a scope up to pin 4 (which does work) as well as pin 3 (which doesn't), took pics and attached them so you can see what I am talking about.

    My code is really long so I'll just show the relevant parts here:

    int pwmPin13 = 3; // test
    ..
    pinMode(pwmPin13, OUTPUT);
    ...
    analogWriteFrequency(pwmPin13, 10000);
    ...
    analogWrite(pwmPin13, 120);

    I'm kind of a newbie at this so I'm hoping the answer is something that is easy to fix.

    Thanks in advance
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Pin 4 connected to DA7280.jpg 
Views:	4 
Size:	117.3 KB 
ID:	29100   Click image for larger version. 

Name:	pin 3 connected to DA7280.jpg 
Views:	5 
Size:	136.4 KB 
ID:	29101  


  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,801
    Pins 0 and 1 are not used by USB serial. That's info which applies to boards like Arduino Uno, but not relevant to any Teensy.

    Please show a complete program which can be copied into Arduino and run on a Teensy, even if it's "trivial".

    For example, I ran this just now on a Teensy 4.0.

    Code:
    void setup() {
      analogWriteFrequency(10, 10000);
      analogWrite(10, 120);
    }
    
    void loop() {
    }
    Here it is on my workbench

    Click image for larger version. 

Name:	1.JPG 
Views:	3 
Size:	54.6 KB 
ID:	29102

    And this is the signal my scope sees on pin 10.

    Click image for larger version. 

Name:	file.png 
Views:	1 
Size:	23.3 KB 
ID:	29103

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,801
    However, as a blind guess, this might be your problem:

    Quote Originally Posted by inevitable jambalaya View Post
    pinMode(pwmPin13, OUTPUT);
    Using pinMode() puts the pin into GPIO mode. If done before analogWrite(), as your message seems to say, it has no effect because analogWrite() will configure the pin to be controlled by the timer.

    But maybe your program actually uses pinMode() after analogWrite()? This is why we always ask to see a complete program, rather than just the relevant parts explained not as a real program which can be actually run on Teensy, because small details matter.

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,969
    As Paul said, it is hard to know what is happening without seeing more..

    I expanded on Paul's example:
    Code:
    void setup() {
      analogWriteFrequency(3, 10000);
      analogWrite(3, 120);
      analogWriteFrequency(23, 10000);
      analogWrite(23, 120);
      analogWriteFrequency(10, 10000);
      analogWrite(10, 120);
    }
    
    void loop() {
    }
    Click image for larger version. 

Name:	Screenshot.jpg 
Views:	2 
Size:	74.3 KB 
ID:	29105
    The first three rows are digital capture of 3, 10, 23 and the last three are the analog

  5. #5
    Thanks for the input guys!

    I think I've found the problem. Nothing to do with the code or even the setup. It is the wires themselves. I used breadboard jumpers made in China. There is almost no copper in the core, and I am using a low voltage signal for PWM. I tried some actual solid core copper wire and everything seemed to work fine.

Posting Permissions

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