i.MX RT1062: How to set VAL4 compare value for PWM and ADC synchronization

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i.MX RT1062: How to set VAL4 compare value for PWM and ADC synchronization

Jump to solution
2,724 Views
kenji
Contributor IV

Hi All.

I'm working on PWM and ADC synchronization.
To synchronize, I need to set TRIG0, PWM VAL4 counter. 

kenji_0-1626689540861.png

I set like this, on time start run PWM. However, when I check the register, the value is set to 0.

kenji_1-1626689652165.png

kenji_0-1626690626848.png

 

Also, VAL4=0 but, ADC_ETC interrupt occurs two times in one PWM cycle like below figure.

kenji_1-1626691211601.png

I want to know how to set VAL4, and solve the two times interrupt in one PWM cycle

※I've already referenced the sample code, but I can't resolve it. 

 

Labels (2)
Tags (1)
0 Kudos
Reply
1 Solution
2,688 Views
kenji
Contributor IV

Hi kerryzhou-san

Yes, posted waveform is from my project code.

I upload my project.
I use config tools for MCU setting.

And I referred "evkmimxrt1060_pwm" and "evkmimxrt1060_mc_pmsm" and AN12200.

Also, I am posting here as a related post.

https://community.nxp.com/t5/i-MX-RT/i-MX-RT1062-How-to-set-hardware-timing-and-synchronization-for/...

The code outputs PWM when the SW8 on the board is pressed.

Please check the code.

View solution in original post

Tags (1)
0 Kudos
Reply
11 Replies
2,713 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @kenji 

Please tell me what's the code you are using? the SDK code or your own designed code?

VAL4 is the used to defines the count value to set PWM45 high. So, do you configure this register or not? Or you just can't write it?

If you can't write it, please check the register information:

NOTE: The VAL4 register is buffered. The value written does not take effect until MCTRL[LDOK] is set
and the next PWM load cycle begins or CTRL[LDMOD] is set. VAL4 cannot be written when
MCTRL[LDOK] is set. Reading VAL4 reads the value in a buffer and not necessarily the value
the PWM generator is currently using.

 

Best Regards,

Kerry

 

 

0 Kudos
Reply
2,709 Views
kenji
Contributor IV

Hi kerryzhou-san

 

I used the SDK code and the evkmimxrt1060_mc_pmsm code, but it doesn't work.
I'm stuck.

I start output PWM like this:

kenji_0-1626858131144.png

The ADC_ETC interrupt is processed as follows:

kenji_1-1626858280329.png

And the PWM cycle is updated inside the function (ESC_MotorControl()) in the ADC_ETC interrupt like follows:

kenji_2-1626858409698.png

MC_PWM_Update() and MC_PWM_Set3Phase() is doing samething. MC_PWM_Update() is only use SDK function. MC_PWM_Set3Phase() use evkmimxrt1060_mc_pmsm sample code MCDRV_eFlexPwm3PhSet() function.

Also I set VAL4, only when start PWM. Not set in update function.

Are there any mistakes in interrupt processing and PWM setting update in my code?
Why interrupts occur twice?

You said that VAL4 is the used to defines the count value to set PWM 45. This means that when set VAL4, interrupt occur at VAL4 and VAL5 count timing?

 

Tags (1)
0 Kudos
Reply
2,701 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @kenji ,

  So now, your first post wave is not from the SDK project, it is your own project code, right?

  Which hardware you have tested, MIMXRT1060-EVK?

 Can you share me your project which can reproduce the issues, then I will find time to check it on my MIMXRT1060-EVK board, please also tell me your related test point which indicate trigger two interrupt.

Best Regards,

kerry

0 Kudos
Reply
2,674 Views
kenji
Contributor IV

Hi @kerryzhou -san

I haven't solved the issue, but I'll let you know about the situation.

kenji_0-1627444293489.png

First, when I started PWM, I added the following two lines, the ADC ETC interrupt became once every PWM cycle. However, interrupt times returned to twice now.

