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.

TMS320F280048-Q1: PWM Configuration change problem and updating during a task or ISR

Part Number: TMS320F280048-Q1

Hi,

My power converter works as bidirectional. Therefore, I need to change my PWM configuration at some working states. 

1) Which method do you offer to change PWM configuration after init? Do I need to write new configuration to registers at ISR or a task that is called at 1msec? Which is safe and flexible to achieve?

2) Do I need to write EALLOW, EDIS lines during configuration change at changing ISR or timer tast?

3) Which PWM configurations can be changed after init which cannot?

4) In my case, I observed a problem during configuration change. I only change AQ module setting.

If I " EPWM_enablePhaseShiftLoad(EPWM3_BASE);" write during initing , after changing configuration. My PWM doesn't work as expected.

MY INIT CODE

EALLOW;
    //
    // Time-Base Submodule Configurations
    //
    EPWM_setPeriodLoadMode(EPWM3_BASE, EPWM_PERIOD_SHADOW_LOAD);
    EPWM_setTimeBasePeriod(EPWM3_BASE, ITIB_PERIOD_TICKS);
    EPWM_setTimeBaseCounter(EPWM3_BASE, 0);
    EPWM_setPhaseShift(EPWM3_BASE, 0);
    EPWM_setTimeBaseCounterMode(EPWM3_BASE, EPWM_COUNTER_MODE_UP_DOWN);
    EPWM_setClockPrescaler(EPWM3_BASE,EPWM_CLOCK_DIVIDER_1,EPWM_HSCLOCK_DIVIDER_1);

    EPWM_setCounterCompareValue(EPWM3_BASE, EPWM_COUNTER_COMPARE_A, 100);
    EPWM_setCounterCompareValue(EPWM3_BASE, EPWM_COUNTER_COMPARE_B, 0);

    // Counter-Compare Submodule Configurations
    // CMPA is updated on ZERO
    // CMPB is updated on PERIODE !!!
    EPWM_setCounterCompareShadowLoadMode(EPWM3_BASE, EPWM_COUNTER_COMPARE_A,
                                         EPWM_COMP_LOAD_ON_CNTR_ZERO);
    EPWM_setCounterCompareShadowLoadMode(EPWM3_BASE, EPWM_COUNTER_COMPARE_B,
                                         EPWM_COMP_LOAD_ON_CNTR_PERIOD);

    EPWM_setActionQualifierShadowLoadMode(EPWM3_BASE, EPWM_ACTION_QUALIFIER_A,
                                          EPWM_AQ_LOAD_ON_CNTR_ZERO);
    EPWM_setActionQualifierShadowLoadMode(EPWM3_BASE, EPWM_ACTION_QUALIFIER_B,
                                          EPWM_AQ_LOAD_ON_CNTR_PERIOD);

    //
    // to start don't configure the PWM to do anything
    //
    HWREGH(EPWM3_BASE + EPWM_O_AQCTLA) = 0;

    // Action-Qualifier Submodule Configurations
    // ePWM3A Actions
    // CTR = ZERO , set to no action
    // CTR = PRD , set to no action
    // CTR = CMPA , set to 1 (Counting Up)
    // CTR = CMPA , set to 0 (Counting Down)
    // CTR = T1U , set to no action
    // CTR = T1D , set to no action
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_T1_COUNT_UP);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_T1_COUNT_DOWN);

    // Action-Qualifier Submodule Configurations
    // ePWM3B Actions
    // CTR = ZERO , set to no action
    // CTR = PRD , set to no action
    // CTR = CMPB, set to 0 (Counting Up)
    // CTR = CMPB, set to 1 (Counting Down)
    // CTR = T1U , set to no action
    // CTR = T1D , set to no action
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_T1_COUNT_UP);
    EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_T1_COUNT_DOWN);
                                  
    //EPWM_enablePhaseShiftLoad(EPWM3_BASE);
    EPWM_setSyncOutPulseMode(EPWM3_BASE, EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN);

    EPWM_setPhaseShift(EPWM3_BASE, 2); // Value*TBCLKs Phase-Shift is Set
    EPWM_setCountModeAfterSync(EPWM3_BASE, EPWM_COUNT_MODE_UP_AFTER_SYNC);

