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.
Root
ADC Sensing block
ADC1_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!