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.

no PWM output

Hi all, I've been trying to setup a PWM output. It is copied from the example which works. All i did was change the pins, but it doesn't seems to work, at all. can't think of any reason why it is going wrong. below is part of the code.

	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

	ROM_GPIOPinTypePWM(GPIO_PORTC_BASE, GPIO_PIN_4);
	ROM_GPIOPinConfigure(GPIO_PC4_M0PWM6);

	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
	PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ui32Load);

	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);
	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
	ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);

  • Hello Hong,

    The PWM output cannot be mapped to any of the GPIO's. The PWM module has 4 generators and each generator has 2 outputs as follows

    GEN0: PWM-0 and PWM-1

    GEN1: PWM-2 and PWM-3

    GEN2: PWM-4 and PWM-5

    GEN3: PWM-6 and PWM-7

    The PWM output on PC4 comes from Generator-3 while in the code configuration you are using Generator-0. If you change the PWM_GEN_0 to PWM_GEN_3 it should get the output.

    Also the PWM_OUT_0* have to be replaced with PWM_OUT_6* appropriately.

    Regards

    Amit

  • hi amit,

    I've did the changes but there don't seem to have any results. below is the updated code. did i made the changes correctly? am i right to also say there is only PWM0_BASE and PWM1_BASE?

    	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
    
    	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    
    	ROM_GPIOPinTypePWM(GPIO_PORTC_BASE, GPIO_PIN_4);
    	ROM_GPIOPinConfigure(GPIO_PC4_M0PWM6);
    
    	ui32PWMClock = SysCtlClockGet() / 64;
    	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
    	PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
    	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, ui32Load);
    
    	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6, ui8Adjust * ui32Load / 1000);
    	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
    	ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_3);

  • Hello Hong,

    Replace

    	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);

    with

    	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true);

    Regards

    Amit