Input PWM Duty cycle measurement Issue using S32k344 and MBDT 1.5

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

Input PWM Duty cycle measurement Issue using S32k344 and MBDT 1.5

Jump to solution
690 Views
RushikeshK_DC
Contributor I

Hello, 

I am trying to measure the PWM Duty cycle using ICU and S32K344 processor with MBDT 1.5.

The input PWM(100Hz and 50% duty) is given on PTB3 pin of MCU and measured duty cycle is observed on FREEMASTER. I don't know about what exactly the active time & period time parameters represent. I have uploaded the images of Input PWM signal measured by HANTEK Oscilloscope & measured values by FREEMASTER with my SIMULINK model here.

Can anyone tell me about how to exactly measure input PWM Duty Cycle and Input Frequency

Thank You!

0 Kudos
Reply
1 Solution
611 Views
dragostoma
NXP Employee
NXP Employee

Hi, @RushikeshK_DC,

First of all, from what I can see, the model in the archive sent is the default model provided in the toolbox. In this configuration, only the ICU channel is set, since the generated PWM signal is external. From the screenshot you refer to, I notice another Simulink model, more complex, whose configuration settings I cannot analyze to suggest improvements.
However, I can provide you a Simulink model that should help you to accomplish your objective. Unfortunately I don't have a signal generator to 100% simulate your application, but instead I generated an internal PWM signal of 100 Hz and making the physical connection through a wire from the PWM channel to the ICU channel.
In the model, the ICU channel and the PWM channel are configured as follows in the following table:

dragostoma_0-1721313630806.png


The generated PWM signal has the following characteristics:

- Core clock frequency = 160 MHz

- PWM default period = 10 000 ticks

dragostoma_1-1721314346795.png

- eMIOS 2 instance default period = 10000 ticks

- eMIOS 2 instance clock divider = 160

dragostoma_2-1721314494264.png

So the PWM signal will be the same as your PWM signal externally generated:

PWM Freq = 160 000 000 / 10 000 / 160 = 100 Hz

 

To be able to ensure the correct connection, you must connect PTA19 to PTD26, so the ICU channel can actually measure the generated PWM signal.

The results will look like this:

dragostoma_0-1721316594167.png

 

dragostoma_4-1721316026643.png

You can notice the variable duty cycle given from Simulink by using the Stateflow, and it varies between 25% and 75%. Also, the active time and period time could be seen.

Now, if you connect your generated PWM signal instead of the one configured in the model, you should achieve in the FreeMASTER project a constant duty cycle of 50%, an active time of 500 and a period time of 1000.

 

I hope this model helps you in achieving your application goal.

 

Best regards,

Dragos

 

 

 

 

View solution in original post

0 Kudos
Reply
3 Replies
651 Views
dragostoma
NXP Employee
NXP Employee

Hi, @RushikeshK_DC,

The ICU Signal Measurement mode is measuring different times between various configurable edges. 

In the configuration tool, when the selected ICU channel is set to ICU_MODE_SIGNAL_MEASUREMENT

dragostoma_1-1721198208442.png

the following property is enabled.

dragostoma_0-1721198096686.png

The measurement property should be set between the above list, and the property can not be changed during runtime, so each channel has only one measurement purpose.

The ICU_DUTY_CYCLE property works with the Icu_GetDutyCycleValues Simulink block. It is returning the a structure that contains ICU Duty cycle parameters. It contains the values needed for calculating duty cycles i.e Period time value and active time value.

- Active Time: this represents the duration during which the signal is in its "active" state (usually the high state for a digital signal). It is the time the signal remains at a high level during one cycle.
- Period Time: this represents the total duration of one complete cycle of the signal, which includes both the active time and the inactive time (low state). It is the time from the start of one high state to the start of the next high state.

dragostoma_4-1721199609493.png

The following picture illustrated the time definitions of a signal:

dragostoma_2-1721198968120.png

The Duty Cycle represents the percentage of Active Time to Period Time and has the following formula:

Duty Cycle = (Active Time / Period Time) * 100%

