MUX and PWM mapping

DrM

Well-known member
Hi,

This question is about pin assignment and pwm output.

In pwm.c, in analogWrite(), we have the following at line 266

Code:
 *(portConfigRegister(pin)) = info->muxval;

The mux value is stored in pwm_pin_info[] at the top of the file, with the structure for the array elements declared at line 6, and the array populated at line 19, with pin number as index into the array.

Code:
struct pwm_pin_info_struct {
    uint8_t type;    // 0=no pwm, 1=flexpwm, 2=quad
    uint8_t module;  // 0-3, 0-3
    uint8_t channel; // 0=X, 1=A, 2=B
    uint8_t muxval;  //
};

So in other words, there seems to be a hard coded relationship between pin number and pwm output.

Now the questions:

1) Is this association between a given pin and a given pwm output, fixed in hardware? How? Or, can the mux value be assigned to a different pin mux to re-route the pwm output?

2) Can the PWM be used without assinging the mux to a pin? An example use case would be to only use the interrupt but not the pin.

3) After starting the pwm for a pin, does calling pinMode() for that pin (digital.c, line 133), leave the pwm running?

Thank you



P/S It occured to me that I should be more specific about what I am trying to do.

What I am looking for is access to all four submodules of any flexPWM for a Teensy 4.0.

At the moment, the board uses pins 4 or 5, 6, 7, and 9 or 10. Being able to mux onto those pins would be fantastic. Otherwise, I will just have to spin the board again.

To that, so far, I was able to program what I need using pins 4,5 and 6 for flexpwm2 submodules 0,1 and 2, and assert the 4th pin as needed from an ISR. I would very much prefer to be able to get to submodule 3 (on one of the pins, not a solder pad on the bottom).

I am still interested in the above question though.
 
Last edited:
1) Is this association between a given pin and a given pwm output, fixed in hardware? How? Or, can the mux value be assigned to a different pin mux to re-route the pwm output?
It's mostly fixed. Pins can choose one function to perform out of their fixed available selection; that's what the "portConfigRegister" assignment does. A pin that doesn't have any PWM function in its selection can't be used for PWM, and the ones that do are generally limited to one specific module and channel. This is all in chapter 11.6 of the IMXRT1060 manual, each pin has a SW_MUX_CTL_PAD register with a MUX_MODE field to select its function.

Some of the PWM functions are made available to more than one pin, in that case there will be an additional register (also detailed in chapter 11.6) that chooses which pin the function gets routed to. But that pin will still need to set the correct value in its mux_mode.

2) Can the PWM be used without assinging the mux to a pin? An example use case would be to only use the interrupt but not the pin.
To use as something like a general counter/timer? Sure.

3) After starting the pwm for a pin, does calling pinMode() for that pin (digital.c, line 133), leave the pwm running?
Without double-checking the code, I would say probably? It's not going to change what has been written to the PWM registers, only the pin control registers.
 
This is all in chapter 11.6 of the IMXRT1060 manual, each pin has a SW_MUX_CTL_PAD register with a MUX_MODE field to select its function.

So, chapter 11.6 begins with a very long table and pin number is not one of the column headings. It repeats for 0 to 41 for EMC, 0 to 15 for B0, 0 to 15 for B1, and etc.

That's pretty confusing.

But there is an entry IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_19 that has a FLEXPWM2_A03 (described on page 445).

That is probably what I am looking for. Does that correspond to pin 19?

Does setting the MUX_MODE field to 001 makes pin 19 the output for FLEXPWM2_A3?

What else needs to be set to make that work?

It also occurs in SW_MUX_CTL_PAD_GPIO_AD_B0_09 page 461, SW_MUX_CTL_PAD_GPIO_B1_02 page 522, SW_MUX_CTL_PAD_GPIO_SD_B1_02 page 544

Some of the PWM functions are made available to more than one pin, in that case there will be an additional register (also detailed in chapter 11.6) that chooses which pin the function gets routed to. But that pin will still need to set the correct value in its mux_mode.

I am not finding that in chapter 11.6, it seems to be just one long contiquous list of registers.
 
So, chapter 11.6 begins with a very long table and pin number is not one of the column headings. It repeats for 0 to 41 for EMC, 0 to 15 for B0, 0 to 15 for B1, and etc.
The physical pin numbers on the Teensy are simply made up, they are not in the hardware manual. You can see how they map to real pin names in KurtE's chart, along with their possible functions/mux values: https://forum.pjrc.com/index.php?attachments/t4-1-mux-jpg.25961/

I am not finding that in chapter 11.6, it seems to be just one long contiquous list of registers.
They are the "daisy chain" registers, towards the end of the list.
 
Back
Top