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.

Not able to control 2 PWMs independently.

Other Parts Discussed in Thread: TM4C123GH6PM, EK-TM4C123GXL

controller =TM4C123gh6pm

IDE=KEIL

In my project I need 2 PWM signals.For that I configured PWM0 and PWM1 like given below

void PWM_Config()  //This fn will cofigure PWM
{
        SysCtlPWMClockSet (SYSCTL_PWMDIV_1); /* Set the PWM clock to the system clock.*/
    SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM1);/* The PWM peripheral must be enabled for use.*/
    SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOD);
    GPIOPinConfigure (GPIO_PD0_M1PWM0);
    GPIOPinTypePWM (GPIO_PORTD_BASE, GPIO_PIN_0);
      PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
//  PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);


}
void PWM1_Config()//This fn will cofigure PWM1
{
    //    SysCtlPWMClockSet (SYSCTL_PWMDIV_1); /* Set the PWM clock to the system clock.*/
     SysCtlPeripheralDisable (SYSCTL_PERIPH_PWM0);
    SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM0);/* The PWM peripheral must be enabled for use.*/
    SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOB);
    GPIOPinConfigure (GPIO_PB6_M0PWM0);
    GPIOPinTypePWM (GPIO_PORTB_BASE, GPIO_PIN_6);
      PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
//  PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);


}

void PWM_On (float duty)  //this function will turn on PWM module with duty cycle based on the function argument duty
{
      
    PWMGenPeriodSet (PWM1_BASE, PWM_GEN_0, PWMFreqency);/* 120000=1KHz  120=1MHz   12=10MHz  */
        duty=duty/100;
    PWMPulseWidthSet (PWM1_BASE, PWM_OUT_0,PWMGenPeriodGet(PWM1_BASE, PWM_OUT_0) * duty);
        PWMOutputState (PWM1_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);
        PWMGenEnable (PWM1_BASE, PWM_GEN_0);/* Enable the PWM generator block.*/
       
}


void PWM1_On (float duty1)//this function will turn on PWM1 module with duty cycle based on the function argument duty1
{
        pulse=no_of_pulse;
    PWMGenPeriodSet (PWM0_BASE, PWM_GEN_0, PWMFreqency);/* 120000=1KHz  120=1MHz   12=10MHz  */
        duty1=duty1/100;
    PWMPulseWidthSet (PWM0_BASE, PWM_OUT_0,PWMGenPeriodGet(PWM0_BASE, PWM_OUT_0) * duty1);
        PWMOutputState (PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);
        PWMGenEnable (PWM0_BASE, PWM_GEN_0);/* Enable the PWM generator block.*/
  
}


code given below is the main programme

main()

{

    PWM_Config();      //PWM configuration
     PWM1_Config();   //PWM1 configuration

PWM_On(50);
    PWM1_On(99);

}

In the above programme PWM module0 is turn on with a pulse width of 99% and PWM module 1 is with 50%. But I am getting same voltage across PB6(PWM1) and PD0(PWM0). But if a use 1 PWM module at a time (ie only configure and turn on eighter PWM module 0 or PWM module 1) then I will get exact voltage across the pins(PB6/PD0) based on the duty cycle..Problem will occur when they configure and turn on together.

PWM module 0 and PWM module 1 are under same generator(generator 0)

When I tried to use another PWM module(ie. another generator) compiler is showing warning Bz macro for only PWM0 and PWM1 is defined(in sysctl.h).

#define SYSCTL_PERIPH_PWM0      0xf0004000  // PWM 0
#define SYSCTL_PERIPH_PWM1      0xf0004001  // PWM 1

I cant use other PWM modules bz it is not defined like above in sysctl.h

So please help me with this problem.

  • Hello Jithin,

    Because on the EK-TM4C123GXL the pins PB6 and PD0 are connected by a 0 Ohm resistor (R9). Remove the resistor

    Regards
    Amit
  • Would it (not) make (far) more sense to NOT (insert) that nuisance resistor?   (and it's "partner in crime" (R10)?)

    You of course had, Nothing to do w/that past, horrendous decision.   Yet it remains the USER PLAGUE - which KEEPS GIVING - and NEVER STOPS!   (and earned one here - guru status...)

    If that (ever so vital) "past compatibility" is to trump "user success/comfort" those "Plague-istors" could be plastic bagged.   Those needing/using (0.1% of your user population) could then install - and ALL OTHERS (99.9%) would ESCAPE this ongoing/unwanted Saga!

    Vendor's ease/limitation clearly (far) outweighs the needs/comfort of your hapless users.   Such cannot be denied - and is SO hard to explain and justify...

  • hello Amit,

                              How to configure other PWM modules(PWM3,PWM4,PWM5,PWM6 ,PWM7 and PWM8)?

    PWM module 0 and PWM module 1 are under same generator(generator 0)

    When I tried to use another PWM module(ie. another generator) compiler is showing warning Bz macro for only PWM0 and PWM1 is defined(in sysctl.h).

    #define SYSCTL_PERIPH_PWM0      0xf0004000  // PWM 0

    #define SYSCTL_PERIPH_PWM1      0xf0004001  // PWM 1

    I cant use other PWM modules bz it is not defined like above in sysctl.h

  • Hello Jithin

    Probably, you are changing tracks too fast. Did the first issue get resolved?

    Secondly, where does the data sheet state that PWM Module 0 and Module 1 are under the same generator?

    Regards
    Amit
  • Hello Amit,

    I am currently working on 2 projects that is why I'm asking 2 questions simultaneously.

    In data sheet of tm4c123gh6pm page No 1232 they are given a PWM Module Diagram.In that they are shown like PWM0 and PWM1 are under same generator.Also in tiva ware peripheral driver library page 419 same thing is mentioned.If I am wrong please correct me.

  • Hello Jithin,

    PWM0 and PWM1 output come from the same generator in one module. PWM0 Module and PWM1 Module are different instances of the same PWM.

    When using two PWM outputs you do not need to have 2 modules enabled.

    Regards
    Amit
  • sir,

    I need 2 separate PWM inputs for my project.So I have to configure PWM modules of different generators.Please tell me how to do that?

    Please tell me how to configure PWM2 and PWM3?