Home Learning Paths ECU Lab Assessments Interview Preparation Arena Pricing Log In Sign Up

Lab: Automotive HVAC Mode Manager

AttributeValue
GoalStateflow mode manager for HVAC with fault handling
StatesOFF, STARTUP (200ms init), COOLING, HEATING, DEFROST, FAULT
Inputsignition, setpoint_C (single), cabin_temp_C (single), compressor_ok, blower_ok
Outputscompressor_on (bool), heater_on (bool), blower_speed (uint8 0-255), hvac_mode (uint8)
Fault handlingcompressor_ok=false debounced 500ms -> FAULT; blower always on in FAULT for safety
Coverage target100% state + transition coverage via 5 test cases

Exercise 1: HVAC State Machine

Stateflowhvac_mm.sf
// HVAC Mode Manager -- Stateflow chart, Ts=100ms
// State: OFF
// entry: compressor_on=false; heater_on=false;
//        blower_speed=0; hvac_mode=0;
// OFF -> STARTUP: [ignition]

// State: STARTUP
// entry: blower_speed=100; hvac_mode=1;
// STARTUP -> COOLING: [after(0.2,sec) && cabin_temp_C >= setpoint_C+1.0]
// STARTUP -> HEATING: [after(0.2,sec) && cabin_temp_C <= setpoint_C-1.0]
// STARTUP -> COOLING: [after(0.2,sec)]  // default: cooling

// State: COOLING
// entry: compressor_on=true; heater_on=false;
//        blower_speed=200; hvac_mode=2;
// COOLING -> HEATING: [cabin_temp_C < setpoint_C - 2.0]
// COOLING -> OFF:     [~ignition]
// COOLING -> FAULT:   [~compressor_ok && after(0.5,sec)]

// State: HEATING
// entry: compressor_on=false; heater_on=true;
//        blower_speed=180; hvac_mode=3;
// HEATING -> COOLING: [cabin_temp_C > setpoint_C + 2.0]
// HEATING -> OFF:     [~ignition]

// State: FAULT
// entry: compressor_on=false; heater_on=false;
//        blower_speed=50; hvac_mode=99;
// FAULT -> OFF: [~ignition]  // operator must cycle ignition to reset

Exercise 2: Coverage Test Script

MATLABhvac_coverage_test.m
% Test case 1: Normal startup -> COOLING
setparam("HVAC_Test","ignition",1,"cabin_temp_C",28,"setpoint_C",22);
setparam("HVAC_Test","compressor_ok",1,"blower_ok",1);
out1 = sim("HVAC_Test", 3.0);
assert(out1.hvac_mode.Data(end)==2, "Expected COOLING");

% Test case 2: COOLING -> HEATING (cabin cooled)
setparam("HVAC_Test","cabin_temp_C",18);
out2 = sim("HVAC_Test", 3.0);
assert(out2.hvac_mode.Data(end)==3, "Expected HEATING");

% Test case 3: Fault injection (compressor failure)
setparam("HVAC_Test","cabin_temp_C",28,"compressor_ok",0);
out3 = sim("HVAC_Test", 3.0);
% After 0.5s debounce -> FAULT; blower_speed=50
assert(out3.hvac_mode.Data(end)==99, "Expected FAULT");
assert(out3.blower_speed.Data(end)==50, "Expected safety blower");

% Test case 4: Glitch (fault clears before debounce)
% compressor_ok=0 for 0.3s only -> stays in COOLING

% Test case 5: Shutdown
setparam("HVAC_Test","ignition",0,"compressor_ok",1);
out5 = sim("HVAC_Test", 1.0);
assert(out5.hvac_mode.Data(end)==0, "Expected OFF");

Summary

The HVAC lab demonstrates the complete MBD unit test workflow for Stateflow: define the chart, create a test harness, write test scripts that cover every state and transition, and verify outputs. Test case 4 (the fault glitch test) is the most revealing: it checks that a brief compressor fault that clears before the 500ms debounce does NOT cause a FAULT state entry - confirming the debounce is working correctly, not just that the fault path exists. This type of negative test (verify a transition does NOT fire) is exactly what ASPICE SWE.4 requires for transition coverage and is impossible to check by review alone.

🔬 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

  1. 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'.
  2. 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.
  3. 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.
  4. 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.

← PreviousState Machine Best PracticesNext →MAAB Guidelines Overview