We use a large number of PWMs on a K10DX to control the dimming levels of LEDs. As these PWMs are generated by one timer module, it turns out that they are in phase when switching the LEDs on or off. This causes some fluctuation in instantaneous current draw. We are wondering if there is a way to stagger the PWMs so that there are phase differences between them. In this way, they will not be on or off at the same time. The attached image illustrates the idea. Is this achievable by programming the time module appropriately? Thank you for your help.
Hi,LiuShouMin,
I see your issue. As you know that the K10 uses FTM to generate PWM, because there is only one FTM_CNT, all the PWM signal are in phase, but the FTM supports combined mode and can generate phase shift signal, so you can get the signals as the figure you drew. But the drawback of the solution is the number of FTM channels you can use is only half of the total channels, you can use only 4 channels.
If you use Combined mode, the corresponding channels has to be set up in complementary mode, and FTM is set up in edge-alignment mode. In complementary mode, the pair of FTM channels are inverter, if you have the duty cycle requirement, only one channels can be controlled, because another channel is the inverter. For example, FTM0 has 8 channels for K10, if you want to control both the rising/falling edge so that both of the duty cycle and phase shift can be controlled, Only four channels FTM0_CH0/FTM0_CH2/FTM0_CH4/FTM0_CH6 can be used and the duty cycle and phase shift for 4 FTM0_CH0/FTM0_CH2/FTM0_CH4/FTM0_CH6 PWM signals. For exanple, You can use FTM0_C0V/C1V registers to control the rising/falling edge of FTM0_CH0 signal. You can use FTM0_C2V/C3V to control the rising/falling edge of FTM0_CH1 signal. If you use different value of FTM0_C0V and FTM0_C2V, the rising edge of FTM0_CH0 and FTM0_CH2 will different, in this way, the two signals of FTM0_CH0 and FTM0_CH2 can shift each other.
You can refer to AN5142 which describes how to generate phase shift signals.
Hope it can help you.
BR
Xiangjun Rong
Hello Xiangjun,
Thank you for your help. Could you please answer a couple more questions?
1. Assume we have 16 PWM signals in the system. We understand that we cannot control the phase and the duty cycle of each PWM signal independently due to the limited number of channels. Can we divide the PWM signals into 4 groups in such a way that each group has its unique phase and duty cycle? For example, PWM0-3 have the same phase shift of P1 and the same duty cycle D1. PWM4-7 have the same phase shift of P2 and duty cycle D2, and so on and so forth. Is this achievable?
2. Does CodeWarrior support programming FTM in complementary/combined mode? If it does support this feature, could you describe how to do it? I am using CodeWarrior 10.6, and I cannot figure out how to program FTM with phase shift.
Thanks and regards,
Shoumin
Hi, ShouMin,
I developed an example based on CodeWarrior for mcu and PE, TWR-K20D50M board. The Example can demo how to set the duty cycle and phase shift for FTM0_CH0/CH2/CH4/CH6. Note that only 4 signals can be used if you want to control both phase shift and duty cycle.
Hope it can help you.
you can use the following code to change the duty cycle and phase shift.
void FTM_Init(void)
{
//initialize the FTM0_CnV register
//the FTM modulo is 1000
FTM_PDD_WriteModuloReg(FTM0_DEVICE,1000);
//the FTM0_CH0 rising at FTM0_CNT=0, falling at FTM0_CNT=200
FTM_PDD_WriteChannelValueReg(FTM0_DEVICE,0,0);
FTM_PDD_WriteChannelValueReg(FTM0_DEVICE,1,200);
//the FTM0_CH0 rising at FTM0_CNT=0, falling at FTM0_CNT=200
FTM_PDD_WriteChannelValueReg(FTM0_DEVICE,2,250);
FTM_PDD_WriteChannelValueReg(FTM0_DEVICE,3,400);
//the FTM0_CH0 rising at FTM0_CNT=0, falling at FTM0_CNT=200
FTM_PDD_WriteChannelValueReg(FTM0_DEVICE,4,500);
FTM_PDD_WriteChannelValueReg(FTM0_DEVICE,5,600);
//the FTM0_CH0 rising at FTM0_CNT=0, falling at FTM0_CNT=200
FTM_PDD_WriteChannelValueReg(FTM0_DEVICE,6,750);
FTM_PDD_WriteChannelValueReg(FTM0_DEVICE,7,800);
}
BR
XiangJun Rong
Hi,
This is the screenshot of scope. the blue is PTC1 output, the yellow is the PTC3 output signals.
BR
XiangJun Rong
Hi XiangJun Rong
From this screenshot of scopeIs is it possible to set only ch1 duty cycle from 0 to 100% maintaining the duty cycle of ch3 in 50% (ch4 is inverted in relation to ch3) and set the phase shift between ch1 and ch3 from 0 to 360°? If yes what registers should I write and what are the calculations (duty of ch1 and phase shift between ch1 and ch3)? By the way, what is the formula for writing the FTM0_MOD register for the desired PWMs frequency?
I have attached a figure to better clarify what I would like to do.