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.

Unable to program PWM M0PWM0 on the EK-TM4c123GXL LaunchPad

Other Parts Discussed in Thread: EK-TM4C123GXL

I am trying to run two PWM generators on the EK-TM4C123GXL LaunchPad. I have one of the PWM generators working (M1PWM0) but I have not been able to get M0PWM3 to operate and produce an output. Here is my code:

#define PWM_FREQUENCY 55000

int main()
{
	volatile uint32_t ui32LoadPW0;
	volatile uint32_t ui32LoadPW1;
	
	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

	//------------------------------------------------------------------
	// Setup PWM1 on port D0
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
	ROM_GPIOPinConfigure(GPIO_PD0_M1PWM0);
	
	ui32LoadPW1 = (SysCtlClockGet() / PWM_FREQUENCY) - 1;
	
	MAP_PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32LoadPW1);
	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0,  ui32LoadPW1 / 2);
	
	ROM_PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
	ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_0);	
	//------------------------------------------------------------------
	// Setup PWM0 on port B5
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
	MAP_GPIOPinConfigure(GPIO_PB5_M0PWM3);
	
	ui32LoadPW0 = (SysCtlClockGet() / PWM_FREQUENCY) - 1;
	
	MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
	MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, ui32LoadPW0);
	MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, ui32LoadPW0 / 2);
	
	MAP_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true);
	MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_3);	
	

	while(1)
	{
	
	
	}
}

Looking at pin PD0 I see the 55KHz signal. But on pin PB5 I have no signal. Would anyone be able to tell me what I am doing wrong?


