Open tutorial_picooz_simulation.slx:
Structure:
[ Setpoint Generator ] βββΊ (+)βββΊ [ Controller ] βββΊ [ Identified Plant ] βββ
β² (picooz_motorBlade_m) β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββ
measured Ο
The plant in the simulation model is the same picooz_motorBlade_m.m ODE you identified on page 3, plugged in via a MATLAB Function block.
Apply a step sequence to the setpoint:
| Time [s] | Setpoint \(\omega_{\text{ref}}\) |
|---|---|
| 0 β 5 | 500 rad/s |
| 5 β 10 | 1500 rad/s |
| 10 β 15 | 0 rad/s |
Check:
u(t) β must not saturate the PWM duty at Β±1 for your operating range.Iterate on the controller gains until you are satisfied. This iteration takes seconds β the simulation runs faster than real time.
Everything you tune here carries unchanged to the hardware β because the hardware runs the same model. The target-specific parts (PWM, ADC, UART) are isolated in MPLAB Device Blocks that the simulation model simply stubs out.
Replace the identified plant block with the PWM HS FEP + ADC HS 12b hardware blocks (same inputs/outputs β they now talk to real peripherals). Switch Simulation β Mode β External.
β¬ tutorial_picooz_deploy_tunable.slxPress Monitor & Tune.
Under the hood, in roughly this order:
.elf / .hex.Typical numbers on a dsPIC33AK512MPS506 @ 200 MIPS:
| Metric | Value |
|---|---|
| Controller (Super-Twisting) execution time | < 2 Β΅s |
| Total code size (controller + scheduler + peripherals) | ~12 KB |
| RAM usage | ~2 KB |
| Control rate | 1 kHz (configurable; MCU can run much faster) |
The Super-Twisting controller uses sqrt(). On dsPIC the toolbox automatically substitutes the generic floating-point sqrt with a hand-tuned assembly implementation from mchp/Lib_dsPIC/MACRO/ β the Code Replacement Library. Same for sin, cos, atan2 in more complex models.
This is transparent. Your model is unchanged; the generated C is optimised.
The model you just deployed is not tied to the dsPIC33A. Change the Master block’s target to, for example, dsPIC33CK256MP508 or SAME70Q21B β the same Simulink model rebuilds for the new target. Peripheral pinning adapts automatically (PPS on dsPIC, PORT mux on SAM).
The controller’s generated C is unchanged. Only the initialisation code for the peripherals differs.
Industrial relevance. This is how a prototype developed on a β¬30 dev kit scales to a production BOM with a different MCU from the same family.
The embedded code is on the target. Time to verify that the hardware response matches the simulation β the final MBD validation step.
Next β 6. Validate & Beyond
Back β 4. Controller Design