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.

TMS320F28379D: Setting up pwm trip event from GPIO input

Part Number: TMS320F28379D
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hello Experts,
I am trying to set up pwm trip from gpio, I am using GPIO 42 as an input.
This is what I have so far:

Fullscreen
1
2
3
4
5
// GPIO42
GPIO_setMasterCore(42, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_42_GPIO42);
GPIO_setDirectionMode(42, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(42, GPIO_PIN_TYPE_PULLUP);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void configurePWMTripFromGPIO()
{
//Select GPIO42 as INPUTXBAR1
XBAR_setInputPin(XBAR_INPUT1, 42);
//inputxbar1 trip
XBAR_setEPWMMuxConfig(XBAR_TRIP4, XBAR_EPWM_MUX01_INPUTXBAR1);
// Disable all the muxes first
XBAR_disableEPWMMux(XBAR_TRIP4, 0xFFFF);
// Enable Mux 0 OR Mux 4 to generate TRIP4
XBAR_enableEPWMMux(XBAR_TRIP4, XBAR_MUX00 | XBAR_MUX04 | XBAR_MUX10 | XBAR_MUX01);
//Setup trip zone actions
// EPWMxA will go low
// EPWMxB will go low
EPWM_setTripZoneAction(EPWM1_BASE, EPWM_TZ_ACTION_EVENT_TZA, EPWM_TZ_ACTION_LOW);
EPWM_setTripZoneAction(EPWM1_BASE, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_LOW);
EPWM_setTripZoneAction(EPWM2_BASE, EPWM_TZ_ACTION_EVENT_TZA, EPWM_TZ_ACTION_LOW);
EPWM_setTripZoneAction(EPWM2_BASE, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_LOW);
EPWM_setTripZoneAction(EPWM3_BASE, EPWM_TZ_ACTION_EVENT_TZA, EPWM_TZ_ACTION_LOW);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This pin(GPIO42) is already configured as an 'input' as it is also being used in some other control logic.

  1. Firstly my question here is , it possible to use the same GPIO pin for setting up the pwm trips? or should it be a dedicated GPIO pin ?
  2. Secondly, How do I control the logic level of the GPIO based pwm trip event? What I mean by this is 'Only if GPIO42 is LOW, activate the pwm trip'
    In future , if I want the pwm trip event to be active whenever GPIO42 is HIGH, How would I go about setting this up?

Thanks,
AK

  • Hi AK,

    Yes you can use the same GPIO as a trip signal.

    You can use the digital compare submodule of the EPWM to reverse the polarity of the trip signal as well as many other features such as filtering or comparing multiple trip signals. I would recommend reading the digital compare submodule section of the EPWM chapter and using SysConfig for the configuration.

    Thank you,

    Luke

  • Yes you can use the same GPIO as a trip signal.

    Thanks for the confirmation.

    You can use the digital compare submodule of the EPWM to reverse the polarity of the trip signal as well as many other features such as filtering or comparing multiple trip signals. I would recommend reading the digital compare submodule section of the EPWM chapter and using SysConfig for the configuration.

    I read through the digital compare module. Do you have any examples that show the requested functionality.

    I tried the following and was able to get some success in changing the polarity and tested it on a LaunchPad

    Could you please confirm if this is an acceptable way to go about it:

    Surprisingly it has nothing to do with the EPWM module at all.

    Reading through the TRM manual, in chapter 15.9.2 , it states that TZn are active low inputs signals.

    For an Active low configuration[1(High) to 0(Low)], we just configure the GPIO as an input

    Example:

    Fullscreen
    1
    2
    3
    4
    GPIO_setMasterCore(42, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_42_GPIO42);
    GPIO_setDirectionMode(42, GPIO_DIR_MODE_IN);
    GPIO_setPadConfig(42, GPIO_PIN_TYPE_PULLUP);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    For an Active high configuration[0(Low) to 1(High)], we configure the GPIO and an 'inverted' input:

    Example:

    Fullscreen
    1
    2
    3
    4
    GPIO_setMasterCore(42, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_42_GPIO42);
    GPIO_setDirectionMode(42, GPIO_DIR_MODE_IN);
    GPIO_setPadConfig(42, GPIO_PIN_TYPE_INVERT);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi AK,

    I will get back to tomorrow on this issue.

    Thank you,

    Luke

  • Hi AK,

    Your method of inverting the signal through the GPIO module is perfectly fine, this is much simpler than using the digital compare module. Let me know if you need any further support.

    Thank you,

    Luke

  • Thanks for the confirmation.

    I have one more clarification:

    Is it possible to change the trip actions dynamically?

    Or should we do the following steps every time:

    "Disable the pwm clock, --->set the trip actions--->Enable the pwm clock back."

    I am trying to implement somthing like this:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    //All pwms are already congifured as complementary during initialization.
    if(state == brake)
    {
    //Make 1A as low and 1B as High and force pwm trip.
    EPWM_setTripZoneAction(EPWM1_BASE, EPWM_TZ_ACTION_EVENT_TZA, EPWM_TZ_ACTION_LOW);
    EPWM_setTripZoneAction(EPWM1_BASE, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_HIGH);
    EPWM_setTripZoneAction(EPWM2_BASE, EPWM_TZ_ACTION_EVENT_TZA, EPWM_TZ_ACTION_LOW);
    EPWM_setTripZoneAction(EPWM2_BASE, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_HIGH);
    EPWM_setTripZoneAction(EPWM3_BASE, EPWM_TZ_ACTION_EVENT_TZA, EPWM_TZ_ACTION_LOW);
    EPWM_setTripZoneAction(EPWM3_BASE, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_HIGH);
    //force pwm trip
    EPWM_forceTripZoneEvent(EPWM1_BASE, EPWM_TZ_FORCE_EVENT_OST);
    EPWM_forceTripZoneEvent(EPWM2_BASE, EPWM_TZ_FORCE_EVENT_OST);
    EPWM_forceTripZoneEvent(EPWM3_BASE, EPWM_TZ_FORCE_EVENT_OST);
    }
    else if(state == stop)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi AK,

    Yes you should disable the PWM clock before changing the trip action.

    Thank you,

    Luke