The following picture illustrated the time definitions of a signal:

dragostoma_2-1721198968120.png

The ICU_HIGH_TIME, ICU_LOW_TIME and ICU_PERIOD_TIME properties work with the Icu_GetTimeElapsed Simulink block. It is returning the value of the time based on the CIU channel configuration.

dragostoma_3-1721199396479.png

 

Based on the above information, you will find the following approach in the model example.

dragostoma_5-1721201994469.png

Based on the dutyCycleValues, represented by a bus signal, you can calculate the dutyCycle percentage of your generated PWM signal.

 

To understand the returned values, you should be aware of the following:

- each ICU channel is configured based on an eMIOS instance (IcueMios_0_Channels_9 in your case);

- each eMIOS instance is configured based either on an external counter, or an internal counter. By using an external counter, an eMIOS bus selector must be configured (EMIOS_ICU_BUS_A in your case), which is based on a MCL master bus (EmiosMclMasterBus_0 in your case).

dragostoma_6-1721202765925.png

- the Default period of the EmiosMclMasterBus used to configure the ICU channel should be in range 0-65535.

To calculate the Frequency and the Period of the Master Bus Counter configured for the ICU channel, you should you the following formulas:

Frequency = Core Clock Frequency / Master Bus Default Period / Emios Common Clock Divider Value / Master Bus Prescaler -> [Hz]

- Period = 1 / Frequency -> [s]

 

In conclusion, to measure the PWM signal correctly, the eMIOS ICU needs to capture both the high and the low times of the PWM signal accurately. I hope the above explanations help in achieving your goal. If you have other questions, let us know.

 

Best regards,

Dragos

 

0 Kudos
Reply
622 Views
RushikeshK_DC
Contributor I
Hello, @dragostoma
I have done my calculations, Where
Core CLK = 160000000, Master Bus Default Period = 65535,
Emios Common CLK divider = 1 & Master Bus Prescaler =1 .
then Calculated Frequency = 2441 Hz & Period = 0.4 ms .
So when I feed an input PWM of 100Hz & 50% Duty, get active time = 24915 & period = 27171(Image is in prev post) which is not correct. So what can I do.
0 Kudos
Reply
612 Views
dragostoma
NXP Employee
NXP Employee

Hi, @RushikeshK_DC,

First of all, from what I can see, the model in the archive sent is the default model provided in the toolbox. In this configuration, only the ICU channel is set, since the generated PWM signal is external. From the screenshot you refer to, I notice another Simulink model, more complex, whose configuration settings I cannot analyze to suggest improvements.
However, I can provide you a Simulink model that should help you to accomplish your objective. Unfortunately I don't have a signal generator to 100% simulate your application, but instead I generated an internal PWM signal of 100 Hz and making the physical connection through a wire from the PWM channel to the ICU channel.
In the model, the ICU channel and the PWM channel are configured as follows in the following table:

dragostoma_0-1721313630806.png


The generated PWM signal has the following characteristics:

- Core clock frequency = 160 MHz

- PWM default period = 10 000 ticks

dragostoma_1-1721314346795.png

- eMIOS 2 instance default period = 10000 ticks

- eMIOS 2 instance clock divider = 160

dragostoma_2-1721314494264.png

So the PWM signal will be the same as your PWM signal externally generated:

PWM Freq = 160 000 000 / 10 000 / 160 = 100 Hz

 

To be able to ensure the correct connection, you must connect PTA19 to PTD26, so the ICU channel can actually measure the generated PWM signal.

The results will look like this:

dragostoma_0-1721316594167.png

 

dragostoma_4-1721316026643.png

You can notice the variable duty cycle given from Simulink by using the Stateflow, and it varies between 25% and 75%. Also, the active time and period time could be seen.

Now, if you connect your generated PWM signal instead of the one configured in the model, you should achieve in the FreeMASTER project a constant duty cycle of 50%, an active time of 500 and a period time of 1000.

 

I hope this model helps you in achieving your application goal.

 

Best regards,

Dragos

 

 

 

 

0 Kudos
Reply