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
 

Attachments

  • Pin 4 connected to DA7280.jpg
    Pin 4 connected to DA7280.jpg
    117.3 KB · Views: 17
  • pin 3 connected to DA7280.jpg
    pin 3 connected to DA7280.jpg
    136.4 KB · Views: 20
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

1.JPG

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

file.png
 
However, as a blind guess, this might be your problem:

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.
 
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() {
}
Screenshot.jpg
The first three rows are digital capture of 3, 10, 23 and the last three are the analog
 
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.
 
Back
Top