Unreliable PWM synchronized ADC acquisition on S32K

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

Unreliable PWM synchronized ADC acquisition on S32K

Jump to solution
1,063 Views
dennymopper
Contributor I

I am having issues implementing an FOC closed loop control for a PMSM, due to unexpected behavior of the ADC acquisition. This is my first project with S32K and the Model Based Design Toolbox, so help in solving or at least better understanding the issue would be greatly appreciated!

I started from the example "PMSM_ClosedLoop_s32k144" provided in the Model Based Design Toolbox for simulink, and I adjusted the inputs basing on my specific setup, by modifying the "ADC Sensing" block, the "Measurements" block and the "Peripherals Initialization" block, as shown in the following screenshots. For the control loop I used a dedicated 5 kHz LPTMR timer. In addition I'm using a CAN interface for debugging.

RootRootADC Sensing blockADC Sensing blockADC1_IRQHandler BlockADC1_IRQHandler Block

The scheme seems to work, but is very unreliable: after a seemingly random time, ranging from some seconds up to few minutes, all the inputs seem to freeze (the ADC interrupt stops working?), while the control loop keep working as expected, as confirmed by the CAN signals. The event seems to manifest quicker if the motor is spinning faster and when I am sending CAN messages to the board. It also seem to be related to changes on the FastLoop block, but despite countless attempts I haven't been able to identify any clear correlation. Sometimes very small changes in the diagram structure cause the ADC acquisition to not even start. I tried to tweak all parameters, from PDB pre triggers to ADC registers and interrupt priority, without success. It is driving me crazy.

Do you have any suggestion on how to fix this problem? Or at least any reference that could help me to identify the issue?

Thank you very much!

0 Kudos
1 Solution
1,040 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @dennymopper 

My guess is that the issue is related to the synchronization between FTM-PDB-ADC timing. You see, in the initial model, the PWM frequency is 20kHz. At each two PWM cycles, the PDB triggers the ADC to perform current measurements. Each complete conversion triggers the control loop, calling each time the FastLoop and 10 times slower the SlowLoop. So the control loop is basically performed at 10kHz

mariuslucianand_0-1613371045883.png

Now, the FTM has an initialization trigger that is sent to PDB each time the FlexTimer's MOD value is 0. The way in which the frequency is halved is by disabling the FlexTimer Initialization trigger for the n+1 PWM cycle when the ADC conversion complete interrupt is triggered in the nth PWM cycle. The PDB interrupt is delayed with 5000 cycles and then the FTM Initialization trigger is enabled again.

The way you want to achieve the 5kHz control loop is by using another timer that is not in sync with this process, while the method above is synchronous, without existing the possibility to let's say disable the triggers forever.

One of the easiest solution would be to delete the FTM init trigger disable enable blocks from inside the PDB1_IRQHandler and ADC1_IRQHanlder to basically perform ADC conversions every PWM cycles, but your control loop every 5kHz. I would also move the measurements block in the control loop. Also, consider using the Lptmr Start Stop Counter block to start the LPTMR counter at the same time when you start the FTM signals generation.

Hope this helps,

Marius

 

 

 

View solution in original post

0 Kudos
2 Replies
1,041 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @dennymopper 

My guess is that the issue is related to the synchronization between FTM-PDB-ADC timing. You see, in the initial model, the PWM frequency is 20kHz. At each two PWM cycles, the PDB triggers the ADC to perform current measurements. Each complete conversion triggers the control loop, calling each time the FastLoop and 10 times slower the SlowLoop. So the control loop is basically performed at 10kHz

mariuslucianand_0-1613371045883.png

Now, the FTM has an initialization trigger that is sent to PDB each time the FlexTimer's MOD value is 0. The way in which the frequency is halved is by disabling the FlexTimer Initialization trigger for the n+1 PWM cycle when the ADC conversion complete interrupt is triggered in the nth PWM cycle. The PDB interrupt is delayed with 5000 cycles and then the FTM Initialization trigger is enabled again.

The way you want to achieve the 5kHz control loop is by using another timer that is not in sync with this process, while the method above is synchronous, without existing the possibility to let's say disable the triggers forever.

One of the easiest solution would be to delete the FTM init trigger disable enable blocks from inside the PDB1_IRQHandler and ADC1_IRQHanlder to basically perform ADC conversions every PWM cycles, but your control loop every 5kHz. I would also move the measurements block in the control loop. Also, consider using the Lptmr Start Stop Counter block to start the LPTMR counter at the same time when you start the FTM signals generation.

Hope this helps,

Marius

 

 

 

0 Kudos
1,000 Views
dennymopper
Contributor I

Restoring the dependency between the PDB trigger and the control loop fixed the issue. Now everything works as expected. Thank you very much for your help and for the illuminating explanation!

0 Kudos