Access Official Technical PDF

Share Summary:LinkedInEmail

Developing control software for an electric powertrain involves more than designing an algorithm. Engineers must translate system requirements into reliable embedded code, account for real-time execution, and verify how the controller interacts with the electrical and mechanical plant. Model-based design for motor control provides a workflow for linking these activities through models, simulation and progressively more representative testing.

A development study of an ePowertrain controller illustrates this approach by comparing two implementation paths: hand-written C and code generated from a model. Both were intended for the same microcontroller-based target, with performance evaluated using hardware-in-the-loop (HIL) testing. The comparison is useful not because one approach is universally superior, but because it highlights the practical questions teams need to answer when selecting a control-software workflow.

What model-based design contributes to motor control

In model-based design (MBD), engineers represent system behaviour and control logic in an executable model. Rather than treating a diagram as documentation alone, the model can be simulated and used to explore how components interact. In an electric-drive project, the work may involve models of the inverter, motor and control algorithm, alongside the signals and operating conditions relevant to the application.

This shared representation can support several activities:

  • System-level simulation: Examine interactions among the controller and plant before relying on physical hardware.
  • What-if analysis: Change model parameters or assumptions to assess alternative design choices.
  • Virtual prototyping: Investigate system behaviour before a physical prototype is available.
  • Continuous verification: Test the design at multiple development stages and identify issues earlier.
  • Knowledge sharing: Use a common model to communicate design intent across engineering teams.

For motor-control engineers, the model is also a place to make assumptions visible. Converter and machine models can begin with simplified representations that capture dominant behaviour, then be refined as the design needs become clearer. This helps teams distinguish between the behaviour they need to validate and effects that have initially been left out.

From control model to embedded code

Automatic code generation can turn a model into source code intended for an embedded processor. In a typical workflow, a build process interprets the model description together with target-specific information, then produces source and header files and build instructions. The generated result must still be integrated with the target platform, including its hardware interfaces and software environment.

This distinction matters: generating algorithm code does not, by itself, complete an embedded control implementation. The controller must interact with peripherals such as analog-to-digital converters (ADCs), which acquire measured signals, and timer or capture/compare units used to manage pulse-width modulation (PWM). The target also needs software scheduling appropriate to the control task.

A real-time operating system (RTOS) is designed to provide predictable task execution and response within defined timing constraints. Its purpose is not simply to make code run as fast as possible. For a control application, engineers need to consider whether execution and scheduling behaviour meet the system’s timing requirements.

A staged path to hardware-in-the-loop testing

MBD supports a progression from model evaluation toward tests involving the target controller. Early simulation can help check the plant and control design without physical hardware. Subsequent stages can assess software behaviour and, where applicable, run compiled code on the target processor. HIL testing adds a real controller to a real-time simulation environment, allowing the embedded implementation to interact with a simulated plant.

In the ePowertrain development work, a real-time HIL system was used to evaluate motor-control implementations on the target board. The test sequence included checks of ADC behaviour and a single inverter leg with an RL load, followed by control tests such as voltage-to-frequency (V/f) and current-to-frequency (I-f) control. An interior permanent magnet (IPM) motor model was also included in the described tests.

Such staged testing helps teams inspect different parts of the control chain. A peripheral test can reveal whether signals are being acquired or generated as expected. A load-based test can exercise inverter switching behaviour. Later control tests can examine the interaction between the algorithm and a model of the motor or load. HIL does not replace all other verification, but it provides a way to assess the controller in a real-time setup before testing against a physical powertrain.

Choosing between generated code and hand-written C

Comparing generated code with user-written C involves more than measuring control performance. Implementation effort, maintainability, target integration and the suitability of available tools also matter. A model-based workflow may help teams simulate and verify designs throughout development, but adopting it requires engineers to learn modelling practices and work within the capabilities of the chosen environment.

Hardware support is another practical consideration. Target-specific libraries or a board support package may be needed to connect generated code to the microcontroller’s peripherals. Developing and maintaining that support can require significant effort, particularly when it serves only a short-term project. Teams should also verify that the generated implementation preserves the intended model behaviour on the target; the model and deployed code should not be assumed to be identical in every operational detail.

Hand-written C gives developers direct control over implementation, but it does not remove the need for structured modelling, testing or timing analysis. A fair comparison therefore uses the same target and test conditions where possible, and considers both engineering workflow and measured behaviour. The available study describes this comparison as an objective; it does not establish a universal result in favour of either implementation method.

Practical implications for engineering teams

For system integrators and product teams, the central value of model-based design is the opportunity to connect requirements, executable behaviour, code generation and verification in one development process. Its usefulness depends on the quality of the models, the fit of the tools to the target hardware and the team’s ability to validate each transition from simulation to embedded execution.

When assessing an MBD workflow for motor control, teams should define which system behaviours need modelling, identify peripheral and RTOS integration requirements, and plan tests that progress from individual interfaces to representative control scenarios. They should also evaluate the learning and support costs alongside potential benefits to simulation and test automation.

In practice, model-based design is best treated as an engineering method to evaluate against project needs—not as a guarantee of faster development or better control performance. Combined with staged verification and HIL testing, it gives teams a structured way to examine electric-drive control software before committing to full system integration.

Access Official Technical PDF

About The Author