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.

CCS/TM4C123GH6PM: Issues Using TivaWare PWM Example

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

I'm trying to use the TivaWare PWM Programming Example in my code on the TM4C123GH6PM. Below is the exact snippet I'm trying to use in a function which I call at the beginning of the program, with the only change being that I change "PWM_BASE" to "PWM0_BASE" so that I could access the Module 0 address:

void PWM0_init(void){
////////////////////////////////////////////////////////

//
// Enable the PWM0 peripheral
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
//

// Wait for the PWM0 module to be ready.
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
{
}
//
// Configure the PWM generator for count down mode with immediate updates
// to the parameters.
//
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
//
// Set the period. For a 50 KHz frequency, the period = 1/50,000, or 20
// microseconds. For a 20 MHz clock, this translates to 400 clock ticks.
// Use this value to set the period.
//
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 400);
//
// Set the pulse width of PWM0 for a 25% duty cycle.
//
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 100);
//
// Set the pulse width of PWM1 for a 75% duty cycle.
//
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 300);
//
// Start the timers in generator 0.
//
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
//
// Enable the outputs.
//
PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);

/////////////////////////////////////////////////////////////////////
}

The code compiles just fine. Based on my understanding from the datasheet, I should be seeing 50kHz square waves with 75% and 25% duty cycles coming out of PB6 and PB7 respectively but when I probe with an oscilloscope I get no voltage from either of those pins to ground. Could someone point out to me a perhaps obvious error I am making? I believe I had this working earlier with Module 1, PWM1 on PD1 but even when I change the code to reflect that I don't get any output.

Thanks!

Jim

  • In the posted code of the PWM0_init() function there are no calls to GPIOPinTypePWM(). Calls to GPIOPinTypePWM() is required to place the pins under hardware control.

    Is GPIOPinTypePWM() called else-ware in the code for the PB6 and PB7 pins?

  • Chester,

    Thanks for pointing that out. That was not previously included int he code. I added in a call to GPIOPinTypePWM but I still don't get any output. This is what the revised code looks like:

    void PWM0_init(void){
    ////////////////////////////////////////////////////////

    //
    // Enable the PWM0 peripheral
    //

    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    //

    // Wait for the PWM0 module to be ready.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
    {
    }
    //
    // Configure the PWM generator for count down mode with immediate updates
    // to the parameters.
    //

    //Added to ensure PB6 and PB7 are ready to go...
    GPIOPinTypePWM(GPIO_PORTB_BASE,GPIO_PIN_6|GPIO_PIN_7);


    PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
    PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
    //
    // Set the period. For a 50 KHz frequency, the period = 1/50,000, or 20
    // microseconds. For a 20 MHz clock, this translates to 400 clock ticks.
    // Use this value to set the period.
    //
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 400);
    //
    // Set the pulse width of PWM0 for a 25% duty cycle.
    //
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 100);
    //
    // Set the pulse width of PWM1 for a 75% duty cycle.
    //
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 300);



    //
    // Start the timers in generator 0.
    //
    PWMGenEnable(PWM0_BASE, PWM_GEN_0);
    //
    // Enable the outputs.
    //
    PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);


    /////////////////////////////////////////////////////////////////////
    }

    Let me know if that looks right or if you have any other theories.

    Thanks,
    Jim
  • Jim Carucci said:
    Let me know if that looks right or if you have any other theories.

    Comparing the above code against TivaWare PWM examples shows your PWM0_init() function is missing calls to GPIOPinConfigure() to set the pin muxing for the PWM pins.

    Try adding the following before the call to GPIOPinTypePWM():

        GPIOPinConfigure(GPIO_PB6_M0PWM0);
        GPIOPinConfigure(GPIO_PB7_M0PWM1);

  • Chester,

    Another good suggestion but sadly, I still get no output to either PB6 or PB7 on the oscilloscope when I attempt to run the following revised code:


    void PWM0_init(void){
    ////////////////////////////////////////////////////////

    //
    // Enable the PWM0 peripheral
    //

    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    //

    // Wait for the PWM0 module to be ready.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
    {
    }
    //
    // Configure the PWM generator for count down mode with immediate updates
    // to the parameters.
    //
    //Configure PB6 and PB7 to PWM
    GPIOPinConfigure(GPIO_PB6_M0PWM0);
    GPIOPinConfigure(GPIO_PB7_M0PWM1);

    //Added to ensure PB6 and PB7 are ready to go...
    GPIOPinTypePWM(GPIO_PORTB_BASE,GPIO_PIN_6|GPIO_PIN_7);


    PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
    PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
    //
    // Set the period. For a 50 KHz frequency, the period = 1/50,000, or 20
    // microseconds. For a 20 MHz clock, this translates to 400 clock ticks.
    // Use this value to set the period.
    //
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 400);
    //
    // Set the pulse width of PWM0 for a 25% duty cycle.
    //
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 100);
    //
    // Set the pulse width of PWM1 for a 75% duty cycle.
    //
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 300);

    //
    // Start the timers in generator 0.
    //
    PWMGenEnable(PWM0_BASE, PWM_GEN_0);
    //
    // Enable the outputs.
    //
    PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);


    /////////////////////////////////////////////////////////////////////
    }

    Any other theories or suggestions?

  • Hello Jim

    Is the clock to GPIO Port B enabled?
  • I believe that was the problem. I am now getting a read on my scope after using SysCtlPeriphalEnable on port B. Thanks Amit and Chester for the quick responses!