Hi All
I'm working on drive FLEXPWM1 and FLEXPWM2.
But can’t update the pulse width (PWM duty) of FLEXPWM2.
Only FLEXPWM1 can update.
[My environment and conditions]
The PWM pulse width of FLEXPWM1 is update in the ADC_ETC interrupt, every 50kHz, and it works fine. So, I use the code of FLEXPWM 1 as used it as a reference, FLEXPWM 2 pulse width couldn't update.
[FLEXPWM1 PWM pulse width update code]
void MC_PWM_Set3Phase(MC_PWM_Handle_t *p)
{
/* get period value */
volatile uint16_t period = (PWM1_PERIPHERAL->SM[kPWM_Module_0].VAL1 + 1U) << 1;
/* phase A */
uint16_t duty = MC_dutyCycleToReloadValue(p->duty_u);
uint16_t pulseWidth = ((period * duty) / 65535U) >> 1;
PWM1_PERIPHERAL->SM[kPWM_Module_0].VAL2 = GetComplement_u16(pulseWidth);
PWM1_PERIPHERAL->SM[kPWM_Module_0].VAL3 = PWM_VAL3_VAL3(pulseWidth);
/* phase B */
duty = MC_dutyCycleToReloadValue(p->duty_v);
pulseWidth = ((period * duty) / 65535U) >> 1;
PWM1_PERIPHERAL->SM[kPWM_Module_1].VAL2 = GetComplement_u16(pulseWidth);
PWM1_PERIPHERAL->SM[kPWM_Module_1].VAL3 = PWM_VAL3_VAL3(pulseWidth);
/* phase C */
duty = MC_dutyCycleToReloadValue(p->duty_w);
pulseWidth = ((period * duty) / 65535U) >> 1;
PWM1_PERIPHERAL->SM[kPWM_Module_3].VAL2 = GetComplement_u16(pulseWidth);
PWM1_PERIPHERAL->SM[kPWM_Module_3].VAL3 = PWM_VAL3_VAL3(pulseWidth);
/* set LDOK bits */
PWM1_PERIPHERAL->MCTRL |= PWM_MCTRL_LDOK_MASK;
}
[FLEXPWM2 PWM pulse width update code]
void MC_PWM_DAC_Set3Phase(MC_PWM_DAC_Handle_t *p)
{
// PWM_SetPwmLdok(PWM2_PERIPHERAL, kPWM_Control_Module_0 | kPWM_Control_Module_1 | kPWM_Control_Module_2, false);
/* get period value */
volatile uint16_t period = (PWM2_PERIPHERAL->SM[kPWM_Module_0].VAL1 + 1U) << 1;
/* phase A */
uint16_t duty = MC_dutyCycleToReloadValue(p->duty_dac1);
uint16_t pulseWidth = ((period * duty) / 65535U) >> 1;
PWM2_PERIPHERAL->SM[kPWM_Module_0].VAL2 = GetComplement_u16(pulseWidth);
PWM2_PERIPHERAL->SM[kPWM_Module_0].VAL3 = PWM_VAL3_VAL3(pulseWidth);
/* phase B */
duty = MC_dutyCycleToReloadValue(p->duty_dac2);
pulseWidth = ((period * duty) / 65535U) >> 1;
PWM2_PERIPHERAL->SM[kPWM_Module_1].VAL2 = GetComplement_u16(pulseWidth);
PWM2_PERIPHERAL->SM[kPWM_Module_1].VAL3 = PWM_VAL3_VAL3(pulseWidth);
/* phase B */
duty = MC_dutyCycleToReloadValue(p->duty_dac3);
pulseWidth = ((period * duty) / 65535U) >> 1;
PWM2_PERIPHERAL->SM[kPWM_Module_2].VAL2 = GetComplement_u16(pulseWidth);
PWM2_PERIPHERAL->SM[kPWM_Module_2].VAL3 = PWM_VAL3_VAL3(pulseWidth);
/* set LDOK bits */
PWM2_PERIPHERAL->MCTRL |= PWM_MCTRL_LDOK_MASK;
// PWM_SetPwmLdok(PWM2_PERIPHERAL, kPWM_Control_Module_0 | kPWM_Control_Module_1 | kPWM_Control_Module_2, true);
}
In the ADC_ETC interrupt, I set PWM in next order.
1. MC_PWM_Set3Phase()
2 . MC_PWM_Set3Phase()
By the way, FLEX PWM2 works with set value at the start of PWM output.
I have a question.
Q1. Any special settings is need for use FLEXPWM1 and FLEXPWM2 at the same time?
Q2. FLEXPWM2 uses Channel B. SM0 is a dummy and does not output. FLEXPWM work only with Channel B, not need Channel A?
Q3. Related to the Q2, is it possible to update the PWM pulse width without using SM0 (master)? Without Master SYNC.
Q4.The way of use LDOK bits setting in my code, is there no problem? I think there is a problem with the LDOK bit setting.
Q5.The outputs of FLEXPWM2_PWM1_B and FLEXPWM2_PWM2_B are PIN1 and PIN2 of SW6 of the board. Any special settings is need for use FLEXPWM2 on MIMXRT1060-EVK?
解決済! 解決策の投稿を見る。
Hi All
Maybe I can solve this problem by myself.
I seem to have misunderstood about PWM VAL0 to VAL5 parameters.
I thought that both A and B channel have a VAL0 to VAL5 params.
Reread the SDK code, to set PWM pulse width, need to set VAL4 and VAL5.
Sorry for the fuss.
Hi All
Maybe I can solve this problem by myself.
I seem to have misunderstood about PWM VAL0 to VAL5 parameters.
I thought that both A and B channel have a VAL0 to VAL5 params.
Reread the SDK code, to set PWM pulse width, need to set VAL4 and VAL5.
Sorry for the fuss.