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.

LAUNCHXL-F2800137: TMS320F2800137 eCAP capture count mismatch between internal and external clock

Part Number: LAUNCHXL-F2800137

My setup:

  • SYSCLK = 120 MHz
  • 1 eCAP count = 8.33 ns
  • Input PWM ON time = 1200 µs

Observed behavior:

  • When using external clock, the captured count converts correctly to 1200 µs
  • When using internal clock, the captured count converts to 1210 µs

Calculation:

Expected count:

1200 us / 8.33 ns = 144000 counts

But internal clock measurement shows about:

145200 counts

This gives about 10 µs error.

My question:

Can someone explain why this happens?

Does anyone have a solution to measure accurate PWM ON time using the internal eCAP clock?



  • Hi,

    Sorry for the delayed response. Can u please ur snippet of your code? 

    Thanks,

    Divesh

  • Hi Divesh,

    Thanks for the response.

    I am working on PWM pulse width measurement using eCAP on the LAUNCHXL-F2800137.

    My setup:

    • eCAP input on GPIO16

    • SYSCLK = 120 MHz

    • eCAP used in one-shot mode

    • Counter reset enabled on every capture event

    My goal is to measure only PWM ON time accurately in microseconds.

    I observed something interesting related to the PLL clock source selection.

    When I use:

    #define USE_PLL_SRC_XTAL
    

    the measured ON time is accurate and stable.

    But when I use:

    #define USE_PLL_SRC_INTOSC
    

    the measured ON time shifts and becomes inaccurate.

    For example:

      • PWM expected ON time ≈ 1500 us

      • With XTAL source → measured correctly near 1500 us

      • With INTOSC source → measured value changes noticeably (~1510) 

        For example:

        • PWM expected ON time ≈ 1500 us

        • With XTAL source → measured correctly near 1500 us

        • With INTOSC source → measured value changes consistently (around 1510 us)

        I also observed that this offset is constant for different PWM ON times.
        For any ON time value, the measured result is shifted by approximately +10 us.

        Because the offset is constant and stable, it seems the eCAP capture itself is working correctly, but the effective SYSCLK frequency derived from INTOSC may be slightly different from the expected DEVICE_SYSCLK_FREQ used in the time conversion calculation.

    Because of this, I suspect the internal oscillator accuracy may be affecting:

    • SYSCLK frequency

    • eCAP counter timing

    • time conversion calculation

    Below is my eCAP configuration.

    I configured:

    • One-shot capture mode

    • Capture till Event4

    • Counter reset on every event

    • No prescaler

    Event sequence:

    • Event1 = Falling edge

    • Event2 = Rising edge

    • Event3 = Falling edge

    • Event4 = Rising edge

    So:

    • CAP2 = LOW/OFF time

    • CAP3 = HIGH/ON time

    • CAP4 = LOW/OFF time

    eCAP configuration:

    ECAP_setCaptureMode(myECAP0_BASE,
                        ECAP_ONE_SHOT_CAPTURE_MODE,
                        ECAP_EVENT_4);
    
    ECAP_setEventPrescaler(myECAP0_BASE, 0U);
    
    ECAP_setEventPolarity(myECAP0_BASE,
                          ECAP_EVENT_1,
                          ECAP_EVNT_FALLING_EDGE);
    
    ECAP_setEventPolarity(myECAP0_BASE,
                          ECAP_EVENT_2,
                          ECAP_EVNT_RISING_EDGE);
    
    ECAP_setEventPolarity(myECAP0_BASE,
                          ECAP_EVENT_3,
                          ECAP_EVNT_FALLING_EDGE);
    
    ECAP_setEventPolarity(myECAP0_BASE,
                          ECAP_EVENT_4,
                          ECAP_EVNT_RISING_EDGE);
    
    ECAP_enableCounterResetOnEvent(myECAP0_BASE,
                                   ECAP_EVENT_1);
    
    ECAP_enableCounterResetOnEvent(myECAP0_BASE,
                                   ECAP_EVENT_2);
    
    ECAP_enableCounterResetOnEvent(myECAP0_BASE,
                                   ECAP_EVENT_3);
    
    ECAP_enableCounterResetOnEvent(myECAP0_BASE,
                                   ECAP_EVENT_4);
    
    ECAP_startCounter(myECAP0_BASE);
    
    ECAP_enableTimeStampCapture(myECAP0_BASE);
    
    ECAP_reArm(myECAP0_BASE);
    
    ECAP_enableInterrupt(myECAP0_BASE,
                         ECAP_ISR_SOURCE_CAPTURE_EVENT_4);
    

    ISR:

    __interrupt void INT_myECAP0_ISR(void)
    {
        cap2Count =
            ECAP_getEventTimeStamp(myECAP0_BASE,
                                   ECAP_EVENT_2);
    
        cap3Count =
            ECAP_getEventTimeStamp(myECAP0_BASE,
                                   ECAP_EVENT_3);
    
        cap4Count =
            ECAP_getEventTimeStamp(myECAP0_BASE,
                                   ECAP_EVENT_4);
    
        // CAP3 used as PWM ON time
        f32gtimefromcap3Count_us =
            ((float32_t)cap3Count * 1000000.0f) /
            DEVICE_SYSCLK_FREQ;
    
        ECAP_clearInterrupt(myECAP0_BASE,
                            ECAP_ISR_SOURCE_CAPTURE_EVENT_4);
    
        ECAP_clearGlobalInterrupt(myECAP0_BASE);
    
        ECAP_reArm(myECAP0_BASE);
    
        Interrupt_clearACKGroup(
            INT_myECAP0_INTERRUPT_ACK_GROUP);
    }
    

    Could you please confirm:

    1. Is the timing difference expected when using INTOSC instead of XTAL?

    2. Does eCAP directly depend on SYSCLK accuracy for timestamp measurement?

    3. Is there any recommended method to improve capture timing accuracy when using INTOSC?

    Thanks.

  • Hi,

    1. The observation that you have noticed is correct. The output frequency of an internal oscillator has an accuracy in the range of -1.8% to 1% (as per datasheet) at 10 MHz If the same is used as a source of SYSCLK, then it can produce an error of around 8.33 microsecond at 120 MHz. Also, variation in temperature would affect accuracy of output frequency of an internal oscillator.

    2. Yes, eCAP timestamp measurement are SYSCLK dependent. Therefore, it is advised to use XTAL for applications where timing requirements are tight (means accuracy is important).

    3.  As per section 3.7.1 Clock Sources  of  TRM (Technical Reference Manual), to improve the accuracy of INTOSC2, an external resistor (ExtR) mode can be used. This mode allows for a highly accurate external resistor to be added to the board and connected to the ExtR-capable pin. See the TMS320F280013x Real-Time Microcontrollers Data Sheet for which pin is ExtR-capable on each package.

    One may refer to clocking chapter in TRM for more details.

    Thanks,

    Divesh