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: Full PWM output

Part Number: TM4C123GH6PM


Tool/software: Code Composer Studio

Hello,

I am using the pwm as:

  SysCtlPWMClockSet(SYSCTL_PWMDIV_8);
  ui32PWMClock = SysCtlClockGet() / 8;
  ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;

  SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

  GPIOPinConfigure(GPIO_PB6_M0PWM0);
  GPIOPinConfigure(GPIO_PB7_M0PWM1);
  GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
  GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);

  PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ui32Load);

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

  // send zero pwm
  PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0 , 0);
  PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1 , 0);

I can observe the waveform on both pins with a scope.

The problem is when I:

PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ui32Load);

I dont get a full pwm output, (a continuous 1) but I get a 0. PWM_FREQUENCY is 18000. if I make a

PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ui32Load-1);

I get a nearly 99.9% pwm waveform

how can i work across this problem?

Edit:

To generate ui32Load, I have the following statements. I make sure that SysCtlClockGet is run after the tiva-c clock is set to 80mhz.

//#define PWM_FREQUENCY 18000
#define PWM_FREQUENCY 500

volatile uint32_t ui32Load;
volatile uint32_t ui32PWMClock;

--

  SysCtlPWMClockSet(SYSCTL_PWMDIV_8);
  ui32PWMClock = SysCtlClockGet() / 8;
  ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;

best regards,

c.

  • Hi,

    can altineller said:
      ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;

    Can you please edit post your code using the syntaxhighlighter tool, thanks.  Please show the value your ui32Load attempt to generate 18kHz and PWMCLK speed etc..

  • all done. it works until ui32Load -1, and fails at ui32Load. best regards.
  • can altineller said:
    it works until ui32Load -1,

    Obviously it does not work or you would not be asking for help, right?

    The period you choose is unknown to anyone that does not know your PWMCLK speed. 

  • PWM_FREQUENCY 500
    ui32Load 19999
    --
    ui32PWMClock = SysCtlClockGet() / 8;
    ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;

    ui32PWMClock = 10000000;
    ui32Load = (10000000 / 500) - 1 = 19999

    The problem is that I do get the pwm working but not the %100 waveform.

    at ui32Load = 19999 i get a 99.99% pwm wave form.
    at ui32Load = 20000 i get 0.

    best regards.
    C.
  • The problem is with using "PWM_GEN_MODE_UP_DOWN". In this mode the counter counts up to the load value and then counts down again. It activates the PWM output whenever the counter is equal to the load value. This happens twice for each cycle, once on the way up and once on the way down. The exception is at the load value. It only counts up to the load value, but never counts down to it (since the direction changes when the counter is equal to the load value). You can use PWM_GEN_DOWN if you don't need center synchronization. Otherwise, if you need 100% duty cycle, you need to make an exception and when the compare value is equal to the load value, change the pin to a GPIO output high.
  • Hello,

    I have changed to PWM_GEN_MODE_DOWN, and it did generate 100% pwm waveform. However, this time giving input 0 generates a 1 high.
    So in otherwords:

    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 0);
    and
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ui32Period);

    Generates the same output, always 1.

    Best Regards,
    C.A.
  • Noticed you posted 10Mhz PWMCLK 18kHz frequency.

    Perhaps 10Mhz PWMCLK is to slow to generate 18kHz frequency (100ns tick times 18k=1.8ms periods)? With TM4C1294 we use 60mHz PWMCLK to generate 8kHz to 80kHz range with up/dwn counts, synchronous mode if more than one generator.

    For example 12.5kHz needs 4800 Ticks of 60mHz(16.6ns)/12.5kHz = 4800*16.6ns=80us periods