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.

Generating Multiple PWM in TM4C123GH6Pm



Dear All , 

I am trying to generate two different PWM signals one for clock and the other one for generating a Single pulse to trigger an output for that i need to generate two different periods i am using PWM module 0 and PWM module 1

here is the code for the same

GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_5);
GPIOPinConfigure(GPIO_PE5_M1PWM3);
PWMGenConfigure(PWM1_BASE, PWM_GEN_0,PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC );
PWMGenConfigure(PWM1_BASE, PWM_GEN_1,PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, 60);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, 60);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, 30);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, 57);
PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT, true);
PWMOutputInvert(PWM1_BASE, PWM_OUT_1_BIT, true);
PWMGenEnable(PWM1_BASE, PWM_GEN_0);
PWMGenEnable(PWM1_BASE, PWM_GEN_1);
PWMIntEnable(PWM1_BASE, PWM_INT_GEN_1);
PWMGenIntTrigEnable(PWM1_BASE, PWM_GEN_1,PWM_INT_CNT_LOAD);

PWMGenConfigure(PWM0_BASE, PWM_GEN_0,PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC );
PWMGenConfigure(PWM0_BASE, PWM_GEN_1,PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC );
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 7000);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 7000);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 30);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 57);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT, true);
PWMOutputInvert(PWM0_BASE, PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
PWMGenEnable(PWM0_BASE, PWM_GEN_1);

the out  that i am getting the same period for both the PWM module the out put pins are 

GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinConfigure(GPIO_PD0_M1PWM0);
GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
GPIOPinConfigure(GPIO_PD1_M1PWM1);


GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinConfigure(GPIO_PB6_M0PWM0);

pls help me i am struck with thie problem 

with regards

Vijay

 

  • Hello Vijay,

    The terminology of the PWM channels is a bit hard to understand. I have these notes below on my code, they help me figure out what is the proper generator and channel for the pins. See if this helps:

    // Read this for explanation: e2e.ti.com/.../344373
    // On PWM0_BASE: "0" is the 0 from M0PWM3 on the pin name
    // On PWM_OUT_3 and PWM_OUT_3_BIT: "3" is the 3 from M0PWM3 on the pin name
    // On PWM_GEN_1: "GEN_0" is for PWM0 and PWM1, GEN_1 for PWM2 and PWM3, GEN_2 for PWM4 and PWM5, GEN_3 for PWM6 and PWM7

    You will need to pay attention to these names, and assign the correct macros to match whatever pin you want your signal on.

  • Hello Vijay,

    Each PWM generator has two outputs. Generator-0 has outputs 0 and 1. The base period is the same for both outputs. What can be changed is the pulse width. In your case you want them to separate. So what you would need to do is to use two different generators and only one output per generator. That is the only way you can have independent width and duty cycle.

    For clarification
    1. Generator 0 controls output 0 and 1
    2. Generator 1 controls output 2 and 3
    3. Generator 2 controls output 4 and 5
    4. Generator 3 controls output 6 and 7
  • Thanks guys since i am using a launch pad to get he prototype running i the launch pad both the pins are connected through a zero ohms resistor

    PD0 is connected to PB6 through through R9 now i am able to get the pwm outputs in different Periods

    thanks all for the support provided
  • Bruno's post which nicely detailed the THREE Variations of PWM nomenclature (names) deserves applause.   Breaking those Three, different naming conventions down should have been better detailed w/in the Peripheral Driver User Guide (where they first appear) - firm/I believe.

    Bruno's post may be rendered even more useful via "Bold" or "Color" to highlight the (very) specific numeral designations.  

    "PWM_OUT_3 and PWM_OUT_3_BIT ...  "3" is the 3 from M0PWM3"

    And perhaps a slight rewording to better detail the fact that TWO Independent PWM Modules exist: (PWM0_BASE & PWM1_BASE) yet all other PWM Generator/Signal naming conventions remain...