Thank you,

  • Hello Boca

    M0PWM3 belongs to Generator 2 Generator 1 and not Generator 3 of the PWM module.

    EDIT: Replaced Generator 2 by Generator 1

    Regards
    Amit

  • Amit Ashara said:
    M0PWM3 belongs to Generator 2

    Please hold on!   Hadn't you always (past) taught:

    • Gen0  controls MxPWMx:   0 & 1
    • Gen 1 controls Mx PWMx:  2 & 3

    Thus poster's M0PWM3 belongs to PWMGen 1. 

  • Hello cb1,

    Yes, that is correct. Apologies to the forum on the miscommunication and thanks to you. And edit'ed the original post as well.

    Regards
    Amit
  • Never is an apology sought nor required - outsiders "pick/choose" - you answer, "any & everything arriving/moving..."

  • "And - may I add a "long held" cb1_firm idea:

    Would it not prove easier & less error-prone to employ this PWM Gen notation:

    • PWMGenx_0   controls    PWMx_0A  &  PWMx_0B    instead of   PWMx_0  &  PWMx_1
    • PWMGenx_1   controls    PWMx_1A  &  PWMx_1B    instead of   PWMx_2  &  PWMx_3
    • PWMGenx_2   controls    PWMx_2A  &  PWMx_2B    instead of   PWMx_4  &  PWMx_5
    • PWMGenx_3   controls    PWMx_3A  &  PWMx_3B    instead of   PWMx_6  &  PWMx_7

    Forcing a different numbering scheme upon all but the very first PWM output bit causes confusion.   (proven here)  

    Method shown (above) is intuitive - employs a common, numeric linkage - which is "broken" by the current (error prone) method.    Adding complexity (via the current method) - when it serves no point - is w/out merit!     (sometimes well-thought, "NIH" proves best..."Poster Guidelines" - yet another - ringing example!)

  • Hello again,

    I did change to PWM generator 1 and I'm still not observing any output on PB5. I agree with cb1, these PWM signal defines are confusing. But again I'm 70+ so getting confused comes easy to me now.

    Here is my revised code for PB5 PWM assignment:
  • #define PWM_FREQUENCY 55000
    
    int main()
    {
    
        volatile uint32_t ui32LoadPW0;
    
        SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
        ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    
    //------------------------------------------------------------------
    
        // Setup PWM on port B5
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
        ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
    
        ROM_GPIOPinConfigure(GPIO_PB5_M0PWM3);
    
        ui32LoadPW0 = (SysCtlClockGet() / PWM_FREQUENCY) - 1;
    
        ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
    
        ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, ui32LoadPW0);
    
        ROM_PWMPulseWidthSet(PWM0_BASE, PWM_GEN_1, ui32LoadPW0 / 2);
    
        ROM_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);
    
        ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);
    
        while(1)
    
        {
        }
    
    }

  • BocaDev said:
    Here is my revised code for PB5 PWM assignment:

    Where's "here?"    Ain't (here) ... this forum.   (and you claimed confusion...)

    [edit]:   In the interest of, "Truth in Advertising" this reporter responded (prior) to poster's (added post) which contained code...

  • BocaDev said:
    ROM_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);

    Should not that parameter be: "PWM_OUT_2_BIT?"   (Ans: mais certainement!)

    Let's look @ the quicksand vendor forces us to wade thru:

    GPIO_PB5_M0PWM3  is  controlled by PWM_GEN_1  and the output bit is...PWM_OUT_2_BIT!"

    Seriously - are they TRYING to confuse us?   THREE DIFFERENT NUMBERS - TO DEFINE "ONE" PWM BIT... ... REALLY?    

    Posters should "flood the forum - adopt cb1's SANITY-driven method!   And press for, "Poster Guidelines" - while inspired...)

    TWO green verifies seem well deserved for tonight's (inspired) session...

  • Hello cb-1

    Since the pin is M0PWM3 shouldn't the out bit PWM_OUT_3_BIT?

    Regards
    Amit
  • You've proved our point, Amit. The variations in PWM: Gen, Num, & Bit defy (reasonable) understanding.
    A (more) confusing method of defining 8 (simple) PWM bits could not have been developed. Nightmare.

    Better yet - have not (both) you & I had (doubts) w/in this thread?   (I've not made the effort to "thumb thru" the defines - simply Nutz that is required!)

    Should poster Robert arrive - and he too stumble (maybe) then this "glorious" PWM definition (cobble) has hit the "Trifecta!"  Clearly there's a much better way!

  • Hello cb1-

    I agree. Let me put a table of what to use for what!

    Regards
    Amit
  • Hi Amit,

    Amit Ashara said:
    Since the pin is M0PWM3 shouldn't the out bit be: PWM_OUT_3_BIT?

    I agree.   Yet the fact that poster, then you, and I - all "stumbled" - speaks to the severe weakness (over-complication) of this (present) PWM labeling scheme!   That's a BIG Deal!

    Really - looking directly at your quote (above) "M0PWM3  "twists/turns"  and then (somehow) is "reincarnated" as, "PWM_OUT_3_BIT!"  Pardon my French - but, "that Stinks!"

    Now normally you/I/Robert all support the API.   And you surely played "no part" in this overly-complex, non-intuitive, PWM label "cobble."   ("cobble" to be kind)

    Earlier w/in this thread I identified that which staff/I find a, "better way:"   

    Would it not prove easier & less error-prone to employ this PWM Gen notation:

    • PWMGenx_0   controls    PWMx_0A  &  PWMx_0B    instead of   PWMx_0  &  PWMx_1
    • PWMGenx_1   controls    PWMx_1A  &  PWMx_1B    instead of   PWMx_2  &  PWMx_3
    • PWMGenx_2   controls    PWMx_2A  &  PWMx_2B    instead of   PWMx_4  &  PWMx_5
    • PWMGenx_3   controls    PWMx_3A  &  PWMx_3B    instead of   PWMx_6  &  PWMx_7

    Do note - this cb1 suggested,  "A & B" notation - which SO clarifies - has (already) been adopted by TM4C's Timers - has it not?  (Timer_0A & Timer_0B etc.)

    The (logical - and far more intuitive) extension then - if we must have 3 labels for: (PWM Generator, PWM Gen "pair", and PWM bit) would be: PWMx_0A_bit & PWMx_0B_bit.  (added to my chart, above)

    Even "poster" - admitting confusion - and heralded cb1 (in denial) MAY have (some) chance of understanding & recalling this!  (commonality & directness of these new labels adds immensely to the API's PWM clarity!)

    The complexity resulting from the (very) uneven/irregular (CLUMSY) current PWM notations - deserves serious rethink - and correction.

  • Hi Fellows,

    Gosh, thanks for all of the feedback you have provided me on this issue. I didn't expect all of the postings, but it has lead to a good cause of having a simple charts and ID labels. I still haven't got my PWM up and running after trying the suggestions. But I'm going to wait for Amit to build a new simple chart.

    Thanks again for your time.

    BocaDev
  • Might it assist Amit, myself (others) to solve your issue if you'd be so good as to list:

    • a simple narrative of what presently is failing.   Identify Port pin and provide your code which fully details the PWM set-up.
    • always - when PWM outputs fail - we advise that the subject MCU pin be re-purposed as GPIO Output - and then set that pin high - and monitor.   Such establishes - at minimum - that when restored to PWM mode - there is (some) chance of success.
    • might you switch to another MCU pin?   Perhaps there is "trouble" on the chosen pin - we'd "spin" endlessly should that be the case.
    • cannot you use the same PWM module - yet a different PWM Generator - to lessen the number of variables

    Your clear presentation - right here - aids our efforts.   Merci.

  • Hello cb1, BocaDev,

    I think the following table should be a good look up for existing TivaWare define.

    PWM Signal Generator Define Output Define
    M0PWM0 PWM_GEN_0 PWM_OUT_0_BIT
    M0PWM1 PWM_GEN_0 PWM_OUT_1_BIT
    M0PWM2 PWM_GEN_1 PWM_OUT_2_BIT
    M0PWM3 PWM_GEN_1 PWM_OUT_3_BIT
    M0PWM4 PWM_GEN_2 PWM_OUT_4_BIT
    M0PWM5 PWM_GEN_2 PWM_OUT_5_BIT
    M0PWM6 PWM_GEN_3 PWM_OUT_6_BIT
    M0PWM7 PWM_GEN_3 PWM_OUT_7_BIT

    Regards

    Amit

  • Hi Amit,

    That surely helps.

    Users should consider that the same relationships "hold" for "M1PWMn" too...

    As good as your chart is, Amit - the clumsiness & distinct differences - between each (required) define, disturbs.   (clearly leads to errors)

    Again - column three, "PWM_OUT_0_BIT" (could) have been represented as M0PWM0_Bit_0.   So much (more) intuitive.  And shorter.  

    Building upon the existing define reinforces both - drives "home" the linkage - undoubtedly superior...

  • Hello cb1-

    May be some more cue's as the first row parameters would make the data readable?

    Regards
    Amit
  • I'm just sitting in the corner amused by the Keystone Kops.

    And thankful I haven't had to do much PWM.

    Robert

    Please carry on.
  • Hello All

    This would be rather more useful. Th table lists out for the PWM Signal what are the variables that need to be passed to the different API's in terms of the PWM sub blocks.

    PWM Signal for PWM Module

    0 and 1

    PWMGenConfigure

    PWMGenPeriodSet

    PWMGenIntTrigEnable

    PWMGenEnable

    PWMIntEnable PWMOutputState PWMPulseWidthSet
    M0PWM0/M1PWM0 PWM_GEN_0 PWM_INT_GEN_0 PWM_OUT_0_BIT PWM_OUT_0
    M0PWM1/M1PWM1 PWM_GEN_0 PWM_INT_GEN_0 PWM_OUT_1_BIT PWM_OUT_1
    M0PWM2/M1PWM2 PWM_GEN_1 PWM_INT_GEN_1 PWM_OUT_2_BIT PWM_OUT_2
    M0PWM3/M1PWM3 PWM_GEN_1 PWM_INT_GEN_1 PWM_OUT_3_BIT PWM_OUT_3
    M0PWM4/M1PWM4 PWM_GEN_2 PWM_INT_GEN_2 PWM_OUT_4_BIT PWM_OUT_4
    M0PWM5/M1PWM5 PWM_GEN_2 PWM_INT_GEN_2 PWM_OUT_5_BIT PWM_OUT_5
    M0PWM6/M1PWM6 PWM_GEN_3 PWM_INT_GEN_3 PWM_OUT_6_BIT PWM_OUT_6
    M0PWM7/M1PWM7 PWM_GEN_3 PWM_INT_GEN_3 PWM_OUT_7_BIT PWM_OUT_7

    Regards

    Amit

  • This reporter awaits the arrival of #1 "Keystone Kop" - poster Robert.  (if he can escape his corner & amusement...)

    Long live labels w/extremely poor linkages and ZERO, intuitive naming.

    Amit - your chart IS helpful - and appreciated - yet avoids addressing the horrendous lack of commonality & linkages - which doom user comfort!

  • Good morning Amit,

    Thank you for your table listing showing the API signal constants for the PWM function. I followed your table and was successful in getting the PWM signal out PB5.

    Here is the code listing for anyone interested.

    int main()
    {
    	ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    	
    	// Configure Port B Pin 5 for PWM
    	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    	ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
    	ROM_GPIOPinConfigure(GPIO_PB5_M0PWM3);
    	
    	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);		// Enable PWM Module 0
    	
    	//------------------------------------------------------------------
    	// Setup PWM0 on port B5 (GPIO_PB5_M0PWM3)
    	
    	uint32_t LoadPW0 = (SysCtlClockGet() / 55000) - 1;
    	
    	ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
    	ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, LoadPW0);
    	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, LoadPW0 / 2);
    	
    	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true);
    	ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);	
    	
    	
    	while(1)
    	{
    		
    	
    	}
    }
    

    Thanks again Amit for the time you spent in coming up with your straight-forward table.

    Regards,
    BoceDev