Abstract
This document outlines the use of the eMIOS module on S32M27x and S32K3 series, detailing various operation modes and their implementations based on the RTD low level API to support diverse application needs.
Contents
1. Introduction
2. eMIOS components of RTD 6.0.0 (LLD)
3. Microcontroller Library (MCL) driver
4. General Purpose Timer (GPT) driver
4.1. GPT Example Project
5. Output Compare Unit (OCU) driver
5.1. SAOC Example Project
6. Pulse Width Modulation (PWM) driver
6.1. OPWMB example project:
6.2. DAOC example project
6.3. OPWMT example project
6.4. OPWMCB example project
6.5. OPWFMB example project
6.6. PWM design considerations
7. Input Capture Unit (ICU) driver
7.1. IPWM example project
7.2. IPM example project
7.3. SAIC example project – Edge Counter
7.4. SAIC example project – Signal Edge Detect
7.5. ICU design considerations
8. Conclusion
9. References
10. Appendix
10.1. Application Software Content
1. Introduction
This document provides an overview of the Enhanced Modular IO Subsystem (eMIOS) module for the S32M27x and S32K3 series. It describes the supported operation modes and their implementations using the RTD 6.0.0 low-level API, designed to meet a wide range of application requirements.
The supported features include:
2. eMIOS components of RTD 6.0.0 (LLD)
S32 Configuration Tools (Peripherals) provide five RTD eMIOS drivers to implement diverse configurations for timer functionality, generation of timed outputs, time measurement of input signals and increment its counter as input edges are detected:
To use them, please take into account the following considerations:
Emios_Mcl_Ip must be added in your project to use the other four drivers.
General process for eMIOS initialization:
To access the User Manual for each driver, click on the button in the upper right corner, for example:
Figure 1. Access the User Manuals
3. Microcontroller Library (MCL) driver
The MCL driver allows you to configure the module's global prescaler and, if needed, multiple master buses. A master bus is a channel operating in Modulus Counter (MC) or Modulus Counter Buffered (MCB) mode (either up or up/down counting) and includes its own internal channel prescaler. This driver is always used in conjunction with the other four drivers.
For more information, please refer to the following sections (GPT, OCU, PWM, ICU).
4. General Purpose Timer (GPT) driver
GPT driver allows to implement timer functionality using channels types X and G, which have internal counters.
It can operate in either continuous or one-shot mode after the time-out has expired.
Main API functions are: start, stop, change next time-out and generate an interrupt notification when time-out is reached.
Time-out is defined by the compare value in clock cycles (or “ticks”), which is calculated as follows:
CompareValueTICKS = (fINPUT × CVDESIRED) / (GPRE × CPRE)
Where:
fINPUT = eMIOS clock frequency (Hz)
GPRE = Global prescaler
CPRE = Channel prescaler
CVDESIRED = Desired compare value (s)
For example:
fINPUT = 120 MHz
GPRE = 200
CPRE = 1
CVDESIRED = 50 ms
CompareValueTICKS = (120,000,000 × 0.05) / (200 × 1) = 30,000 ticks
Note: Consider the width of the 16-bit eMIOS timer, which allows a maximum count of 65,534 ticks (for S32K388/S32K389: 24-bits).
Connections:
S32M27XEVB-C064 / S32K31XEVB-Q100 -> Pin -> Signal -> Label
J60-1 / J40-12 -> PTE16 -> siul2_gpio_144 -> GPIO1
J60-4 / J38-3 -> PTD0 -> siul2_gpio_96 -> GPIO2
Note:
For S32M27XEVB-C064, consider remove following resistors: R208 and R181.
Clocking:
EMIOSx_CLK = CORE CLK -> 120MHz
4.1. GPT Example Project
This example shows how to use GPI functionality with two channels initialized in the following way:
Both channel interrupts are enable and each one toggles one GPIO (GPIO1 and GPIO2).
Then it is counted when Emios1_Ch0_Notification() function is called. When g_gptCount = 4, it change the compare value to 30,000 ticks. And when g_gptCount = 8, stop the counter. See Figure 2.
Note: Both eMIOS channel are not synchronized.
Application Software:
S32M276_RTD600_eMIOS_GPT_Ip_example
S32K311_RTD600_eMIOS_GPT_Ip_example
Figure 2. Signals of GPT Example Project
5. Output Compare Unit (OCU) driver
OCU driver can implement Single Action Output Capture (SAOC) mode. It is used to run a counter until a predefined value is reached. When a compare-match (also called threshold) occurs, a hardware interrupt and/or a state change of an output pin will be triggered. It can use any channel types (X, Y, G and H).
Threshold can be calculated in the similar way than compare value of GPT.
Connections:
S32M27XEVB-C064 / S32K31XEVB-Q100 -> Pin -> Signal -> Label
J60-1 / J40-12 -> PTE16 -> siul2_gpio_144 -> GPIO1
J21-1 / J38-6 -> PTD16 -> emios_0_ch_1_g -> OCU1
Note:
For S32M27XEVB-C064, consider remove following resistors: R208 and R169.
Clocking:
EMIOSx_CLK = CORE CLK -> 120MHz
5.1. SAOC Example Project
This example shows how to use SAOC mode with one channel initialized in the following way:
Then it is counted when Emios0_Ch1_Notification() function is called. When g_ocuCount >= 4, it change the threshold to 30,000 ticks. And when g_ocuCount = 8, stop the channel. Additionally, GPIO1 is toggled in the same notification function. See Figure 3.
Application Software:
S32M276_RTD600_eMIOS_SAOC_Ip_example
S32K311_RTD600_eMIOS_SAOC_Ip_example
Figure 3. Signals of SAOC Example Project
5. Pulse Width Modulation (PWM) driver
The PWM driver can implement the following modes:
The following sections detail the implementation of each mode and highlight their key characteristics.
Period in clock cycles (or “ticks”) is calculated as follows:
PeriodTICKS = fINPUT / (GPRE × CPRE × fDESIRED)
Where:
fINPUT = eMIOS clock frequency (Hz)
GPRE = Global prescaler
CPRE = Channel prescaler
fDESIRED = Desired signal frequency (Hz)
Duty cycle in clock cycles (or “ticks”) is calculated as follows:
DutyCycleTICKS = (DutyCycle% × PeriodTICKS ) / 100 %
One tick in seconds is calculated as follows:
1 tick = fINPUT / (GPRE × CPRE)
For example:
fINPUT = 120 MHz
GPRE = 200
CPRE = 1
fDESIRED = 2 kHz
DutyCycle% = 50 %
PeriodTICKS= 120,000,000 / (1 × 1 × 2,000) = 60,000 ticks
DutyCycleTICKS = (50 × 60,000) / 100 = 30,000 ticks
1 tick = 120,000,000 / (1 × 1) = 8.33 ns
Note: Consider the width of the 16-bit eMIOS timer, which allows a maximum of 65,534 ticks (for S32K388/S32K389: 24-bits).
Connections:
S32M27XEVB-C064 / S32K31XEVB-Q100 -> Pin -> Signal -> Label
J60-1 / J40-12 -> PTE16 -> siul2_gpio_144 -> GPIO1
J21-1 / J38-6 -> PTD16 -> emios_0_ch_1_g -> PWM1
J21-3 / J39-1 -> PTB5 -> emios_0_ch_5_g -> PWM2
J60-4 / J38-3 -> PTD0 -> siul2_gpio_96/ emios_0_ch_2_g -> GPIO2/PWM3*
*PWM3 is used in OPWMCB example project, for the rest GPIO2 is used.
Note:
For S32M27XEVB-C064, consider remove following resistors: R208, R169, R208 and R181.
Clocking:
EMIOSx_CLK -> 120MHz
6.1 OPWMB example project
OPWMB generates a simple output PWM signal, using any channel types (X, Y, G and H).
This example implements one channel as GPI (for time reference in scope) and two channels in OPWMB mode initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure 4) that will be described later.
The eMIOS_0_ch_23 channel is configured as global counter bus A. In this setup, it can act as the time base for other eMIOS_0 channels—specifically PWM1 and PWM2 in this case—enabling synchronization between them. This synchronization ensures that both channels share the same time base, thereby defining a common period for their operation.
Despite both channels being synchronized, phase shift feature is possible in this mode. Note PWM2 is phase shifted with respect to global counter bus A, and therefore with respect to PWM1.
An interrupt is requested on every flag event, during which GPIO2 is toggled. In this configuration, the flag is generated on the trailing edge—interpreted here as the falling edge, considering HIGH polarity. Alternatively, it can be configured to trigger on both the trailing and leading edges, allowing interrupts on both transitions.
The three events shown in Figure 4 are described as follows:
Application Software:
S32M276_RTD600_eMIOS_OPWMB_Ip_example
S32K311_RTD600_eMIOS_OPWMB_Ip_example
Figure 4. Signals of OPWMB Example Project
6.2. DAOC example project
DAOC generates a single PWM pulse, it can be implemented using channel types G and H.
This example implements one channel as GPI (for time reference in scope) and two channels in PWM mode—one in DAOC mode (PWM1) and the other in OPWMB mode (PWM2)—initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure 5) that will be described later.
The eMIOS_0_ch_23 channel is configured as global counter bus A. In this setup, it can act as the time base for other eMIOS_0 channels—specifically PWM1 and PWM2 in this case—enabling synchronization between them. This synchronization ensures that both channels share the same time base, thereby defining a common period for their operation.
An interrupt is requested on every flag event, during which GPIO2 is toggled. In this configuration, the flag is generated on the trailing edge.
The three events shown in Figure 5 are described as follows:
Note: Disabling DAOC notification in interrupt function and set the state of output pin LOW are necessary because the PWM driver does not support single PWM pulse generation. See details in application software.
Application Software:
S32M276_RTD600_eMIOS_DAOC_Ip_example
S32K311_RTD600_eMIOS_DAOC_Ip_example
Figure 5. Signals of DAOC Example Project
6.3. OPWMT example project
OPWMT generates a PWM signal with a fixed offset and a trigger signal. It can be implemented using any channel types (X, Y, G and H).
This example implements one channel as GPI (for time reference in scope) and two channels in OPWMT mode initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure 6) that will be described later.
The eMIOS_0_ch_23 channel is configured as global counter bus A. In this setup, it can act as the time base for other eMIOS_0 channels—specifically PWM1 and PWM2 in this case—enabling synchronization between them. This synchronization ensures that both channels share the same time base, thereby defining a common period for their operation.
Despite both channels being synchronized, phase shift feature is possible in this mode. Note PWM2 is phase shifted with respect to global counter bus A, and therefore with respect to PWM1.
An interrupt is requested on every flag event, during which GPIO2 is toggled. In this configuration, the flag is generated. This flag event, can be configured using Trigger parameter.
The three events shown in Figure 6 are described as follows:
Application Software:
S32M276_RTD600_eMIOS_OPWMT_Ip_example
S32K311_RTD600_eMIOS_OPWMT_Ip_example
Figure 6. Signals of OPWMT Example Project
6.4. OPWMCB example project
OPWMCB generates a centered aligned PWM output signal with dead time insertion. It can be implemented using channel type G.
This example implements one channel as GPI (for time reference in scope) and three channels in OPWMCB mode initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure 7) that will be described later.
The eMIOS_0_ch_23 channel is configured as global counter bus A. In this setup, it can act as the time base for other eMIOS_0 channels—specifically PWM1, PWM2 and PWM3 in this case—enabling synchronization between them. This synchronization ensures that these three channels share the same time base, thereby defining a common period for their operation.
Note: Synchronization in OPWMCB mode means PWM signals are center-aligned, instead of edge-aligned.
Despite all three PWM channels are center-aligned, and PWM2 and PWM3 have the same duty cycle, deadtime insertion feature is supported in this mode. Note trailing edge of PWM3 includes deadtime insertion with respect to PWM2, increasing high time.
Alternatively, by selecting the EMIOS_PWM_IP_MODE_OPWMCB_LEAD_EDGE mode, deadtime insertion is applied to the leading edge of PWM3 instead, decreasing high time.
The three events shown in Figure 7 are described as follows:
Application Software:
S32M276_RTD600_eMIOS_OPWMCB_Ip_example
S32K311_RTD600_eMIOS_OPWMCB_Ip_example
Figure 7. Signals of OPWMCB Example Project
6.5. OPWFMB example project
OPWFMB generates a output PWM signal with variable period and variable duty cycle using its internal counter. It can be implemented using channel types G.
This example implements one channel as GPI (for time reference in scope) and two channels in OPWFMB mode initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure
Due to its reliance on an internal counter, OPWFMB mode does not support synchronization with other eMIOS channels. However, it enables both Pulse Frequency Modulation (PFM) and Pulse Width Modulation (PWM) functionalities within a single eMIOS channel.
An interrupt is requested on every flag event, during which GPIO2 is toggled. In this configuration, the flag is generated on the trailing edge—interpreted here as the rising edge, considering HIGH polarity. Alternatively, it can be configured to trigger on both the trailing and leading edges, allowing interrupts on both transitions.
The three events shown in Figure 8 are described as follows:
Application Software:
S32M276_RTD600_eMIOS_OPWFMB_Ip_example
S32K311_RTD600_eMIOS_OPWFMB_Ip_example
Figure 8. Signals of OPWFMB Example Project
6.6. PWM design considerations
During pin assignment for application, beyond the “eMIOS Channel Types” tables for PWM mode support, “eMIOS channel configuration” tables for channel types per instance and the “Counter Buses, Channels, and Timebase Sources” tables for clocking in the reference manuals, consider the following support features for each PWM mode.
Table 1 summarizes the support features available for each PWM mode.
| OPWMB | DAOC | OPWMT | OPWMCB | OPWFMB | |
| Interrupts | x | x | x | x | x |
| Triggering | x | x | x | x | x |
| Single PWM pulse | x | x | x | x | x |
| Output state control | x | x | x | x | x |
| Frequency modulation | x | x | x | x | x |
| Synchronization | x | x | x | x | |
| Edge-alignment | x | x | x | ||
| Center-alignment | x | x | x | ||
| Dead-time insertion | x | x | x | ||
| Complementary output | x | x | x | ||
| Phase shift | x | x | |||
| Lower PWM frequencies | x | x | x | x | x* |
Table 1. Supported features across PWM modes
7. Input Capture Unit (ICU) driver
The ICU driver can implement the following eMIOS modes:
The following sections detail the implementation of each ICU measurement mode and highlight their key characteristics.
Connections:
S32M27XEVB-C064 / S32K31XEVB-Q100 -> Pin -> Signal -> Label
J60-1 / J40-12 -> PTE16 -> siul2_gpio_144 -> GPIO1
J21-1 / J38-6 -> PTD16 -> emios_0_ch_1_g -> PWM1
J21-3 / J39-1 -> PTB5 -> emios_0_ch_5_g -> ICU1
J60-4 / J38-3 -> PTD0 -> siul2_gpio_96 -> GPIO2
Connect:
PWM1 -> ICU1
Note:
For S32M27XEVB-C064, consider remove following resistors: R208, R169, R208 and R181.
Clocking:
EMIOSx_CLK -> 120MHz
7.1. IPWM example project
IPWM determines the width of an input signal, using channel types G and H.
This example implements one channel as GPI (for time reference in scope) and one channels in OPWMB mode (PWM1) and one channel in IPWM mode (ICU1) initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure 9) that will be described later.
The eMIOS_0_ch_23 channel is configured as global counter bus A. In this setup, it can act as the time base for other eMIOS_0 channels—specifically PWM1 in this case.
ICU1 measures PWM1 twice in code and toggles GPIO2 once the results are available.
The three events shown in Figure 9 are described as follows:
Application Software:
S32M276_RTD600_eMIOS_IPWM_Ip_example
S32K311_RTD600_eMIOS_IPWM_Ip_example
Figure 9. Signals of IPWM Example Project
When you suspend debug session, in Expressions tab (Figure 10) you can observe results: g_icuResults[0] corresponds to the first signal measurement meanwhile g_icuResults[1] corresponds to the second signal measurement.
Figure 10. Expressions tab of IPWM Example Project
7.2. IPM example project
IPM determines the period of an input signal, using channel types G and H.
This example implements one channel as GPI (for time reference in scope) and one channels in OPWMB mode (PWM1) and one channel in IPM mode (ICU1) initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure 11) that will be described later.
The eMIOS_0_ch_23 channel is configured as global counter bus A. In this setup, it can act as the time base for other eMIOS_0 channels—specifically PWM1 in this case.
ICU1 measures PWM1 twice in code and toggles GPIO2 once the results are available.
The three events shown in Figure 11 are described as follows:
Application Software:
S32M276_RTD600_eMIOS_IPM_Ip_example
S32K311_RTD600_eMIOS_IPM_Ip_example
Figure 11. Signals of IPM Example Project
When you suspend debug session, in Expressions tab (Figure 12) you can observe results: g_icuResults[0] corresponds to the first signal measurement meanwhile g_icuResults[1] corresponds to the second signal measurement.
Figure 12. Expressions tab of IPM Example Project
7.3. SAIC example project – Edge Counter
SAIC mode can emulate Pulse Edge Counting (PEC) mode using any channel types (X, Y, G and H).
This example implements one channel as GPI (for time reference in scope) and one channels in OPWMB mode (PWM1) and one channel in SAIC mode (ICU1) initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure 13) that will be described later.
The eMIOS_0_ch_23 channel is configured as global counter bus A. In this setup, it can act as the time base for other eMIOS_0 channels—specifically PWM1 in this case.
ICU1 count PWM1’s edges and toggles GPIO2 when an overflow occurs, which is defined by max counter value.
The three events shown in Figure 13 are described as follows:
Application Software:
S32M276_RTD600_eMIOS_SAIC_Edge_Counter_Ip_example
S32K311_RTD600_eMIOS_SAIC_Edge_Counter_Ip_example
Figure 13. Signals of SAIC Example Project – Edge Counter
When you suspend debug session, in Expressions tab (Figure 14) you can observe g_icuResults = 3, which correspond to edge count, after having overflowed 6 times.
Note: ICU is initialized after PWM, so first edge is not counted.
Figure 14. Expressions tab of SAIC Example Project – Edge Counter
7.4. SAIC example project – Signal Edge Detect
SAIC mode can also generate an interrupt when detects an edge using any channel types (X, Y, G and H).
This example implements one channel as GPI (for time reference in scope) and one channels in OPWMB mode (PWM1) and one channel in SAIC mode (ICU1) initialized as follows:
Clock Divider Value from MCL eMIOS_1, along with Compare Value from GPT eMIOS_1_ch_0 generates a time-out period. Once time-out is reached its Emios Notification toggles GPIO1. This allows us to observe in scope 3 events (see Figure 15) that will be described later.
The eMIOS_0_ch_23 channel is configured as global counter bus A. In this setup, it can act as the time base for other eMIOS_0 channels—specifically PWM1 in this case.
ICU1 detect PWM1’s edges and generates an interrupt for each of them. At every interrupt, GPIO2 is toggled and g_icuCount is increased by one.
The three events shown in Figure 15 are described as follows:
Application Software:
S32M276_RTD600_eMIOS_SAIC_Signal_Edge_Detect_Ip_example
S32K311_RTD600_eMIOS_SAIC_Signal_Edge_Detect_Ip_example
Figure 15. Signals of SAIC Example Project – Signal Edge Detect
When you suspend debug session, in Expressions tab (Figure 16) you can observe g_icuCount = 21, which correspond to edge count.
Note: ICU is initialized after PWM, so first edge is not counted.
Figure 16. Expressions tab of SAIC Example Project – Signal Edge Detect
7.5. ICU design considerations
During pin assignment for application, beyond the “eMIOS Channel Types” tables of reference manuals, consider the following points for each ICU mode.
Advantages of IPWM and IPM modes over SAIC mode:
Limitation of IPWM and IPM modes over SAIC mode:
Overflow support
Table 2 summarizes the support features available for each ICU mode.
| IPWM | IPM | SAIC | |
| Duty cycle measurement | x | x | |
| High time measurement | x | x | |
| Low time measurement | x | x | |
| Period time measurement | x | x | x |
| Edge counter | x | ||
| Edge detection | x | ||
| Timestamp measurement | x |
Table 2. Supported features across ICU modes
8. Conclusion
This document provides an overview of the driver structure, operating modes, and key features of the eMIOS module for the S32M27x and S32K3 series. It includes example codes to illustrate function implementation, helping users integrate the module effectively into their applications. Additionally, it outlines design considerations to support optimal usage and system integration.
9. References
10. Appendix
Following examples were built and tested using the following IDE and Driver versions:
10.1. Application Software Content:
S32M276_RTD600_eMIOS_Ip_examples.zip:
S32k311_RTD600_eMIOS_Ip_examples.zip: