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.

RTOS/TM4C123GH6PM: Setting the PWM to 100%

Part Number: TM4C123GH6PM


Tool/software: TI-RTOS

Hi all,

I'm using the PWM to operate a motor and I need to set it to 100% sometimes in order to turn the motor off (the value is inverted).

I understood that setting 0% and 100% duty cycles on the PWM is problematic but can be done.

What I tried is disabling the PWM and inverting the output:

PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, false);
PWMOutputInvert(PWM0_BASE, PWM_OUT_6_BIT, true);

I also tried changing the output pin to a digital output and setting it as 0xff:

GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4, 0xff);

Both methods didn't stop the PWM, I'm still getting a very small voltage, am I doing something wrong?

Thanks.

  • Nadav Bahana said:
    Both methods didn't stop the PWM, I'm still getting a very small voltage, am I doing something wrong?

    Feel your pain - and "Bravo to you" - for making the effort to note the,  "Known Limitation in PWM Duty Cycle Range" - felt across  most  Vendors' - ARM MCU devices.     (thus NOT - a single vendor issue!)

    Your writing - to my mind - is insufficiently clear.     You note,  "Didn't stop the PWM" ... and then,  "getting a very small voltage."

    What (quantitatively) does "Didn't Stop" really mean?    Surely the PWM's Duty Cycle decreased - did it not?    This detail is what is (really) required - "Didn't Stop" ... Not so much!

    "Getting a very small voltage" - we must assume upon the PWM Output pin - is that correct?    And - what connects to that "MCU's PWM Output pin?"    Such would prove "useful information" would it not?    Further - you are "silent" as regards your,  "Measuring Device" - if (only) a "DMM" - and the duty cycle is small - then a  "small voltage" ...  is to be expected!   Indeed - details - details - yet those ARE required - if you seek (real) answers.

    Description of your  "MCU -> Motor" interface - also is "missing."    Unless your motor is "tiny" - it is always advisable to impose a suitable, "Buffer/Booster Circuit" - between the MCU and Motor.    Our motors impose "current enhanced" Gate Driver ICs - between EACH/EVERY - of our MCU's Three PWM Phased Outputs - and our BLDC Motors.    

    I would suggest that you,  "Isolate the PWM Output pin"  (i.e. remove all connections - but for the addition of (say) 10K  "load resistor" - tied to Gnd.)    Under those (and only those) conditions - repeat your measurements.    Scope use - severely trumps DMM.

    What (may) prove a "weakness w/in your code" - is the (possible) "Lack of sufficient DELAY" - between your,  "Switch from Pin's Configuration as "PWM" - to its (new) "GPIOOutput" Mode.    That's a rather "violent change over" - and I'd "Err on the Safety" - possibly afforded - by the imposition of (some) delay...

    Note too that vendor's (limited) RTOS also may "prove suspect" - I would much prefer that you "Escape from RTOS Influence" and (only then) conduct the tests - herein outlined.    Adding Variables (i.e. vendor's RTOS) - is a SURE Violation of  "KISS" (notable when such issues rage) - and "KISS" proves  (very) much favored - by (some) here...

  • "am I doing something wrong?"

    you are on the right path. I don't recall for your part but the Luminary datasheets aren't exactly right about the 0% or 100% duty cycle case - the module is able to reproduce one of them correctly, but not the other.

    So the trick is to detect for the incorrect case (see 100%), invert the polarity and set the dutycycle to 0%. I would suspect the TI chips behave similarly.
  • Thanks for the reply guys.

    It just occurred to me to check the issue when defining the output pin as GPIO from the start instead of PWM.

    I still get the same results , so it looks more like a hardware issue, I let the electrical engineer take a look at it.

  • Removing ALL Connections from that (specific) pin - and then (properly) measuring - remains HIGHLY INDICATED.

    You are silent as to the connection(s) to the motor - "Sunshine" (i.e. some detail) is a powerful "Disinfectant!"