Hi all,
I am working with an S32K3 series MCU and I want to measure the frequency of an external signal coming on a GPIO pin using the eMIOS peripheral. I have checked the S32K3 reference manual, S32 Design Studio, MCUXpresso Config Tools, and available SDK examples, but I could not find any clear documentation or example that explains how to configure eMIOS for frequency measurement, including pin routing, channel mode selection, clock configuration, or the required settings in the .mex file. I would appreciate it if you could guide me on the correct eMIOS mode to use for this purpose or share any reference example, code snippet, or configuration screenshot that demonstrates a working frequency measurement setup on S32K3.
Hi
Please refer to these examples for configuring eMIOS in IPWM mode:
Example S32K344 eMIOS DS3.5 RTD500
S32K344_Example_Emios_Icu_IPWM_measurement_DS34_RTD_100_v2
Example IP S32K312 EMIO PWM Generation & Duty capture using Polling DS3.5 RTD300
Example IP S32K312 EMIO PWM Generation & Duty capture using Interrupt DS3.5 RTD300
Example ASR S32K312 EMIO PWM Generation & Duty capture using Polling DS3.5 RTD300
Example ASR S32K312 EMIO PWM Generation & Duty capture using Interrupt DS3.5 RTD300
Please note that the S32K3 projects are usually used with S32DS(S32 Configuration Tool) or EBTresos as configuration tools, and not with MCUXpresso Config Tools.
Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "ACCEPT AS SOLUTION" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi @Robin_Shen,
I am using the Example S32K344 eMIOS DS3.5 RTD500 as my base code. I modified the project to measure input frequency by configuring eMIOS_1 Channel 7 as an input (IPWM mode). I updated the S32 Configuration Tool accordingly and added the required changes in the main file.
I am reading the measured value using the Ipwm_duty_cycle_array(checked inside the watchdog task). However, even when no external signal is applied on PTA24, the measured value is always 100.
Could you please explain why a constant value is reported without any input signal? Is this expected behavior due to default pin state, internal pull-up, clock source, or IPWM configuration? I have attached snapshots for reference.
If you want to use polling method instead of interrupt method, please poll the status via Emios_Icu_Ip_GetInputState before calling Emios_Icu_Ip_GetDutyCycleValues.
while(TRUE != Emios_Icu_Ip_GetInputState(INSTANCE_1, CHANNEL_7)){}
Emios_Icu_Ip_GetPulseWidth(INSTANCE_1, CHANNEL_7);
Emios_Icu_Ip_GetDutyCycleValues(INSTANCE_1, CHANNEL_7, &Ipwm_duty_cycle);
Ipwm_duty_cycle_array[index] = (Ipwm_duty_cycle.ActiveTime * 100) / Ipwm_duty_cycle.PeriodTime;
Hi @Robin_Shen ,
As I want to use interrupt-based measurement, I unchecked IcuSignalMeasureWithoutInterrupt (please refer to the image below) and modified the main.c according to the interrupt-based example code.
Currently, the IRQ handler is triggered, which confirms that the interrupt configuration is working. However, the measured ActiveTime and Period
Time values are always 0.
Could you please help explain why the interrupt is generated but both timing values remain zero? Is this related to IPWM mode configuration, edge selection, signal level on the pin, or missing ICU start/notification API calls?
I have attached the configuration snapshot for reference. In this code same as the example code but I just changed the channel 5 instead of 7.
This seems similar to the discussion in the S32K344 MCAL IPWM ICU CAPTURE: Please call Emios_Icu_Ip_IrqHandler first, and then call Emios_Icu_Ip_GetDutyCycleValues.
Hi @Robin_Shen ,
Thank you for the clarification, the issue is resolved now and the interrupt-based measurement is working as expected.I have one additional question. I want to know how to run the eMIOS module using an external clock source? Could you please guide me on what key configuration changes are required for this?
You are welcome.
I may not have understood your question. Please correct me if I am wrong.
I see that your Emios_Icu has IcuEmiosBusSelect set to EMIOS_ICU_BUS_A. Would you like to change it to something else?
By the way, the S32K3_RTD_Training_eMIOS_public.pdf file in the S32K311 EMIOS GPT might be helpful to you.
Please post a new question in community you have any questions that are not related to the original topic of an existing case. It helps to keep it clear.
Hi @Robin_Shen ,
I am trying to measure input frequency on multiple eMIOS channels. When I configure and enable only one channel, the project builds and works correctly. However, when I enable a second eMIOS/ICU channel for frequency measurement, I immediately get configuration errors and the project fails to build.
I have attached a screenshot of the configuration error for reference.
Hi @Robin_Shen,
I am trying to measure the input frequency on PTE25 (eMIOS1 Channel 5). I am applying a 10 Hz signal from a DSO, and I have verified that the input signal is stable. However, the measured frequency value is unstable and fluctuates around 900–1200, even though the input is only 10 Hz. To debug this, I changed the IcuSignalMeasurementProperty to ICU_PERIOD_TIME and updated the IRQ handler as shown below:
void EMIOS1_4_IRQ_Customized(void)
{
Emios_Icu_Ip_IrqHandler(1, 5);
period_time = Emios_Icu_Ip_GetTimeElapsed(1, 5);
if (period_time)
{
uint64_t emios_freq = 48000000ULL; // hardcoded
signal_frequency = emios_freq / period_time; captured = 1;
}
}
Even after these changes, the frequency value remains unstable.
Could you please help me understand why the measured frequency is incorrect and unstable for a low-frequency input, and what configuration changes are required to correctly measure a 10 Hz signal using eMIOS/ICU?
I will be on leave until February 2nd. I suggest you post a new question; my colleague will provide technical support.
Thank you for your understanding.