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/TM4C123GH6PZ: PWM When I give Duty Cycle 0, I get output like I'm giving 255

Part Number: TM4C123GH6PZ

Tool/software: Code Composer Studio

Hi, I am using the PWM module in the project. When I give Duty Cycle 0, I get output like I'm giving 255

  • SysCtlClockSet(
    SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ
    | SYSCTL_OSC_MAIN);

    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

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

    GPIOPinConfigure(GPIO_PD0_M1PWM0);
    GPIOPinConfigure(GPIO_PD1_M1PWM1);

    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);

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

    PWMGenPeriodSet(PWM1_BASE,PWM_GEN_0 , 255);
    //PWMGenPeriodSet(PWM1_BASE,PWM_GEN_0 , 255);

    //PWMGenEnable(PWM1_BASE,PWM_GEN_0);

    PWMOutputState(PWM1_BASE,(PWM_OUT_0_BIT | PWM_OUT_1_BIT),true);
    PWMGenEnable( PWM1_BASE, PWM_GEN_0 );

    /*******************************************************************/

    PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0,0);
    PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1,150);
  • This has long been known/recognized - and occurs across ARM MCUs from (many) ARM vendors.

    [edit] 01:38 - Just noted that you are using PDO & PD1 - and should yours be a "LaunchPad" - vendor has (forever) emplaced "devil Plague-istors" (R9/R10) - which "tie PDO/PD1 to PB6/PB7!"    Now if you've not addressed PB6/PB7 - then no harm - no foul.   (other than the "potential" for FUTURE HARM!)   I recommend that you de-solder - then "tombstone" (stand up those Rs by soldering (just) one leg) which removes their potential for MCU pin contention - and "signals" that you've CORRECTED this vendor's (ill advised) "FILL of those 2 resistors".    Again - unless you've "ordered" PB6/PB7 to GPIO Outputs - this proves an unlikely cause of your issue...

    With the great control provided by the PWM Module/Generator - arrives (some) limitation.

    Two solutions enable your "fix" of this "known" (PWM issue @ MAX & MIN Settings:   (i.e. PWM @ 100 or 0%)

    • Hardware - employ an external logic gate(s) following" the MCU's PWM Output which is able to "force" (either) a logic "1" or "0" upon (an added) GPIO command
    • Software - at each/every "PWM Update" - test for, "PWM set to (either) limit."    If/when such occurs - "over-ride the MCU's (@ limit) output" by presenting (instead) a PWM value of (say) 2% or 98% duty cycle - which will prove (in most all instances) "Acceptable to your PWM Controlled device."

    Should you be employing a "Gate Driver IC" to (tech term follows) "beef up" the MCU's PWM output - prior to its presentation to a (likely) Power FET - you may add a series resistor between the MCU's PWM signal & gate driver's input.    Then - via a (separate) GPIO signal - which connects (directly) to that (same) "gate driver input" you are (effectively) able to "over-ride" the PWM signal - presenting (instead) a logic "1" or "0."    

    Note that, "No added hardware" (but for the series resistor) is required - and you must, "Test for & recognize" the MCU's "@ the limit" output - and cause the GPIO to switch from "high impedance" (i.e. input) to "Output" - and set it to the proper (1 or 0) logic level.     This (GPIO Moderated) "Adjunct to PWM" technique may be (even) extended to, "Non Gate Driver" applications!     (by substituting any "single pin, level controlled IC" for the gate driver.)

    It has been noted that the MCU's (far simpler) "Timer Method" of "Generating PWM" (likely) "escapes" this, "PWM Generator's "issue" when "commanded to extremes."

  • Might a slower "re-read" assist?
    Great (necessary) detail has been supplied...
  • answer code please. I'm low english
  • I "feel your language pain" - yet the issue is "NOT within the code!"

    If you set the PWM Period to 255 - you cannot set the PWM Pulse Width, "HIGHER than around 249" - to be safe.
    Likewise - you cannot set the PWM Pulse Width, "LOWER than around 5 or so" - again to be safe.

    For example:

    PWMGenPeriodSet(PWM1_BASE,PWM_GEN_0 , 0);  //   You report this as FAILING - yields 100% Duty Cycle!

    Instead - try:

    PWMGenPeriodSet(PWM1_BASE,PWM_GEN_0 , 5);  //    This should work - produces a (very small) Duty Cycle (< 2%)

    This is NOT a fault w/in your code - it IS a (known) limitation w/in the ARM (and other) MCUs.

    Possibly you can get a friend or teacher to assist your further read & understanding.     Wish you well...

  • What do I need to do to make the PWM signal 0 ?
    If I make the PWM signal 0, this will solve my problem
  • Ali YOLCU said:
    What do I need to do to make the PWM signal 0 ?

    I have answered that - and supplied several methods to achieve just that - in my (first) responding post.

    You may (also) choose to, "Switch the pin from "PWM (type & config) to GPIO" and then set it to logic "0."    Again - as past described (first post) - you must "test" for the desire to "set the Duty Cycle to ZERO" - and at that time - and that time only - reconfigure the pin from PWM to GPIO - and order it low!

    Note that along w/(very) exhaustive written descriptions (several methods) I earlier provided sample code - which comes "so very close" to "0 Duty" PWM.

    PWMGenPeriodSet(PWM1_BASE,PWM_GEN_0 , 5);   //  Provides less than 2% Duty when (your value) 255 provides the period.   You (may) attempt values of "1-4" - to lower the duty cycle even further!   (which "encroaches" upon the "safety factor" - may or may not work ... see the legal "boilerplate" (page bottom) specifically: "Providers of Content" (that's my work) beneficial to ALL "outsiders" here.)

  • I have this same problem.

    cb1, do you know where this problem is documented? I can accept limits and faults as long as they are canon (datasheet or errata). You can't ship product on a hunch.
  • As you seek to "avoid" hunch - why not start w/ARM - try & determine if this (known) PWM issue originated w/them - or is caused by the individual "implementation team." (that would be this vendor, here.)

    It is assumed that your desire to "escape" hunch has propelled you to a serious, "Search & Review" of all known Vendor published errata!

    As past Secretary Rumsfeld noted - it is recognized that, "Not all "known unknowns" - make it into errata - and worse yet, there exist, "unknown unknowns" - only (later) - if ever - to make it into errata.

    As you chose to characterize this "known finding" as a, "hunch" - does it not fall to you to adequately investigate - and then agree with or dispute that finding?
  • cb1_mobile said:
    As you seek to "avoid" hunch - why not start w/ARM - try & determine if this (known) PWM issue originated w/them

    Manufacturers don't seem to be sharing PWM peripherals (although I may have missed a clue).

    I don't know why this oversight keeps happening. It's not as if PWMs that cover the full range haven't been implemented before.

    Robert

  • Robert Adsett said:
    Manufacturers don't seem to be sharing PWM peripherals

    Agreed!      And this is proves, "one more justification" for my firm's key clients/investors to  have pushed us to,  "Investigate the ARM MCU offerings of MANY (certainly NEVER just ONE) ARM Vendor."       And - we have noted that,  "Several ARM MCU Vendors - yet NOT ALL - appear to, "suffer"  this,  "PWM issue @ Duty Cycle Extremes!"     (thus the claim of  "hunch" was rather "uninformed" - or itself was, "poster's hunch!")

    Now this, "Variation in Peripheral Implementation" extends beyond the PWM Module.     Many/most modern ARM MCUs contain a DAC, and highly capable, TFT Interface (absent here) , differences arise w/in Timers, ADCs, QEIs,  I2C (another  PWM-like, "difficult one") - the list grows.

    And yes - years long past - our mighty Intel MCU (even Zilog) could dial up PWM Extremes - w/out (any) special care/handling.     In the defense of ARM -  vastly raised performance -  has necessarily raised the complexity level - of  many/most such MCU peripheral implementations.      And each "Vendor Implementation Team" has different design goals - different price points - so (some degree) of  peripheral variation is the "New Norm" - and IS to be  (grudgingly) expected!       (while being unwillingly - accepted...)

  • cb1_mobile said:
    And yes - years long past - our mighty Intel MCU (even Zilog) could dial up PWM Extremes - w/out (any) special care/handling.

    Also ST, Infineon and probably others. IIRC the TI PWM peripherals on their DSPs can also go the full range.

    cb1_mobile said:
    In the defense of ARM -  vastly raised performance -  has necessarily raised the complexity level

    Well, no. That's a self inflicted wound really. Not everything needs to be more complex. CAN and UART come to mind, they're not more complex. Although TI's UART also appears to make some simple mistakes.

    And really the PWM on the TM4C is not more complex than that on other devices that have got it right. At least as far as I can see.

    I don't know whether I should be dismayed that they are repeating old specification mistakes or glad that they are repeating ones that we have know work arounds for. Maybe this peripheral design issue lies with the previous developer rather than TI? At least they had the excuse of unfamiliarity.

    Robert

  • Robert Adsett said:
    cb1_mobile
    In the defense of ARM -  vastly raised performance -  has necessarily raised the complexity level

    Should we (or our "pre-carnations") have existed in the 1800's - we'd each, "Reach for a pistol."     (Aaron Burr & Alexander Hamilton - for US history fans)

    The ability of the ARM devices to:

    • Synchronize Multiple PWM Channels
    • Cease all PWM Outputs (immediately) - via a changed logic level - applied to a single MCU pin
    • Accommodate so wide a range of PWM Frequencies
    • produce coordinated PWM outputs - across 4 separate PWM Generators - impressed upon 8 MCU pins
    • ability to, "Alter, Cease, or Add" the PWM (or multiple other) Functions - or key aspects of its operation - "on the fly"
    • and maintain higher "accuracy & precision" - under varying temperature & voltage conditions (w/in spec)

    works to support the (proper) claim of  "ARM's general superiority..."    (you could have wandered to the MSP device - is that not true?)

    I must note your listing of one MCU vendor - claimed "not" to suffer from,  "PWM issue @ extremities" - which we must challenge.    (note: many MCUs are offered - our experience is unlikely to have (completely) overlapped.)

    Should you "resist" - I've ordered a "dual set of matching pistols" - both fully loaded - and provided (only) minimal direction to the "border authorities" ... ("unload" the pistol - crossing to (your) side...)

  • Key word there may be needs. Although many or most of those features existed previous to ARM in other controls, notably in DSPs although the ST10 and C166 families from ST and Siemens/Infineon had fairly complex PWMs as well (also some reasonably complex timers). So none of this is specific to ARM processors

    cb1_mobile said:

    The ability of the ARM devices to:

    • Synchronize Multiple PWM Channels
    • Cease all PWM Outputs (immediately) - via a changed logic level - applied to a single MCU pin
    • Accommodate so wide a range of PWM Frequencies
    • produce coordinated PWM outputs - across 4 separate PWM Generators - impressed upon 8 MCU pins
    • ability to, "Alter, Cease, or Add" the PWM (or multiple other) Functions - or key aspects of its operation - "on the fly"
    • and maintain higher "accuracy & precision" - under varying temperature & voltage conditions (w/in spec)

    Not specific to ARM devices. Other devices have this capability. I don't see why the added complexity of these features would make full PWM more difficult. Also to add to your list

    • the ability to choose centre aligned or edge aligned PWM. I think some may have control over the phase shift between PWMs as well but it's been a while since I read the details.

    cb1_mobile said:
    I must note your listing of one MCU vendor - claimed "not" to suffer from,  "PWM issue @ extremities" - which we must challenge.

    I'm just noting they have at least one device that did not suffer from that malady. Like having an interrupt occur on transmit buffer empty this is a widely solved problem, there's really no need to keep repeating it. Especially since it's a design/specification problem not an implementation one.

    Is there a reason to believe it has a large cost in silicon? I don't think so but...

    Now if your PWM was only aimed at controlling LEDs or, maybe, providing D/A then this oversight is fairly small. But for things like DC motor control* this capability is necessary and although there are workarounds the actual implementation of those can get a little tricky.

    Robert

    * AC motor control doesn't need to go full range and maybe that's the key. Maybe the PWM peripherals are designed with AC motor control in mind and the needs or other devices just aren't considered.

  • Do realize that you (may) be placing my "bi-weekly, stipend from ARM" - in (some) jeopardy...    C'est fini - et bien - mercî...

  • Please find similar discussion and workaround solutions in this post.
    e2e.ti.com/.../2417089