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.

TM4C129ENCPDT: TM4C129ENCPDT

Part Number: TM4C129ENCPDT


I am trying to generate PWM output in Pwm_out_4 & 5.   But it is not working.  Code given below

   SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
    {
    }
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    GPIOPinConfigure(GPIO_PG0_M0PWM4);
       GPIOPinConfigure(GPIO_PG1_M0PWM5);
       GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_0);
          GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
          GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_0, GPIO_STRENGTH_10MA, GPIO_PIN_TYPE_STD);
          GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_1, GPIO_STRENGTH_10MA, GPIO_PIN_TYPE_STD);
         PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN |
                             PWM_GEN_MODE_NO_SYNC);
          PWMGenPeriodSet(PWM0_BASE, PWM_OUT_4, 2500);

          PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4,1250);
          PWMDeadBandEnable(PWM0_BASE, PWM_GEN_2, 160, 160);
             PWMOutputState(PWM0_BASE, PWM_OUT_4_BIT | PWM_OUT_5_BIT, true);
             //
             // Enables the counter for a PWM generator block.
             //
             PWMGenEnable(PWM0_BASE, PWM_GEN_2);
Any issues with this code. 
  • Hello Ramesh,

    I found the issue, it took me a little bit to figure out what was wrong too even while staring at the example. Just one little parameter needs to be adjusted! :)

    On your code you have this:

       PWMGenPeriodSet(PWM0_BASE, PWM_OUT_4, 2500);

    But the PWMGenPeriodSet API is not based on the PWM OUT register, but the GEN register, because the generator impacts both PWM channels. So what you need is:

    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 2500);

    Then it should work just like you want.

  • Thank you very much Ralph.  It worked.

    Regards,

    Ramesh