Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
AMDC Platform
AMDC Platform

GitHub Repositories

  • AMDC-Hardware
  • AMDC-Firmware

Getting Started

  • Onboarding
  • Tutorials
    • Meet the AMDC
    • Blink
    • Hardware Commands
    • Voltage Source Inverter
    • Profiling Tasks
    • Timing & Sensors
    • Autogen
  • Advanced Tutorials
    • Custom Control Rate
    • Custom FPGA IP Core
  • User Guide
    • Host Interface
      • Python Wrapper
    • Signal Logging
      • Buffered
      • Streaming
    • Signal Injection
    • Task Profiling
    • Math Benchmarks
    • AMDS Interface
  • Control with AMDC
    • Current Sensor Calibration
    • Encoder Feedback
    • Firmware Development Using Simulink Code Generation
    • Integrator Anti-Windup

Hardware

  • Hardware Overview
  • Obtaining Hardware
  • Subsystems
    • PicoZed
    • Analog Input
    • Encoder Input
    • Power Distribution
    • Power Stack Interface
    • Expansion Port
  • PCB Revisions
    • Firmware Upgrades Per Hardware Target
    • REV D Hardware
      • REV D Bring-Up
      • REV D Errata
      • REV D Pin Mapping
    • REV E Hardware
      • REV E Bring-Up
      • REV E Pin Mapping
    • REV F Hardware
      • REV F Bring-Up
      • REV F Pin Mapping

Firmware

  • Firmware Overview
  • Development
  • Architecture
    • Drivers
      • GPIO Port Mux Driver
      • Inverter Status Mux Driver
      • Encoder Driver
      • Eddy Current Sensor Driver
    • System
    • Timing Manager
    • User Apps
  • Xilinx Tools
    • Installing Xilinx Tools
    • Building and Running Firmware
    • Flashing AMDC
    • Create Private Repo
    • Create Custom User App
    • Dual Core
    • Low-Level Debugging

Accessories

  • AMDS
    • AMDS in Action
    • Firmware
      • AMDS Daisy Chain
      • Building and Running Firmware
    • Mainboard
    • Sensor Cards
      • High Voltage
      • Low Voltage
      • Current
  • μInverter
    • Hardware Design
    • Connections
    • RL Estimation
  • DAC
    • PCB Electrical Tests
  • TestBoard
  • Analog Encoder

Contribution

  • Developers

Versions

  • v1.0
  • v1.1
  • v1.2
  • v1.3
  • v1.4
  • Latest
Back to top
View this page
Edit this page

Firmware Development Using Simulink Code Generation¶

Background¶

Simulink provides a MATLAB-based graphical environment for modeling and simulating control systems. It is extensively used to model, simulate, and analyze complex dynamical systems, including motor drives. Its user-friendly block diagram environment in Simulink allows control algorithm to be developed and validated in simulation before they are implemented on the embedded hardware.

To apply the controller developed in Simulink to the AMDC platform, we use Simulink Code Generation and Embedded Coder capabilities provided by MathWorks to generate C code from Simulink models for embedded implementation. This article describes how these MathWorks code generation practices can be applied to the AMDC platform. In this article, this workflow is referred to as Autogen (Automatic Code Generation).

Development Approach with Simulink and AMDC¶

The figure below shows the Simulink + AMDC workflow, which separates control development into two domains:

  • Design domain (Simulink):
    The control algorithm is developed and validated using a graphical model.

  • Execution domain (AMDC):
    The generated C code is executed in real time on the embedded controller at a fixed time interval.

../../../_images/block-diagram1.svg ../../../_images/block-diagram-dark1.svg

Structure the Simulink model into three subsystems, as follows:

  1. Input/Output (I/O): Use this for simulation and visualization only

  2. Plant: Use this subsystem to represent the physical system for simulation

  3. Controller: Place the control algorithm to be deployed in this subsystem

Within the AMDC domain, the deployed controller is implemented in the DSP user app. The user app communicates with the FPGA-based sensor and PWM interfaces. See the related articles for more information on User Apps and PWM interface.

Recommended Workflow¶

The recommended workflow for developing control code is:

  1. Develop and validate the control algorithm in Simulink.

  2. Convert the controller to an atomic subsystem and then to a referenced model.

  3. Generate C code using Simulink Autogen.

  4. Integrate the generated code into the AMDC project.

  5. Execute and validate on hardware.

Key Implementation Requirements and Best Practices¶

For successful development and integration of control code, follow the implementations requirements and best practices below:

  • Discrete-Time Implementation: All blocks within the controller must be discrete-time, since the AMDC executes control logic at fixed sampling intervals.

  • Fixed-Step Solver: The Simulink model must use a fixed-step solver to ensure compatibility with real-time execution.

  • Consistent Sample Time: The entire controller subsystem should operate at a single, well-defined sample time before converting to an atomic subsystem and creating a referenced model.

  • Code Generation Settings: The code generation target should be set to Embedded Coder (ert.tlc). The build configuration should enable “Generate Code Only”.

  • Referenced Model Usage: The controller subsystem should be converted to an atomic subsystem, then converted to a referenced model. Any updates to model settings should be performed after opening the referenced model as the top model.

  • AMDC Integration Details

    • All generated source (*.c) and header (*.h) files must be included in the AMDC project.

    • The autogenerated folder must be added to the compiler include paths.

    • Do not delete any generated files, as some auxiliary files may be required during compilation.

  • File and Path Constraints

    • File paths must not contain whitespace.

    • The path to the folder containing the MATLAB script and the Simulink model, as well as any parent directory, must not include whitespace. Otherwise, it will result in a build error.

This organization ensures that the autogenerated controller code is correctly compiled and integrated into the AMDC firmware.

Example Model¶

An example tutorial, Tutorial: Autogen, is provided to demonstrate the Simulink code generation workflow for control implementation and its integration with the AMDC.

Conclusion¶

The Simulink workflow provides a structured and efficient approach for implementing control algorithms on the AMDC. By separating control design from embedded implementation, this approach enables:

  • Rapid development and iteration

  • Improved reliability through simulation

  • Clear mapping between design and execution

This methodology is recommended for developing advanced control systems on the AMDC platform.

Next
Integrator Anti-Windup
Previous
Encoder Feedback
Copyright © 2018-2026, Electric Machinery and Levitation Laboratory
Made with Sphinx and @pradyunsg's Furo
This page uses Google Analytics to collect statistics. Disable by blocking JavaScript from www.google-analytics.com.
On this page
  • Firmware Development Using Simulink Code Generation
    • Background
    • Development Approach with Simulink and AMDC
      • Recommended Workflow
    • Key Implementation Requirements and Best Practices
    • Example Model
    • Conclusion