| PWM Property | AUTOSAR API | Example |
|---|---|---|
| Channel | Pwm_ChannelType - identifies one PWM output pin | PWM_CH_FAN_MOTOR = 3 |
| Period | Fixed at init (prescaler + period register); not changed at runtime | 10 kHz = 100 us period; set in config |
| Duty cycle | Pwm_SetDutyCycle(ch, duty); duty in 0x0000-0x8000 (0-100%) | 50% = 0x4000; 75% = 0x6000 |
| Idle state | Output level when duty=0 or duty=100%: HIGH or LOW | Fan off = LOW (idle = STD_LOW) |
| Notification | Pwm_EnableNotification(ch, RISING/FALLING/BOTH) - callback on edge | Use for timing measurement (not common in PWM) |
| Period change | Pwm_SetPeriodAndDuty() - only allowed if configured as VARIABLE period | Use for variable-frequency PWM (e.g., speaker, buzzer) |
PWM MCAL Concepts
PWM Configuration: Cooling Fan and Fuel Injector
/* PWM configuration: cooling fan (10 kHz) and fuel injector (200 Hz) */
#include "Pwm.h"
const Pwm_ChannelConfigType Pwm_ChannelConfig[] = {
/* Cooling fan: 10 kHz PWM, 0-100% duty, active high */
{
.PwmChannelId = PWM_CH_COOLING_FAN,
.PwmChannelClass = PWM_FIXED_PERIOD,
.PwmHwChannel = PWM_HW_GTM_TOM0_0, /* GTM timer output */
.PwmPeriodDefault = 10000u, /* 10 kHz: 100 us period in ns */
.PwmDutyCycleDefault = 0x0000u, /* 0% = fan off */
.PwmIdleState = PWM_LOW, /* idle: output low = fan off */
.PwmPolarity = PWM_HIGH, /* high = active */
},
/* Fuel injector: 200 Hz max, variable duty (injection pulse width) */
{
.PwmChannelId = PWM_CH_INJECTOR_1,
.PwmChannelClass = PWM_VARIABLE_PERIOD,
.PwmHwChannel = PWM_HW_GTM_TOM0_1,
.PwmPeriodDefault = 5000000u, /* 200 Hz: 5 ms in ns */
.PwmDutyCycleDefault = 0x0000u, /* 0% = injector closed */
.PwmIdleState = PWM_LOW,
.PwmPolarity = PWM_HIGH,
},
};
/* Usage: set fan speed */
void Fan_SetSpeed(uint8 speed_pct) /* 0-100 */
{
uint16 duty = (uint16)((uint32)speed_pct * 0x8000u / 100u);
Pwm_SetDutyCycle(PWM_CH_COOLING_FAN, duty);
}ICU MCAL: Input Capture for Speed Sensors
| ICU Mode | Use Case | API |
|---|---|---|
| Edge detection | Count pulses (wheel speed, hall sensor) | Icu_EnableEdgeDetection(); Icu_GetEdgeNumbers() |
| Signal measurement | Measure pulse width (e.g., PWM input from load cell) | Icu_StartSignalMeasurement(); Icu_GetDutyCycleValues() |
| Timestamp | Capture time of each edge (high-resolution) | Icu_StartTimestamp(); Icu_GetTimestampIndex() |
| Edge counting | Count edges in a time window (frequency measurement) | Icu_EnableEdgeCount(); Icu_GetEdgeNumbers() |
ICU Configuration: Wheel Speed Sensor
/* ICU: wheel speed sensor (48-tooth hall effect) */
#include "Icu.h"
const Icu_ChannelConfigType Icu_ChannelConfig[] = {
{
.IcuChannelId = ICU_CH_WSS_FL,
.IcuChannelMode = ICU_MODE_EDGE_COUNTER,
.IcuDefaultStartEdge= ICU_RISING_EDGE,
.IcuHwChannel = ICU_HW_GTM_TIM0_0,
.IcuMeasurementMode = ICU_MODE_EDGE_COUNTER,
.IcuSignalNotification = NULL_PTR, /* polled, no interrupt */
},
};
/* Read wheel speed every 10ms task */
#define WSS_TEETH_PER_REV 48u
#define WHEEL_CIRCUMFERENCE_MM 1950u /* 195/65R15 */
float32 Icu_GetWheelSpeedKph(Icu_ChannelType ch)
{
static Icu_EdgeNumberType prev_edges = 0u;
Icu_EdgeNumberType current_edges = Icu_GetEdgeNumbers(ch);
Icu_EdgeNumberType delta = current_edges - prev_edges; /* wraps OK */
prev_edges = current_edges;
/* edges in 10ms -> speed */
/* revolutions/s = edges / teeth / 0.01s */
float32 rev_per_s = (float32)delta / (float32)WSS_TEETH_PER_REV / 0.01f;
float32 speed_mps = rev_per_s * (float32)WHEEL_CIRCUMFERENCE_MM / 1000.0f;
return speed_mps * 3.6f; /* m/s -> km/h */
}Summary
PWM duty cycle in AUTOSAR is expressed as a 16-bit fraction of 0x8000 (not 0xFFFF) - so 50% duty = 0x4000, 100% = 0x8000. This is one of the most common MCAL integration bugs: engineers familiar with other platforms express duty cycle as 0-255 or 0-1000 and produce incorrect scaling. ICU edge counting for wheel speed sensors is preferred over ICU signal measurement (period measurement) at low speeds: at 5 km/h a 48-tooth wheel produces only 33 pulses/second, making period measurement noisy, while edge counting accumulates reliably over 10 ms regardless of speed.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.