i.MX RT1060: The PWM pulse width (PWM duty) cannot be updated

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

i.MX RT1060: The PWM pulse width (PWM duty) cannot be updated

ソリューションへジャンプ
1,512件の閲覧回数
kenji
Contributor IV

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]

  • Board: MIMXRT1060-EVK
  • FLEXPWM1 ports:
    Use PWM for motor control.
    - FLEXPWM1_PWM0_A, GPIO_SD_B0_00, SM0, master
    - FLEXPWM1_PWM1_A, GPIO_SD_B0_02, SM1
    - FLEXPWM1_PWM3_A, GPIO_SD_B0_10, SM3
    - PWM freq: 50kHz
  • FLEXPWM2 ports:
    Use PWM as a DAC. 
    - FLEXPWM2_PWM0_x, not output, SM0, as master
    - FLEXPWM2_PWM1_B, GPIO_B0_09, SM1
    - FLEXPWM2_PWM2_B, GPIO_B0_11, SM2
    - PWM freq: 50kHz

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?

 

ラベル(3)
タグ(1)
0 件の賞賛
返信
1 解決策
1,503件の閲覧回数
kenji
Contributor IV

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. 

 
 
 

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
1,504件の閲覧回数
kenji
Contributor IV

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. 

 
 
 
0 件の賞賛
返信