i.MX RT1062: How to set hardware timing and synchronization for PWM and ADC using Config Tools

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

i.MX RT1062: How to set hardware timing and synchronization for PWM and ADC using Config Tools

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

Hi All

To drive a BLDC motor, I want to synchronize the PWM and ADC timings as shown in the figure below using MCXpresso Config Tools. I know that there "evkmimxrt1060_mc_pmsm" sample code but this code not works, so I want to setup peripheral using Config Tools. 

kenji_0-1626160904351.png

The current problem is that the PWM output works well, but the ADC interrupt does not works.
So I would like to know how to set up ADC, ADC‗ETC, XBAR1 using Config Tools.

I don't know how to do it because there is almost no information on how to synchronize and how to set using Config Tools.

It would be helpful if there YouTube, online training and documents like STMicroelectronics.

I post my code below. In addition, the code that cannot be disclosed has been deleted.

 

 

ラベル(3)
タグ(1)
0 件の賞賛
返信
1 解決策
2,168件の閲覧回数
jingpan
NXP TechSupport
NXP TechSupport

Hi,

When start PWM, you set the output trig as

PWM_ActivateOutputTrigger(PWM1_PERIPHERAL, kPWM_Module_0, kPWM_ValueRegister_4);

I think is is not correct. TCTRL[OUT_TRIG_EN] has 6 bit. Each bit control a VALx comparator output. So, this function should be 

PWM_ActivateOutputTrigger(PWM1_PERIPHERAL, kPWM_Module_0, 1<<kPWM_ValueRegister_4);

After the change, you can see the double trig disappear.

 

Regards,

Jing

元の投稿で解決策を見る

0 件の賞賛
返信
7 返答(返信)
2,263件の閲覧回数
jingpan
NXP TechSupport
NXP TechSupport
0 件の賞賛
返信
2,251件の閲覧回数
kenji
Contributor IV

Thank you for the information. For now I could trigger ADC interrupt. But not work properly. I want to do 4CH ADC, synchronized with PWM's VAL4 compare.

Below is the ADC and PWM timing signals.
I want to do ADC for 4 -CH, once within one PWM cycle.
However, the ADC is doing the ADC regardless of the timing of VAL4 Compare.

High level period of the "ADC1 IRQ" signal in below figure, means that ADC1 IRQ Handler(void) function called.

kenji_0-1626343597109.png

My setting is like below, and I post my project.
Is there anything wrong with it?

[PWM1]

kenji_1-1626343974653.pngkenji_2-1626344005451.png

kenji_3-1626344029361.png

[ADC]

kenji_4-1626344060678.png

kenji_5-1626344076482.png

[ADC_ETC]

kenji_6-1626344111804.png

kenji_7-1626344123402.png

 

[ADC1_IRQHanler]

 

 

volatile uint32_t adcConversionValue[4];

void ADC1_IRQHandler(void)
{
  DBG_OUT_CH1_SET_HIGH();

  adcConversionValue[0] = ADC_GetChannelConversionValue(ADC1, 0U);
  adcConversionValue[1] = ADC_GetChannelConversionValue(ADC1, 1U);
  adcConversionValue[2] = ADC_GetChannelConversionValue(ADC1, 2U);
  adcConversionValue[3] = ADC_GetChannelConversionValue(ADC1, 3U);

  DBG_OUT_CH1_SET_LOW();

  SDK_ISR_EXIT_BARRIER;
}

 

 

0 件の賞賛
返信
2,245件の閲覧回数
jingpan
NXP TechSupport
NXP TechSupport

Hi,

AN12200 has software package. You can use its driver directly. It seems the ADC_ETC usage are same.

https://www.nxp.com/webapp/Download?colCode=AN12200SW&location=null

 

Regards,

Jing

0 件の賞賛
返信
2,240件の閲覧回数
kenji
Contributor IV

Hi.

 

I have already referred to the AN12200 documentation and code, but synchronization of PWM and ADC doesn't work. ADC interrupt does not work. I get into ADC_ETC_ERROR_IRQ_IRQHandler.

  • This is a simple question. 
    Is there a bug in the code generated by the Config tool? 
  • And about AN12200 document, what is trigger queue?
    What's the difference with channel group?

kenji_0-1626424155918.png

  • ADC_ECT is set to interrupt with VAL4 Compare of PWM1. Is it possible to check by outputting a signal to the port whether VAL4 Compare of PWM1 is outputting the trigger signal correctly?
  • If the settings are correct, is there any special way to write the code in the interrupt process? Below is my code.
    kenji_0-1626425621380.png

     

 

0 件の賞賛
返信
2,235件の閲覧回数
kenji
Contributor IV

Hi

It has improved a little. But now new problem has happened as below figure.

kenji_0-1626430562121.png

Interrupts are applied twice within one PWM cycle.
I am triggering the ADC with VAL4. Why this happen?

I will post my test code as reference.

0 件の賞賛
返信
2,169件の閲覧回数
jingpan
NXP TechSupport
NXP TechSupport

Hi,

When start PWM, you set the output trig as

PWM_ActivateOutputTrigger(PWM1_PERIPHERAL, kPWM_Module_0, kPWM_ValueRegister_4);

I think is is not correct. TCTRL[OUT_TRIG_EN] has 6 bit. Each bit control a VALx comparator output. So, this function should be 

PWM_ActivateOutputTrigger(PWM1_PERIPHERAL, kPWM_Module_0, 1<<kPWM_ValueRegister_4);

After the change, you can see the double trig disappear.

 

Regards,

Jing

0 件の賞賛
返信
2,156件の閲覧回数
kenji
Contributor IV

Hi @jingpan -san

You're right.
I set value instead of mask value.

 

0 件の賞賛
返信