Hello,
I am using S32K396-BGA-DC1 board, with Simulink in matlab2024a.
I am trying to control the duty cycle of a FlexPwm output (PTD24) with an ADC reading input (PTD1). For that, I need the ADC synchronized with the PWM as it is explained in Module 6:Current Sensing
I followed the configuration proposed in AN14326-3-phase Motor Control Kit with S32K396 , S32K396-MBDT and AN13767-S32K344 motor without success. I get a "Error(s) encountered while building" message and does not compile.
Can you please give me support on this and tell me what is missing or wrong in the config?
I attached the project.
Thanks, Agustin.
Solved! Go to Solution.
Hi @agus_idiada
Thank you for sharing your project with us. I have downloaded the attached archive, and I am still debugging your project for being able to provide a complete solution for your use case. However, I would like to share this intermediate support on the issues found so far. Please find each of them depicted below, together with its associated fix.
1. Disable Mcl Enable User Mode Support
The Simulink model does not build successfully due to the fact that the Mcl Enable User Mode Support check box is enabled. If that checkbox is enabled and the Mcl component must be used in this configuration mode, the MCAL_ENABLE_USER_MODE_SUPPORT flag must be also provided during the compilation process. This is due to the RTD (Real-Time Drivers) implementation that our toolbox integrates for configuring and controlling the on-board peripherals, pins and clocks. Since we have not tested, inside our toolbox, the RTD components configured in this mode so far, I have disabled the option from your attached .mex file, thus being able to obtain an executable file (.elf) for the application. Please let us know if there is a specific need for this user mode support enablement and we could analyze and come back with the necessary details for its operating mode.
2. DMA configuration
After performing step 1, I have downloaded the application on target, and its execution resulted in a hard fault during the Mcl_Init function. This is because inside the Mcl component you are also enabling the DMA Support, without configuring the DMA peripheral clocks. Hence, when DMA registers are trying to be read/set, a hard fault occurs. My proposal would be to disable it for now, and focus only on the use case you are trying to achieve, thus taking the functionalities step by step. We could perform the DMA configuration later on during the application development process.
Together with this, please also disable the Adc Bctu Control Mode Enable DMA Support as well.
3. Adc_EnableCtuControlMode
Now, for being able to trigger your ADC conversion using Bctu, Trgmux and FlexPwm, I have seen that you are using the Adc_CtuEnableHwTrigger function inside the model's initialization. For being able to use this function, and enable the hardware trigger provided as a parameter, you would need to enable the Bctu control mode for the Adc instance.
For more details on the Control and Trigger modes of the Bctu, please refer to the RTD_ADC_UM.pdf document, available inside <toolbox_installation_path>/S32K3_RTD/SW32K3_RTD_R21-11_4.0.0_P19/eclipse/plugins/Adc_TS_T40D34M40I0R0/doc folder. A short snippet with relevant information is attached below
4. BCTU Configuration
Inside the Bctu configuration tab you have the Adc Target Mask option, which will specify to what ADC instance is the Bctu trigger associated to. Please note that in this field, as you are using ADC1, you should type the value of 2, based on the embedded help associated to this setting.
1 - ADC0, 2 - ADC1, 4 - ADC2, and so on.
5. [UNDER INVESTIGATION] BCTU FIFO data unavailable
After performing these steps, I was able to debug the application which now enters the Bctu ISR Handler. Inside this BCTU ISR Handler, the Watermark notification Motor_Isr is called whenever the number of elements in the FIFO will be greater than the specified value. As the application currently does not execute the Motor_Isr callback, I have debugged and seen that no data reached the FIFO. Hence, my guess is that something is still missing on the configuration side, and we are currently looking into this, for being able to provide a complete solution to your problem.
I have attached to this thread the .mex file containing the modifications mentioned above. We will come back with a solution for addressing your use case as soon as we reach a resolution for the last item.
Thank you for your understanding,
Irina
thanks @Irina_Costachescu , I'll be waiting for the final answer.
Hi @agus_idiada
I have continued to debug the application you have sent and I would like to provide the following information.
Inside the Mcl component you are configuring the PWM0_0_3_OUT_TRG0_1 as an input routed via Trgmux to the BCTU0_TRG39, hence using the eFlexPWM output triggers to control the ADC conversions. The output trigger signals are generated based on the configuration enabled inside each submodule's TCTRL (Output Trigger Control) register. The setting which enables the generation of these signals, and writes the TCTRL[OUT_TRIG_EN] for each eFlexPWM submodule, is controlled by the setting illustrated below.
With the FLEXPWM_IP_NO_TRIGGER option, the PWMn_OUT_TRIG_0_1 signals are not generated, hence the ADC conversion is not started. Please enable one of the selection in the dropdown list (FIRST, SECOND or BOTH edges) based on the use case that you would like to achieve inside your application. For more details on the eFlexPWM operating modes, output triggers, master sync, and reload signals, I would like to point you to the eFlexPWM chapter inside the S32K396 Reference Manual, as it provides comprehensive details on all these notions, providing more clarity on the configurable options inside the .mex file.
Besides this, one additional setting that must be made inside your configuration is related to the Pins routing. Even if the pwm_0_a is routed to PTD24 inside the Pins Tool, the setting of this pin must also be enabled inside the Port component. During the initialization, the Port_Init function will be called for initializing the pins used inside your application. Hence, not having it enabled inside the Port component as well, won't perform the complete routing of the PWM signal to the desired pin. Please see attached image below. For more details on this correspondence, please check the S32K3 Release Notes, Section 3.6.
With these configurations in place, I have obtained the following results, by connecting a logic analyzer to PTD24 on my EVB.
I have attached the .mex used to this thread. Please let us know if this solves the issue you are currently encountering.
Thank you,
Irina
Dear@Irina_Costachescu , thanks for the answer. So I implemented your proposed configuration and I was able to get the same as you in the oscilloscope. But, that result does not work for me as I can not read the adc and the pwm duty cycle and frecuency are others that the expeted. Where the 2.4khz come from? and the duty cycle of 12.5%? According to the blocks and mex config, the pwm should be 10kHz and duty cycle should be controlled by reading the adc.
Hi @agus_idiada
Could you please provide more information on the test you are performing for verifying that ADC data can't be read?
Also, have you placed the Dio_FlipChannel block inside the Motor_Isr callback? I added one myself on the current software setup that I have also shared with you, and the Motor_Isr callback notification is executed. Visually, on the board, the LED remains constantly turned on, and the reason you can't see it blinking is because the Motor_Isr callback gets executed at a frequency which is to high for this on/off behavior to be noticed.
Please share with us more details so that we could identify your issue.
Thank you,
Irina
Dear @Irina_Costachescu , my LED is not turning on at all. Can you send to me the all project in a .zip file please? I can not understand why is not working for me. Thanks.
Ok, I solved it by adding and Adc_EnableCtuControlMode block
@dragostoma @Irina_Costachescu could you please take a look on this? Thanks in advance.
Hi @agus_idiada
Thank you for sharing your project with us. I have downloaded the attached archive, and I am still debugging your project for being able to provide a complete solution for your use case. However, I would like to share this intermediate support on the issues found so far. Please find each of them depicted below, together with its associated fix.
1. Disable Mcl Enable User Mode Support
The Simulink model does not build successfully due to the fact that the Mcl Enable User Mode Support check box is enabled. If that checkbox is enabled and the Mcl component must be used in this configuration mode, the MCAL_ENABLE_USER_MODE_SUPPORT flag must be also provided during the compilation process. This is due to the RTD (Real-Time Drivers) implementation that our toolbox integrates for configuring and controlling the on-board peripherals, pins and clocks. Since we have not tested, inside our toolbox, the RTD components configured in this mode so far, I have disabled the option from your attached .mex file, thus being able to obtain an executable file (.elf) for the application. Please let us know if there is a specific need for this user mode support enablement and we could analyze and come back with the necessary details for its operating mode.
2. DMA configuration
After performing step 1, I have downloaded the application on target, and its execution resulted in a hard fault during the Mcl_Init function. This is because inside the Mcl component you are also enabling the DMA Support, without configuring the DMA peripheral clocks. Hence, when DMA registers are trying to be read/set, a hard fault occurs. My proposal would be to disable it for now, and focus only on the use case you are trying to achieve, thus taking the functionalities step by step. We could perform the DMA configuration later on during the application development process.
Together with this, please also disable the Adc Bctu Control Mode Enable DMA Support as well.
3. Adc_EnableCtuControlMode
Now, for being able to trigger your ADC conversion using Bctu, Trgmux and FlexPwm, I have seen that you are using the Adc_CtuEnableHwTrigger function inside the model's initialization. For being able to use this function, and enable the hardware trigger provided as a parameter, you would need to enable the Bctu control mode for the Adc instance.
For more details on the Control and Trigger modes of the Bctu, please refer to the RTD_ADC_UM.pdf document, available inside <toolbox_installation_path>/S32K3_RTD/SW32K3_RTD_R21-11_4.0.0_P19/eclipse/plugins/Adc_TS_T40D34M40I0R0/doc folder. A short snippet with relevant information is attached below
4. BCTU Configuration
Inside the Bctu configuration tab you have the Adc Target Mask option, which will specify to what ADC instance is the Bctu trigger associated to. Please note that in this field, as you are using ADC1, you should type the value of 2, based on the embedded help associated to this setting.
1 - ADC0, 2 - ADC1, 4 - ADC2, and so on.
5. [UNDER INVESTIGATION] BCTU FIFO data unavailable
After performing these steps, I was able to debug the application which now enters the Bctu ISR Handler. Inside this BCTU ISR Handler, the Watermark notification Motor_Isr is called whenever the number of elements in the FIFO will be greater than the specified value. As the application currently does not execute the Motor_Isr callback, I have debugged and seen that no data reached the FIFO. Hence, my guess is that something is still missing on the configuration side, and we are currently looking into this, for being able to provide a complete solution to your problem.
I have attached to this thread the .mex file containing the modifications mentioned above. We will come back with a solution for addressing your use case as soon as we reach a resolution for the last item.
Thank you for your understanding,
Irina