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.

TM4C123BE6PZ PWM channels, PWMPulseWidthSet changes two outputs

Hi,

I am trying to use each PWM output individually, but when I set the PWM to one output, two outputs gets the same value.

when I use PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 2500)...PWM_OUT_2 gets the same value.

int main(void) {

	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ);;
	ui32SysClkFreq = SysCtlClockGet();




	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
	PWMClockSet(PWM0_BASE,PWM_SYSCLK_DIV_8);

	//M0PWM2
	GPIOPinConfigure(GPIO_PH2_M0PWM2);
	GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_2);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 10000);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 1);
	PWMGenEnable(PWM0_BASE, PWM_GEN_1);
	PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);



	//M0PWM1
	GPIOPinConfigure(GPIO_PH1_M0PWM1);
	GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_1);//pf1
	PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 10000);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 1);
	PWMGenEnable(PWM0_BASE, PWM_GEN_0);
	PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);





	//set pwm
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 2500);


	while(1);


	return 0;
}

  • Hello Moha,

    PWMClockSet is a TM4C129 function. On TM4C123 the equivalent function is SysCtlPWMClockSet. That is one change that you have to make to your code.

    Other than that I do not see any reason why PH2 will get the same value as PH1 unless
    (a) PH2 is not well connected to the PCB
    (b) There is a short on the PCB between PH2 and PH1

    Regards
    Amit
  • Hi Amit,

    Agreed - and (c) a low impedance path between "off-board" device/connections...   (routing to user's PUT (pins under test))

    And - as you/I have so often advised - always best to place "subject" pins (first) into GPIO mode and toggle/observe. (i.e. basic KISS - so that the more complex PWM has a "chance" to succeed!) Assuming/hoping/praying that, "all is well" may not prove best/brightest...

  • Thanks Amit, its the short between two pin.