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.

CCS/TM4C123GH6PM: API function PWMGenConfigure stuck at FaultISR infinite loop

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

I am trying to use PWM on my TI board. I found this problem when I used single step into in the debug mode. My codes are shown below:

#include "inc/tm4c123gh6pm.h"
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/pwm.h"
#include "driverlib/gpio.h"
#include "inc/hw_GPIO.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"


void PWMInitTom(void) {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // Enable the PWM0 peripheral
    //while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0)) {/* Wait for the PWM0 module to be ready.*/}
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1); //Set the PWM clock to the system clock
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Enable GPIOB
    GPIOPinConfigure(GPIO_PB6_M0PWM0); // configure the GPIO pin to select PWM0 functions
    GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6); // Configure the PWM function for this pin.

    //Configure the PWM generator for count down mode with immediate updates to the parameters.
    PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

    // Set the period. For a 50 KHz frequency, the period = 1/50,000, or 20
    // microseconds. For a 20 MHz clock, this translates to 400 clock ticks.
    // Use this value to set the period.
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 400);
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 100); //Set the pulse width of PWM0 for a 25% duty cycle.
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 300); //Set the pulse width of PWM1 for a 75% duty cycle.
    PWMGenEnable(PWM0_BASE, PWM_GEN_0); // Start the timers in generator 0
    PWMOutputState(PWM0_BASE, (PWM_OUT_6_BIT | PWM_OUT_7_BIT), true); // Enable the output for PWM6 and PWM7 on Module 0

}

unsigned long freq, width, period, pwmfreq;

int main(void) {
    SysCtlClockSet( SYSCTL_USE_PLL |SYSCTL_SYSDIV_10| SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN); //set clock to 20MHz
    freq = SysCtlClockGet();
    PWMInitTom();
    pwmfreq = SysCtlPWMClockGet();
    width = PWMPulseWidthGet(PWM0_BASE, PWM_OUT_0);
    period = PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0);
    while (1) {

    }
}

So when CCS tried to compile PWMGenConfigure, it would jump into FaultISR and stuck at there forever. 

And when I used the example file (invert.c), I had this same problem. And PWMGenConfigure caused the problem.

I have included pwm.c , sysctl.c , gpio.c to my project. 

Can anyone explain?

Thanks

  • Hi Tom,
    Have you seen this application note?
    www.ti.com/.../spma043.pdf

    Follow up questions are best served in the TM4C forums.

    Thanks
    ki
  • Thanks Ki for your reference. I found out that SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0) actually failed to enable my PWM0 peripheral. Even though I added 1 second delay to the system, my PWM0 is still in disabled state. I also tried to add while loop to delay
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0)) {/* Wait for the PWM0 module to be ready.*/}
    but it's even worse because PWM0 is never enabled, so system stuck at this while loop forever.
    My conclusion is SysCtlPeripheralEnable is not working.
    Any solution?
  • This is a question best asked to the experts in the TM4 forums. I will move this thread to that forum.

    Thanks
    ki
  • Thanks Ki.
    I want to add 1 additional information.
    I tested SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB) and GPIOB peripheral was successfully enabled.
    only SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0) had problem.
  • Using a past (LX4F) device - ours worked - yet we enabled Port_B - prior to enabling PWM0.

    I know we succeeded more recently - w/your MCU - and staff are looking for that code...
  • Hi,
    Your problem is with the below line. PWM0 generator can only assert PWM_OUT_0_BIT and PWM_OUT_1_BIT. The PWM_OUT_6_BIT and PWM_OUT_7_BIT are for PWM3_BASE.

    PWMOutputState(PWM0_BASE, (PWM_OUT_6_BIT | PWM_OUT_7_BIT), true); // Enable the output for PWM6 and PWM7 on Module 0

    Please change to below and try again.

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

  • Hi Charles, thanks for your attention and time.
    I changed that line, but SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0) is still having problem.

    and I called SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0) before PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true)
  • ok, that is weird. I just ran your code with the only change to the PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true) and I'm able to see a 50kHz PWM on the scope.
  • Thanks again Charles. At least I know my code is not the major problem. I guess my board has some problems.
  • Hi Tom,
    I also tested the invert.c and it is behaving correctly on my TM4C launchpad.
  • Mes Amis,

    Is not PB_6 one of those pins "gifted" w/one of those 0Ω "Plague-Istors" - and thus shorted to another MCU GPIO?
    Yet - even if true - the function call should not (itself) fail.

    Charles - might this poster have imported code from 'StellarisWare" (as we have - exclusively) and might parameter, "SYSCTL_PERIPH_PWM0" have changed under tivaWare?
  • Hi cb1,
    SYSCTL_PERIPH_PWM0 is correct.

    You are right about the 0ohm between the PB6 and PD0. It will be good for Tom to check if he has PD0 tied to VDD or ground.
  • Thank you, Charles.

    Either way - should PD_0 be config'ed as Output - and ordered "high or low" - (poor) PB_6 will suffer. (and perhaps PD_0 as well (when both are outputs - and driven to opposing states)     Most protective procedure - should those resistors remain - is to order PD0 into Input Mode.

    Best (we've found) is to "tombstone" plague-istors R9,10 (break their MCU to MCU connects - and Tack solder one lead - serves as neat reminder (graveyard like) of Big Brother's (always) "helpful" (yet intrusive) manner!)       Much like tossing cb1 "sunscreen" - when Great White - mouth agape - is closing & upon FINAL...

    Might the Periph Enable of PWM0 - before Port_B - cause poster's issue? Thanks.

  • Thanks cb1. I also have LX4F and I will test PWM on that. I want to ask can LX4F use TivaWare? I heard from somewhere that LX4F and TM4C are the same thing. Is that true?
  • I also tried configured PWM0 before GPIOB. still had the problem :(
    I think I would just buy a new board.
    Thank you so much for devoting
  • Indeed LX4F can use TivaWare - but w/some cautions. (you will have to manually enter LX4Fxyz w/in pin_map.h - as it is "banned" from TivaWare)

    As StellarisWare 9453 was the "last" API which supported LM3S AND LX4F - and was (near) Bullet-Proof - our clients "locked us into StellarisWare!" And - we have succeeded in making StellarisWare accommodate TM4C123 (via the pin_map.h mod - possibly a few (simple) others)

    Do TRY to enable Port_B before you enable PWM0 - see if that corrects. If not - carefully review "pwm.h" to insure that "PWMGenConfigure() is present" and its parameters - are as you expected. Very, very strange behavior.

    And DO "tombstone" those Plague-istors - which marks your board as SAFE - and prevents damage.

    [edit]... Tom - do not discard your board!    Even if that pin is damaged - the bulk of your board (should) be reasonably intact.    When you've a moment - config PB6 as an Output - and toggle it - monitoring the behavior.    *** *** DO THIS ONLY AFTER "Tombstoning" those 2 Plague-istors!  *** ***