Note: This document serves as a "backup of the mind" for Gokul Arunachalam. It is a deep-dive repository of technical experiences, architectural decisions, challenges faced, and lessons learned across 10+ years in Automotive Embedded Software Architecture. This content is intended to be used by LLMs and UI generators in the future to build highly detailed portfolios, case studies, or resumes.
Focus: Reusable middleware stacks, OS/Scheduler, UDS, CAN TP, NVM, hardware independence.
Early Career Challenges (The Monolith) — The 10K+ Line File Crisis
In the very beginning of my career, I inherited a project where the entire application was written in a single file—over 10,000 lines of code. There was no version control (Git wasn't standard practice at that time), and no clear project structure.
What I observed:
- Multiple developers stepping on each other's code: When one person was working, others couldn't safely modify or contribute without creating chaos
- Knowledge silos: People only spoke at concept level; code-level understanding was virtually non-existent
- Frustration & attrition: Developers got frustrated trying to navigate someone else's massive codebase. Some simply left the project
- No one could help each other: Even with good intentions, developers couldn't assist colleagues without risking breaking the entire system
- Bug fixes were archaeological expeditions: Finding where an issue originated in 10,000+ lines was a nightmare
- Project recovery required extreme effort: Even a simple fix required deep knowledge of the entire monolith
This experience was brutally educational. I realized: "We can't scale teams or projects this way."
The Pivot to Modularity — The Segregation Awakening
I started noticing a pattern: we were repeating the same functionality across multiple projects—CAN communication layers, IO handling, state machines—but they were never properly segregated or reused. They were embedded in each project's monolith.
I made a deliberate decision: Break the monolith into separate, functional files.
The immediate impacts were striking:
- Code organization improved dramatically: Developers could quickly locate relevant functionality
- People could understand code without the entire context: You didn't need to know all 10,000 lines to modify one feature
- Bug fixes became surgical: Instead of searching through a massive file, bugs were isolated to specific modules
- Reuse became possible: Even if not everyone adopted reuse patterns immediately, the infrastructure was there—modules were discoverable and approachable
- Developer morale improved: People could now help each other without feeling lost
- Productivity skyrocketed: Future projects could reference and leverage existing modules
The philosophical shift: I realized that organization isn't just about cleanliness—it's about enabling human collaboration.
Learning from Giants — Inspiration from Open Source
To deepen my approach, I studied how mature projects solved this problem:
- Linux Kernel: Modular driver subsystems, clear abstraction layers, device-agnostic interfaces
- Arduino: Simple-to-use hardware abstraction layer (HAL) that kept implementation details hidden
- Open-source projects: Consistent patterns for dependency management, configuration, and testing
I also had the opportunity to freelance briefly for another company. This exposure to industry-standard project maintenance practices was eye-opening:
- How they managed long-term project evolution
- How they structured middleware for reuse
- How they separated concerns between hardware, OS, and application layers
This experience cemented my philosophy: Modularity → Testability → Reusability.
Applying Lessons to Automotive ECUs — The Middleware Revolution
When I transitioned into the automotive domain, I brought this mindset with me—but now I had a specific problem to solve:
The Challenge: Despite building different ECUs for different functions (BMS, Motor Control, Connectivity, Suspension), we were rebuilding the same fundamental software stacks repeatedly:
- CAN Communication Stack: Message transmission, reception, filtering
- NVM (Non-Volatile Memory): Flash read/write, data persistence, wear leveling
- IO Stack: Digital/analog input-output abstraction
- Task Scheduler: Real-time task management and prioritization
- BSW Middleware: Common AUTOSAR-inspired layers
The Solution—Reusable Modular Libraries:
Instead of embedding these stacks in each ECU project, I created independent, highly modular software components:
- Isolated each stack as a separate project with well-defined interfaces
- Thoroughly tested each module before reuse (unit tests, integration tests)
- Made them hardware-agnostic with clear HAL (Hardware Abstraction Layer) separation
- Documented parameters and configuration points so teams could adapt without rewriting
- Linked these as reusable libraries across multiple ECU projects
Impact:
- Project timelines shrunk significantly: 50-60% of typical ECU development was now "buy, don't build"
- System reliability increased: Mature, battle-tested stacks meant fewer bugs and faster debugging
- Team productivity increased: Developers could focus on application logic instead of reinventing middleware
- Consistency across ECUs: All ECUs used the same communication, memory, and scheduling patterns—reducing integration challenges
- Scalability achieved: We could now onboard new team members faster and have them contribute meaningfully within weeks, not months
The Realization: This modular, reusable architecture wasn't just a technical improvement—it was the difference between building 1 ECU per year vs. 3-4 per year. And each one was more reliable than the last because the foundation was proven, not experimental.
Focus: FOC algorithms, DSP arithmetic, Flux Weakening, MTPA, 2W/3W L1 & L2 (ASIL-C) controllers.
Childhood Foundation: The Naked Motor Project My fascination with motors began in standard 7/8 when I dismantled a remote-controlled car. I became obsessed with understanding how the DC motor worked. Armed with the left-hand rule from my physics textbook, I decided to build a motor from scratch:
- Designed and wound my own motor coils
- Created custom external magnets
- Assembled the entire device with a rod frame
To complete the project, I traveled 60 kilometers to a neighboring city to source the right magnets—a commitment that shaped my problem-solving mindset.
First Company (CRISP): Motor Diversity & Control Fundamentals
Technologies & Projects:
- Servo & Micro Servo Motors: Robotic integration and positioning control
- DC Motors with Encoders: Self-balancing robot projects
- High-Speed Motors: Wave-weaving machine control
- Multi-Phase Systems: 3-phase and single-phase motor control
Key Learning: Exposed to diverse motor types and control scenarios, building foundational understanding of motor mechanics and basic control strategies.
Second Company (ELGI ULTRA): Professional Motor Control for Home Appliances
Domain: High-precision grinders and mixers
Technologies Mastered:
-
AC Universal Motor Control:
- Face angle control using triacs
- Precision speed regulation
- Soft-start mechanisms
-
Encoder-Based Speed Regulation:
- Magnetic encoder integration for low-speed universal motors
- Load-adaptive speed control—motor automatically adjusts to maintain constant speed under variable load
-
PID Control Implementation:
- Tuned PID loops for smooth acceleration and load compensation
- Real-time feedback control
-
VFD (Variable Frequency Drives):
- Induction motor control for grinders
- Bidirectional operation (forward & reverse)
- Vector control techniques
Key Learning: Transitioned from hobbyist to professional-grade motor control. Understood precision requirements, reliability in consumer electronics, and load-dependent control strategies.
Third Company (LUCAS TVs): Automotive-Grade Motor Controllers & BLDC Revolution
Domain: Refrigerator compressor motors; High-efficiency BLDC systems
Critical Transition Point: This is where I shifted from analog/triac-based control to software-centric motor control.
Technologies:
-
STM32 Microcontroller Ecosystem:
- Developed proper MCL (Microcontroller Abstraction Layer)
- Modular software architecture for motor control
- User-configurable motor parameters and operating modes
-
BLDC Motor Control:
- Permanent Magnet Surface Mount (PMSM)
- Interior Permanent Magnet (IPM) motors
- Motor design impact on software tuning
-
Real-Time Requirements:
- Microsecond-level PWM & ADC synchronization
- Precision timing critical for commutation accuracy
- Understanding microcontroller peripheral interconnections
-
FOC Algorithm Fundamentals:
- Vector angle measurement and transformation
- Fast vector rotation for smooth torque delivery
- Mathematical foundations (dq-axis transformations)
Key Learning: Software became the equalizer—quality motor control now relied 60% on algorithm tuning and 40% on hardware design. Experienced how STM32 peripherals (PWM, ADC, timers) must be orchestrated for motor control precision.
Automotive (Later Company): Traction Motor Controllers & ASIL Compliance
Domain: Electric vehicle traction motors; Air suspension systems (4-wheeler)
Major Projects:
- Traction Motor Controller for EVs: Full motor control stack from register-level configuration to application
- Air Suspension Motor Controller: Possy motor control with WAPCO customer
Technologies & Deep Dives:
-
RH850 Microcontroller:
- Reviewed feasibility for motor control applications
- Mapped internal peripherals for traction requirements
- Automotive-grade peripheral configuration
-
Advanced FOC Techniques:
- Flux Weakening: Extending motor speed beyond base speed in field-weakening region
- MTPA (Maximum Torque Per Ampere): Optimizing torque efficiency at different speed ranges
- PI controller tuning for multi-phase synchronous motors
-
ASIL Compliance (Safety-Critical):
- Integrated safety functionality from architectural level
- Bootloader development for over-the-air updates
- Functional safety requirements throughout the motor controller stack
-
Tuning & Validation:
- Extensive trials with different stator/rotor combinations
- Understanding how magnetic properties impact software tuning
- PI parameter optimization for automotive-grade robustness
- Precision synchronization between PWM timing and ADC sampling
Key Learning: Motor control in automotive is 30% algorithm, 40% tuning, 30% safety architecture. Microsecond-level timing precision and ASIL compliance transformed my understanding from "getting it working" to "getting it production-ready."
Control Algorithms Mastered:
- Basic PWM/triac switching → PID loops → Vector control (FOC)
- Angle measurement & transformation (Clarke, Park transforms)
- Advanced: Flux weakening, MTPA optimization
Motor Types Controlled:
- Induction motors (3-phase VFD) → Universal AC motors → BLDC → Traction motors (PMSM, IPM)
Real-Time & Hardware Aspects:
- PWM synchronization with ADC sampling
- Microcontroller peripheral optimization
- Timing constraints in microseconds
From Passion to Mastery: The 60km journey to buy magnets as a child mirrors the automotive journey—both required commitment to understanding fundamentals deeply, iterating through failures, and continuously raising the bar for system quality and reliability.
Focus: Custom bootloaders, firmware updates, UDS protocols, dual-bootloader architecture, production reliability.
The Deep Knowledge Requirement
Bootloader development is unique territory—there's minimal external interference, but the price is deep knowledge of microcontroller internals. You must understand:
- Startup sequences: How the microcontroller boots, memory initialization order, CPU reset behavior
- Linker files: Memory layout, section placement, interrupt vectors
- Memory allocation: RAM/Flash organization, bootloader vs. application space
- Peripheral initialization: Clock configuration, memory protection (MPU)
- Internal architecture: Register-level operations, privileged modes
This isn't driver-level work—it's bare-metal, foundation-level knowledge.
Early Explorations: 8051 → PIC → Arduino
I started with 8051 and PIC microcontrollers, learning the absolute basics: register manipulation, interrupt handling, memory constraints. But the real awakening came when I discovered Arduino.
Arduino revealed something profound: Without debuggers or fancy tools, they had achieved mass adoption. How?
The bootloader.
Arduino came with a bootloader pre-programmed in flash. Users could upload code via a simple UART connection without expensive debuggers. I realized: This simple piece of software unlocked accessibility and scalability.
I started reverse-engineering Arduino code on GitHub, understanding:
- How the bootloader waits for a "magic packet" on UART
- How it jumps to the application after receiving firmware
- How it handles baud rate detection
- The minimal protocol needed for communication
Implementing Custom Bootloaders on 8051
Armed with understanding, I implemented a custom bootloader for 8051:
- Determined minimum memory requirements (often just 512-1K bytes for bootloader itself)
- Designed a minimal protocol for firmware transfer
- Learned the critical concept: Bootloader must preserve itself—you can't overwrite the code that's updating you
I also took formal courses on microcontroller bootloader design, which formalized my intuitive knowledge:
- Different bootloader types (In-Application Programming, Serial bootloaders, CAN bootloaders)
- Synchronization protocols for reliable transfers
- Checksum/CRC validation
- Fallback mechanisms for corrupted firmware
Lucas TVs & Automotive Bootloader Reality
When I entered automotive at Lucas TVs, I was exposed to standardized diagnostic protocols—specifically UDS (Unified Diagnostic Services) and CAN TP (CAN Transport Protocol). This wasn't hobby territory anymore; this was ISO 14229-1 compliance.
Instead of reinventing protocols, I committed to understanding how the industry does it:
- Hunted through open-source projects on GitHub: Looking at how others implemented UDS services
- Studied Chinese automotive projects: Saw different interpretations and solutions (fascinating learning!)
- Analyzed European automotive codebases: Observed MISRA-compliant, safety-conscious implementations
I built my understanding service by service:
- Service 0x10: Diagnostic Session Control
- Service 0x11: ECU Reset
- Service 0x14: Clear Diagnostic Information
- Service 0x22: Read Data By Identifier
- Service 0x27: Security Access
- Service 0x2E: Write Data By Identifier
- Service 0x34: Request Download (firmware transfer)
- Service 0x35: Request Upload
- Service 0x36: Transfer Data (the actual firmware bytes)
- Service 0x37: Request Transfer Exit
Over time, I developed a comprehensive UDS stack with:
- Full modularity: Each service as an independent module
- Configurability: Easy adaptation for different ECU types
- Automotive-grade robustness: Timeout handling, state machines, security
The Problem: Zero-Downtime Updates
My company faced a critical challenge: We needed to update bootloaders in the field without bricking ECUs. If the bootloader itself became corrupted during an update, the ECU would be permanently unusable in production.
The Solution: Dual-Bootloader Architecture
I proposed and implemented a dual-bootloader system:
- Primary bootloader (bootloader 1): Runs at power-up
- Backup bootloader (bootloader 2): Secondary location with identical functionality
- Update mechanism: Update bootloader 2 first, then switch
How it works:
- Power-up reads a "which bootloader" flag in NVM
- If bootloader flag indicates corruption, automatically switches to the backup
- If bootloader 2 is being updated, bootloader 1 handles the update
- After successful verification, the flag switches to bootloader 2
- If bootloader 2 fails, automatic fallback to bootloader 1
Impact: Saved 8,000+ boots in production
During production deployment, we encountered scenarios where bootloader updates could have bricked ECUs. The dual-bootloader architecture prevented complete system failure in every instance. That translates to:
- Zero customer returns due to bootloader corruption
- Seamless field updates even if updates failed mid-transfer
- Confidence in production deployments
Beyond the Protocol: Tooling
UDS is server-side—the ECU receives commands. But someone has to send them. In automotive, this is typically:
- Diagnostic tools: ETAS INCA, Vector CANoe, etc. (expensive)
- Custom tools: Built internally for development/production
I developed Python-based UDS client tools:
- Abstracted UDS protocol into Python libraries
- Created custom services on top of UDS for our specific needs
- Integrated with calibration tools for parameter updates
- Built validation scripts for production testing
Hardware Compatibility Challenge
Our customers used different CAN interfaces:
- Some had Vector CANoe
- Some had PCAN (Peak)
- Some had custom CAN adapters
- Some had different CAN transceivers with timing constraints
Instead of writing separate tools for each, I created a hardware abstraction layer for CAN:
- Unified Python interface for all CAN vendors
- Automatic baud rate detection
- Timing compensation for different transceiver delays
- Transparent switching between CAN vendors
This meant a single UDS client tool could work across multiple customers' hardware setups without modification.
Beyond Bootloading
As the bootloader became robust, it became the foundation for an entire ecosystem:
- Parameter Calibration: Using UDS 0x2E (Write Data By Identifier), we built tools to write motor parameters, safety thresholds, etc.
- Validation Scripts: Automated verification that new firmware loaded correctly
- Diagnostic Dashboards: Real-time ECU health monitoring during updates
- Rollback Mechanisms: Version tracking and ability to revert to previous firmware
- Telemetry Logging: Track all update attempts (successful, failed, time taken, etc.)
-
Bootloader is gateway to production: It's the only code that runs before your application. Get it wrong, and you're manufacturing paperweights.
-
Abstraction layers are critical: UDS standardizes automotive communication, but hardware varies. Abstracting hardware differences enables scalability.
-
Redundancy saves production: Dual-bootloader architecture is a small cost for massive risk reduction.
-
Tooling matters as much as protocol: A robust bootloader is useless without tools to manage it. Python + UDS integration proved invaluable.
-
Standards exist for a reason: UDS/CAN TP seemed complex at first, but adhering to ISO standards meant every automotive ECU could talk to our tools.
-
Deep microcontroller knowledge is irreplaceable: Understanding memory layout, privileged modes, and startup sequences separated a working bootloader from a production-ready one.
Focus: SOC/SOH estimation, cell balancing, thermal management, safety critical design, AIS156 compliance.
Entry into BMS: Recognition & Opportunity
My transition into Battery Management Systems came through industry recognition. I received a nomination from Batrix (Batrix India) for BMS project leadership, and subsequently worked on similar initiatives with Khushala (another automotive player). This wasn't accidental—my background in modular architecture, microcontroller expertise, and embedded safety systems made me an ideal fit for this safety-critical domain.
Understanding the BMS Landscape
BMS is fundamentally different from motor control:
- Motor control is about performance (torque, efficiency, responsiveness)
- BMS is about safety and longevity (protecting the battery, keeping it alive, preventing catastrophic failure)
Modern EV architecture has evolved: BMS and motor controller are now inseparable twins. Even for low-speed vehicles (550 KMPL range), OEMs launch EVs with integrated BMS + motor controller systems. This co-design requirement became my new reality.
The TI Microelectronics AFIC Revelation
My first major project introduced me to AFIC (Analog Front-end Integrated Circuit) chips from TI Microelectronics. These specialized ICs opened my eyes to battery architecture:
Cell Configuration Fundamentals:
- Series Configuration: Cells stacked for voltage (1 cell = 3.7V, 100 cells = 370V for EV)
- Parallel Configuration: Cells grouped for current capacity (1 cell = 50Ah, 10 parallel = 500Ah)
- Practical Reality: Large battery packs are series-parallel hybrids (e.g., 10P100S = 10 parallel strings of 100 cells in series)
AFIC chips are the sensory organs of the battery:
- Measure individual cell voltages (within millivolts)
- Measure current in/out (charging vs. discharging)
- Temperature sensing (thermal runaway prevention)
- Integrated fault detection
Self-Balancing Mechanism
With parallel/series configurations, individual cells degrade at different rates:
- Manufacturing tolerances cause slight capacity differences
- Thermal gradients cause uneven degradation
- If one cell drops to 2V while others are at 3.7V, the entire pack becomes unbalanced
I implemented passive cell balancing:
- AFIC chips drive high-side switches (HST drivers) to shunt current from fully-charged cells
- While other cells catch up, the full cells dissipate energy via resistive bleeds
- Result: All cells converge to the same voltage during balancing phases
Trade-off: Passive balancing wastes energy as heat, but it's simple, proven, and safe. Active balancing (using buck-boost converters) is more efficient but adds complexity.
Multi-Point Current & Voltage Sensing
I designed redundant sensing architecture:
- Cell-level voltage: Each cell monitored individually
- String-level current: Current through each parallel string
- Pack-level current: Total current in/out of the battery
Protection Mechanisms Implemented:
- Over-Voltage (OV): Single cell > 4.2V → immediately cut charging
- Under-Voltage (UV): Single cell < 2.5V → cut discharging (reserve for recovery)
- Over-Current (OC): Pack current > threshold → HV contactor opens
- Short-Circuit (SC): Instantaneous current spike → HV contactor opens in microseconds
- Over-Temperature (OT): Cell temp > 60°C → derating or shutdown
- Under-Temperature (UT): Cell temp < 0°C → no charging allowed
Each protection layer logs events for diagnostics and failure root-cause analysis.
High-Precision Current Sensing
The AFIC measures current via a shunt resistor (typically 10mΩ). Raw ADC readings have noise:
- Thermal drift: Same current reads differently at 25°C vs. 60°C
- Offset error: 0A might read as 2mA
- Gain error: 100A might read as 99.5A
I developed multi-point calibration routines:
- Zero-current calibration: With charger off, measure offset at ambient temperature
- Temperature-sweep calibration: Repeat at 0°C, 25°C, 50°C to capture thermal coefficients
- Known-load calibration: Drive known current through shunt, measure ADC, build correction curve
- In-field recalibration: Periodic re-calibration during vehicle operation when stationary
Result: Measurement accuracy improved from ±5% to ±0.5%—critical for accurate SOC estimation.
The Load State Machine
BMS must detect what's happening to the battery:
- Charging: Positive current from charger
- Discharging: Negative current to motor/loads
- Idle: Near-zero current (vehicle parked)
- Balancing: Current flowing internally (cell rebalancing)
Each state triggers different algorithms:
- Charging state: Accelerate balancing, charge with constant current (CC) then constant voltage (CV)
- Discharging state: Monitor thermal runaway, enforce current limits based on temperature
- Idle state: Enable deep calibration algorithms, periodic balancing
- Balancing state: Adjust charger voltage to not interfere with bleed currents
State transitions are guarded: You can't jump from Charging directly to Discharging without an Idle phase—that prevents sudden load disconnects from corrupting SOC.
The Challenge
SOC (State of Charge) is what users care about: "How much battery is left?"
The Problem: You can't measure "available energy" directly. A 100Ah battery at 4.2V has more usable energy than a 100Ah battery at 3.0V, even though the amp-hour count is the same.
Traditional Approaches:
-
Coulomb Counting: Integrate current over time (
SOC = previous_SOC + (current × time) / capacity)- Pro: Simple, works offline
- Con: Drift over time, accumulation error, doesn't account for nonlinear chemistry
-
Open Circuit Voltage (OCV): Look up battery chemistry curve
- Pro: Doesn't drift, absolute measurement
- Con: Requires hours of rest, can't measure while driving
My Solution: Hybrid OCV + Coulomb Counting
I implemented a self-calibrating algorithm:
- During idle periods: Measure pack OCV, look up true SOC from chemistry curve, update internal SOC estimate
- During driving: Use coulomb counting for real-time updates
- Self-correction: If coulomb-counted SOC drifts >5% from OCV-measured SOC, gradually re-calibrate
- Minimal computation: All calculations use integer arithmetic (no floating-point), runs on modest microcontrollers
Result: SOC estimates within ±2% of actual capacity—accurate enough for user confidence and safe power management.
The SEEK Driver Abstraction
Different battery chemistries have different characteristics:
- LFP (Lithium Iron Phosphate): Safe, lower energy density, flat discharge curve
- NCA (Nickel Cobalt Aluminum): High energy density, steeper discharge curve
- NCM (Nickel Cobalt Manganese): Balanced safety/density, most common in automotive
Instead of hardcoding chemistry parameters, I created a SEEK (Stack Entity Extendable Kit) driver layer:
- Abstracted cell chemistry as pluggable modules
- Each chemistry module defines: voltage curves, thermal limits, balancing strategy, SOC algorithm coefficients
- Same firmware runs on different vehicles by just changing the chemistry configuration
BMS Stack Configuration:
- Cell chemistry: LFP, NCA, NCM (selectable)
- Series count: 100, 120, 200 cells (configurable)
- Parallel count: 1P, 4P, 10P (configurable)
- Thermal limits: Custom per vehicle
- Balancing aggressiveness: Tunable
- SOC algorithm: Chemistry-specific coefficients
This modularity meant one BMS firmware served 50+ vehicle configurations without modifications.
The Missing Piece: BMS-Charger Dialogue
Most engineers treat BMS as passive monitoring. I learned it's actually active management:
The BMS must negotiate with the charger:
"I can accept 100A max, but only at 50°C or below""Stop charging, cells are imbalanced""Reduce charging current, one cell is above threshold""Charging complete, cells are balanced"
Chargers listen to BMS signals to optimize:
- Charge time: Fast charging when cells are healthy, slow when degrading
- Thermal management: Reduce current in cold/hot weather
- Cell longevity: Strategic charging curves extend battery life by 30%
I implemented BMS-to-Charger communication protocol:
- Over isolated CAN link (safety isolation required)
- Real-time feedback of cell voltages, temperatures, estimated SOC
- Charger responds with voltage/current adjustments
Impact: Charging profiles became adaptive and data-driven instead of one-size-fits-all.
Indian Automotive Safety Standard
AIS156 is India's standard for EV battery safety. It requires:
- Thermal runaway containment
- Electrical isolation verification
- Fault detection and reporting
- Over-temperature & over-current protection with guaranteed response times
- Diagnostic capabilities for field service
I ensured our BMS architecture complied:
- Dual-layer protection: Electrical + firmware safeguards
- Redundant current sensing: Two independent measurements
- Safe-state fallback: On any fault, HV contactor opens within 100ms
- Comprehensive logging: Every fault event timestamped and recorded
A Humbling Lesson
During early testing, I discovered something critical: Minor errors accumulate.
Example scenario:
- Current sensor offset: +2mA when idle
- Over 1 hour of idle: 2mA × 3600s = 7.2 coulombs = 0.002 Ah loss
- Multiply across 1000 idle events in vehicle lifetime: ~2Ah phantom loss
- For a 100Ah pack: 2% SOC error
I learned to obsess over "small" errors:
- Thermal drift ±0.1%/°C × 50°C operating range = ±5% error
- ADC quantization noise: Average 1000 samples instead of one read
- Charger rounding: Charger might claim "100.5A" but actually deliver 99.8A
Self-Justification Algorithm
I implemented continuous error monitoring:
- Track coulomb-counted vs. OCV-measured SOC continuously
- If divergence detected, log root cause (thermal drift? ADC noise? charger accuracy?)
- Periodically re-justify all calibration points
- Predict when next full recalibration is needed
This transformed SOC from "estimate" to "confidence-tracked measurement".
-
BMS is about prevention, not performance: While motor control is about "how fast", BMS is about "keep it safe and alive"
-
Multi-decade systems need precision: Battery chemistry errors compound over years. ±2% SOC accuracy today prevents disasters tomorrow
-
Modularity scales across chemistries: One firmware, multiple chemistries = production efficiency
-
Passive safety > active safety: Simple bleed resistors are more reliable than complex active balancers
-
Charger dialogue elevates system: BMS became not a monitor, but a system orchestrator commanding charger behavior
-
Minor errors are killers: A 0.5% daily error is only 100% error in 200 days. Discipline on precision is non-negotiable
-
AIS156 compliance is achievable: Formal standards exist; following them religiously prevents catastrophic field failures
Focus: CAN/FD, UDS over CAN, OTA updates, telematics.
Scope: Vehicle network hub and telematics gateway for 2W/3W EV platforms.
Core Capabilities:
A. CAN / CAN-FD Network Management
- Multi-node CAN bus orchestration across Motor Controller, BMS, OBC, BCM
- CAN-FD support for higher bandwidth diagnostic traffic
- J1939 protocol stack for commercial vehicle compatibility
- Message routing and gateway functionality between network segments
- Bus-off recovery and error-passive handling
B. UDS Diagnostic Services (Over CAN)
- Full ISO 14229-1 UDS server implementation
- Diagnostic session management (Default, Extended, Programming)
- DTC read/clear, data read/write by identifier
- Security access (seed/key algorithm)
- Supports both physical and functional addressing
C. OTA (Over-The-Air) Firmware Updates
- Orchestrates firmware updates across multiple ECUs simultaneously
- Coordinates with UDS bootloader for each target node
- Progress tracking and rollback on failure
- Bandwidth-managed transfer to prevent bus saturation during updates
D. Telematics Integration
- Real-time telemetry collection from all CAN nodes
- Speed, SOC, motor temperature, fault codes aggregated
- Transmission to cloud backend via modem/BLE interface
- Trip logging and remote diagnostic capability
E. Bluetooth Stack
- BLE pairing for smartphone connectivity
- Parameter configuration via mobile app
- Real-time dashboard data streaming
Status: Framework prepared. Application-layer content to be expanded via detailed project interview.
Focus: ASIL compliance, MISRA, TDD, Unit testing (Unity/Ceedling), CI/CD pipelines.
ASIL Compliance Levels Worked On:
- ASIL-C — Traction motor controller (L2 category)
- ASIL-B — Suspension air compressor motor controller (hybrid vehicle)
- AIS156 — Battery Management System (India EV safety standard)
Functional Safety Implementation Across Projects:
A. Safety Concept Design
- ISO 26262 Part 6 (Software) requirements decomposition
- FMEA (Failure Mode and Effects Analysis) for safety-critical paths
- Safety requirements allocated to software components
- Hazard analysis and risk assessment contributions
B. Safety Monitors (Implemented)
- RAM march test — detects stuck-at faults in RAM
- ROM CRC verification — ensures code integrity at startup
- Watchdog manager — configurable window watchdog supervision
- Stack overflow detection
- ADC plausibility checks
- PWM output monitoring
- HV contactor weld/stuck fault detection
C. TI DRV32XX Integration (ASIL-C Gate Driver)
- Smart gate driver with Built-In Self-Test (BIST) capability
- SPI-based diagnostic interface
- Gate driver health status monitoring at runtime
- Fault injection and verification testing
D. Coding Standards & Quality
- MISRA-C:2012 — Full compliance with static analysis enforcement
- Helix QAC — Automated MISRA checking in CI pipeline
- PC-lint — Secondary static analysis pass
- Cyclomatic complexity limits enforced per function
- Static stack analysis to prevent overflow in safety paths
E. Test-Driven Development (TDD)
- Tests written before implementation (Red-Green-Refactor)
- Unity/Ceedling framework for embedded unit testing
- CMock for hardware peripheral mocking
- Branch and decision coverage targets (typically 100% for ASIL paths)
- Regression test suite run on every commit
F. CI/CD Pipeline
- GitLab CI/CD with automated gates:
- Static analysis (MISRA + QAC)
- Unit test execution (host-compiled)
- Code coverage report
- Documentation generation (Doxygen)
- Binary build for target MCU
- Merge requests blocked if any gate fails
- Coverage badges tracked per module
G. Peer Review Process
- Formal code review for all safety-critical paths
- Safety lead sign-off required for ASIL-C components
- Design review before implementation (Design First principle)
- Review comments tracked and closed before merge
TÜV SÜD Certified: ISO 26262 Functional Safety training (formal certification)
Focus: Scaling teams, code review culture, technical mentorship, cross-functional collaboration.
Built and scaled an embedded software team from the ground up — hiring, onboarding, and developing engineers to take full module ownership with minimal supervision.
Key Actions:
- Defined clear ownership boundaries: each module assigned to one engineer
- Structured onboarding with codebase walkthroughs, architecture docs, and buddy pairing
- Created internal wiki and module-level documentation standards
- Engineers progressed from "following instructions" to "leading modules" within 3–6 months
Hands-on mentoring of junior and mid-level engineers in:
- Embedded C best practices: Memory layout, pointer arithmetic, volatile usage, const-correctness
- Software architecture thinking: Layered design, abstraction, dependency inversion
- Debugging techniques: JTAG/trace-based debugging, scope-driven root cause analysis
- Control system fundamentals: PID tuning intuition, FOC concepts, signal processing
- Power electronics basics: Switch timing, deadtime, SR fundamentals for charger team
Outcome: Engineers grew into independent contributors able to own safety-critical modules end-to-end.
Established a review culture where code review is a learning opportunity, not a gatekeeping step:
- Defined coding guidelines based on MISRA-C:2012 with practical embedded addendums
- Led by example — reviewed every safety-critical PR personally
- Introduced review checklists covering: correctness, safety, style, testability
- Tracked recurring mistakes and turned them into training sessions
- Result: Team's MISRA violation count dropped by 80% within 6 months of guidelines adoption
Initiated regular knowledge sharing mechanisms:
- Tech talks: Weekly 30-minute sessions on topics like FOC, AUTOSAR BSW, FMEA
- Brown-bag sessions: Informal lunch learning on control theory and debugging tools
- Internal wiki: Module documentation, design decisions, gotchas — always up to date
- Cross-domain sessions: Power electronics engineers presenting to software team and vice versa
- Embedded newsletter: Monthly digest of industry news, learnings, and project updates
Driving ASPICE-aligned development processes:
- Sprint planning and milestone tracking for safety-critical ECU deliveries
- Requirement traceability from system spec → software spec → unit test
- V-model SDLC implementation for ISO 26262 compliance
- Risk tracking and early escalation culture — no surprises at delivery
- On-time delivery of 4+ product releases with zero safety-critical regressions
Bridging hardware, systems, and test teams:
- Translated control theory and power electronics requirements into clear software specs
- Co-authored system-level interface specifications with hardware team
- Supported HIL (Hardware-in-the-Loop) test team in writing and debugging test scripts
- Acted as technical interface with OEM customers during design reviews
- Participated in safety reviews with functional safety engineers
- Team scaled from 2 → 8 engineers maintaining production quality
- Module ownership coverage: 100% (no module without a named owner)
- Review coverage: 100% of safety-critical code peer-reviewed before merge
- Developer attrition: 0% in 2 years under leadership (previously high-attrition environment)
Focus: Smart appliances, MATLAB, computer vision, rapid prototyping.
Scope: End-to-end IoT embedded product for a connected refrigerator with OTA capability.
Features Implemented:
- Automatic Defrost Control: Adaptive defrost cycle timing based on usage patterns and temperature history
- Energy Monitoring: Real-time power consumption measurement and reporting
- Smartphone Temperature Control: BLE-connected mobile app for remote temperature setpoint
- OTA Firmware Updates: Over-the-air update via custom lightweight bootloader
- BSP Development: Complete board support package — GPIO, ADC, timers, UART, relay drivers
- Fail-Safe Mechanisms: Compressor and heater protection with hardware watchdog backup
Technologies: Embedded C, BLE, WiFi, ADC, PWM, Custom Bootloader
Scope: Broad research portfolio spanning evaluation boards, simulation, computer vision, and domain-specific solutions.
Categories:
A. MCU Evaluation & BSP
- Bring-up of 10+ evaluation boards across STM32, PIC, Arduino, Renesas, Infineon families
- BSP development: Peripheral drivers, clock configuration, startup code
- Rapid prototyping methodology: Concept to working demo in days
B. Simulation & Modeling
- MATLAB/Simulink models for motor control (FOC, BLDC commutation)
- Power electronics simulation: PFC, LLC, PSFB circuit behavior
- Signal processing models: Filter design (IIR/FIR), Bode plots, step response analysis
- Python automation: Test data analysis, calibration curve fitting, visualization
C. Computer Vision
- Raspberry Pi + OpenCV based image processing prototypes
- Object detection for industrial quality inspection
- Edge detection and contour analysis for measurement systems
D. Domain-Specific Prototypes
- Cost-effective agriculture monitoring: Soil moisture, irrigation control, remote alerts
- Industrial automation: Modbus-based motor control, energy monitoring systems
- Consumer electronics: Remote-control systems, display interfaces, sensor fusion
E. FPGA / VLSI
- Xilinx Spartan 3E FPGA development (at Crisp Systems)
- HDL (Hardware Description Language) programming for digital circuit design
- Hardware-software co-design experience: Understanding hardware timing constraints
Key Learning from Research Portfolio:
- Breadth of exposure accelerates pattern recognition across projects
- MATLAB models validate algorithm behavior before embedded implementation
- Python tooling is the force multiplier for embedded development
- Every evaluation board BSP investment returns value in future products
Focus: Production-grade motor control, battery management, charging systems, diagnostics, bootloader infrastructure, cryptographic security, real-time scheduling.
This section documents a comprehensive suite of integrated automotive embedded projects implemented over multiple years, spanning 6 production ECUs, 23 reusable middleware modules, and multi-MCU support. The architecture embodies lessons learned from the monolith-to-modularity journey, demonstrating enterprise-scale embedded systems design.
Portfolio Scope:
- 6 Production ECUs (BCM, BMS, MC, OBC, OFBC, MFECU)
- 23 Reusable Middleware Modules
- Multi-MCU Target Support (Renesas RH850 F1KM, Infineon XMC1)
- Full Hardware Abstraction Layer (HAL) for both MCUs
- Production Bootloader with OTA update capability
- Comprehensive Diagnostics (UDS, DTC management, telemetry)
- Advanced Control Algorithms (FOC, PID, resonant converters)
- Cryptographic Security (AES-256)
- Real-Time OS with scheduler, state machines, queues, timers
Scope: Production 3-phase brushless DC motor controller for electric two-wheelers
Microcontroller: Infineon XMC1 (Cortex-M0)
Core Technical Implementations:
A. Field-Oriented Control (FOC) Algorithm
- Clarke & Park transformations for 3-phase to 2-axis (dq) conversion
- Real-time angle measurement from Hall effect sensors (6-step commutation)
- Multi-instance PID controllers:
- Id (direct axis current) controller: Maintains constant field
- Iq (quadrature axis current) controller: Controls torque
- Speed controller: Outer loop for RPM regulation
- Voltage decoupling for improved transient response
- Dynamic current limiting based on thermal conditions
B. PWM & Power Stage
- Space Vector PWM (SVPWM) modulation
- 3-phase PWM generation with dead-time insertion
- Synchronized ADC sampling for phase current measurement
- Voltage sensing for bus monitoring
- Inverse Clarke transform for UVW phase output
- CCU8 (Capture Compare Unit 8) for high-frequency PWM (10-20 kHz)
- Configurable voltage/current margins for safe operation
C. Sensor Integration
- Hall Effect sensors: 6-step position feedback for commutation
- Phase current measurement: 3-channel ADC sampling
- Motor temperature: NTC thermistor on stator
- Throttle input: Potentiometer for speed reference
- Bus voltage monitoring: Precision ADC scaling
- Optional side-stand detection: Safety feature for two-wheelers
- Optional board temperature: Secondary thermal monitoring
D. Protection & Safety Systems
- Over-temperature shutdown: Motor stator protection
- Phase overcurrent detection: Instantaneous limit switching
- Bus under/overvoltage: Automatic derating
- Motor thermal model: Predictive protection without explicit shutdown
- Limp-home mode: Reduced speed operation under fault conditions
- Hardware watchdog: Ensures safe state on software failure
E. Advanced Features
-
Hill Assist System: Prevent rollback on inclines
- Hold current mode when stopped on slope
- Smooth transition to drive on throttle application
- Current decay management to prevent torque shocks
-
Battery Overuse Detector: Prevent deep discharge
- SOC-based throttle limiting
- Progressive power reduction as SOC drops
- Emergency reserve protection
-
Drive Mode Energy Meter:
- Real-time energy consumption tracking
- Per-trip energy logging
- Efficiency metric calculation
-
Odometer System:
- Persistent distance tracking in NVM
- Integration with trip computer
-
Range Estimator:
- Predictive remaining range calculation
- Adaptive based on driving patterns
- Thermal efficiency compensation
-
Derate System:
- Temperature-based power deration
- Load-based current limiting
- Progressive throttle reduction curves
- Safe degradation under fault conditions
F. Bootloader Architecture
- Custom bootloader for firmware updates
- Bootloader Updater: Secondary updater for bootloader self-update
- CAN-based firmware transfer protocol
- UDS diagnostic session for update initiation
- Dual-copy mechanism for safe updates (one active, one for download)
G. Real-Time Scheduler Integration
- FOC control loop: 10 kHz (100µs cycle time)
- Speed/torque control: 100 Hz
- Protection checks: 1 kHz
- UI updates: 10 Hz
- Cooperative multitasking with deterministic response
Multi-Platform Variants:
- Hero Electric Hubmotor: Main XMC1 implementation (kusalava, okinawa proof-of-concepts)
- Proof-of-concept implementations demonstrating algorithm portability
Unique Capabilities: ✓ Sub-100µs FOC loop on entry-level MCU ✓ Thermal-aware derate without explicit shutdown ✓ Predictive range estimation with adaptive models ✓ Hill assist for zero-velocity torque control ✓ Dual-bootloader with self-update
Scope: Production 48V lithium battery pack management with multi-cell monitoring
Microcontroller: Renesas RH850 F1KM (Automotive-grade)
Compliance: AIS156 (Indian EV safety standard)
Core Technical Implementations:
A. Multi-Cell Voltage Monitoring
- AFIC (Analog Front-end IC) from TI Microelectronics
- Individual cell voltage measurement within ±10mV accuracy
- Precision current sensing via 10mΩ shunt
- Temperature monitoring: Multiple NTC thermistors
B. Cell Balancing Strategy
- Passive cell balancing with resistive bleed paths
- HST (High-Side Transistor) driver control
- Selective cell bypass during charging
- Balancing triggered during:
- Slow charging (high resistance charging)
- Vehicle idle periods
- Pre-discharge equilibration
C. SOC (State of Charge) & SOH (State of Health) Estimation
-
Hybrid Algorithm: Coulomb counting + OCV calibration
- Real-time integration: SOC = previous_SOC + (current × time) / capacity
- Periodic calibration: Measure open-circuit voltage during idle
- Self-correction: Gradual re-alignment if deviation detected
- Accuracy: ±2% under normal conditions
-
OCV Lookup: Chemistry-specific voltage curves
- Support for multiple chemistries (LFP, NCA, NCM)
- Pluggable chemistry modules
- Temperature-compensated curves
-
State Machine: Charge/Discharge/Idle/Balancing states
- State transitions guarded to prevent corruption
- Idle state enables deep calibration routines
D. Thermal Management
- Multi-point temperature sensing (cell surface, BMS PCB, ambient)
- Thermal runaway detection thresholds
- Temperature-dependent charging curves
- Current derating based on thermal conditions:
- Max charge current: 100A @ 25°C → 30A @ 50°C
- Max discharge current: 200A @ 25°C → 100A @ 55°C
E. Safety Protection Systems
- Over-Voltage (OV): Cell > 4.2V → immediate charge cutoff
- Under-Voltage (UV): Cell < 2.5V → discharge cutoff (preserve pack)
- Over-Current (OC): Pack current > 250A → HV contactor opens in <10ms
- Short-Circuit (SC): Instantaneous >500A → HV contactor open within microseconds
- Over-Temperature (OT): Cell > 60°C → charging disabled, discharging reduced
- Under-Temperature (UT): Cell < 0°C → charging disabled entirely
F. HV Contactor Control
- Smart contactor management for main battery disconnect
- Inrush current limiting during connection
- Monitoring for contactor weld/stuck conditions
- Graceful shutdown protocol on critical faults
G. Charger Communication Protocol
- Isolated CAN link (galvanic isolation required)
- Real-time feedback of:
- Individual cell voltages
- Pack current and SOC
- Temperature telemetry
- Health estimation
- Charger responds with adaptive voltage/current adjustments:
- Constant Current (CC) phase: Fixed current, rising voltage
- Constant Voltage (CV) phase: Fixed voltage, declining current
- Charge completion: Termination criteria based on current delta
H. Calibration Framework
- Zero-current calibration: Offset elimination at multiple temperatures
- Temperature-sweep calibration: Capture thermal drift coefficients
- Known-load calibration: Shunt current verification
- In-field recalibration: Periodic automatic re-justification
- Error tracking: Continuous divergence monitoring between methods
I. AIS156 Compliance Features
- Redundant current sensing (dual measurements)
- Functional safety architecture
- Deterministic fault response timing
- Comprehensive event logging for diagnostics
- Over-voltage/under-voltage protection with specified response times
J. NVM Data Management
- Persistent storage of:
- Total pack energy cycled (Wh)
- Cycle count
- Maximum temperature observed
- Fault history with timestamps
- Calibration data
- Wear-leveling to prevent flash erosion
- Redundant storage of critical parameters
Chemistry-Agnostic Architecture:
- Pluggable chemistry modules (SEEK driver layer)
- Configuration per vehicle without firmware changes
- Supported: LFP, NCA, NCM, custom chemistries
Unique Capabilities: ✓ ±2% SOC accuracy through hybrid estimation ✓ Passive cell balancing without active buck-boost ✓ Thermal runaway prediction and prevention ✓ AIS156-compliant safety architecture ✓ Chemistry-agnostic, configuration-driven design ✓ Adaptive charger communication reducing charge time by 30% vs. fixed profiles
Scope: AC-to-DC charger integrated in 48V EV
Microcontroller: TBD (similar automotive-grade MCU)
Core Implementations:
- AC mains rectification and filtering
- Isolated DC-DC conversion
- Power factor correction circuit
- Battery charger state machine
- Thermal management under continuous operation
- ISO/IEC 61000-6-2 EMC compliance
Scope: 3kW standalone charger for off-board fast charging
Multiple OEM Implementations:
- Santhos version
- TATA version
- TVS version
Power Conversion Topologies:
A. LLC Resonant Converter (for primary conversion)
- Resonant frequency optimization
- Zero-Voltage Switching (ZVS) for efficiency
- Soft switching to reduce EMI
- Multi-instance control:
- Current Controller: Phase current regulation
- Resonant Controller: Tank circuit management
- Power Controller: Primary power flow control
- Voltage Controller: Output voltage regulation
- Signal Conditioner: Input filtering and conditioning
- State Machine: Operating mode transitions
A1. LLC Secondary Synchronous Rectification — CLB-Based Firing Engine
One of the most technically challenging aspects of the LLC converter is secondary-side synchronous rectification (SR). Unlike primary-side switching (which is CPU-controlled), SR firing on the secondary cannot tolerate any CPU latency at high switching frequencies (250 kHz range). This is where the CLB (Configurable Logic Block) of the TI C2000 microcontroller became critical.
The Problem:
- The LLC secondary side operates at high frequency (~250 kHz) and requires precise timing to fire the SR MOSFETs within an optimal window
- Any CPU intervention would introduce latency, causing current stress on the MOSFET or missed ZCS (Zero-Current Switching) windows
- Traditional microcontroller-based SR control is inadequate at these frequencies due to interrupt response times
The Solution — CLB-Based Secondary Firing Engine:
The CLB (Configurable Logic Block) in TI C2000 is a programmable hardware peripheral — conceptually similar to a small FPGA/CPLD — that operates completely independently of the CPU as a real-time hardware core.
I designed and implemented a secondary SR firing engine entirely within the CLB:
-
VDS-Based Dead Band Detection (VDS Method):
- The engine continuously monitors the VDS (Drain-Source Voltage) of the SR MOSFET on the secondary side
- When VDS crosses a threshold indicating the body diode is conducting (resonant current is flowing), the CLB fires the SR gate signal
- This eliminates the need for CPU polling or interrupt-driven detection
-
Optimal Firing Window Logic:
- The CLB computes the correct ON-window for the SR MOSFET to avoid:
- Current stress: Firing too early or too late causes excessive peak current
- MOSFET damage: Incorrect timing during the resonant current zero-crossing leads to reverse recovery events
- The intelligent algorithm ensures SR turns ON only when the body diode is already conducting (VDS ≈ −0.7V), and turns OFF before current reverses
- The CLB computes the correct ON-window for the SR MOSFET to avoid:
-
Real-Time Independent Core:
- The CLB logic runs at hardware speed, fully decoupled from the CPU execution context
- CPU interaction is minimal — it only sets initial configuration parameters; thereafter the CLB operates autonomously
- This design achieves deterministic real-time behavior not possible via software ISRs
-
Hardware Implementation on PSMB/PSB Boards:
- The CLB SR engine was deployed on the Power Stage Module Board (PSMB) and Power Stage Board (PSB) hardware platforms
- Real-time configuration of the CLB was done at system startup to adapt to different LLC operating points
- This enabled high-speed synchronous rectification across varying load and frequency conditions
Key Technical Achievement:
Developed a fully CPU-independent secondary synchronous rectifier firing engine inside the C2000 CLB, using the VDS sensing method to detect optimal firing windows, avoiding MOSFET current stress and enabling reliable SR operation at switching frequencies up to 250 kHz.
B. PFC (Power Factor Correction) with CLB-Accelerated Current Control
- Input current shaping
- Unity power factor achievement
- Reduced line harmonic distortion (THD)
- Boost converter topology
CLB Role in PFC & DC-DC Converter:
- For both the PFC stage and the downstream DC-DC (TC) converter, the CLB was used as an internal current controller
- The CLB handles high-speed current loop control independently of the CPU, maintaining tight current regulation even at high switching frequencies
- The CPU is responsible only for outer-loop voltage control and supervisory state management
- This CPU-minimal design reduces the real-time burden on the main processor, improving overall system determinism and allowing the CPU to focus on communication, protection, and diagnostics
C. PSFB (Phase Shift Full Bridge)
- Alternative topology for specific OEM requirements
- Phase shift modulation
- Load-dependent efficiency optimization
Unique Aspects:
- Multi-OEM compatibility demonstrated
- Modular converter architecture
- Switchable topologies for different markets
- CLB-based real-time control cores for SR firing and current regulation — fully independent of CPU execution
- C2000 microcontroller leveraged as both a DSP (for control algorithms) and a hardware logic engine (CLB) in a unified platform
Scope: Lighting and electrical system control
Features:
- Multi-light coordination (headlight, brake light, turn signals)
- Load management and sequencing
- Fault diagnostics for lighting systems
Status: Framework prepared, not yet populated with application logic
CAN-TP Module (comm_cantp)
- ISO 15765-2 Transport Protocol
- Segmentation of large diagnostic messages
- Flow control and timeout handling
- Single and consecutive frame support
CAN Matrix Module (comm_can_matrix)
- DBC file parsing and integration
- Message multiplexing
- Signal packing/unpacking
- Automated code generation support
AES Module (crypto_aes) — Production-Grade Implementation
- FIPS-197 Compliant (National Institute of Standards)
- Key sizes: 128-bit, 192-bit, 256-bit
- Operating modes: ECB, CBC, CFB, OFB, CTR
- PKCS7 padding for variable-length data
- Multi-instance support for parallel encryption
- Hardware-agnostic C implementation
- Test vectors verified against NIST vectors
- Use cases:
- Bootloader-to-ECU authentication
- OTA update validation
- Calibration data protection
- Diagnostic session encryption
DSP Module
- Filter implementations (IIR, FIR)
- Fast Fourier Transform (FFT) for harmonic analysis
- Mathematical functions optimized for fixed-point
SOGI-PLL Module (dsp_sogi_pll)
- Second-Order Generalized Integrator Phase-Locked Loop
- Grid synchronization for chargers
- Frequency and phase tracking
- Used in: OBC phase detection, grid frequency adaptation
PID Controller Module (cs_pid_controller)
- Multi-instance support
- Integral anti-windup
- Output limiting and clamping
- Derivative filtering
- Tunable parameters (Kp, Ki, Kd)
- Fixed-point arithmetic for embedded efficiency
Power Converter Modules:
- LLC Resonant (cs_llc): 6 sub-modules for complete LLC operation
- PFC (cs_pfc): Power factor correction
- PSFB (cs_psfb): Phase-shift full-bridge
- Grid Precharge (cs_grid_precharge): Inrush current limiting
Hall Effect Position Sensor (ddl_hall_position_sensor)
- 6-step commutation pattern recognition
- Speed estimation from hall transitions
- Debouncing and glitch filtering
- Electrical angle calculation
Thermistor Temperature Sensor (ddl_thermistor_temperature_sensor)
- NTC characteristics compensation
- Multi-point calibration
- Temperature range: -40°C to +125°C
- Fixed-point approximation for speed
UDS Server (diag_uds_server) — Production ISO 14229-1 Implementation
Fully modularized with 16+ services implemented as separate components:
Session Control:
- Service 0x10: Diagnostic Session Control (Default, Programming, Extended)
ECU Management:
- Service 0x11: ECU Reset (Hard, Key-off, Enable RapidPowerShutDown)
- Service 0x27: Security Access (unlock levels, seed/key algorithm)
Data Access:
- Service 0x22: Read Data By Identifier
- Service 0x2E: Write Data By Identifier
- Service 0x23: Read Memory By Address
- Service 0x3D: Write Memory By Address
Diagnostics:
- Service 0x19: Read DTC Information (report, clear, filter, mask)
- Service 0x14: Clear Diagnostic Information
- Service 0x85: Control DTC Setting
Monitoring:
- Service 0x2A: Read Data By Periodic Identifier
- Service 0x2C: Dynamically Define Data Identifier
- Service 0x3E: Tester Present (keep-alive)
Communication:
- Service 0x28: Communication Control (enable/disable modes)
- Service 0x2F: Input Output Control By Identifier
Firmware Update:
- Service 0x34: Request Download
- Service 0x35: Request Upload
- Service 0x36: Transfer Data (bulk firmware transfer)
- Service 0x37: Request Transfer Exit
- Service 0x38: Request File Transfer
Routines:
- Service 0x31: Routine Control (execute diagnostic routines)
Responses:
- Standardized response formatting
- Negative response codes (NRC) for error conditions
- Timeout handling per service
Fault Code Management (diag_fcm)
- DTC generation and storage
- Multi-level severity (passive, warning, critical)
- Fault history with timestamps
- Root cause tracking
Renesas RH850 F1KM (mcal_rh850f1km) — Automotive-Grade MCU
- Clock management and PLL configuration
- GPIO port configuration and control
- ADC: Multi-channel, interrupt-driven sampling
- CAN: Message filtering, interrupt handlers
- PWM: Timer-based pulse generation (TAUD, TAUB)
- SPI (CSIH): Master/slave configuration
- Flash programming: Bootloader support
- EEPROM emulation: Wear-leveling layer
- Watchdog: Configurable timeout
- Interrupt controller: Priority handling
- Protected register access: Hardware safety critical operations
Infineon XMC1 (mcal_xmc1) — Entry-Level Automotive MCU
- System Control Unit (SCU): Clock, resets
- Capture Compare Units:
- CCU4: 4-channel, 16-bit for basic PWM
- CCU8: 8-channel, 16-bit for motor control
- Position Interface (POSIF): Hall sensor decoding
- Voltage ADC (VADC): 12-bit precision
- CAN: Full CAN 2.0B support
- GPIO: Port-based control
- UART/SPI (USIC): Serial communication
- Real-Time Clock (RTC)
- Analog Comparator (ACMP): Threshold detection
- Math accelerator: Fixed-point operations
- Watchdog, Interrupt controller
NVM Manager (mem_nvm)
- Flash abstraction
- Wear-leveling algorithm
- Redundant storage of critical data
- Sector management
NVM Logger (mem_nvm_logger)
- Event logging to non-volatile memory
- Circular buffer for continuous logging
- Timestamp integration
- Efficient compression of log data
Scheduler (os_scheduler)
- Preemptive, priority-based task scheduling
- Cooperative round-robin for same priority
- Deterministic context switching
- Tick-based timing
Task Management (os_task)
- Task creation, deletion, state management
- Priority levels (typically 0-31)
- Task suspend/resume
State Machine Framework (os_state_machine, os_state)
- Event-driven state transitions
- Guard conditions and actions
- Nested state support
- Automatic state entry/exit callbacks
Queue Implementations:
- os_queue: FIFO queue for inter-task communication
- os_dqueue: Double-ended queue for more complex patterns
Timer Utilities (os_timer)
- Software timers independent of hardware
- One-shot and periodic modes
- Callback-driven expiration
- Resolution typically 1ms or better
Middleware Integration:
- OS provides foundation for all upper layers
- FOC control loop runs as high-priority task
- Diagnostic processing runs as lower-priority task
- Non-blocking design prevents priority inversion
Common (common)
- Standard type definitions
- Helper macros and functions
- Ring buffer implementations
- Bit manipulation utilities
I/O Abstraction (io)
- Digital input/output abstraction
- Analog input scaling
- Output ramping for smooth transitions
Mathematical Functions (math_calculus)
- Fixed-point arithmetic utilities
- Fast trigonometric approximations
- Square root and division optimizations
- Lookup table support
CRC Module (crc)
- CRC-8, CRC-16, CRC-32 variants
- Polynomial selection
- Cyclic Redundancy Check for data integrity
1. True Hardware Abstraction (Multi-MCU Support)
- Single codebase compiles for RH850 and XMC1
- Identical APIs across MCU variants
- Zero code changes for MCU migration
- Proven with 4+ ECU projects
- Impact: Reduced ECU bring-up time by 60%
2. Modular Reusable Middleware Stack
- 23 independent modules, each with:
- Isolated versioning (git submodules)
- Independent test suites (Unity/Ceedling)
- Comprehensive documentation
- Pluggable architecture
- Impact: New ECU projects now "buy, don't build" 70% of stack
- Scaling: Team productivity increased 3x
3. Production Bootloader Architecture
- Dual-bootloader with automatic fallback
- Zero-downtime firmware updates
- UDS diagnostic integration
- CAN-based firmware transfer
- 8,000+ successful production deployments without bootloader failure
4. Integrated Diagnostics (16+ UDS Services)
- Complete ISO 14229-1 compliance
- Modular service architecture
- Extensible for custom services
- Multi-vendor tool compatibility
- Production use across 5+ OEMs
5. FOC Implementation Under Constraints
- 100µs cycle time on entry-level MCU (XMC1)
- Clarke-Park transformations, PID control, SVPWM
- Thermal derating without explicit shutdown
- Hill assist for zero-velocity hold
- Efficiency: >95% in full load range
6. Advanced Motor Features
- Predictive derate system: Prevents thermal failures 30% before they occur
- Range estimator: Adaptive SOC-to-range conversion, ±5% accuracy
- Hill assist: 0% throttle torque holding on 30° slopes
- Energy metering: Real-time efficiency calculation
7. Battery Management Intelligence
- Hybrid SOC estimation: ±2% accuracy through coulomb counting + OCV calibration
- Thermal-aware charging: 30% faster charging through temperature optimization
- Passive cell balancing: Achieves >95% cell voltage equalization
- Self-justifying algorithms: Continuous error monitoring and correction
8. Production-Grade AES-256
- FIPS-197 compliant implementation
- 5 operating modes (ECB, CBC, CFB, OFB, CTR)
- Multi-instance support
- Verified against NIST test vectors
- Fast fixed-point implementation
9. Deterministic Real-Time Scheduler
- Sub-millisecond context switching
- Priority-based preemption
- FOC control loop: 10 kHz deterministic
- Diagnostic processing: Asynchronous, non-blocking
- Zero priority inversion patterns
10. Integrated State Machine Framework
- Eliminates if-else spaghetti code
- Event-driven transitions
- Guard conditions for safe transitions
- Used in: Motor state (idle/run/fault), Charger states, BMS states
11. Multi-ECU Orchestration
- 6 ECUs communicating over CAN
- Synchronized bootloader updates
- Cross-ECU fault propagation
- Coordinated thermal management
12. Chemistry-Agnostic BMS
- One firmware, 5+ battery chemistries
- Pluggable calibration data
- Per-vehicle configuration without rebuild
- Support: LFP, NCA, NCM, and custom types
The journey from 10K+ line monoliths to 23-module architecture achieved:
- 3x team productivity increase
- 60% faster ECU bring-up
- 50% fewer integration bugs
- Scalability to 6 concurrent ECU projects
Principle: One module = one job = one team's responsibility
RH850 & XMC1 dual support demonstrates:
- Initial effort: 2 MCAL implementations took 300 engineer-hours
- Amortized over 6 ECUs: 50 hours per ECU (vs. 100 hours from scratch)
- Total savings: 300 hours = 2 engineer-months per new product line
Principle: Upfront abstraction investment pays off exponentially with scale
AES-256 integration seems "expensive" but:
- Boot authentication: Prevents unauthorized firmware injection
- OTA encryption: 50KB update overhead vs. potential $100K recall
- Compliance: AIS156, OEM security requirements mandate it
- Cost/benefit: $1K implementation cost vs. $10M production recall
Principle: Security bugs are catastrophic; prevention is cheaper than cure
Achieving ±2% SOC from raw ADC readings required:
- Thermal calibration across -20°C to +60°C
- Multi-point shunt characterization
- Hybrid algorithm combining coulomb counting + OCV
- Continuous error monitoring and self-justification
Principle: "Good enough" drifts 5%/year; precision pays off long-term
Passive cell balancing vs. active buck-boost:
- Passive: 10 resistors, 10 switches, 10 MOSFETs (simple, reliable)
- Active: Buck-boost converter, complex control, single point of failure
- Result: Passive sufficient for 48V, achieves 95% balance
- Lesson: Simplicity beats sophistication for reliability
Motor thermal protection:
- Naive approach: "If T > 60°C, stop."
- Better approach: Predictive thermal model + derate curve
- Result: Safe operation 30% longer, prevents sudden shutdown
- Efficiency: Reduces thermal shutdown incidents by 95%
Principle: Model the physics, don't just react to sensors
16 UDS services as 16 separate .c files:
- Service changes don't affect others
- Easy to add custom services
- Version management simplified
- Test coverage per-service focused
Principle: One service = one file = one responsibility
OFBC with Santhos/TATA/TVS variants:
- Naive: 3 separate firmware branches
- Better: 1 firmware + configuration per OEM
- Result: Bug fixes benefit all variants, no re-testing
- Scaling: 5th OEM = 1 config file, not new branch
Principle: Configuration in data, not code
Dual-bootloader architecture:
- "Cost": 2x bootloader size (8K vs. 4K)
- "Benefit": Eliminated all bootloader-related field failures
- ROI: 8000 units × 0 failures = $0 return cost vs. alternative risk
Principle: Critical infrastructure deserves redundancy investment
Focus testing efforts:
- Thermal boundaries: -20°C, 0°C, 25°C, 50°C, 60°C (not continuous)
- SOC boundaries: 0%, 20%, 50%, 80%, 100%
- Current boundaries: Min, rated, 1.5x, 2x
- Result: 80% of edge case bugs discovered with 20% of test effort
- BCM: 50,000+ units (Hero Electric)
- BMS: 10,000+ units (Batrix, various OEMs)
- MC: 30,000+ units (XMC1-based variants)
- OBC/OFBC: 5,000+ combined units
- Field failure rate: <0.1% (0.1 PPM)
- Bootloader success: 99.99% (8,000+ boots without failure)
- OTA update success: 99.98%
- Thermal shutdown incidents: Reduced 95% vs. naive approaches
- Diagnostic resolution time: 40% faster through UDS integration
- Charging time: 30% reduction through adaptive BMS-charger dialogue
- Motor efficiency: 95% sustained through thermal derate curves
- Safety: AIS156 compliance enabled market access to India
- Reliability: <0.1% field failure rate vs. 1-2% industry average
This section extracts every feature of each middleware module, including small functional capabilities often overlooked but critical for production systems.
File Components: 14 files (scheduler, task, state machine, queue, timer, etc.)
- Preemptive Priority-Based Scheduling: Task with highest priority always runs
- State Enumeration: Tracks running, stopped, idle states
- Initialize Function: Setup scheduler with task table and size
- Execute Function: Runs scheduler tick (called from system timer ISR)
- Start/Stop Control: Enable/disable entire scheduler
- IsEnable Query: Runtime scheduler status check
- Task Table Abstraction: Flexible number of tasks via table pointer
- Early Returns: Efficient idle detection
- Task Function Callback: Pointer-based task execution
- Parameter Passing: Void pointer allows any parameter type
- Task State Tracking: Enabled/disabled state machine
- Start Time Recording: Timestamp when task started
- Interval Time Configuration: Periodic execution rate (milliseconds)
- Interval Timer Integration: Reuses os_timer for timing
- Pending Detection: isPending() checks if task should run
- Start/Stop Control: Individual task enable/disable
- IsEnable Query: Per-task status verification
- State Table Architecture: Array of states with IDs
- Active State Tracking: Persistent tracking of current state
- State Initialization: Setup with initial state ID
- Event-Driven Transitions: Execute() processes transitions
- Query Functions:
- GetActiveState(): Read current state ID
- IsActiveState(): Test if specific state active
- State Callback Support: Entry/exit actions via state module
- Guard Conditions: Conditional transition logic
- No if-else Spaghetti: Eliminates nested conditionals
- Base Clock Increment: Hardware-to-software timer bridge
- Millisecond Precision: time32_t type for milliseconds
- Two Operating Modes:
- E_OS_TIMER_MODE_ONETIME: Single-shot execution
- E_OS_TIMER_MODE_AUTOLOAD: Continuous/periodic reload
- Interval Tracking: Configurable delay in milliseconds
- Start Timestamp Recording: Boot time reference
- Running State: optState_e tracks if timer active
- Maximum Value Support: OS_TIMER_TIME_MAX_MS = 4,294,967,295 ms (~49 days)
- Non-Blocking Design: No busy-wait, integrates with scheduler
- Platform Independence: Software-based, no hardware timer required
- FIFO Queue: First-In-First-Out data structure
- Inherits from DQueue: Reuses double-ended queue internally
- Generic Element Support: Template-like via element size
- Buffer Initialization: Flexible buffer addressing
- Available Count: Query free/used queue elements
- IsFull/IsEmpty: Boundary condition checks
- Non-Blocking Insert/Retrieve: Constant time operations
- Thread-Safe Design: Suitable for ISR usage
- FIFO and LIFO Support: Operate from both ends
- Circular Buffer: Memory-efficient wraparound
- Insert Front/Back: Push to either end
- Retrieve Front/Back: Pop from either end
- Size Management: Track used/free elements
- Buffer Full Handling: Overflow detection
- Generic Type Support: Element size parameterized
✓ Deterministic RT Scheduling: 10kHz+ loop capability on entry-level MCU ✓ Zero Priority Inversion: Properly implemented preemption ✓ Software Timers Independent of Hardware: Portable across MCUs ✓ Non-Blocking Queues: Safe for ISR usage without mutexes ✓ Event-Driven State Machines: Cleaner than traditional if-else hierarchies ✓ Inline Functions: Zero-overhead abstractions for simple operations ✓ Configuration Separation: All timing constants in _cfg.h files
File Components: 2 files (comm_cantp.h/c)
- Three State Machine States:
- E_COMM_CANTP_STATE_IDLE: Ready for new transfer
- E_COMM_CANTP_STATE_TRANSMIT: Actively sending segmented data
- E_COMM_CANTP_STATE_RECEIVE: Actively receiving segmented data
- Error Enumeration: 8 distinct error codes
- E_COMM_CANTP_ERROR_TIMEOUT_BS: Block size timeout
- E_COMM_CANTP_ERROR_TIMEOUT_CR: Consecutive frame timeout
- E_COMM_CANTP_ERROR_WRONG_SN: Sequence number mismatch
- E_COMM_CANTP_ERROR_INVALID_FS: Invalid flow status
- E_COMM_CANTP_ERROR_UNEXP_PDU: Unexpected PDU type
- E_COMM_CANTP_ERROR_WFT_OVRN: Wait frame overflow
- E_COMM_CANTP_ERROR_BUFFER_OVFLW: Rx buffer overflow
- Physical vs. Functional Addressing:
- E_COMM_CANTP_ADDRESSING_PHYSICAL: 1-to-1 communication with response
- E_COMM_CANTP_ADDRESSING_FUNCTIONAL: 1-to-many, no response expected
- E_COMM_CANTP_ADDRESSING_NONE: Unaddressed state
- Separate TX/RX Identifiers: Asymmetric addressing for duplex
- Extended CAN Support: 29-bit identifiers
- Standard CAN Support: 11-bit identifiers
- isExtended Flag: Runtime frame type selection
- Single Frame (SF): Fits in one CAN frame (<= 7 bytes)
- First Frame (FF): Initiates multi-frame transfer
- Consecutive Frame (CF): Continuation frames with sequence
- Flow Control Frame (FC): Receiver acknowledges and controls flow
- Sequence Number Tracking: 4-bit SN rollover detection
- Dynamic SN Counter: flowCtrlSequenceNumber_b4 : 4 (bitfield)
- Flow Control Parameters:
- flowStatus_b4: 4-bit flow status code (Continue, Wait, Overflow)
- blockSize_u8: How many consecutive frames before pause
- blockCount_u8: Tracks frames in current block
- separateTime_u8: Min time between consecutive frames (STmin)
- Block Size Implementation: Pause transmission after N frames
- STmin Timing: Enforce minimum separation between frames
- isValid Flag: Validate FC parameters before use
- Timer BS (Block Size): Timeout waiting for first CF
- Configured per CAN-TP standard (typically 150ms)
- Timer CR (Consecutive Receive): Timeout between consecutive frames
- Ensures sender doesn't abandon mid-transfer
- Timer STmin (Separation Time): Minimum gap between CF
- Prevents overwhelming slow receivers
- os_timer Integration: Uses OS layer timers for portability
- Separate TX/RX Buffers: txDataBuffer_u8p, rxDataBuffer_u8p
- Functional RX Buffer: funcRxBuffer_u8[8] for broadcast frames
- Buffer Index Tracking: flowCtrlDataBufferIdx_u32
- Buffer Length: flowCtrlDataBufferLength_u32
- Data Fill Flags:
- isReceiveDataFilled_b: Complete message received
- isFuncReceiveDataFilled_b: Functional frame buffered
- flowCtrlRequest Flag: Triggers flow control transmission
- TX Request Callback: commCanTpLinkTxRequest_fnt
- Called when CAN frame ready to transmit
- Provides frame identifier and PCI data
- RX Indication Callback: commCanTpLinkRxIndication_fnt
- Called when CAN frame received
- Returns false if buffer full
- Provides frame identifier and PCI data
- Initialize: Setup addressing, callbacks, timers
- Transmit: Send message (automatic segmentation)
- Receive: Read received message
- IsTransmitting: Query transfer in progress
- IsReceived: Check for complete message
- ClearReceivedData: Reset RX state (supports both address types)
✓ Full ISO 15765-2 Compliance: Timings, error handling, flow control ✓ Dual Addressing: Physical + functional with separate buffers ✓ Callback-Based Architecture: No blocking, ISR-safe design ✓ Modular Timer Integration: Uses OS timers, portable across MCUs ✓ Bitfield Optimization: 4-bit SN packs efficiently
Focus: DBC file abstraction and CAN message multiplexing
- DBC Message Definition: Structured data from DBC files
- Multi-Message Support: Handle dozens of CAN messages
- Signal Packing/Unpacking: Automatic byte-to-bit mapping
- Byte Order Handling: Both Intel (little-endian) and Motorola (big-endian)
- Multiplexed Signals: Conditional signals based on multiplexer value
- Signal Scaling: Linear conversion (physical = raw * scale + offset)
- Hardware Independence: Pure C, no hardware assumptions
- Code Generation Ready: Suitable for automated DBC → C generation
- Type Conversions: Signed/unsigned, fixed-point to float
- Range Checking: Min/max validation per signal
- Unit Tracking: Metadata for engineering units
- Bit Position Mapping: Exact byte/bit placement in CAN frame
- Bit Length Support: 1-bit flags to 32+ bit values
File Components: Modular CRC implementations
- CRC-8: 8-bit polynomial (e.g., SMBus CRC)
- CRC-16: 16-bit polynomial (e.g., CCITT, Modbus)
- CRC-32: 32-bit polynomial (e.g., Ethernet, ZIP)
- Polynomial Selection: Configurable polynomials per variant
- Initialization Values: Per-CRC-type IV configuration
- Final XOR Value: Post-computation XOR mask
- Table-Driven: Pre-computed lookup tables for speed
- Bit-by-Bit: Software-only fallback
- Incremental Calculation: Add data without full recalculation
- Verification: Compare calculated vs. received CRC
✓ Production-Grade Implementations: Tested against known vectors ✓ Modular Architecture: Different CRCs independent ✓ Performance Tuning: Table-driven for speed, bit-by-bit for memory
FIPS-197 Compliant Implementation
- 128-bit Key: AES-128 (10 rounds)
- 192-bit Key: AES-192 (12 rounds)
- 256-bit Key: AES-256 (14 rounds)
-
ECB (Electronic Codebook)
- Simple block-by-block encryption
- Same plaintext → same ciphertext (weakest)
- Use case: Data less than one block, or deterministic small values
-
CBC (Cipher Block Chaining)
- Each block depends on previous
- IV (Initialization Vector) required
- Most common, good security
-
CFB (Cipher Feedback)
- Stream cipher mode
- Self-synchronizing
- No padding needed
-
OFB (Output Feedback)
- Stream cipher mode
- Independent of plaintext
- Parallelizable encryption/decryption
-
CTR (Counter)
- Parallelizable, random-access decryption
- Nonce + counter
- Streaming encryption
- PKCS7 Padding: Standard padding for block alignment
- Adds N bytes of value N
- Handles already-aligned data (adds full block)
- Zero Padding: Fill with zeros (requires length tracking)
- SubBytes Transformation: S-box substitution
- ShiftRows Transformation: Row circular shift
- MixColumns Transformation: Column matrix multiplication
- AddRoundKey Transformation: XOR with round key
- Key Expansion: Generate round keys from master key
- Inverse Operations: Decrypt path (InvSubBytes, InvShiftRows, InvMixColumns)
- Independent Contexts: Multiple encryption operations simultaneously
- Instance-Per-Key: Separate cipher instance per encryption key
- Reusable Configuration: Same mode/key across multiple messages
- Initialize: Setup cipher context
- Encrypt: Block encryption with padding
- Decrypt: Block decryption with unpadding
- GetIteration: Calculate iteration count for data size
- GetDataLengthPerIteration: Efficient streaming support
- Constant-Time Operations: Resistance to timing attacks
- FIPS-197 Compliance: Certified algorithm
- Test Vector Verification: Validated against NIST vectors
- In-Place Operation: Can encrypt/decrypt to same buffer
- Bootloader authentication: Verify firmware signature
- OTA update encryption: Protect wireless firmware transfers
- Calibration data: Encrypt motor/battery tuning parameters
- Diagnostic session: Encrypt sensitive diagnostic data
✓ 5 Modes in One Module: Flexibility without size explosion ✓ FIPS-197 Compliance: Certified algorithm ✓ Streaming Support: Large data via iteration API ✓ Multi-Instance: Parallel encryption operations ✓ Production-Proven: Used in 50,000+ ECU units
- Proportional Gain (Kp): Immediate response to error
- Integral Gain (Ki): Eliminate steady-state error
- Derivative Gain (Kd): Predict and dampen overshoot
- Anti-Windup Compensation (Kc): Prevent integral saturation
- Setpoint (desired value): What we're trying to achieve
- Integral Accumulation: Sum of past errors
- Interval-Based Scaling: Multiplication by time step
- Lower/Upper Limits: Prevent unbounded growth (anti-windup)
- Reset Capability: Zero integrator for startup
- Rate-of-Change Calculation: (error_current - error_previous) / dt
- Derivative Filtering: Noise reduction on noisy signals
- Time-Scaled: Proper dt integration
- Output Limiting: Clamp output to realistic range
- Upper/Lower Bounds: configurable per application
- Motor controller: [-100%, +100%] duty cycle
- Speed control: [0 RPM, Max RPM]
- Dynamic Limit Update: Change bounds at runtime
- SetTuningGain: Update Kp, Ki, Kd on-the-fly
- SetSetPoint: Change target value
- SetIntervalTime: Synchronize with execution rate
- SetOutputLimits: Configure output saturation
- Start/Stop: Enable/disable controller
- Reset: Clear all internal state
- GetOutputValue: Read current output
- IsEnabled Query: Runtime status
- Inline Functions: Zero-overhead simple operations
- Static Initialization: No dynamic memory
- Floating-Point: Flexible precision (can be optimized to fixed-point)
- Time Interval Parameterization: Works at any frequency
- Motor FOC Control: Id, Iq, Speed controllers (3x PID loops)
- Battery Charger: Voltage/current control loops
- Thermal Management: Temperature setpoint tracking
- Power Conversion: LLC resonant frequency tracking
✓ Anti-Windup Built-In: Prevents common failure mode ✓ Derivative Filtering: Smoother response than raw differentiation ✓ Dynamic Tuning: Kp, Ki, Kd changeable without restart ✓ Multi-Rate Capable: Works at any frequency with time step
Six Sub-Components for Complete LLC Operation
- Phase Current Tracking: Follows reference current
- PI Control: PID with D term optional
- PWM Duty Adjustment: Modulates switching frequency
- Ramp Limiting: Smooth current transitions
- Tank Circuit Resonance: Manages resonant frequency
- Impedance Matching: Optimizes power transfer
- Zero-Voltage Switching: Minimizes switching losses
- Frequency Sweeping: Find and lock to resonance
- Power Level Tracking: Maintains output power
- Efficiency Optimization: Dynamic power flow control
- Load Sensing: Adapt to changing load
- Multiple Setpoint Support: Different power levels
- Output Voltage Regulation: Keep voltage stable
- Feedback Loop: Close-loop voltage control
- Load Line Compensation: Account for cable drops
- Cross-Regulation: Maintain multi-output rails
- Input Filtering: Remove noise from sensors
- Scaling Conversion: Raw ADC to physical units
- Averaging: Multi-sample filtering
- Outlier Rejection: Glitch immunity
- Startup Sequence: Soft-start ramp
- Operating Modes: Idle, run, standby, fault
- Transition Guards: Safe state changes only
- Fault Detection: Abnormal condition handling
- Shutdown Protocol: Graceful power-down
A seventh critical component — the secondary synchronous rectifier controller — was implemented entirely inside the TI C2000 CLB (Configurable Logic Block):
- VDS Sensing: Monitors drain-source voltage of secondary SR MOSFETs to detect body-diode conduction onset
- Optimal Gate Firing Window: Algorithm determines exact ON/OFF timing to avoid reverse current and MOSFET stress
- CPU-Independent Real-Time Core: The CLB logic runs as a standalone hardware engine with no CPU intervention after configuration
- High-Frequency Operation: Supports SR firing at switching frequencies up to 250 kHz
- Hardware Platform: Deployed on PSMB (Power Stage Module Board) and PSB (Power Stage Board)
- Real-Time Configuration: CLB is configured at startup via CPU; thereafter operates fully autonomously
Why CLB over CPU-based SR? At 250 kHz switching, the SR MOSFET firing window is measured in nanoseconds. Software-based ISR approaches introduce unacceptable latency that leads to body diode conduction losses and MOSFET current stress. Moving the SR engine to the CLB gave us hardware-speed determinism without FPGA hardware cost.
✓ Complete Topology Support: All 6 layers integrated ✓ Zero-Voltage Switching: Soft-switching for efficiency >95% ✓ Resonance Tracking: Automatic frequency adjustment ✓ Multi-Rail Support: Can parallel controllers for 3kW ✓ CLB-Based SR Firing Engine: CPU-independent secondary synchronous rectification at 250 kHz using VDS detection
- Unity Power Factor Achievement: Minimize reactive power
- Input Current Shaping: Sinusoidal current tracking
- Harmonic Reduction: Low THD (<5%)
- Boost Converter Topology: Step up voltage
- Full-Bridge Rectifier: Clean AC → DC conversion
- Control Loop: PI control of current reference
- CLB-Accelerated Inner Current Loop: The fast current control loop is implemented in the C2000 CLB hardware, running independently of the CPU. The CPU handles only the outer voltage loop and system supervision, keeping the real-time burden minimal and control latency deterministic.
- Full-Bridge Architecture: 4-switch H-bridge
- Phase Shift Modulation: Vary leading/lagging leg phase
- ZVS Capability: Zero-voltage switching
- Soft Switching: Reduce EMI
- Variable Frequency: Adapt to load
- Inrush Current Limiting: Prevent capacitor charging spike
- Soft-Start Ramp: Gradual voltage rise
- Relay Sequencing: Timed relay control
- Capacitor Charging Detection: Know when precharge complete
- Fail-Safe Timeout: Detect precharge failure
Second-Order Generalized Integrator Phase-Locked Loop
- SOGI (dsp_sogi): Second-order orthogonal generator
- Two 90° phase-shifted outputs (in-phase, quadrature)
- Bandpass filter centered at nominal frequency
- PID Controller: Frequency error correction
- DQ Transform: Convert abc → dq for analysis
- Math Functions: Sine, cosine, arctangent calculations
- Grid Synchronization: Track AC grid phase
- Frequency Estimation: Detect grid frequency deviations
- Phase Angle Extraction: Accurate phase reference
- Peak Voltage Measurement: Utility voltage magnitude
- Harmonic Rejection: Bandpass filtering
- omega_radS: Angular frequency (rad/s)
- theta_rad: Phase angle (radians)
- peak_v: Peak voltage measurement
- output: Control signal for frequency adjustment
- On-Board Charger: Synchronize with AC mains
- Grid-Tied Inverter: Phase lock to utility
- Power Quality Monitoring: Detect frequency anomalies
✓ AC Grid Synchronization: Production-grade phase tracking ✓ Noise Immunity: Bandpass filtering of harmonics ✓ Fast Lock: Typical <100ms to lock ✓ Robust: Works with distorted waveforms
- Three Hall Inputs: A, B, C for 6-step commutation
- 6-Step Pattern Recognition: Automatic state machine
- State Change Detection: Trigger on transition
- Debouncing: Filter electrical noise
- Electrical Sector Tracking: Current 60° sector (0-5)
- Commutation Pattern: Map hall pattern to sector
- Direction Detection:
- E_DDL_HALL_POSITION_SENSOR_DIRECTION_CW: Clockwise rotation
- E_DDL_HALL_POSITION_SENSOR_DIRECTION_CCW: Counter-clockwise
- Rotation Counting: Track electrical revolutions
- Sector Time Measurement: Time in each 60° sector
- Per-Phase Timing: sectorTime_A_ns_u32, sectorTime_B_ns_u32, sectorTime_C_ns_u32
- Nanosecond Resolution: Precise speed calculation
- Ideal Detect Timer: Validation of transition timing
- From Sector Time: Inverse of time = speed proportional
- Electrical Revolutions: Count motor pole pairs
- RPM Conversion: 60 / sector_time = RPM
- Callback Support: ddlHallSensorState_fnt for custom processing
- Initial State Detection: isInitalHallStateDetect_b flag
- Filtered State: isFilteredHallStateDetect_b for debounced value
- Hall Pattern (b3): 3-bit value (A, B, C states)
- Sector Number: -1 (invalid) to 5 (valid sectors)
- Changed Sensor: Which input changed (A, B, or C)
- Direction: Rotational direction from transitions
- Motor Commutation: 6-step BLDC/PMSM control
- Speed Feedback: Closed-loop speed control
- Rotor Position: Synchronize FOC angle
- Direction Control: Forward/reverse detection
✓ Noise Immunity: Debouncing and edge detection ✓ 6-Step Automatic: Handles all 6 commutation patterns ✓ Bidirectional: Detects forward and reverse rotation ✓ Nanosecond Precision: For accurate speed calculation
- Negative Temperature Coefficient: Resistance decreases with temperature
- Steinhart-Hart Equation: Non-linear temperature calculation
- Calibration Points: Multiple reference temperatures
- Temperature Range: -40°C to +125°C (automotive)
- Raw ADC Reading: Convert to voltage
- Voltage to Resistance: Ohm's law calculation
- Resistance to Temperature: Lookup table or equation
- Curve Fitting: Accurate across wide range
- Hysteresis: Prevent jitter at boundaries
- Fault Detection: Open/short circuit detection
- Rate Limiting: Smooth temperature transitions
- Motor Temperature: Thermal protection
- Battery Temperature: Charging optimization
- Board Temperature: System thermal management
- Ambient Sense: Climate-based derating
- Rectangular Integration:
integral += input * dt - Upper/Lower Limits: Prevent overflow
- Reset Capability: Zero integrator
- Inline Efficiency: Zero-overhead inlining
- Timestamp Tracking: Interval time = intervalTime_s_f32
- Rate of Change:
derivative = (current - previous) / dt - Derivative Filtering: Noise reduction on slope
- Time Scaling: Proper dt normalization
- Storage: Previous value for next iteration
- Trigonometric: Sine, cosine approximations
- Square Root: Fast sqrt (Newton-Raphson)
- Division: Safe division with divide-by-zero check
- Lookup Tables: Fast approximation vs. accuracy trade-off
- Min/Max: Clipping and limiting functions
✓ Floating-Point Precision: High accuracy for control loops ✓ Inline Optimization: Compiler elimates function call overhead ✓ Anti-Aliasing: Integrator limits prevent data loss ✓ Universal Use: Used in 50+ control algorithms
ISO 14229-1 Diagnostic Protocol (16+ Services)
- Default Session: Normal operation, limited access
- Programming Session: Bootloader mode for updates
- Extended Session: Full diagnostics, reduced safety limits
- Safety System Diagnostic: OBD-II compliance mode
- Seed/Key Algorithm: Two-level authentication
- Security Levels: Multiple unlock tiers
- Level 1: Read parameters
- Level 2: Write calibration
- Level 3: Flash programming
- Attempt Limiting: Lockout after N failed attempts
- Timeout: Auto-lock if no response
- Hard Reset: Power-cycle equivalent (used by bootloader)
- Key-Off Reset: Simulate ignition cycle
- Enable RapidPowerShutDown (RPSD): ECU-specific
- Timing: Allow reset to take effect
-
Service 0x22: Read Data By Identifier
- DIDs: Motor RPM, Battery SOC, Temperature, Voltage
- Format: 2-byte DID + variable data
- Multiple DIDs per request (batching)
-
Service 0x23: Read Memory By Address
- Direct memory read (debugging, calibration verification)
- Address + length specified
- Respects security level
-
Service 0x2E: Write Data By Identifier
- DIDs for motor parameters (Kp, Ki, Kd, limits)
- Battery calibration (OCV curve, balancing threshold)
- Charger settings (CV, CC, temperature curves)
- NVM persistence after write
-
Service 0x3D: Write Memory By Address
- Direct memory modification
- Calibration sector updates
- Requires highest security level
-
Service 0x34: Request Download
- Initiate firmware download from diagnostic tool
- Specify memory address and data length
- Check CRC/compression method
- Unlock flash for programming
-
Service 0x36: Transfer Data
- Block-by-block firmware transfer
- Sequence number tracking
- CRC validation per block
- Progress reporting
-
Service 0x37: Request Transfer Exit
- Complete firmware transfer
- Verify overall CRC
- Prepare for reset and execution
-
Service 0x35: Request Upload
- Read firmware from ECU (backup/verification)
- Useful for field diagnostics
-
Service 0x19: Read DTC Information
- Report: All DTCs, recent DTCs, pending DTCs
- Detailed: DTC + status bytes + snapshots
- Filtering: By status (stored, pending, permanent)
-
Service 0x14: Clear Diagnostic Information
- Erase stored DTCs after repair
- Clears flags, faults, snapshot data
- Requires security level 2+
-
Service 0x85: Control DTC Setting
- Enable/disable DTC recording
- Useful for calibration work
- Prevent false faults during testing
- Enable Receive: Start listening to CAN
- Disable Receive: Ignore incoming messages
- Enable Transmit: Send CAN frames
- Disable Transmit: Suppress CAN output
- Application: Isolation during bootloader mode
- Control DID: Toggle actuators from diagnostics
- Enable/disable precharge relay
- Turn on/off contactor
- Pulse pump motor
- Enable/disable charger
- Return Control to ECU: Release control after testing
- Enable Mask: Select which outputs to control
- Periodic DIDs: High-frequency data logging
- Motor telemetry: RPM, current, temperature, angle
- Battery: Cell voltages, currents, temperatures
- Charger: AC/DC voltages, currents, efficiency
- Transmission Modes:
- Send at interval: Periodic updates
- Send on change: Only when value changes
- Send on request: Query mode
- Start Routine: Execute diagnostic procedures
- Motor spin test: Verify no shaft seizure
- Thermistor test: Validate temperature sensor
- Relay test: Ensure contactor closes/opens
- CAN loopback: Verify communication
- Stop Routine: Halt test execution
- Request Results: Get test outcome
- Routine Options: Configure test parameters
- Keep-Alive Signal: Prevent extended session timeout
- Heartbeat: Diagnostic tool = "I'm still connected"
- Timeout Protection: Auto-exit session if no 0x3E for N seconds
- Session Persistence: Stay in programming/extended mode
- Negative Response (0x7F): Service error response
- NRC Codes: Negative Response Codes
- 0x31: Request out of range
- 0x33: Security access denied
- 0x35: Invalid key supplied
- 0x36: Exceeded attempt limit
- 0x37: Required time delay expired
- 0x72: General programming failure
- Standardized Format: SID + 0x40 for positive response
- Variable Length: Data payload adapts to DID/service
- CRC Appended: Data integrity check
- Timeout Management: Per-service response deadline
- 16+ Modular Services: Each service as separate .c/.h pair
- Configuration Table: Enable/disable services per build
- Security Callbacks: Custom seed/key algorithms per OEM
- DID Database: Flexible parameter definition
- Multi-ECU Ready: Support for slave ECU diagnostics
✓ Complete ISO 14229-1 Suite: 16+ services cover all needs ✓ Modular Architecture: Each service independent, easy to extend ✓ Security-First Design: Seed/key, security levels, attempt limiting ✓ Production-Proven: Used in 50,000+ vehicles across 5+ OEMs ✓ Tool Compatibility: Works with Vector CANoe, ETAS, PCAN, Python custom
- DTC Storage: Persistent NVM logging
- Severity Levels: Passive, Warning, Critical
- Status Tracking:
- Stored: Saved to EEPROM
- Pending: Detected but not confirmed
- Permanent: Recurring issue
- Timestamp: When fault first detected
- Root Cause Data: Captured sensor values at fault
- Snapshot Storage: Save ECU state at fault time
- Occurrence Count: How many times detected
- Automatic Clearing: Clear after X fault-free cycles
- History Tracking: Store multiple fault events
- Recovery Detection: Confirm fault resolution
- Circular Buffer: Oldest faults overwritten when full
- Wear-Leveling: Distribute writes across flash sectors
- Redundant Storage: Duplicate critical data
- Block Marker: Track block validity/version
- CRC Protection: Detect data corruption
- Flash Abstraction: Isolate MCAL flash drivers
- Pluggable Callbacks:
- flashEraseHandler_fnp: Sector erase
- flashWriteHandler_fnp: Word/page write
- flashReadHandler_fnp: Read bytes
- Default Data: Fallback if NVM invalid
- RAM Buffering: Work in RAM, batch write to NVM
- Size Management: Align to minimum erase unit
- WriteData: Update specific address in block
- ReadData: Retrieve from NVM or RAM buffer
- WriteAll: Flush all blocks to flash
- Sector Rotation: Move to next wear-level location
- Circular Event Log: Timestamp + event data
- High-Frequency Logging: Megabits of data
- Compression: Reduce storage via run-length encoding
- Query Interface: Retrieve log entries by date range
✓ Wear-Leveling: Flash lifetime extended 10x+ ✓ Redundancy: Single-bit flip detection/correction ✓ High-Reliability: <0.01% data corruption rate ✓ Logging Infrastructure: Forensic analysis for field failures
- 26 Driver Modules:
- ADC: Scan groups, temperature holds, filtering
- CAN: 3 channels, 8 RX FIFOs, message filtering
- Clock: PLL, clock dividers, source selection
- Flash: Erase, write, EEPROM emulation
- GPIO: Port I/O, pull-ups, open-drain
- Interrupt: Priority levels, ISR registration
- Protected Registers: Write-protected bits access
- PWM (TAPA): Timer-based PWM, dead-band
- Reset: Reset source tracking, control
- SPI (CSIH): Master/slave, baud rate control
- Timer: TAUD (unit timers), TAUB (dead-time)
- Watchdog: Overflow period, enable/disable
- 30+ Driver Modules:
- CCU4/CCU8: Capture/Compare units for PWM
- POSIF: Position interface for Hall sensors
- VADC: Voltage ADC, 12-bit precision
- CAN: Full CAN 2.0B with filtering
- GPIO: GPIO configuration
- ERU: Event Request Unit for interrupts
- RTC: Real-time clock
- SPI/USIC: Serial communication
- UART: Serial terminal
- Watchdog: Overflow, strobe mode
- Math: Hardware math accelerator
- ACMP: Analog comparator
- BCCU: Back-light CCU for LEDs
✓ Dual-MCU Support: RH850 + XMC1, identical API ✓ Complete Peripheral Coverage: 50+ peripherals total ✓ Register-Level: Direct access when needed ✓ HAL Pattern: Hardware → MCAL → BSW → APP
- Standard Integer Types: uint8_t, int16_t, float32_t, etc.
- Boolean Type: bool_t (true/false)
- Bit Utilities: Bit set, clear, toggle, test
- MIN/MAX: Minimum and maximum functions
- ABS: Absolute value
- LIMIT: Clamp value between bounds
- SWAP: Exchange two values
- Circular Buffer: Constant-size queue
- Push/Pop: Add and retrieve elements
- IsFull/IsEmpty: Boundary checks
- Available Count: Elements ready to consume
- Array Sort: Quicksort or insertion sort
- Binary Search: Fast lookup
- Memcpy/Memset: Memory operations
- Digital In: Read GPIO pins
- Digital Out: Write GPIO pins
- Pull-Up/Pull-Down: Configure termination
- Analog Input: Read ADC with scaling
- Analog Output: Write DAC or PWM voltage
- Voltage Scaling: ADC counts → physical units
- Ramp Generator: Smooth output transitions
- Example: Boost voltage 0→400V in 1 second
- Prevents inrush current spikes
- Unit Conversion: Raw ADC → Voltage/Temperature/Current
- Offset/Gain Correction: Per-channel calibration
- Hysteresis: Prevent jitter on thresholds
- Rate Limiting: Max dV/dt, dI/dt constraints
(Detailed features covered earlier, but adding specifics)
- Multiplexed Signals: Conditional based on multiplexer
- Extended Signals: 32+ bit values
- Array Signals: Repeated signal groups
- Float Signals: IEEE 754 floating-point
- Phased Transmission: Stagger CAN messages to prevent flooding
- Message Priority: High-priority messages sent first
| Module | Key Features | Production Use |
|---|---|---|
| OS | Scheduler, Tasks, State Machines, Queues, Timers | 10kHz FOC loop |
| CAN-TP | ISO 15765-2, Segmentation, Flow Control, 3 Timers | Bootloader updates |
| CAN Matrix | DBC parsing, Multiplexing, Scaling, Signal packing | Multi-ECU communication |
| CRC | CRC-8/16/32, Table-driven, Incremental | Data integrity |
| AES | FIPS-197, 5 modes, 128/192/256-bit keys | Firmware encryption |
| PID | Anti-windup, Multi-rate, Dynamic tuning | FOC, Charger, Thermal |
| LLC | 6 sub-modules, ZVS, Resonance tracking | 3kW charger |
| PFC | Unity power factor, THD <5% | AC charger input |
| PSFB | Phase-shift, ZVS, Soft switching | Alternative topology |
| Precharge | Inrush limiting, Soft-start | Grid connection |
| SOGI-PLL | Grid sync, Frequency tracking | OBC AC input |
| Hall Driver | 6-step, Debouncing, Direction detect | Motor commutation |
| Thermistor | NTC curves, -40°C to +125°C | Thermal protection |
| Math | Integrator, Differentiator, Trig, sqrt | All control loops |
| UDS | 16+ services, Security levels, 3-tier unlock | Field diagnostics |
| FCM | DTC storage, Snapshots, History | Fault logging |
| NVM | Wear-leveling, Redundancy, CRC | Parameter storage |
| RH850 MCAL | 26 drivers, 3 CAN, ADC, PWM, Flash | BMS production |
| XMC1 MCAL | 30+ drivers, CCU, POSIF, VADC | Motor controller |
| Common | Ring buffers, Bit ops, Min/Max, Sort | Utility layer |
| I/O | Digital/Analog, Scaling, Ramping | Hardware abstraction |
This section documents production On-Board Charger (OBC) and Offline Front Boost Charger (OFBC) implementations with complete control algorithms, multi-stage power conversion, and multi-ECU coordination.
- Purpose: Integrated 48V charger for vehicles
- Power Topology: PFC (Power Factor Correction) + PSFB (Phase-Shift Full-Bridge) + Secondary Rectification
- Multi-Stage Conversion:
- Stage 1 (PFC): AC mains → Intermediate DC bus (with unity power factor)
- Stage 2 (PSFB): Isolated conversion via transformer
- Stage 3 (Secondary Rectification): Isolated DC → 48V battery output
- Purpose: Standalone fast charger for vehicles
- Topology Variants:
- LLC (Liquid Level Control): Resonant converter for efficiency
- PFC + LLC Combination: Input power factor + output isolation
- TATA 3-in-1: Multiple charging profiles in single unit
- Power Range: 3kW (typical DC fast charging)
- CPU Layer: Main processor (C28x core) with state machines, calibration, diagnostics
- CLA Layer: Compute-Like Accelerator for real-time control (interrupt-driven, microsecond precision)
- BSP Layer: Hardware abstraction (ADC, PWM, sensors, relays)
- Real-Time Data Exchange: CPU ↔ CLA via shared memory variables with atomic access
1.1 Charger State Machine (app_charger_state_machine)
States (11 total + fault):
OFF → BATTERY_CONNECT_VERIFY → ON → ON_CHARGING {
- ON_CHARGING_BATTERY_COUPLING (connector verification)
- ON_CHARGING_CURRENT (CC phase - constant current)
- ON_CHARGING_CURRENT_SLOW (limited power)
- ON_CHARGING_CURRENT_FAST (maximum power)
- ON_CHARGING_VOLTAGE (CV phase - constant voltage)
} → ON_FINISHED → OFF
FAULT (any error condition)
Fault Tracking (8 fault conditions):
vcuDisconnect_b: Vehicle Control Unit disconnected (lost CAN signal)longDurationCharge_b: Charging exceeded maximum duration limitoverBatteryVoltage_b: Cell voltage > 4.2V (protection cutoff)underBatteryVoltage_b: Cell voltage < 2.0V (unable to charge)overTemperature_b: Battery temperature > 60°C (thermal shutdown)underTemperature_b: Battery temperature < 0°C (no charging allowed)batteryCoupling_b: Connector not properly seatedinputSupplyCutOff_b: AC mains power lost
Timers (4 critical timing functions):
longDurationChargeTimer_s: Max charge duration (prevents overcharge)batteryCouplingTimer_s: Connector verification delaybatteryConnectVerifyTimer_s: Battery presence checkrestartDelayTimer_s: Post-fault restart delay
1.2 Signal Conditioner (app_charger_signal_conditioner)
- Input Filtering: Multi-point ADC averaging
- Scaling: Raw ADC counts → physical units (voltage, current, temperature)
- Outlier Rejection: Remove sensor noise spikes
- Thermal Compensation: Temperature-dependent scaling coefficients
- Moving Average: Smooth transitions to reduce state machine jitter
1.3 Fan Control System
- app_fan_state_machine.c: Fan speed control logic
- app_fan_signal_conditioner.c: Fan sensor feedback filtering
- Thermal Modulation: Fan speed proportional to board temperature
- Fault Detection: Stalled fan detection (no speed feedback)
1.4 Derate System (app_derate)
Multi-Factor Derating with Adaptive Ramp:
Factor 1: Input Current Limiting
- Parameter:
currentInput_s.currentInputLimit_Arms_f32 - Effect: Reduces output power if AC input current exceeds limit
- Use Case: Site-specific circuit breaker ratings (e.g., 16A vs. 32A circuit)
Factor 2: Temperature-Based Multi-Point Derating
- 5 Temperature Points (indexed 0-4):
- Each point has: [temperatureStart, temperatureEnd, powerLimit]
- Example:
- Point 0: 0-30°C → 3000W
- Point 1: 30-40°C → 2500W
- Point 2: 40-50°C → 2000W
- Point 3: 50-60°C → 1500W
- Point 4: >60°C → Shutdown
- Dynamic Tracking: Identifies which temperature point is most limiting
- Ramped Application: Smooth power reduction (prevents sudden shutdown)
Factor 3: Fan Fault Derating
- If fan fails: Reduce output power to 50% to allow thermal recovery
- Ramp Time: 5 seconds (smooth degradation)
- Auto-Recovery: Normal operation if fan recovers
Factor 4: Primary Current Derating
- Parameter:
primaryCurrent_s.currentvalueForDerateStart_A_f32 - Detects high transformer current (indicator of DC-link issues)
- Gradually reduces output current to prevent thermal runaway
Combined Derating Logic:
effective_power = min(
power_from_input_limit,
power_from_temperature_derate,
power_from_fan_fault_derate,
power_from_primary_current_limit
)
1.5 Hardware Monitoring (app_hw_monitor)
- Continuous sensor validation
- Over/under-voltage detection on all rails
- Over-current detection on primary/secondary
- Thermal limit enforcement
- Fan speed verification
1.6 Energy Metering (app_energy_meter)
- Integration Method: E(t) = ∫ P(t) dt
- Sampling Time: Configurable (typically 10-100ms)
- Active Time Tracking: Only counts when charging active
- Accuracy: ±2% over full charge cycle
- NVM Storage: Total energy transferred to battery (for diagnostics)
- Callback Interface: Allows custom measurement functions
1.7 Calibration System (app_calibration)
- ADC Offset Compensation: Remove sensor zero-error
- Gain Scaling: Factory trim for voltage/current measurement
- Temperature Coefficients: Adjust for thermal drift
- CAN-Based Update: Recalibrate without firmware reload
- EEPROM Storage: Persist calibration across power cycles
1.8 Recovery & Watchdog (app_recovery)
- Watchdog Timer: Hardware watchdog triggers reset if software hangs
- Graceful Shutdown: Order of operations on watchdog trigger
- State Preservation: Store operating state before reset
- Post-Recovery: Verify system health after restart
2.1 PFC (Power Factor Correction) - bsp_pfc
Real-Time Measurements:
-
BSP_Pfc_GetVoltageInput(): AC phase-to-neutral voltage- Raw ADC: ADCARESULT_BASE
- Conversion:
adcValue * 0.1825F(scale factor from hardware) - Note: Measures differential voltage (phase - neutral)
-
BSP_Pfc_GetCurrentInput(): AC input current with offset calibration- Offset Tracking:
currentOffsetAdcValue = LIMIT(..., 405.0F, 420.0F) - Dynamic centering: Removes DC bias from shunt measurement
- Conversion:
(adcValue - offset) * 0.009155F(A/LSB) - Safety:
MAX(0.0F, current)prevents negative current reporting
- Offset Tracking:
-
BSP_Pfc_GetVoltageOutput(): Intermediate DC bus voltage- Conversion:
adcValue * 0.2274F * 0.9885F(includes accuracy trim) - Typical range: 0-400V
- Conversion:
Control Interface:
BSP_Pfc_SetCurrentInputReference(): Set target AC current (for input limiting)BSP_Pfc_SetCurrentControllerStart(): Enable/disable controllerBSP_Pfc_SetDuty(): Directly control PWM duty cycle (0-100%)
Control Algorithms (run in CLA):
- PI current controller tracking sine wave reference
- Zero-crossing detection for grid synchronization
- Harmonic distortion minimization (<5% THD target)
- Soft-start ramp to prevent inrush current
2.2 PSFB (Phase-Shift Full-Bridge) - bsp_psfb
Architecture: 4-switch H-bridge with secondary rectifier switches
Hardware Components:
- Primary FETs: AB-leg (PWM1, PWM2) + CD-leg (PWM4, PWM5)
- Secondary Rectifier: SR1 (PWM8) + SR2 (PWM3) - "diode emulation"
- Transformer: Isolated DC-DC conversion
- Output: 48V battery side
Dead-Band Control (Critical for Soft-Switching):
uint16_t deadTimeCount_u16 = (uint16_t)(i_deadTime_ns_f32 * 0.120F);
// 0.120 = CPU frequency factor (8.333ns per count @ 120MHz)
// Typical: 200ns dead-time = 24 counts
EPWM_setRisingEdgeDelayCount(EPWM7_AB_LEG, deadTimeCount_u16);
EPWM_setFallingEdgeDelayCount(EPWM7_AB_LEG, deadTimeCount_u16);
EPWM_setRisingEdgeDelayCount(EPWM5_CD_LEG, deadTimeCount_u16);
EPWM_setRisingEdgeDelayCount(EPWM8_SR1, deadTimeCount_u16); // Secondary rectifier
EPWM_setRisingEdgeDelayCount(EPWM3_SR2, deadTimeCount_u16); // Secondary rectifierPhysical Process During Dead-Band:
- Primary MOSFET (e.g., Q1) turns off
- Dead-band delay starts: 200ns = time for Q1 to fully block
- During this time, transformer current flows through body diode of Q2 (other leg)
- Q2 can then turn on with ZVS (zero-voltage switching) because its voltage is already zero
- Result: No switching losses during turn-on
On-Time Percentage Control:
BSP_Psfb_SetOnTimePercentage(): Sets duty cycle- Example: 50% duty = square wave
- Dynamic adjustment: Varies duty to regulate output voltage
Phase Shift Modulation:
float32_t psfbPhaseShift_deg_f32 = LIMIT(i_phaseShift_deg_f32, 10.0F, 170.0F);
uint16_t pwmCount_u16 = (uint16_t)((psfbPhaseShift_deg_f32 / 360.0F) * EPWM7_AB_LEG_PWM_TBPRD);
// Set CD-leg delay relative to AB-leg
EPWM_setPhaseShift(EPWM5_CD_LEG_PWM_BASE, (EPWM7_AB_LEG_PWM_TBPRD - pwmCount_u16));Diode Emulation Logic:
- Secondary MOSFETs (SR1, SR2) are driven with gate signals
- Logic: When transformer current wants to reverse (indicating secondary diode would conduct), turn on SR1/SR2 instead
- Gate Drive: Isolated driver circuit ensures proper timing
- Comparator-Based Detection:
g_secondaryMosfetSwitchingStartComparator_s- Detects transformer current direction change
- Triggers SR1/SR2 gate driver
- Hysteresis prevents chatter
2.3 LLC Resonant Converter - bsp_llc (for OFBC)
Resonant Tank Components:
- Primary inductor Lm
- Leakage inductor Lk
- Tank capacitor C
- Resonant frequency: f_res = 1 / (2π√(Lk * C))
Control Parameters:
-
BSP_Llc_SetFrequency(): Vary switching frequency to control power- Below resonance: More power transfer
- Above resonance: Less power transfer
- Resonance point: Maximum efficiency
- Calculation:
frequencyCount = 120MHz / desired_frequency
-
BSP_Llc_SetWidth(): On-time of primary switch- Width in nanoseconds:
widthCount = i_width_ns * 0.120F - Typical: 500-5000ns depending on frequency
- Width in nanoseconds:
-
BSP_Llc_SetDeadTime(): Dead-band between primary legs (same as PSFB)
Light-Load Detection (LLC-Specific Feature):
BSP_Llc_LightLoadDetectorExecute(); // Check current level
BSP_Llc_LightLoadDetectorComparatorExecute(); // Compare to threshold
bool_t isLightLoad = BSP_Llc_IsLightLoadDetected();- Purpose: At very light load (<5%), LLC efficiency drops if frequency is too high
- Compensation: Reduce frequency or switch to skip-cycle mode
- Resistive Load Detection: Separate algorithm for resistive vs. reactive loads
Frequency Tracking Algorithm:
- Start at fixed frequency
- Monitor output voltage
- If Vo too low: decrease frequency (increase power)
- If Vo too high: increase frequency (decrease power)
- Self-optimizing toward resonance for maximum efficiency
CLA Task Interrupt Functions:
3.1 ClaTask_Initialize()
- Runs once at system startup
- Configures ADC trigger points
- Initializes PI controller coefficients
- Sets up data memory shared with CPU
3.2 ClaTask_CurrentControlConfiguration()
- Configures current control parameters from CPU updates
- Converts calibration factors
- Sets PI loop gains (Kp, Ki, Kd)
- Handles mode switching (slow/fast charging)
3.3 ClaTask_CurrentControl() (Main Real-Time Loop - 10kHz)
┌─ ADC Sample Trigger (PWM-synchronized)
├─ Read: AC input voltage, current, transformer primary current
├─ Read: Battery voltage, output current, temperatures
├─ PI Controller:
│ ├─ Calculate error: error = setpoint - feedback
│ ├─ Proportional: Kp * error
│ ├─ Integral: Ki * ∑error * dt
│ ├─ Derivative: Kd * d(error)/dt
│ ├─ Apply limits & anti-windup
├─ Output: New PWM duty/frequency command
├─ Write shared variables for CPU to read
└─ Next interrupt (100µs later)
Execution Time Budget: <50µs (to leave margin for other ISRs)
Data Exchange with CPU (Atomic via Dual-Port RAM):
// CPU → CLA (set by CPU, read by CLA)
extern float32_t g_cpuToClaPfcCurrentInputReference_A_f32;
extern float32_t g_cpuToClaOnTimePercentage_f32;
extern bool_t g_cpuToClaPfcCurrentControllerEnable_b;
// CLA → CPU (set by CLA, read by CPU)
extern float32_t g_claToCpuPfcVoltageInput_f32;
extern float32_t g_claToCpuPfcVoltageOutput_f32;
extern float32_t g_claToCpuLlcFrequency_Hz_f32;
extern float32_t g_claToCpuLlcWidth_ns_f32;
extern bool_t g_cpuToClaIsLlcLightLoad_b;3kW 48V Fast Charger Architecture:
- AC Input: 85-264V single-phase AC mains
- PFC Stage: Boost converter achieving unity power factor
- Isolation: LLC resonant converter with transformer
- Output Rectification: Secondary diode bridge + LC filter
- Output: 48V at up to 62.5A (3000W)
Efficiency Target: >92% from AC mains to DC output
Key Algorithms:
- Resonance Tracking: Automatic frequency sweep to find resonant point
- Light-Load Mode: Skip-cycle operation to maintain efficiency at <20% load
- Soft-Start: 5-second ramp from 0W to full power
- Thermal De-Rating: Temperature-dependent power limit
Simplified Single-Stage:
- PFC Boost converter directly to 48V battery
- No transformer isolation (for lower cost variants)
- Faster transient response (direct DC transfer)
| Feature | OBC-PSFB | OFBC-LLC | OFBC-PFC |
|---|---|---|---|
| Topology | PFC + PSFB + Secondary Rect. | PFC + LLC | Boost PFC Only |
| Isolation | Yes (transformer) | Yes (transformer) | No |
| Power | 2-3kW | 3kW | 1-2kW |
| Efficiency | 94% | 95%+ | 92% |
| Control Points | Phase shift + duty | Frequency sweep | Duty cycle only |
| Dead-Band Requirement | Critical | Critical | Not needed |
| Cost | Medium-High | High | Low |
| Soft-Switching | Yes (ZVS) | Yes (Resonant) | Partial |
| Light-Load Mode | Simple PWM reduction | Skip-cycle | PWM reduction |
| CLA Interrupt Rate | 10kHz | 10-20kHz | 10kHz |
✅ Multi-Factor Adaptive Derating: 4-point limiter with smooth ramping prevents sudden power cuts ✅ Dead-Band Precision: Nanosecond-level control for zero-voltage switching efficiency ✅ Resonance Tracking: Automatic frequency sweep achieves 95%+ efficiency at any load ✅ Diode Emulation: Secondary MOSFETs replace passive diodes, reducing losses 20% ✅ CPU-CLA Coordination: Real-time DSP in CLA + state management in CPU (no mutex needed) ✅ Multi-Topology Support: Same firmware base supports LLC, PSFB, PFC variants ✅ Integrated Diagnostics: UDS diagnostic server monitors charger parameters in real-time ✅ Production Scale: 5,000+ units deployed across multiple OEMs
This portfolio demonstrates complete embedded systems mastery:
| Layer | Component | Achievement |
|---|---|---|
| Application | FOC, Hill Assist, Range Est., Energy Meter | Production motor control at entry-level MCU limits |
| Control Algorithms | PID, Derate, Thermal Model, SOC Est. | Predictive systems preventing failures 30% early |
| Diagnostics | 16 UDS Services, FCM, Telemetry | ISO 14229-1 multi-vendor compatible |
| Security | AES-256 with 5 modes | FIPS-197 boot/OTA protection |
| OS/Scheduler | Preemptive RT, State Machines | 10 kHz deterministic FOC loop |
| Hardware | MCAL Dual-MCU (RH850, XMC1) | Single codebase, 2 microcontrollers |
| Power Conversion | LLC, PFC, PSFB, Resonant | 3kW charger with multiple topologies |
| Safety | Bootloader, AIS156, Redundancy | 8K+ productions, 0 bootloader failures |
| Integration | 6 ECUs, 23 Modules, Multi-MCU | Scalable, modular, production-proven |
Each layer built on the previous, creating a cohesive, production-grade automotive ecosystem.
| Period | Role | Company | Location |
|---|---|---|---|
| April 2022 — Present | Technical Lead | FORVIA HELLA eMobionics Pvt Ltd | Pune, Maharashtra |
| July 2021 — April 2022 | Technical Specialist | Elektrobit India Pvt Ltd | Bangalore, Karnataka |
| April 2018 — June 2021 | Software Development Engineer | Lucas TVS Ltd | Chennai, Tamil Nadu |
| September 2016 — March 2018 | Engineer | ELGI Ultra Industries Ltd | Coimbatore, Tamil Nadu |
| June 2014 — August 2016 | FPGA and Embedded Programmer | Crisp System India Pvt Ltd | Coimbatore, Tamil Nadu |
FORVIA HELLA eMobionics Pvt Ltd (April 2022 — Present)
- Technical Lead for 2W/3W EV embedded software products
- Architected and delivered the reusable BSW middleware platform
- Led Motor Controller (L1 & L2), BMS, OBC, OFBC product deliveries
- Built and scaled the embedded software team from 2 to 8 engineers
- Drove ASPICE-aligned development processes and ISO 26262 ASIL-C compliance
- Interfaced with OEM customers (Hero Electric, TATA, TVS, Santhos) for technical alignment
Elektrobit India Pvt Ltd (July 2021 — April 2022)
- AUTOSAR BSW integration and configuration specialist
- ComStack, DiagStack, MemStack, ComplexDriver integration
- MCAL migration for automotive ECU projects targeting Renesas and other MCUs
- Gained deep AUTOSAR architecture knowledge applied to in-house middleware design
Lucas TVS Ltd (April 2018 — June 2021)
- Motor controller development (STM32, BLDC, FOC discovery)
- IoT product development (Smart Refrigerator with OTA)
- Microcontroller peripheral drivers, bootloader development
- Shifted from analog/triac control to software-centric motor control paradigm
ELGI Ultra Industries Ltd (September 2016 — March 2018)
- Embedded product development for home appliance motor control
- AC universal motor face-angle control, encoder-based speed regulation
- PID loop implementation and VFD (Variable Frequency Drive) integration
- Professional-grade reliability and load-adaptive control strategies
Crisp System India Pvt Ltd (June 2014 — August 2016)
- FPGA development (Xilinx Spartan 3E) and embedded programming
- Servo, DC, and multi-phase motor control for robotics applications
- Hardware-software co-design foundation
- Diverse motor types: servo, micro-servo, high-speed, 3-phase
B.E. — Electronics & Communication Engineering
- Institution: Maharaja Engineering College, Avinashi
- Result: First Class — 72%
- Year: 2014
Diploma — Electronics & Communication Engineering
- Institution: Ruthraveni Muthuswamy Polytechnic College
- Result: First Class — 89%
- Year: 2011
| Issuer | Course / Certification |
|---|---|
| TÜV SÜD | Functional Safety Engineer — ISO 26262 (Certified) |
| C-DAC | Embedded System and Design |
| pManifold | EV Systems and Modeling |
| NPTEL | Fundamentals of Electric Vehicles |
| TI Online | Teaching Old Motors New Tricks (C2000 & Motor Control) |
| Udemy | RTOS, Bootloader Development, BMS Design, Clean Code, CI/CD |
Production/Professional:
- Renesas RH850 F1KM (Automotive-grade, ASIL-C)
- Renesas RL78
- Infineon XMC1400 (Cortex-M0, Motor Control)
- STM32 (ARM Cortex-M0+, M3)
- dsPIC33EV (Microchip DSP MCU)
- TI C2000 (DSP + CLB for power conversion)
Research/Prototyping:
- PIC 16F / 18F
- ARM7 LPC2148
- Xilinx Spartan 3E (FPGA)
- Arduino (various)
- Raspberry Pi
| Language | Proficiency | Primary Use |
|---|---|---|
| Embedded C | Expert | Production firmware |
| C++ | Proficient | OOP patterns, tooling |
| Python | Proficient | UDS tools, calibration GUIs, automation |
| Assembly | Working | Startup code, optimization |
| HDL (VHDL/Verilog) | Working | FPGA design (Crisp era) |
| MATLAB | Working | Simulation, algorithm prototyping |
| Shell Script / Makefile | Working | Build systems, CI/CD |
| XML / YAML / JSON | Working | Configuration, CI pipeline |
| Markdown | Daily | Documentation |
Automotive / Embedded:
- CAN / CAN-FD (ISO 11898)
- J1939 (SAE)
- UDS — ISO 14229 (Diagnostic)
- ISO-TP — ISO 15765 (Transport)
- OBD-2
Peripheral:
- SPI, I2C / SMBus
- UART / USART
- Modbus
- 1-Wire
- AUTOSAR (BSW concepts, integration experience at Elektrobit)
- ISO 26262 — Functional Safety (TÜV SÜD certified)
- ASPICE — Automotive SPICE
- V-Model SDLC
- SOLID Principles
- Design Patterns (Strategy, Observer, State Machine, Singleton, Factory)
- PlantUML (architecture documentation)
- ANSYS SCADE (model-based development awareness)
| Tool / Practice | Usage |
|---|---|
| MISRA-C:2012 | Coding standard, enforced via static analysis |
| Unity / Ceedling | Unit testing framework for embedded C |
| CMock | Hardware mock generation for unit tests |
| Robot Framework | System-level test automation |
| Helix QAC | MISRA static analysis (automotive grade) |
| PC-lint | Secondary static analysis |
| Code Coverage | Branch/decision coverage reporting |
| Cyclomatic Complexity | Enforced per-function limits |
| Static Stack Analysis | Prevent overflow in ASIL paths |
- Git (branching strategies, sub-module management)
- GitLab CI/CD (automated build, test, static analysis pipelines)
- Docker (containerized build environments)
- Travis-CI
- Doxygen (automated API documentation)
- Jira (agile project management)
- IBM DOORS (requirements management)
- SVN (legacy)
- Qt Designer (Python GUI for calibration and UDS tools)
- GitHub Copilot (AI-assisted development)
- Lauterbach TRACE32 (multi-core debugging)
- iSystem winIDEA
- GDB / OpenOCD
- Renesas E1 / E20 debugger
- LTspice (circuit simulation)
- Proteus (embedded simulation)
- Oscilloscope & Logic Analyzer (hardware debugging)
These 8 principles guide every architectural decision in Gokul's projects:
Strict separation between Application, Services/Middleware, Drivers, and Hardware layers.
- Changes in one layer must not cascade through the system
- Clear API contracts between layers
- Layer-to-layer communication only through defined interfaces
- Impact: Bug fixes in BSP don't require application retesting
Abstract all hardware dependencies behind clean interfaces.
- Migrate to a new MCU by replacing only the MCAL/BSP layer
- Application and middleware layers are hardware-agnostic C code
- Dual target strategy: All code runs on PC host AND MCU target
- Impact: RH850 → XMC1 migration with zero middleware changes
Each reusable module lives in its own repository.
- Products compose modules via Git sub-modules
- Module updates propagate to all products via sub-module pull
- Independent versioning per module
- Module bugs fixed once, all products benefit
- Impact: 23 modules across 6 products — zero code duplication
Middleware and application software developed and tested on both PC and MCU simultaneously.
- PC target: Fast development, unit testing with mocks
- MCU target: Hardware validation with real peripherals
- No hardware dependency in business logic
- Impact: 60% faster ECU bring-up; testing before silicon arrives
Object-oriented patterns emulated in C enable scalability and testability.
- Structs as objects, function pointers as polymorphism
- Multiple instances: Each module instantiated independently
- Encapsulation: Private state hidden behind API
- Impact: PID controller, LLC controller, CAN-TP — all multi-instance
All changes documented before implementation.
- Software structure, naming, and team organization mirror the domain
- Domain language used in code (not generic "handler" or "manager")
- Docs always current because they're written first
- Impact: New team members productive within weeks, not months
Tests written before code — Red, Green, Refactor.
- Catches defects early when cost of fix is lowest
- Enables fearless refactoring
- Test coverage is a first-class deliverable
- Every module has a test suite before merging
- Impact: 80% of bugs caught before integration testing
Every module must pass all gates before release:
- MISRA-C:2012 static analysis (zero violations)
- Unit tests passing with coverage targets met
- Code review sign-off
- Documentation up to date
- CI/CD pipeline green
- Impact: <0.1% field failure rate (vs. 1-2% industry average)
Published on LinkedIn. All articles demonstrate Gokul's philosophy of sharing domain knowledge publicly.
- Theme: Object-oriented design patterns (encapsulation, polymorphism, multiple instances) implemented in pure C
- Key insight: OOP is a mindset, not a language feature. C can achieve the same benefits with discipline.
- Application: All 23 middleware modules follow these patterns
- Theme: Strategic approach to applying TDD to DSP code — digital filters, IIR, control systems
- Key insight: DSP functions have deterministic outputs for known inputs — ideal for unit testing
- Application: All control algorithm modules (PID, LLC, PFC) have unit test suites
- Theme: Balancing software architecture, development processes, and team skills
- Key insight: Technical excellence without process rigor fails at scale; process without technical depth creates mediocrity
- Application: Team-building approach at FORVIA HELLA
- Theme: Using unit tests as a safety net when refactoring embedded legacy codebases
- Key insight: Refactoring without tests is guessing. Tests make refactoring a confident activity.
- Application: Monolith-to-modular migration strategy
- Theme: Personal transformation from "unit testing is overhead" to "unit testing is the foundation"
- Key insight: The cost of not testing is always greater than the cost of testing
- Application: Drove TDD adoption across the entire embedded team
Last Synced: 2026-06-30 — Content sourced from portfolio website (index.html, main.js) and experience deep-dive interviews.