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.

TM4c1230E6pm: PWM issue

Part Number: TM4C1230E6PM

i m working on TM4c1230E6Pm device and having  problem with  PWM code , below is the code.

the code is compiled with out error and when running device it is going to fault isr after executing    PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN );  line .

Pls help on same or share me a reference code  for PWM.

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
// HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
// HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;


GPIOPinConfigure(GPIO_PF1_M1PWM5);
GPIOPinConfigure(GPIO_PF2_M1PWM6);
GPIOPinConfigure(GPIO_PF3_M1PWM7);

GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2|GPIO_PIN_3);


// PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN |PWM_GEN_MODE_NO_SYNC);
// PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN |PWM_GEN_MODE_NO_SYNC);

PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN );
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN );

PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, 400);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, 400);

PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, 400);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, 400);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, 400);


PWMGenEnable(PWM1_BASE, PWM_GEN_2);
PWMGenEnable(PWM1_BASE, PWM_GEN_3);

PWMOutputState(PWM1_BASE, (PWM_OUT_4_BIT | PWM_OUT_5_BIT | PWM_OUT_6_BIT|PWM_OUT_7_BIT), true);

// PWMGenDisable(PWM1_BASE, PWM_GEN_2);
// PWMGenDisable(PWM1_BASE, PWM_GEN_3);

}

  • vijender Singh said:
    it is going to fault isr after executing    PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN );

    Might this result as you've NOT implemented the appropriate "Pin Config" code for PWM_GEN_2?    Nor have you "Pin Typed"  ...  ANY PWM pins!

    Your code:

    GPIOPinConfigure(GPIO_PF1_M1PWM5);
    GPIOPinConfigure(GPIO_PF2_M1PWM6);  
    GPIOPinConfigure(GPIO_PF3_M1PWM7);

    neglects xyz_M1PWM4 - does it not?

    "PWM_GEN_2" embraces:   "xyz_M1PWM4 and xyz_M1PWM5?"       You've created a listing for bit 5 - but not for bit 4!

    I've not checked your MCU's datasheet - is it "sure" that pin "xyz_M1PWM4" is contained w/in Port F?      (as that's the only Port you've (earlier) enabled?)

    And - you've NOT made the REQUIRED CALL to, "GPIOPinTypePWM()"   which is mandated for ALL Pins which are configured as PWM.

    Vendor provides excellent code examples - appears you've not fully/properly "found nor deployed."     TWare/examples/peripherals/pwm ...  signposts ...

  • Hi,

     I don't see an issue with your code but upon checking the feature  availability on the TM4C1230E6, the PWM is not available. This is why you will get a hard fault.

     I will suggest you go to the TM4C product page and look for the parts that best meet your application need. 

  • Good grief - this is "shades" of poster Danny's LX4F120 - which also NEGLECTED ANY PWM Module! This has to be the "lowest cost TM4C!"
    Such an "ill equipped MCU" could do well in an, "Off Grid Cabin" - where, "rubbing sticks together (maybe) yields Fire!"     (Be still my heart...)

    Is it true that the PWMPinType() function - which WAS REQUIRED UNDER STELLARISWARE - has been eliminated under TWare?    (Poster's code left any/all calls to the PinType out...)     Along w/missing the config of bit 4...     Other than that - the code was FINE.     (suddenly - I smell smoke... and it is no longer dark...)

  • Hi cb1,
    I think the poster uses GPIOPinTypePWM which is fine. Even without proper pin type configuration it should not result in hard fault. It is the unavailability of the PWM module in this part number that caused the fault.
  • Hi Charles,

    May we note that poster did NOT use GPIOPinTypePWM()?     It never appeared.

    May it be asked, "How his line of code, "SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);"  produced NO FAULT!"    

    This line of code appeared before "PWMGenConfig()" - should it not have caused the fault?     (yet did not!)      (as just as you've noted - this MCU contains NO PWM Module!)

  • Hi cb1,

     Below is the snippets of poster's code. I think the SysCtlPeripheralEnable() will enable the clock to the PWM1 module. The clock enable register is inside the SYS module. The fault will not occur until the PWM1 registers are accessed. The poster said the fault happens when PWMGenConfigure() is called which makes sense. Code before that are accessing the registers in the SYS and GPIO modules. 

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    // HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;


    GPIOPinConfigure(GPIO_PF1_M1PWM5);
    GPIOPinConfigure(GPIO_PF2_M1PWM6);
    GPIOPinConfigure(GPIO_PF3_M1PWM7);

    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2|GPIO_PIN_3);

    // PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN |PWM_GEN_MODE_NO_SYNC);

    // PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN |PWM_GEN_MODE_NO_SYNC);

    PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN );

  • Charles Tsai said:
    I think the SysCtlPeripheralEnable() will enable the clock to the PWM1 module.

    Not to (further) beat this dead horse (although it IS fun) but ... this feeble MCU has NO/ZERO PWM Module!     Thus - is it "reasonable" that "enabling a clock - to a non-existent peripheral module" - will "Yield NO Fault?"     Such is "Crazy-Making" - is it not?

    We know that you don't "make the rules" - but (any) logic here is "tortured" at best -  "Non-Existent" (just like the PWM Module w/in this MCU) at worst!

  • There must be something wrong with his project settings. The code should not compile because the PWM pin macros aren't defined in driverlib/pin_map.h when PART_TM4C1230E6PM is defined.

  • Hi cb1,

    As mentioned, the register to enable the PWM or any modules is in the SYS. The peripheral present register is also inside the SYS. Either one will block any access to the PWM1 module but only until the registers inside the PWM1 is accessed.
  • It is not the first time someone said something less than true on the internet, .

    To the OP: always read the datasheet. What you are trying to do can be done, on your chip, so long as you figure out how your chip works and which peripherals can be configured to do what you want to do.

    Specifically, those chips can be configured to generate pwm from their timers, or if available, from their pwm modules. But you need to read the datasheet. Copy and paste someone elses code doesn't get you remotely close to your goal.
  • Danny F said:
    Copy and paste someone elses code doesn't get you remotely close to your goal.

    Since when?"    Is not that method (often) used -  "right here?"

    Danny F said:
    It is not the first time someone said something less than true on the internet

    Some here ... find that  "hard to believe."

    Poster's device (appears) to be the "reincarnation" of  (your)  LX4F120.     (both PWM Module-free ... landfill  "calls out" to each...)