kenji_2-1627444615748.png

 

Second, ADC_ETC interrupt after PWM starts, it seems that it is taking a long time. Is this help you to know the cause of two times interrupt?  Is there anything I should do to VAL4 during a PWM update or ADC_ETC interrupt? 

0 Kudos
Reply
2,670 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @kenji 

   Thanks for your updated information, these days, a lot of cases in the testing queue, so I still have no time to help you to test it.

   you mentioned,  ADC_ETC interrupt occurs two times, whether this just when your set the VAL4=0 it will happens, if you don't configure the VAL4, ADC_ETC interrupt just one time?

  I just checked the RM at first, and find the PWM ADC related information:

kerryzhou_0-1627450685624.png

From the above wave, one is VAL4 trigger, one is VAL5 trigger.

So, your two ADC trigger, should happens when different VAL is matched.

Please check the RM and your code again. When I have time, I will also help you to check more details.

Any updated information, kindly let me know.

Best Regards,

Kerry

 

 

 

 

0 Kudos
Reply
2,665 Views
kenji
Contributor IV

Hi @kerryzhou -san

When press SW8, call MC_PWM_Start() function and inside this function I'm setting VAL4 like below:
But I found that VAL4 was not setting, it's value is 0.

kenji_0-1627463248625.png

If you comment out the VAL4 setting, write the VAL4 value directly in Global Variables during PWM drive, stop PWM, and redrive it, ADC_ETC will be interrupted once after that.

kenji_0-1627465771877.png

The operation of the ADC_ETC and PWM synchronization has been verified by NXP, right?
Does it work properly?

A day work for other MCU to set ADC and PWM synchronization, but I spend a few weeks working on this.
I want to see the test or sample code, do you have it?

0 Kudos
Reply
2,662 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @kenji 

The value written does not take effect until MCTRL[LDOK] is set
and the next PWM load cycle begins or CTRL[LDMOD] is set. VAL4 cannot be written when
MCTRL[LDOK] is set.

Please check, whether your LDOK is set when you write VAL4?

Best Regards,

Kerry

0 Kudos
Reply
2,655 Views
kenji
Contributor IV

HI @kerryzhou -san

Setting like this, I could solve the interrupt problem. 
Thank you!

kenji_0-1627526302677.png

And, a new question, the first interrupts inner operation take a time. I only read out the four ADC channels.

kenji_1-1627526532501.png

When restart PWM, the first interrupts inner operation, end normally.

kenji_2-1627526575562.png

What could be the cause of this phenomenon?

 

 

 

0 Kudos
Reply
2,638 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @kenji 

 My colleague jingpan tell me, he has tested your project yesterday, and find the twice trigger reason:

https://community.nxp.com/t5/i-MX-RT/i-MX-RT1062-How-to-set-hardware-timing-and-synchronization-for/...

Do you use his recommend code:

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

And whether twice interrupt trigger is resolved or not?

 

Best Regards,

kerry

0 Kudos
Reply
2,612 Views
kenji
Contributor IV

Hi @kerryzhou -san

As already replied, the twice interrupt problem have been resolved.
I will repost the fixed code.

kenji_0-1627863342023.png

Instead of "1<<kPWM_ValueRegister_4", I used "kPWM_ValueRegisterMask_4".

Also, as replaied above, the new problem is that the first interrupt processing time is long when the first PWM is output.

 

0 Kudos
Reply
2,689 Views
kenji
Contributor IV

Hi kerryzhou-san

Yes, posted waveform is from my project code.

I upload my project.
I use config tools for MCU setting.

And I referred "evkmimxrt1060_pwm" and "evkmimxrt1060_mc_pmsm" and AN12200.

Also, I am posting here as a related post.

https://community.nxp.com/t5/i-MX-RT/i-MX-RT1062-How-to-set-hardware-timing-and-synchronization-for/...

The code outputs PWM when the SW8 on the board is pressed.

Please check the code.

Tags (1)
0 Kudos
Reply