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.

Tiva TM4C123GXL PWM configuration issue



Hi, I need to configure two PWMs but only the first one is working, as seen in the oscilloscope. This is the code that I am using:

int main(void) {
	DeviceInit();

    MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_16);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    MAP_GPIOPinConfigure(GPIO_PB6_M0PWM0);
    MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
    MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, SERVO_PERIOD);
    MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
    MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
    MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, SERVO_CENTER);

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    MAP_GPIOPinConfigure(GPIO_PF0_M1PWM4);
    MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
    MAP_PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    MAP_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, SERVO_PERIOD);
    MAP_PWMOutputState(PWM1_BASE, PWM_OUT_4_BIT, true);
    MAP_PWMGenEnable(PWM1_BASE, PWM_GEN_2);
    MAP_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, SERVO_CENTER);

    while (1);
}

I just can't figure out why the second one doesn't work. This makes me feel so stupid :(

Angelo

  • Hello Angelo

    PF0 is a locked pin which must be unlocked before reconfiguration. Please see the following post for details

    e2e.ti.com/.../374640

    Regards
    Amit
  • Angelo Cirino said:
    This makes me feel so stupid :(

    Such feeling is unnecessary my friend - you are far, far, far from alone.  

    The designer & implementer of that, "well known, vast expanse of missing highway" should absorb that feeling.   Inept roadsign markings (mice-type, non-bolded, too few manual alerts) are rarely noted - death toll rises - yet the trap continues its (duly noted) destruction...

    Comfort/convenience works best when aimed at client/user - not vendor - who long has "known" yet (apparently) feels free to allow such issues to continue...

  • Hi Amit, that information is easy to forget. I gave up PF0 but the issue remains. My problem is that I am using a Boosterpack (Orbit by Digilent) that uses a lot of pins and left me with too little options. I created a side-project just to test the pins that were left for me to use.

    Well, I changed the test code and only M0PWM0 is working:

    int main(void) {
        MAP_SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ | SYSCTL_USE_PLL | SYSCTL_SYSDIV_4);
    
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_16); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); MAP_GPIOPinConfigure(GPIO_PB6_M0PWM0); MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6); MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, SERVO_PERIOD); MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true); MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_0); MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, SERVO_CENTER); MAP_GPIOPinConfigure(GPIO_PF1_M1PWM5); MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_5); MAP_PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); MAP_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, SERVO_PERIOD); MAP_PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true); MAP_PWMGenEnable(PWM1_BASE, PWM_GEN_2); MAP_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, SERVO_CENTER); while (1); }

    Where is the error?

    Angelo

  • cb1- said:
    Inept roadsign markings (mice-type, non-bolded, too few manual alerts) are rarely noted - death toll rises - yet the trap continues its (duly noted) destruction...

    Indeed I agree, that kind of information should be kept in every point where it is useful.

  • Hello Angelo,

    Well PF1 is GPIO_PORTF_BASE, GPIO_PIN_1 and not GPIO_PIN_5

    MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_5);

    Regards
    Amit
  • EDIT: Hi Amit, I corrected the assignment and now the PWM output is correct.

    Thanx a lot.


    Angelo

  • Hello Angelo,

    And I was trying to still figure why it was not working.... My LPad showed it to be working.

    Regards
    Amit