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!
已解决! 转到解答。
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:
The generated PWM signal has the following characteristics:
- Core clock frequency = 160 MHz
- PWM default period = 10 000 ticks
- eMIOS 2 instance default period = 10000 ticks
- eMIOS 2 instance clock divider = 160
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:
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
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
the following property is enabled.
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.
The following picture illustrated the time definitions of a signal:
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:
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.
Based on the above information, you will find the following approach in the model example.
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).
- 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
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:
The generated PWM signal has the following characteristics:
- Core clock frequency = 160 MHz
- PWM default period = 10 000 ticks
- eMIOS 2 instance default period = 10000 ticks
- eMIOS 2 instance clock divider = 160
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:
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