| Element | Detail |
|---|---|
| Sensor | Throttle position sensor (TPS): 0.5-4.5V on ADC_CH_3 |
| Actuator | Cooling fan: PWM on PWM_CH_0 at 10 kHz |
| Logic | Simple: fan speed proportional to throttle position |
| Safety | Watchdog shuts down fan if software hang detected |
| Timing | ADC triggered by 10ms GPT; fan updated in 10ms task |
Lab Scope: Sensor-to-Actuator Chain
Exercise 1: Complete Sensor Reading Chain
/* Complete sensor reading chain: ADC -> IoHwAb -> Application */
#include "Adc.h"
#include "IoHwAb_Adc.h"
#include "SchM_IoHwAb.h"
static Adc_ValueGroupType g_adc_buf_tps[1]; /* TPS result buffer */
static float32 g_tps_angle_deg = 0.0f; /* filtered result */
static boolean g_tps_ready = FALSE;
/* Step 1: ADC group conversion complete callback (ISR context) */
void Adc_TpsGroup_Notification(void)
{
Adc_ReadGroup(ADC_GROUP_TPS, g_adc_buf_tps); /* copy atomically */
g_tps_ready = TRUE;
}
/* Step 2: IoHwAb processing (10ms task context) */
void IoHwAb_UpdateTps(void)
{
float32 raw_angle;
uint32 mv;
if (!g_tps_ready) return;
g_tps_ready = FALSE;
mv = ((uint32)g_adc_buf_tps[0] * 5000u) / 4095u;
if (mv < 500u) mv = 500u;
if (mv > 4500u) mv = 4500u;
raw_angle = 90.0f * (float32)(mv - 500u) / 4000.0f;
/* Low-pass filter: alpha = 0.3 */
SchM_Enter_IoHwAb_ADC();
g_tps_angle_deg = 0.3f * raw_angle + 0.7f * g_tps_angle_deg;
SchM_Exit_IoHwAb_ADC();
}
/* Step 3: Application reads filtered value */
Std_ReturnType IoHwAb_GetThrottleAngle(float32 *angle)
{
if (angle == NULL_PTR) return E_NOT_OK;
SchM_Enter_IoHwAb_ADC();
*angle = g_tps_angle_deg;
SchM_Exit_IoHwAb_ADC();
return E_OK;
}Exercise 2: Actuator Control Chain
/* Actuator chain: Application -> IoHwAb -> PWM */
#include "Pwm.h"
#include "IoHwAb_Pwm.h"
/* Step 1: IoHwAb PWM output */
void IoHwAb_SetFanSpeed(uint8 speed_pct) /* 0-100 */
{
uint16 duty;
/* Clamp input */
if (speed_pct > 100u) speed_pct = 100u;
/* AUTOSAR PWM duty: 0x0000-0x8000 */
duty = (uint16)((uint32)speed_pct * 0x8000u / 100u);
Pwm_SetDutyCycle(PWM_CH_COOLING_FAN, duty);
}
/* Step 2: Application control logic (10ms task) */
void App_FanControl_10ms(void)
{
float32 throttle_deg;
uint8 fan_pct;
if (IoHwAb_GetThrottleAngle(&throttle_deg) != E_OK) {
IoHwAb_SetFanSpeed(0u); /* safe: fan off if sensor error */
return;
}
/* Fan proportional to throttle: 0-90 deg -> 20-100% */
fan_pct = (uint8)(20.0f + (throttle_deg / 90.0f) * 80.0f);
IoHwAb_SetFanSpeed(fan_pct);
}
/* Safe shutdown: called by WdgM on watchdog violation */
void App_SafeShutdown(void)
{
Pwm_SetDutyCycle(PWM_CH_COOLING_FAN, 0u); /* fan off */
Dio_WriteChannel(DIO_CH_RELAY_POWER, STD_LOW); /* power off */
}Summary
The sensor-to-actuator chain demonstrates why each layer in the MCAL/IoHwAb stack exists. ADC MCAL handles raw conversion and result buffering. IoHwAb handles voltage-to-degrees conversion, filtering, and thread-safe access (SchM critical sections). The application handles control logic (proportional mapping). This separation makes the system testable at each layer: IoHwAb can be tested with mock ADC values, the application can be tested with mock IoHwAb values, and MCAL can be tested against hardware registers directly. ISO 26262 ASIL-D requires this kind of layered design with documented interfaces - a monolithic function that reads ADC registers and drives PWM in one step cannot be traced, reviewed, or tested at the required depth.
🔬 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.