This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EK-TM4C123GXL: Enabling Pins for PWM

Part Number: EK-TM4C123GXL

Hi, Think I missing something on the SDK.

How do you configure PF1, PF2 and PF3 as PWM pins, specifically M1PWM5, M1PWM6 and M1PWM7, which document spmu296 indicates I can do by setting GPIOPCTL to 5.

Now what I was expecting to do is something like "SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM5);", but you can only pass SYSCTL_PERIPH_PWM0 or SYSCTL_PERIPH_PWM1 to that function (so I've misunderstood it - are 0 and 1 the two PWM on a Generator).

So the only other way I can see to configure the pin is commands like "GPIOPinConfigure(GPIO_PF1_M1PWM5);" - so is that all that is needed?

  • Hi,

      There are two PWM modules and each module has four PWM generators. Each generator can produce two PWM outputs. Below is an example to use PD0 as a PWM output. PD0 is mapped to M1PWM0. 

    //
    // The PWM peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

    //
    // For this example PWM0 is used with PortD Pin0. The actual port and
    // pins used may be different on your part, consult the data sheet for
    // more information.
    // GPIO port D needs to be enabled so these pins can be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Configure the GPIO pin muxing to select PWM00 functions for these pins.
    // This step selects which alternate function is available for these pins.
    // This is necessary if your part supports GPIO pin function muxing.
    // Consult the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinConfigure(GPIO_PD0_M1PWM0);

    //
    // Configure the PWM function for this pin.
    // Consult the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);

    //
    // Configure the PWM0 to count up/down without synchronization.
    //
    PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |
    PWM_GEN_MODE_NO_SYNC);

    //
    // Set the PWM period to 250Hz. To calculate the appropriate parameter
    // use the following equation: N = (1 / f) * SysClk. Where N is the
    // function parameter, f is the desired frequency, and SysClk is the
    // system clock frequency.
    // In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles. Note that
    // the maximum period you can set is 2^16.
    // TODO: modify this calculation to use the clock frequency that you are
    // using.
    //
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, 64000);

    //
    // Set PWM0 to a duty cycle of 25%. You set the duty cycle as a function
    // of the period. Since the period was set above, you can use the
    // PWMGenPeriodGet() function. For this example the PWM will be high for
    // 25% of the time or 16000 clock ticks (64000 / 4).
    //
    PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0,
    PWMGenPeriodGet(PWM1_BASE, PWM_GEN_0) / 4);

    //
    // Enable the PWM0 Bit0 (PD0) output signal.
    //
    PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);

    //
    // Enable the PWM generator block.
    //
    PWMGenEnable(PWM1_BASE, PWM_GEN_0);

  • Thanks Both. I see where my misunderstanding came in now. There are two PWM Modules, called M0 and M1 and PWM0 and PWM1 - each module contains 4 PWM Generators, and each Generator can do 2 PWM signals. I had missed the module element - doesn't seem to be shown in any figures of the chip set up, and many documents don't really describe it well.  spms376e seems best, but need to read words carefully.

    Haven't yet corrected my code, but can see what I need to do now, so will cure this evening or tomorrow.

    Not sure who to give credit to for the solution. What I found most helpful was 5 year old link on the forum, for some reason I didn't find this when looking before - the code there had many comments, and that was enough for me to find what i needed to in the documentation.

    Anyway thanks both.