Goal. Verify that the real hardware response matches the simulated prediction β€” and draw the conclusion that gives MBD its name.

The final check β€” does the real rotor behave like the model said it would?

With the controller running on the target, capture the closed-loop response the same way you captured the open-loop response on page 2: External Mode, Data Inspector, export to workspace. Overlay this hardware response with the simulation output from page 5.

Simulation vs. real hardware β€” large-step closed-loop response

The simulated and real curves lie on top of each other. No tuning iteration was performed on the hardware. This is the deliverable of Model-Based Design β€” a faithful simulation predicts reality, so you can explore the design space on your PC and commit the result to hardware with confidence.


The MBD promise, summarised

  1. Simulate the model + controller faster than real time on the PC.
  2. Generate the embedded C code automatically.
  3. Validate on target β€” and the response matches the simulation.

Fidelity of the model is the enabler. A faithful model makes simulation a reliable prediction of reality.

Model-Based Design β€” overview

Going further β€” where to explore next

This tutorial deliberately stopped at the basic closed-loop-validated controller. Here is where to go from here:

Tune the controller live with External Mode

Replace the fixed setpoint with a Slider in Simulink. Drag it at runtime β€” the motor follows. Add live read-out of the integral term and watch it compensate disturbances. Inject a step load (press the rotor briefly); watch the controller recover. All of this happens without recompiling.

See External Mode & PIL .

Multi-rate scheduling

The controller runs at 1 kHz; BEMF sampling runs at 20 kHz; UART logging runs at 100 Hz. Put each in its own triggered subsystem with distinct sample times β€” the toolbox’s Rate-Monotonic Scheduler handles real-time scheduling automatically.

See Scheduler & Multi-Tasking .

Port to another target

Change the Master block chip from dsPIC33AK512MPS506 to a dsPIC33CK, a PIC32MK or a SAM E70. The controller’s C code is unchanged. Peripheral pinning adapts.

Fixed-point vs. floating-point

The dsPIC33A has a hardware single-precision FPU β€” use floats guilt-free. On a dsPIC33C without FPU, the same controller works but at a higher CPU cost. The toolbox supports Fixed-Point Designer conversion for maximum efficiency.

The INSA Lyon 2022 course goes deep into this topic.

Apply to a different plant

The four-phase workflow (acquire β†’ identify β†’ control β†’ validate) is identical for:

  • PMSM / BLDC motors β€” see Motor Control Examples and the ctrl-elec project .
  • Power converters β€” PFC on dsPIC33A is a future tutorial in this series.
  • Industrial axes, thermal systems, battery models β€” anywhere you have a measurable state and a controllable input.

Advanced controllers

Once Super-Twisting is familiar, explore:

  • Higher-order sliding mode β€” arbitrary convergence order for systems where chatter on \(\ddot{s}\) also matters.
  • Extended-state observers β€” estimate disturbances online and feed them forward.
  • Model Predictive Control (MPC) β€” solve an optimisation at each step; increasingly practical on modern dsPIC33A with FPU and 200 MIPS.

Source material and credits

  • Figures and walkthrough are derived from the 30-minute live demo delivered at Γ‰cole Centrale Nantes on 2025-12-04 (Model-Based Design: From Laboratory to Embedded Deployment).
  • INSA Lyon 2022 Rapid Control Prototyping course β€” 3-hour French reveal.js slide deck covering the Picooz + data types + multi-rate scheduling.
  • ctrl-elec project β€” advanced motor control research and teaching, INSA Lyon Γ— Microchip.
  • ICEM 2024 Tutorial β€” academic reference (Delpoux, Kerhuel).

Original Picooz work: R. Delpoux (INSA Lyon, Laboratoire AmpΓ¨re) and L. Kerhuel (Microchip Technology), with assistance from many students and interns over the 2012–2025 iterations.


You’ve finished the tutorial

You now know how to:

  • Acquire data on a running MCU using External Mode.
  • Fit a physics-based model to that data using base MATLAB or a paid toolbox β€” your choice.
  • Design a robust non-linear controller.
  • Simulate the closed loop before touching hardware.
  • Generate embedded C code and deploy it in one click.
  • Validate on hardware β€” and see that the simulation was right.

That is the entire MBD workflow. Every project you tackle next β€” PMSM, PFC, autopilot, whatever β€” is a specialisation of these six pages.

Back to the series index β†’ Tutorial β€” Picooz Helicopter

Back β†’ 5. Simulate & Deploy