Demo for Input Period Measurement of S32K344

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

Demo for Input Period Measurement of S32K344

Jump to solution
2,115 Views
RegulusCheng
Contributor III

Hi, 

I am trying to build an MCU (Motor Control Unit) program with S32K3X4EVB-Q172, which is a part of MCSPTE1AK344 EVB.

I am using Simulink in Matlab 2021b, with MBDT 1.4.0.

I notice there are no PWM input measurements or eMIOS/ICU  models in this toolbox, only an ISR custom code example using ICU functions. However, I am a beginner in AutoSar or C-code programming, I only have some experience in Simulink, so I really need some Demo about PWM input signal measurement.

Since I need to get the encoder signal and Motor speed/position information, I think the most helpful demo would be something about input period measurement and input edge count. Would it be possible to provide me with some related demos for learning? I really need it.

Regards,

Regulus

0 Kudos
Reply
1 Solution
1,870 Views
dragostoma
NXP Employee
NXP Employee

Hi, @RegulusCheng ,

After investigating over your model and its associated configuration, I've included an example version that illustrates the ICU functionality.

It came to my attention that you were attempting to use the PTE11 pin, which is designated as DNP (Do Not Populate) in the schematic datasheet. Taking this into account, I've switched from PTE11 (EMIOS_0_CH_1) to PTB13 (EMIOS_0_CH_1). The Pins tool for the EMIOS_0_CH_1 instance was the only modification, as it was the same eMIOS instance for both pins.

dragostoma_0-1708457552703.png

It's also important to note that the Icu_GetTimeElapsed function returns an Icu_ValueType data type, which is an uint32. According to your model, this output was set to uint16.

Considering these suggestions, you'll be able to integrate the Icu_GetTimeElapsed functionality into your application.

It should be noted that in the attached model, the signal was generated by USER_SW0 (PTB26). Therefore, in order to measure the period, you need to connect the PTB13 (J2.4), the ICU channel that is set to Signal Measurement mode, Period Time setting, and the PTB26 (J3.3), which is the generated signal, in this case USER_SW0. For the purpose of visualizing the measure time and confirming that the implementation is accurate, I also included a FreeMaster file (s32k344Test.pmpx).

I hope you can accomplish your goal using this approach. Please let us know if you require any more information.

 

Best regards,

Dragos

View solution in original post

6 Replies
2,034 Views
georgevictor
NXP Employee
NXP Employee

Hi, @RegulusCheng,

Currently, the Model-Based Design Toolbox (MBDT) release for S32K3xx does not include support for the ICU component but we are going to add it in a future release. Taking into consideration that we include the entire RTD drivers package, you can still use the component in our toolbox by accessing the ICU's API using custom code blocks.

Beside the ISR custom code example, you could also check the s32k344_mc_bldc_ebt example which is a motor control application that is using custom code to read PWM signals. Beside the custom code usage you should also check the associated configuration project and see an example of ICU settings.

The following threads contain useful information about custom code usage:  

https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/PWM-Capture-for-S32K3-in-Simulink/m-p/1...

https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/SENT-Protocol-Support-in-S32K3-MBDT/m-p...

 

Best regards,

Victor

0 Kudos
Reply
1,918 Views
RegulusCheng
Contributor III

Hi, Victor

I learned the BLDC example and know I can use the Matlab Function module to call C function. However, I can not finish Period measurement as well. 

Since the BLDC example is configured by EB tresos, but I only know a little about S32CT, I do the configuration with S32CT Refer to EB project, I also learn from some other examples. But I don't know if I finished the Icu configuration correctly and if it's the reason why I can not get period data.

Here is my configuration file, and I finished the following configuration :

1. Set PTE11 and PTD0 to eMios in Pins setting.

RegulusCheng_0-1708338752443.png

2. Set eMios MasterCounter in Mcl setting:

RegulusCheng_1-1708338848838.png

3. Enable peripheral clock of eMios0 in Mcu setting.

RegulusCheng_2-1708338912225.png

4. Enable relating eMios interrupt controller in Platform setting

RegulusCheng_3-1708338964499.png

5. Set Icu channels

5.1 Set Icu_channel0, using eMios0_channel1, using SiganlMeasurement mode, and set to Period_Time measurement function.

