Measure Phase Currents of PMSM Motor in Open Loop Teensy Hardware
R2026bThis example shows how to use Simulink® Support Package for Arduino® Hardware to measure three-phase currents of a permanent magnet synchronous motor (PMSM). The example deploys an open-loop voltage-frequency (V/F) control algorithm on a Teensy® development board.
Prerequisites
Complete the Run PMSM Motor in Open Loop on Teensy Hardware example.
Required Hardware
To run this example, you will need the following hardware.
Teensy 4.0 hardware board
TI-Motor Bridge Driver BOOSTXL-DRV8305EVM
Teknic2310P PMSM motor
24-V DC supply
Connecting wires
Hardware Setup
Connect a 24-V DC supply source to the supply header of the DRV8305EVM driver.
Connect a PMSM motor to the motor header of the DRV8305EVM driver.
Use the connections specified in this table to connect Teensy development board and DRV8305EVM driver.

Configure Motor and Inverter Parameters
Run the arduinoTeensyPmsmPwmAdcSetup script provided with the example.
The script is pre-configured for the Teknic 2310P PMSM motor and defines the PWM timing, ADC offset, motor and inverter parameters, target hardware settings, and per-unit (PU) system parameters required by the control algorithm. If you are using a different motor, modify the motor parameters in this script to match the specifications of your motor.
Model Description
Open the arduinoMcbOpenLoopMeasurePmsmCurrent Simulink model.

The model has four main stages:
Hardware Initialization — The Initialize Function subsystem enables DRV8305EVM gate driver registers and configures SPI communication. It also configures the motor control hardware and triggers the hardware initialization sequence required for safe motor operation.

ADC interrupt — The Hardware Interrupt block generates a function-call trigger every 50 microseconds, synchronized with the PWM timer. This trigger executes the current control loop at each PWM cycle, enabling accurate current sampling and voltage updates.
Open-Loop Control and Phase Currents Estimation — The ADCTrigger50us subsystem performs these operations during each interrupt service routine (ISR) execution:

1. The Analog Input block reads the motor phase currents from ADC channel 1 (ISENA) and ADC channel 2 (ISENB).
2. The Calculate Phase Currents subsystem computes phase currents using the measured phase currents on the ADC channels and Kirchhoff's Current Law (KCL). Ia_ADC and Ib_ADC represent the voltage-equivalent phase currents when PWM input signal is active (duty cycle of the signal lies between 0 to 100%). inverter.CtSensAOffset and inverter.CtSensBOffset represent the current-sensor offsets when PWM is inactive (duty cycle of the signal is 0). The subsystem calculates the third phase current using KCL and determines the ADC gain from the shunt resistor value and ADC resolution.

3. The VbyF Controller (Motor Control Blockset) block implements open-loop V/f control for the PMSM motor. The controller regulates motor speed by varying the stator voltage and frequency. You can specify these motor parameters in the arduinoTeensyPmsmPwmAdcSetup file provided with this example. The controller uses these parameters to compute the three-phase motor voltages (Vabc) required to drive the motor.
4. The subsystem generates three-phase PWM signals (PWM1, PWM2, and PWM3) for the PMSM motor voltages Vabc and controls their duty cycle.
Serial Communication with Host Model — The Serial Receive and Serial Transmit blocks in the target model, arduinoMcbOpenLoopMeasurePmsmCurrent implement the communication interface between the host model arduinoHostModelOpenLoopPmsm and the target hardware. This host model runs on the development computer and communicates with the deployed target over a serial USB connection. It transmits a speed reference and receives the estimated currents for visualization and analysis.

Generate Code and Deploy Model to Target Hardware
This example uses a target model and a host model. The target model runs on the Teensy hardware board and implements the motor control algorithm. The host model runs on the host computer and provides a user interface for monitoring signals and sending commands to the target hardware over serial connection.
1. Complete the hardware connections.
2. Open the target model, arduinoMcbOpenLoopMeasurePmsmCurrent.
3. Configure the model for Teensy development board. On the Modeling tab, click Model settings to open the Configuration Parameters dialog box. In the Hardware Implementation pane, set Hardware board to Teensy 4.0 or Teensy 4.1. Click OK.
4. Configure SPI mode. In the Hardware Implementation pane, expand Target hardware resources and select SPI properties. Set SPI mode to Mode 1 - Clock Polarity 0, Clock Phase 1, which is supported by the DRV8305EVM gate driver.

5. Configure baudrate for serial communication. In the Target hardware resources pane, select Serial port properties. Set Serial 0 baud rate to 115200.
6. Deploy the target model to the hardware. On the Hardware tab, in the Mode section, select Run on board.
In the Deploy section, click Build, Deploy & Start.
7. Open the host model, arduinoHostModelOpenLoopPMSM.
8. Select the serial Port in the Host Serial Setup (Motor Control Blockset), Host Serial Receive (Motor Control Blockset), and Host Serial Transmit (Motor Control Blockset) blocks.
9. Specify Baud rate parameter in the Host Serial Setup (Motor Control Blockset) block. The value must match with the value set in step 5.
10. To run the host model, on the Simulation tab, click Run.
11. Modify the reference speed in the Slider block and monitor motor operation and measured currents using the scopes and display blocks in the host model.
See Also
Open-Loop and Closed-Loop Motor Control Techniques (Motor Control Blockset)
Current Sensor ADC Offset and Position Sensor Calibration (Motor Control Blockset)
Host-Target Communication (Motor Control Blockset)
Sensorless Field-Oriented Control of PMSM Motor Using Teensy Hardware