MY  CHANGE PWM CONFIGURATION CODE (THAT RUNS ONE TIME AT ISR)

    EALLOW;

    // Action-Qualifier Submodule Configurations
    // ePWM3A Actions
    // CTR = ZERO , set to no action
    // CTR = PRD , set to no action
    // CTR = CMPA , set to 1 (Counting Up)
    // CTR = CMPA , set to 0 (Counting Down)
    // CTR = T1U , set to no action
    // CTR = T1D , set to no action
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_HIGH,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_T1_COUNT_UP);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_T1_COUNT_DOWN);
    
        // Action-Qualifier Submodule Configurations
    // ePWM3B Actions
    // CTR = ZERO , set to no action
    // CTR = PRD , set to no action
    // CTR = CMPB, set to 0 (Counting Up)
    // CTR = CMPB, set to 1 (Counting Down)
    // CTR = T1U , set to no action
    // CTR = T1D , set to no action                              
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_HIGH,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_T1_COUNT_UP);
    EPWM_setActionQualifierAction(base1,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_NO_CHANGE,
                                  EPWM_AQ_OUTPUT_ON_T1_COUNT_DOWN);
                                  
    EDIS;                              

  • Hi,

    1) Which method do you offer to change PWM configuration after init? Do I need to write new configuration to registers at ISR or a task that is called at 1msec? Which is safe and flexible to achieve?

    Typically, it is expected that all the changes to the PWM registers happen in the ISR, which mostly would be your control loop. Is it just the updates in the compare, period, phase registers or are you expecting any updates in the action qualifier registers as well?

    2) Do I need to write EALLOW, EDIS lines during configuration change at changing ISR or timer tast?

    If the registers have write protection enabled, you'll have to write "EALLOW, EDIS" whenever you wish to make any changes to the register.

    In your case, I see you've used the functions to write to the registers, so you don't need to again write "EALLOW, EDIS". It'll be taken care within the functions.

    3) Which PWM configurations can be changed after init which cannot?

    You should be able to update all the configurations. Any specific configuration that you're looking at?

    4) In my case, I observed a problem during configuration change. I only change AQ module setting.

    Hi, this should work just fine. Just one point, why do you reconfigure the settings in the initialization itself? What behavior are you observing when you enable the phase shift load?

    Thanks,
    Aditya

  • Hi, 

    1) Yes, I use below lines to change configuarions.

    EPWM_setTimeBasePeriod

    EPWM_setCounterCompareValue

    EPWM_setCounterCompareShadowLoadMode

    EPWM_setActionQualifierShadowLoadMode

    EPWM_setActionQualifierAction

    EPWM_disableTripZoneAdvAction

    EPWM_setDeadBandDelayMode

    EPWM_setDeadBandOutputSwapMode

    EPWM_disablePhaseShiftLoad or EPWM_enablePhaseShiftLoad 

    Actually, In my example if I don't write "EPWM_disablePhaseShiftLoad(EPWM3_BASE);" during configuration change procedure, the PWM output characteristics changes so much. I could do it fine by writng disablePhaseShiftLoad. 

    2) OK

    3) I asked as a general question. Specific configuration parameters for me are listed at 1).

    4) I need to reconfigure my PWMs if any power direction change command is received. Actually, I resolved issue but I don't know how it fixed. I need to write EPWM_disablePhaseShiftLoad.

  • Actually, In my example if I don't write "EPWM_disablePhaseShiftLoad(EPWM3_BASE);" during configuration change procedure, the PWM output characteristics changes so much. I could do it fine by writng disablePhaseShiftLoad.

    The random behaviour in the EPWM output is expected up to some extent if you don't disable the PWM phase shift. Reason being that the counter value at the instant when you update your period, counter compare value would be directly affecting the phase update event, if enabled. Since, these changes are happening run time for you and you are updating both your period and counter values, you may see 1 cycle of indeterministic behaviour in the PWM output.

    I hope this answers.

    Thanks,
    Aditya

  • Hi Aditya,

    In my application, I'm designing bidirectional power converter. Buck mode and boost mode PWM configurations are quiet different and depending on mode select I change PWM configuration and re-run power converter. 

    After calling PWM buck mode init or boost mode init functions at ISR, I needed also to write a  delay function like DEVICE_DELAY_US(10), which has 10usec delay.

    I observed that 5usec delay isn't enough to get registers updated. If it is 5usec, it sometimes configure my PWM as randomly.

    Is it normal or am I missing something at the other side?

    Is it always required to set a delay after init?

    Can you comment on this?

  • Hi Gokhan,

    The PWM registers will instantaneously update as you execute that particular instruction. Can you please put a breakpoint just before exiting the ISR and check what all registers have not been updated WITHOUT the delay being added?

    Can you share the piece of code on which you're seeing the problem?

    Thanks,

    Aditya