Goal. Record how the motor reacts to a known PWM input signal, so we have the data needed to fit a mathematical model in the next step.

πŸ’» Try the interactive version. This chapter also exists as an auto-graded hands-on lesson built with MATLAB’s R2026a Course Builder. You start from a minimal Simulink model containing just the Master and UART blocks; three auto-graded tasks guide you through adding the Chirp, the PWM HS FEP and the ADC HS 12b with correct wiring and parameters. Each task shows green/red feedback immediately.

In MATLAB R2026a or newer, from the Command Window:

>> picCourse

This opens the lesson in the Course Builder runtime. On R2025b or older releases, picCourse prints a pointer back to this page β€” the Course Builder framework is not available there.

External Mode β€” the diagnostic tool you cannot live without

External Mode is the Simulink feature that turns MBD from “compile-flash-print-debug” into a real-time instrument. Once enabled:

  • Your Simulink model runs on the MCU.
  • Simulink on the PC is connected live over UART (using the industry-standard XCP-on-SxI protocol).
  • Scopes, Data Inspector and parameter tuners inside Simulink update in real time β€” while the MCU is running, without recompile.

Drag a gain slider to change a PI gain β†’ watch the motor response on the scope instantly. Start recording β†’ export the captured timeseries straight to the MATLAB workspace for analysis. That is what we will do for the Picooz.

See External Mode & PIL for the deep-dive.


⬇ tutorial_picooz_acquire.slx ⬇ tutorial_picooz_acquire_extmode.slx

The model is intentionally minimal:

[ Chirp Generator ] ──► [ PWM HS FEP block ] ──► (motor on hardware)
                                                    β”‚
                                                    β–Ό
                                             [ ADC HS 12b block ] ──► [ External Mode scope ]
                                                                         ↑
                                                                  (live-streamed to PC)

Everything runs on the MCU; the scope on your PC is just a viewer for the data the MCU is sending over UART.

The main blocks

BlockRoleReference
MasterTarget chip + clock + fusesβ€”
PWM HS FEP20 kHz PWM carrier, duty driven by the chirp signalβ€”
ADC HS 12bSample BEMF during the PWM-OFF windowβ€”
UART ConfigurationExternal Mode transportβ€”
ChirpSimulink Sources library β€” swept sine from 0.1 Hz to 10 Hz over 30 sβ€”

Why a chirp, not a step?

A chirp (swept-sine) excites every frequency in the 0.1 Hz–10 Hz range in one 30-second experiment. Its autocorrelation is low and it visits every operating point β€” exactly the property we need for grey-box identification.

Compare:

Input signalFrequency contentSuitable for ID?
StepOnly excites the dominant time constantβœ— Poor β€” misses fast dynamics
Multi-step sequenceBetter, but discrete~ Ok, many experiments
White noise / PRBSExcites everythingβœ“ Good β€” industry standard
ChirpControlled sweep, smooth, boundedβœ“ Excellent β€” and visually interpretable

For educational clarity chirps win: you can see on the scope which frequencies are still able to drive the rotor and which ones the mechanical inertia filters out.


Step-by-step β€” run the acquisition

  1. Open tutorial_picooz_acquire_extmode.slx.
  2. In the Master block, confirm the target chip matches your board (default: dsPIC33AK128MC106).
  3. Check PWM settings: 20 kHz carrier, single channel, duty = block input.
  4. Check ADC settings: triggered on PWM-OFF window, 12-bit resolution.
  5. Select Simulation β†’ Mode β†’ External.
  6. Press Monitor & Tune (recent release) or Run on hardware (older releases).

Within ~10 seconds the toolbox:

  1. Generates C code from your Simulink model.
  2. Compiles with XC-DSC.
  3. Flashes the MCU.
  4. Starts the model running on the target.
  5. Opens a live scope view of the streamed signal.

Capturing data to MATLAB

Open the Data Inspector, select the BEMF signal, and Export β†’ To workspace. You now have timeseries u(t) (the chirp) and omega_meas(t) (the measured BEMF) in your MATLAB workspace β€” ready for identification.


Reference dataset shipped with the tutorial

If you don’t have hardware handy (or just want to reproduce the tutorial exactly), the bundled dataset below was captured on a real Picooz + Curiosity dsPIC33AK512MPS512 with this exact acquisition model. Use it unchanged through the rest of the series.

⬇ tutorial_picooz_chirp.mat (clean (t, u, omega_meas) for identification) ⬇ tutorial_picooz_chirp_log.mat (raw Simulink Dataset log) ⬇ tutorial_picooz_process_log.m (raw-to-clean conversion script)

What’s in tutorial_picooz_chirp.mat:

VariableSizeDescription
t6001 Γ— 1Time vector, 5 ms period, 30 s total
u6001 Γ— 1PWM duty cycle, chirp in [βˆ’0.3, +0.3]
u_abs6001 Γ— 1abs(u) β€” the rotor only responds to magnitude, single-quadrant drive
omega_meas6001 Γ— 1Rotor speed proxy (BEMF-derived voltage) in [0, 3.6] V

The waveform:

Chirp input and measured response

Observation: the rotor accelerates quickly at low chirp frequency (left side), then has visibly reduced amplitude at high frequency (right side) β€” the mechanical low-pass due to rotor inertia + aerodynamic drag. This is exactly what identification will quantify.


External Mode β€” advanced features to explore

These go far beyond the basic acquisition above and are worth knowing even after you finish the tutorial:

FeatureWhen it pays off
Live parameter tuningPlace a Slider Gain in your controller and drag it at runtime. Explore a PI gain sweep in seconds rather than minutes.
Log-to-disk with picguiSimulink Data Inspector buffers in RAM. For multi-hour experiments, the blockset’s picgui tool streams the signals straight to disk. See Data Visualization .
Triggered captureStart recording on an event (rising edge of a digital signal). Useful for transient capture of one-shot startup sequences.
Per-signal log rateCurrent at 20 kHz, setpoint at 10 Hz β€” each signal captured at its own rate, keeping the UART bandwidth in check.
XCP-on-SxIThe underlying transport is a standard automotive XCP protocol. Any CAN-bus calibration tool (CANape, INCA, …) can talk to your firmware.

What’s next

With t, u and omega_meas in hand, we can fit a mathematical model of the motor. The next page shows five different ways to do it β€” most of them needing no MATLAB add-on toolbox.

Next β†’ 3. Identification β€” Five Methods

Back β†’ 1. Hardware