Hi All.
I'm working on PWM and ADC synchronization.
To synchronize, I need to set TRIG0, PWM VAL4 counter.
I set like this, on time start run PWM. However, when I check the register, the value is set to 0.
Also, VAL4=0 but, ADC_ETC interrupt occurs two times in one PWM cycle like below figure.
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.
已解决! 转到解答。
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.
The code outputs PWM when the SW8 on the board is pressed.
Please check the code.
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
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:
The ADC_ETC interrupt is processed as follows:
And the PWM cycle is updated inside the function (ESC_MotorControl()) in the ADC_ETC interrupt like follows:
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?
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
Hi @kerryzhou -san
I haven't solved the issue, but I'll let you know about the situation.
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.
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?
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:
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
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.
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.
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?
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
HI @kerryzhou -san
Setting like this, I could solve the interrupt problem.
Thank you!
And, a new question, the first interrupts inner operation take a time. I only read out the four ADC channels.
When restart PWM, the first interrupts inner operation, end normally.
What could be the cause of this phenomenon?
Hi @kenji
My colleague jingpan tell me, he has tested your project yesterday, and find the twice trigger reason:
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
Hi @kerryzhou -san
As already replied, the twice interrupt problem have been resolved.
I will repost the fixed code.
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.
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.
The code outputs PWM when the SW8 on the board is pressed.
Please check the code.