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/TM4C1294NCPDT: Accuracy of Timer PWM

Part Number: TM4C1294NCPDT

Tool/software: Code Composer Studio

Dear team

My customer used Timer PWM and PWM module to generate 250KHZ square wave. 

He tested with an oscilloscope and found that the square wave frequency of the PWM module is very accurate, but the square wave generated by the Timer PWM jumps between 249.8~250.2 KHZ.

What is the problem? Please help because i do not have TM4C129 board.

uint32_t g_cpuFrequency = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

// timer 
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
ROM_GPIOPinConfigure(GPIO_PD3_T1CCP1);


ROM_GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_3);
ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);
ROM_TimerLoadSet(TIMER1_BASE, TIMER_B, 480);
ROM_TimerMatchSet(TIMER1_BASE, TIMER_B,
ROM_TimerLoadGet(TIMER1_BASE, TIMER_B) / 2);
ROM_TimerEnable(TIMER1_BASE, TIMER_B);



//PWM 

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);


ROM_GPIOPinConfigure(GPIO_PF0_M0PWM0);
ROM_GPIOPinConfigure(GPIO_PF2_M0PWM2);
ROM_GPIOPinConfigure(GPIO_PK4_M0PWM6);


ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_2);
ROM_GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_4);

ROM_PWMClockSet(PWM0_BASE,PWM_SYSCLK_DIV_2);


ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |
PWM_GEN_MODE_NO_SYNC);
ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN |
PWM_GEN_MODE_NO_SYNC);
ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN |
PWM_GEN_MODE_NO_SYNC);

ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 240); // 120M/2/240 = 250K
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 240);
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, 480);


ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
ROM_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) / 2);


ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,
ROM_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_1) / 2);


ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6,
ROM_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_3) / 2);


ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);

ROM_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);

ROM_PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true);

  • Hello Susan,

    Running their code after adding the lines required for enabling GPIO Port D and the PWM Generator Outputs, I am not seeing a difference in performance between the Timer PWM and the PWM module. How are they measuring this difference? Are they using the same channel for each measurement? Measuring all at once? If so, using same probes for all channels?

    In my case I am looking at a 16 MHz logic state analyzer. I do see the LSA occasionally reporting a slightly shorter frame for PWM of 246.2 kHz, but that occurs on all signals, and I am certain it is a measurement error with the LSA (I don't have a full o-scope at home) as I see it on both PWM and Timer outputs.

    Based on the very small amount of error listed, my lean is towards a measurement issue.

    I don't see any issue with the setup of his code, though one area to possibly tinker with would be GPIO port settings, the current call uses:

    GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);

    They could try GPIO_STRENGTH_8MA to see if that has any improved performance.

    Even if we confirm that it isn't a measurement issue, I anticipate that the device just has that amount of variance on the Timer PWM output which is pretty negligible in the scheme of things as it is a single TM4C clock cycle of difference roughly (my calculations indicate 6.4ns whereas TM4C clock period is 8.3ns). I would have doubts that the system they are interfacing with is sensitive to that small of a change in PWM frequency.