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

Why Fixed-Point Instead of float

Aspectfloat (IEEE 754)Fixed-Point (integer)
Hardware FPUNot available on Cortex-M0/M0+Any integer ALU
Speed (no FPU)20–100× slower (software emulation)Same as integer (1–4 cycles)
Code size+8–16 kB for soft-FP libraryZero library overhead
DeterminismNon-associative: (a+b)+c ≠ a+(b+c)Exact integer arithmetic; deterministic
MISRARule 14.4 requires float comparisons to use toleranceInteger == is exact
Use in ASILRequires justification for each float operationPreferred for ASIL-C/D control loops

Q Format: Qm.n Notation

Cfixed_point.c
#include 

/* Q15 format: 1 sign bit + 15 fractional bits
   Range: -1.0 to +0.999969... (1 - 2^-15)
   Resolution: 2^-15 = 0.0000305... */

typedef int16_t  q15_t;   /* Q1.15: signed fixed-point */
typedef int32_t  q31_t;   /* Q1.31: higher precision */
typedef uint16_t uq16_t;  /* Q0.16: unsigned 0..1 */

/* Q15: physical_value = raw / 32768.0 */
#define Q15_FROM_FLOAT(x)  ((q15_t)((x) * 32768.0f))
#define Q15_TO_FLOAT(x)    ((float)(x) / 32768.0f)

/* Common format for automotive control: Q4.12 (4 integer bits + 12 fractional)
   Range: -8 to +7.999756...   Resolution: 2^-12 = 0.000244 */
typedef int16_t  q4_12_t;
#define Q4_12_SCALE  4096  /* 2^12 */
#define Q4_12_FROM_FLOAT(x)  ((q4_12_t)((x) * Q4_12_SCALE))

/* Examples */
q15_t sin_value  = Q15_FROM_FLOAT(0.707f);  /* sin(45°) in Q1.15 */
q4_12_t speed    = Q4_12_FROM_FLOAT(5.75f); /* 5.75 m/s in Q4.12 */

Fixed-Point Arithmetic Operations

Cfp_arithmetic.c
#include 

typedef int16_t q15_t;
typedef int32_t q31_t;

/* Addition: same format → just add (check for overflow!) */
q15_t q15_add(q15_t a, q15_t b) {
    int32_t result = (int32_t)a + (int32_t)b;
    /* Saturate to Q15 range */
    if (result >  32767) return  32767;
    if (result < -32768) return -32768;
    return (q15_t)result;
}

/* Multiplication: Q15 × Q15 = Q30 (in int32), then rescale to Q15 */
q15_t q15_mul(q15_t a, q15_t b) {
    int32_t product = (int32_t)a * (int32_t)b;   /* Q15 × Q15 = Q30 in 32 bits */
    product += (1 << 14);                          /* round: add 0.5 LSB */
    return (q15_t)(product >> 15);                 /* rescale back to Q15 */
}

/* Division: expand numerator by 2^15 before dividing */
q15_t q15_div(q15_t a, q15_t b) {
    int32_t numerator = (int32_t)a << 15;
    if (b == 0) return (a >= 0) ? 32767 : -32768; /* saturation on div/0 */
    int32_t result = numerator / (int32_t)b;
    if (result >  32767) return  32767;
    if (result < -32768) return -32768;
    return (q15_t)result;
}

/* PI controller in Q4.12 fixed-point */
q4_12_t pid_update(q4_12_t error, q4_12_t *integral, q4_12_t kp, q4_12_t ki)
{
    *integral = q15_add(*integral, error);  /* accumulate integral */
    int32_t p_term = ((int32_t)kp * error)     >> 12;
    int32_t i_term = ((int32_t)ki * *integral) >> 12;
    int32_t output = p_term + i_term;
    /* Saturate output to actuator limits */
    if (output > 4095) output = 4095;
    if (output < 0)    output = 0;
    return (q4_12_t)output;
}

Summary

Fixed-point arithmetic is the standard approach for deterministic, ASIL-compatible control algorithm implementation on MCUs without hardware FPU. Q15 (1.15) is the most common format for normalised signals (−1 to +1); Q4.12 suits physical quantities with a few integer digits (temperatures, speeds, voltages). The critical operations to always implement with saturation are addition (overflow) and multiplication (intermediate 32-bit result must be rescaled). ARM Cortex-M DSP instructions (QADD16, SMUL, SMLAL) provide hardware-accelerated saturating fixed-point arithmetic when available.

🔬 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.

← PreviousEndianness & Data SerialisationNext →Hands-On: GPIO & Timer Driver in C