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.

AM263P4: AM2634 ePWM Fast Switching Issue

Part Number: AM263P4
Other Parts Discussed in Thread: AM2634, TIDM-02018

Hi,

I am using the AM2634 MCU and have three GPIO inputs (U, V, W) that determine which of three ePWM channels should be active.

I am currently reading the GPIO states in a continuous loop and changing the ePWM configuration based on the GPIO combination.

The basic implementation is:

while (1)
{
    gpioValue  = GPIO_pinRead(gGpioBaseAddr,  pinNum);    /* U */
    gpioValue2 = GPIO_pinRead(gGpioBaseAddr2, pinNum2);   /* V */
    gpioValue3 = GPIO_pinRead(gGpioBaseAddr3, pinNum3);   /* W */

    if ((gpioValue == 1) && (gpioValue2 == 0) && (gpioValue3 == 0))
    {
        EPWM_configureSignal(gEpwm1Base, &pwmSignal_off);
        EPWM_configureSignal(gEpwm2Base, &pwmSignal);
        EPWM_configureSignal(gEpwm3Base, &pwmSignal_off);

        /* GPIO outputs are also updated here */
    }

    /* Other GPIO combinations are handled similarly */

    else if ((gpioValue == 0) &&
             (gpioValue2 == 0) &&
             (gpioValue3 == 0))
    {
        EPWM_configureSignal(gEpwm1Base, &pwmSignal_off);
        EPWM_configureSignal(gEpwm2Base, &pwmSignal_off);
        EPWM_configureSignal(gEpwm3Base, &pwmSignal_off);
    }

    ClockP_usleep(375);
}

Problem

The ePWM output does not switch reliably or as expected when I remove the:

ClockP_usleep(375);

When the 375 µs delay is present, I can observe the expected PWM output. However, the switching response is slow.

If I remove the delay, I expect the PWM channels to switch immediately according to the GPIO input states, but the PWM output does not behave as expected.

I would like to understand why this delay appears to be necessary.

Questions

  1. Why is ClockP_usleep(375) required for the PWM output to appear correctly?

  2. Is EPWM_configureSignal() intended to be called repeatedly during runtime, or should it only be used during ePWM initialization?

  3. What is the recommended AM2634 ePWM API/function for fast runtime switching between PWM channels?

  4. Should the ePWM modules be configured once and then controlled using lower-level ePWM functions/registers for fast switching?

  5. What type of ePWM configuration is recommended if I need to change the active PWM channel based on GPIO inputs with minimum latency?

  6. Is there a recommended way to update the ePWM output using shadow registers, compare registers, Action Qualifier, Trip Zone, or another ePWM hardware mechanism?

  7. Is there a recommended function flow for achieving fast GPIO-state-to-PWM switching without using a software delay such as ClockP_usleep()?

The main issue I am trying to resolve is the latency and dependency on ClockP_usleep(375). I would appreciate guidance on the appropriate AM2634 ePWM configuration and runtime API for this use case.

Thank you,
ANBURAJA A.

  • Hi ANBURAJA,

    ClockP_usleep(375) should not be required by the ePWM hardware. The behavior you are seeing is related to repeatedly calling EPWM_configureSignal() inside the polling loop. EPWM_configureSignal() is a convenience function that configures the ePWM waveform, including frequency and duty-cycle related settings. Although it can technically be called at runtime, I would not recommend repeatedly calling it for fast PWM enable/disable or commutation control.
    For this application, I recommend configuring all three ePWM modules once during initialization, and then only controlling whether each PWM output is enabled or forced inactive during runtime.

    If both A and B outputs are being used, the corresponding force should be applied to both outputs as required.

    If the transition should occur immediately, EPWM_AQ_SW_IMMEDIATE_LOAD can be used. If the transition must occur at a defined PWM boundary to avoid a shortened/glitched PWM pulse, configure the continuous software-force shadow load for counter zero or counter period instead. The three ePWM time bases should also be synchronized if the outputs need to change coherently.

    For minimum GPIO-to-PWM latency, I would also recommend using GPIO interrupts rather than continuously polling the GPIOs. On an input edge, read U/V/W, determine the new state, and perform only the required AQ update.
    For even faster hardware-based shutdown/control paths, GPIO signals can be routed through the Input XBAR into the ePWM Digital Compare/Trip Zone logic. This is particularly useful when an external signal must disable a PWM without CPU/ISR latency.

    Best Regards,

    Masoud

  • Hi Masoud,

    Thank you for the clarification.

    Is there any example project or reference implementation available for the recommended approach on the AM2634?

    In particular, could you provide a simple example code flow showing how to:

    • Configure the three ePWM modules during initialization.
    • Use GPIO interrupts to detect U/V/W state changes.
    • Update the ePWM output using AQ software force with immediate or shadow loading.
    • Synchronize the ePWM modules if required.
    • Handle the runtime switching between the three PWM channels with minimum latency.

    A small example covering the initialization and GPIO ISR/runtime update flow would be very helpful.

    If there is an existing TI SDK example or documentation demonstrating this approach, please share the reference.

    Thank you,

    ANBURAJA A

     

  • Hi ANBURAJA,

    Yes, there are AM263x MCU+ SDK examples that can be used as references, although I am not aware of a single example that combines GPIO interrupts + three ePWMs + AQ software force exactly as in your application.

    I would recommend starting from the following examples:

    GPIO Input Interrupt

    examples/drivers/gpio/gpio_input_interrupt/

    This demonstrates GPIO input configuration, interrupt generation, and the GPIO ISR flow.

    EPWM Synchronization

    Use the TIDM-02018 inverter SW in AM263 motor control SDK.


    EPWM Action Qualifier examples
    The SDK also contains: EPWM UP-Count Action Qualifier, EPWM UPDOWN-Count Action Qualifier examples.

    Regards,

    Masoud