Other Parts Discussed in Thread: SYSCONFIG
Hello,
After reading the section in TRM regarding using shadow registers to change PWM settings on the fly, I am still not clear how to do that in the application.
Is there any example?
Thanks!
Crane
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.
Hello,
After reading the section in TRM regarding using shadow registers to change PWM settings on the fly, I am still not clear how to do that in the application.
Is there any example?
Thanks!
Crane
Thank you Santosh and Nima for the reply.
enable
It seems not that simple.
I have PWM2, PWM3 and PWM4. PWM3's frequency and duty cycle are same as PWM2 with a phase shift. PWM4 A and B's rising and falling depends on the rising and falling of PWM2 and PWM3 respectively.
The program is to switch the frequency of PWM2 between one another. I use the below code in the PWM initialization and get the best result I can get so far.
EPWM_enableGlobalLoad(myEPWM2_BASE);
EPWM_enableGlobalLoadOneShotMode(myEPWM2_BASE);
EPWM_setGlobalLoadOneShotLatch(myEPWM2_BASE);
EPWM_setGlobalLoadTrigger(myEPWM2_BASE, EPWM_GL_LOAD_PULSE_CNTR_ZERO);
EPWM_enableGlobalLoad(myEPWM3_BASE);
EPWM_enableGlobalLoadOneShotMode(myEPWM3_BASE);
EPWM_setGlobalLoadOneShotLatch(myEPWM3_BASE);
EPWM_setGlobalLoadTrigger(myEPWM3_BASE, EPWM_GL_LOAD_PULSE_CNTR_ZERO);
EPWM_enableGlobalLoad(myEPWM4_BASE);
EPWM_enableGlobalLoadOneShotMode(myEPWM4_BASE);
EPWM_setGlobalLoadOneShotLatch(myEPWM4_BASE);
EPWM_setGlobalLoadTrigger(myEPWM4_BASE, EPWM_GL_LOAD_PULSE_CNTR_ZERO);
The result is that PWM2 and PWM3 can changed correctly. For PWM4A and B, it is correct sometimes, not always.
I am wondering what's missing in the initialization. And does it need any operation after writing the new values to the period and compare registers?
Thanks!
Crane
Since both PWM2 and PWM3 works fine and the duty cycle of PWM4 is correct always as wanted, I assume that the problem is that the PWM4 couldn't sync with PWM2 and PWM3 after the frequency of PWM2 and PWM3 is changed to a new one.
Crane,
There are two different modes that we have referenced together in this thread.
One is the standard SHADOW mode which is present on a lot of the registers.
The other one is an additional global load mode which I don't think you need.
Correct me if I'm wrong you are just trying to use the standard shadow mode? I can point you to an example of this.
I am not sure as I don't think I already completely understand the difference. I am using global load mode as suggested in all the relevant documents to update all registers at the same time when the trigger events happens.
Anyway, I don't care as long as it can help switch the frequency while all PWM2, PWM3 and PWM4 changes accordingly.
Crane,
The normal shadow mode is separate from the global load. I recommend normal shadow load mode.
Take a look at this example:
Nima
This uses the SysConfig tool as well. For PRD to be in shadow mode:
These are the four options. If EPWM2/3/4 all are the same, the LINKING feature could help as well.
Thanks Nima.
I took a look and tried the example. The difference it has with my case is that these signals are changed independently.
My case is that the PWM4 needs to sync with PWM2. As I said, the PWM4's duty cycle is changed correctly according to the new frequency. But it doesn't sync with PWM2.
// Configure period and compare values for PWM2
EPWM_setTimeBasePeriod(myEPWM2_BASE, tbPrdVal);
EPWM_setCounterCompareValue(myEPWM2_BASE, EPWM_COUNTER_COMPARE_A, cmpAVal);
EPWM_setCounterCompareValue(myEPWM2_BASE, EPWM_COUNTER_COMPARE_B, cmpBVal);
// Configure period and compare values for PWM3
EPWM_setTimeBasePeriod(myEPWM3_BASE, tbPrdVal);
EPWM_setCounterCompareValue(myEPWM3_BASE, EPWM_COUNTER_COMPARE_A, cmpAVal);
EPWM_setCounterCompareValue(myEPWM3_BASE, EPWM_COUNTER_COMPARE_B, cmpBVal);
// Configure phase shift for EPWM3
configurePhase(myEPWM3_BASE, myEPWM2_BASE, phaseShift);
EPWM_enablePhaseShiftLoad(myEPWM3_BASE);
// Configure period and compare values for PWM4
EPWM_setTimeBasePeriod(myEPWM4_BASE, tbPrdVal);
EPWM_setCounterCompareValue(myEPWM4_BASE, EPWM_COUNTER_COMPARE_A, 0);
temp = (float)tbPrdVal/2 + (float)tbPrdVal * phaseShift / PHASE360;
value = temp + 0.5;
value = value % tbPrdVal;
EPWM_setCounterCompareValue(myEPWM4_BASE, EPWM_COUNTER_COMPARE_B, value);
The above is how the compare value A and B are updated according to the new period (frequency). Similar to value, cmpAVal and cmpBVal are calculated based on tbPrdVal as well.
PWM3 changes correctly when the frequency is changed, even the phase shift with PWM2.
The relevance between PWM4 and PWM2 is supposed to be fixed. But what I got is a often random when the frequency is changed.
Thanks!
Crane
The closest example I found is from the page 8 of this document. Leverage New Type ePWM Features for Multiple Phase Control.
I followed and it is not working.
You are trying to synchronize EPWM4 to EPWM2?
This device has a synchronization chain:
For you to be able to synchronize your Time base modules you have to pass the synchronization signal through the chain.
The chain of EPWMs cannot be longer than 4 I believe. Including the SYNC master EPWM.
You can sync:
EPWM2-EPWM3 very easily as shown.
You can also sync EPWM1-2-3 as shown.
You can sync EPWM1-4-5 as shown.
For you to be able to sync EPWM2-3-4, you have to set up EPWM1 as the sync master and configure all needed muxes.
In the GUI configuration tool, you have the SYNC module that shows how to configure the muxes in the image above.
I thought of that the tried to use PWM1, 2, 3 to replace PWM2, 3, 4. It still didn't work. Same result as using PWM2, 3, 4.
Also the EPWM1-2-3 is the same as the example 3 I sent you. At least the sync part of it with PHSEN.
Did you configure the SYNCOUT for each EPWM?
I didn't config them this way before. Now I made the changed and the result stays the same.
Also the EPWM1-2-3 is the same as the example 3 I sent you. At least the sync part of it with PHSEN.
When using PWM1, 2, and 3, only PWM2 is enabled phase shift as only PWM2 needs the phase shift.
When using PWM2, 3, and 4, only PWM3 is enabled phase shift as only PWM3 needs the phase shift.
Can you share your EPWM synchronization chain configuration? for both scenarios.
Yes, it is enabled for PWM2. As only it has a phase shift to PWM1. It is enabled in application, not in Sysconfig.
Just realize that PWM1 sync is re-configured in application. The configuration I posted previously is in Sysconfig.
Then this should be all that is needed to sync PWM2 and PWM1.
You can follow the same between PWM4 and PWM1. Given the settings you showed me in the SYNC module.
But if the statement is commented out which means the sync configuration will stay like this,
then the result for PWM3 is the same (not correctly generated), even the PWM2 will not be generated properly and stays high.
even the PWM2 will not be generated properly and stays high.
What is the signal you are getting now? All time high signal?
Okay can you share the zip of your whole project?
You want EPWM1-2 synced and EPWM1-4 synced. Correct?
Please see the attached file.
We want EPWM2 has a phase shift to EPWM1, EPWM4's rising edge is EPWM1's falling edge, and EPWM4's falling edge is EPWM2's falling edge. And we want this works when the frequency is changed on the fly.
Right now, everything works fine. Even the duty cycle of EPWM4 changed correctly with the frequency change. Only thing left is that EPWM4's rising edge is not always EPWM1's falling edge.
I think the cause is EPWM4 is not synced with EPWM1 when the frequency is switched.
The code really well put together. I dont see a EPWM_enablePhaseShiftLoad(myEPWM4_BASE); line of code to sync EPWM1 and 4.
The phase shift is between EPWM1 and EPWM2. There is no phase shift between EPWM4 and EPWM1. But, as EPWM4 is relevant to both EPWM1 and EPWM2, so EPWM4 and EPWM1 are somehow related to the phase shift.
That is the problem. From the result, I don't think they are synced. How to sync EPWM4 and EPWM1? In SYNC Cynchronization in Sysconfig, EPWM4 sync in source is set as 'SYNC IN SRC EPWM1SYNCOUT, also tried SYNC IN SRC EXTSYNCIN1, none of them work.
You still need to have this line of code:
EPWM_enablePhaseShiftLoad(myEPWM4_BASE);
This will sync it to EPWM1.
Yes, it works now. Thank you for much. Finally it is resolved.
Regards,
Crane