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

Thread: Teensy 4.1 FlexPWM capture problems

  1. #1
    Junior Member
    Join Date
    May 2021
    Posts
    13

    Teensy 4.1 FlexPWM capture problems

    My goal is to capture the times between input pulses using DMA. I got this working on Teensy 3.6, based on input_capture_dma.ino. But moving to Teensy 4.1, I can't get capture to work.

    I'm using pin 6 (FLEXPWM2_PWMA02) so I reimplementing everything with FlexPWM, but DMA capture didn't work at all. Working backward, I looked at the capture register directly, then edge counting, then just the PWM_A input directly, but none of those worked at all. I verified that the counter register is counting, though.

    I've boiled it down to this code. Expected behavior: pin 6 will go to the PWM_A input and should show up in the value I'm printing. Observed behavior: continually prints 0. (Pin 6 is getting pulses externally, verified both by an oscilloscope and by digitalReadFast(6).)

    Code:
    void setup() {
      pinMode(6, INPUT); // Initialize the direction
      *(portConfigRegister(6)) = 2; // Mux 2 = FLEXPWM2_PWMA02, for IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_10
      FLEXPWM2_OUTEN = 0; // No outputs
      while (1) {
        Serial.println(FLEXPWM2_SM2OCTRL, HEX); // top bit should be PWM_A Input
      }
    }
    void loop() {
    }
    I suspect I'm messing up the pin mux or misconfiguring FlexPWM. I've studied the FlexPWM chapter in the manual but I get nothing from the input even after trying a bunch of plausible settings.

  2. #2
    Junior Member
    Join Date
    May 2021
    Posts
    13
    My problem was that I needed to set the daisy chain register so the right input pad would be used.
    Code:
      IOMUXC_FLEXPWM2_PWMA2_SELECT_INPUT = 1;
    Apparently the Teensy 4.1 has an additional "daisy chain" register if two pads can drive the same module input pin. It seems to me that the chip should be able to figure it out from the pin mux register, but the daisy chain register needs to be set too. See sections 11.3.3 and 11.7.284 in the manual.

Posting Permissions

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