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

Thread: pwm pins 24 - 33 vs 34 - 39 teensy 4.0

  1. #1
    Junior Member
    Join Date
    Feb 2020

    pwm pins 24 - 33 vs 34 - 39 teensy 4.0

    this is what I'm working with so far (Paul wrote most of my code ).. going to be working on some other features using a low pass filter / pwm outputs on the underside pins.. anyways I have a layout question.. why can't I use pins 0-11 for the main frequency output? and is there any reason I can't use 24, 25, 28, and 29 vs the extra itty bitty pads by the usb connector? Thanks folks!

    float pitch_change;
    float duty_change;

    void loop() {

    pitch_change = (analogRead(2) - 512) * .0059 ;

    analogWriteFrequency(2, 2093.00 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(4, 1108.73 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(5, 1174.66 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(6, 1244.51 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(7, 1318.51 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(10, 1396.91 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(11, 1479.98 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(12, 1567.98 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(13, 1661.22 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(14, 1760.00 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(15, 1864.66 * (pow (1.059463, pitch_change)));
    analogWriteFrequency(18, 1975.53 * (pow (1.059463, pitch_change)));

    analogWrite(2, 128);
    analogWrite(4, 128);
    analogWrite(5, 128);
    analogWrite(6, 128);
    analogWrite(7, 128);
    analogWrite(10, 128);
    analogWrite(11, 128);
    analogWrite(12, 128);
    analogWrite(13, 128);
    analogWrite(14, 128);
    analogWrite(15, 128);
    analogWrite(18, 128);


  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Sorry I am not totally sure what your question is, or what the issues are.

    But then I have not done a tone of stuff with the PWM stuff in this context. I did play around some with them more in the capture case. So my assumptions here may be complete wrong.

    My Guess is that you are trying to get a lot of pins outputting at different frequency at 50% ? Don't have complete code but guessing 8 bit?

    My first guess is that with the FlexPWM code you can only have one frequency on a Module/SubModule pair and that pair can have up to 3 different pins on them (A, B, X). My guess is you are skipping some of the pins as to not grab two of the ones on a module/submodule.

    If I extract stuff from my Excel document for T4. And we look at the underlying PWM hardware associated with each pin, we have:
    Pin	PWM
     0	PWM1_X1
     1	PWM1_X0
     2	PWM4_A2
     3	PWM4_B2
     4	PWM2_A0
    5	PWM2_A1
    6	PWM2_A2, QT4_1
    7	PWM1_B3
    8	PWM1_A3
     9	PWM2_B2, QT4_2
    10	QT1_0
    11	QT1_2
    12	QT1_1
    13	QT2_0
    14/A0	QT3_2
    15/A1	QT3_3
    18/A4	QT3_1
    19/A5	QT3_0
    22/A8	PWM4_A0
    23/A9	PWM4_A1
    ---	---
    24/A10	PWM1_X2
    25/A11	PWM1_X3
    28	PWM3_B1
    29	PWM3_A1
    30	GPT1_3 
    31	GPT1_2
    33	PWM2_B0
    34	PWM1_B1
    35	PWM1_A1
    36	PWM1_B0
    37	PWM1_A0
    38	PWM1_B2
    39	PWM1_A2
    So for example if you look at pins 2 and 3, you will see they are on PWM4 Sub module 2 and Pins A and B. Which is why I am guessing you are not using pin 3.
    Note some of the Other pins use QT (Quad timers) and might need to double check on what the limitations are on each of the Quad timers (if any).
    Again you skip pin 8 (PWM1_A3) as you are already used this timer on Pin 7 (PWM1_B3) and as such you can also not use pin 25 (PWM1_X3)

    Again not sure if I am barking down the right tree here, but that would be my guess on what is going on

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Maybe this was adapted from the code here?

    As Kurt explained, certain groups of PWM pins always have the same frequency because they're controlled by the same timer. I wrote that example to use a specific set of 18 pins which to access the 18 distinct timers without any duplication, for 18 unique frequencies. Most of those 18 pins have 1 or 2 other PWM pins at the same frequency, so if you swap out a pin for one of the others from the same timer, you can have some small flexibility about which pins to you.

    But you can't arbitrarily pick any group of PWM pins, like 0 to 15. Even though all those pins support PWM, some are controlled by the same timer, so they can not generate an independent frequency. That's why I created the example, to demonstrate the maximum number of independent frequencies by selecting the correct PWM pins so no timer usage is duplicated.

  4. #4
    Junior Member
    Join Date
    Feb 2020
    Thanks! that's what I was thinking it was, but hoping otherwise. I figured you picked those pins for a reason.. was hoping I could use the larger pads, I'm not even going to attempt to solder to those extra small pads, Hell it took me 20 minutes to figure out those were the 34-39 pins. and yes Kurt you nailed it. that was my question.. going to take a few to look at that spec sheet to see if I can understand it, then probably have 10 more questions lol. Thanks again guys for helping this dummy out!

Posting Permissions

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