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.

PWM output on PG0/1

Hi 

I can enable PWM output on PF2/3, but not on PG0/1.

I guess that should be GPIO configuration problem, but I can't config it work.

Does anyone provide some suggestion for me?

//
    // Set the PWM clock to the system clock.
    //
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
	// Enable the peripherals used by the Handle Light.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

	HWREG(GPIO_PORTG_BASE + GPIO_O_AFSEL) &= ~0xFF;
	HWREG(GPIO_PORTG_BASE + GPIO_O_AFSEL) |= 0x03;
	HWREG(GPIO_PORTG_BASE + GPIO_O_DEN) |= 0x03;
	HWREG(GPIO_PORTG_BASE + GPIO_O_PCTL) &= ~0xFF;
	HWREG(GPIO_PORTG_BASE + GPIO_O_PCTL) |= 0x66;

	//
	// Set GPIO as PWM pins.  They are used to output the PWM signals
	//
	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_8MA, GPIO_PIN_TYPE_STD);
	GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_1, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);


	//
	// Set the PWM period to PWM_FREQUENCY
	//
	PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 400);
	
	//
	// Start the PWM outputs with one clock long pulses.
	//
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 200);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 200);

	PWMDeadBandEnable(PWM0_BASE, PWM_GEN_2, 5, 5);
	//
	// Disable the PWM0  output signals.
	//
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
	PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);

	//
	// Enable the PWM generator.
	//
	PWMGenEnable(PWM0_BASE, PWM_GEN_2);

BTW, I work on TM4C129.

thanks,

Gavin

 

  • Hello Gavin,

    Which device is this? In most likelihood it is the following lines that may be the cause of issue

    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 200);
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 200);

    PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
    PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);

    Since it PWM2, the OUT lines must be 4 and 5.

    Regards
    Amit
  • Hi Amit,

    You are correct, Sir.  (as usual)

    Posters must maintain consistency - note that (earlier) poster correctly listed "PWM Out bits" - then "ran amuck" in the 2 final (critical calls.)

    GPIOPinConfigure(GPIO_PG0_M0PWM4);
    GPIOPinConfigure(GPIO_PG1_M0PWM5);

    I note that poster likely "unrolls" the good done by "GPIOPinTypePWM()" w/"GPIOPadConfigSet()."  Most always the PinType function properly manages that pin detail...

  • Hi Amit

    Thanks for correcting my mis-understanding.

    Gavin