RegulusCheng_4-1708339192768.png

5.2 Set IcueMios, using using eMios0_channel1, using MasterCounter0(eMios0_23), using IcuSubModeforMeasurement IPWM

RegulusCheng_6-1708339373375.png

5.3 Enable eMios IcuHwlnterruptConfigList

RegulusCheng_7-1708339503436.png

I think I have finished all related settings. Then I make a simple model to get PWM period, the model is post as follow.

RegulusCheng_8-1708339647509.png

In the initialize function, I configured FreeMaster and called Icu_StartSignalMeasurement function to enable Icuchannel0.

RegulusCheng_9-1708339737926.png

RegulusCheng_10-1708339758292.png

In the main function, I set a flashing LED to ensure the program is running successfully.

Then I used the Icu_getTimeElapsed() function which is copied from the BLDC example. 

RegulusCheng_11-1708339891334.png

 

The program can be downloaded to the board and the LED is flashing as wish. However, the period data keeps zero when I give PTE11 a 3V 1kHz PWM signal, which means the Icu_getTimeElapsed() function gets nothing returned.

I really appreciate it if you or anybody could check my configuration file and Simulink model, and tell me what is wrong and how can I get period data successfully. It is really important for me.

thanks again! 

 

Best regards,

regulus

 

0 Kudos
Reply
1,871 Views
dragostoma
NXP Employee
NXP Employee

Hi, @RegulusCheng ,

After investigating over your model and its associated configuration, I've included an example version that illustrates the ICU functionality.

It came to my attention that you were attempting to use the PTE11 pin, which is designated as DNP (Do Not Populate) in the schematic datasheet. Taking this into account, I've switched from PTE11 (EMIOS_0_CH_1) to PTB13 (EMIOS_0_CH_1). The Pins tool for the EMIOS_0_CH_1 instance was the only modification, as it was the same eMIOS instance for both pins.

dragostoma_0-1708457552703.png

It's also important to note that the Icu_GetTimeElapsed function returns an Icu_ValueType data type, which is an uint32. According to your model, this output was set to uint16.

Considering these suggestions, you'll be able to integrate the Icu_GetTimeElapsed functionality into your application.

It should be noted that in the attached model, the signal was generated by USER_SW0 (PTB26). Therefore, in order to measure the period, you need to connect the PTB13 (J2.4), the ICU channel that is set to Signal Measurement mode, Period Time setting, and the PTB26 (J3.3), which is the generated signal, in this case USER_SW0. For the purpose of visualizing the measure time and confirming that the implementation is accurate, I also included a FreeMaster file (s32k344Test.pmpx).

I hope you can accomplish your goal using this approach. Please let us know if you require any more information.

 

Best regards,

Dragos

1,824 Views
RegulusCheng
Contributor III

Hi, Dragos

Thanks a lot ! It is exactly the key point to solve the problem!

I can now get the period and use the edge count function, which I use to analyze motor encoder signals.

However, I still have a question although it does not prevent me from completing the task at hand. When I try to get duty-cycle data of the PWM input signal, I found that the corresponding function "Icu_GetDutyCycleValues" needs an input parameter, which is a pointer to a buffer where the results (high time and period time)shall be placed. I have created a structure bus type (a bus that has two unint32 variables "period time" and "high time") in Simulink to store these results, but I don't know how to put the pointer into the Matlab Function module.

I have tried to build a DataStoreMemery which has a data type of custom bus type and use it as input, but it didn't work.

Is it possible to give some suggestions? Or it would be better if you could show me how to realize it and just add it to the model you provided earlier. I hope you don't think this is too much  

 

Best regards,

Regulus

0 Kudos
Reply
1,932 Views
RegulusCheng
Contributor III

Hi,

I was told to use Matlab function or C function in Simulink should set the used head file and source file in "Model configuration - Simulation target", like this:

RegulusCheng_0-1708310686787.png

However, I found that the example "s32k3xx_mc_bldc" didn't set these files, directly using the Matlab function to call C functions. Does it mean that this operation is not necessary?

RegulusCheng_1-1708310930038.png

 

 

0 Kudos
Reply
2,053 Views
RegulusCheng
Contributor III

Is this difficult? I really need some help cause the PMSM control program need be done 

0 Kudos
Reply