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.
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:
// 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);
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); EPWM_setTripZoneAction(EPWM3_BASE, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_LOW); //Enable the PWM trip zone signals (OSH1) EPWM_enableTripZoneSignals(EPWM1_BASE, EPWM_TZ_SIGNAL_OSHT1); EPWM_enableTripZoneSignals(EPWM2_BASE, EPWM_TZ_SIGNAL_OSHT1); EPWM_enableTripZoneSignals(EPWM3_BASE, EPWM_TZ_SIGNAL_OSHT1); }
This pin(GPIO42) is already configured as an 'input' as it is also being used in some other control logic.
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:
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);
For an Active high configuration[0(Low) to 1(High)], we configure the GPIO and an 'inverted' input:
Example:
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);
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:
//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) { //Set the pwm trip back to its origenal conditions, incase a fault does occur from the gpio 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); EPWM_setTripZoneAction(EPWM3_BASE, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_LOW); //clear the trip flags which would have been set in the brake condition EPWM_clearTripZoneFlag(EPWM1_BASE,EPWM_TZ_FLAG_OST); EPWM_clearTripZoneFlag(EPWM1_BASE,EPWM_TZ_FLAG_OST); EPWM_clearTripZoneFlag(EPWM1_BASE,EPWM_TZ_FLAG_OST); //The pwms should now go back to being complementary } else if(state == run) { //DO nothin, make sure the trip actions are set so that to low, so that when ever the GPIO catches a fault, the pwms 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); EPWM_setTripZoneAction(EPWM3_BASE, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_LOW); }
Hi AK,
Yes you should disable the PWM clock before changing the trip action.
Thank you,
Luke