Skip to content

02_basicVectorControl_labBlockConfigurationForMotorControl

rdelpoux edited this page Oct 6, 2025 · 3 revisions

Block configuration for Motor Control

System Configuration

The Mplab Solution do not support continuous time. Indeed micro-controllers are themselves discrete.

  • The first step is to define the Simulink model settings as follow :

The Mplab Solution for Simulink adds to the Simulink Library Browser a library including all the available blocks for the microcontroller.

  • Systems configuration :

Add the following blocks :

and configure the Microchip master. It allows the choice of the micro-controller and the oscillator. For this project, the block must be configured as follow:

Blink a LED

  • Debug LED : to verify the configuration let's blink 3 LED at different sampling frequencies. The LED are linked to outputs PINs D5 C9 and C0.

Read Potentiometer on UART

The objective of this section is to read the potentiometer value and read it on matlab using a serial link.

  • ADC configuration

    • Add an ADC block on the model

    • In the main menu configure the ADC1 channel only, with priority $5$

    • In the Seq 0 tab :

      • Select as trigger starting seq : at end of previous time step
      • Select the correct ADC channel for the potentiometer : AN10

    • In the other sequences Seq 1 to 5 select not Used in the AD1 menu

    • The block should look like this:

  • Configure the UART

    • Add a UART configuration block

    • In the Main menu of the UART configuration

      • Select a baudrate of 460800 baud/s
      • Select Rx Pin to: C11
      • Select Tx Pin to: C10

    • Add a UART Tx-Matlab

      • Select only one channel
      • Set the sampling time to $5e-5$

    • The block should look like this

  • Add a rate transition between the two blocks and link the blocks.

  • The final schematics should be as follow

  • Compile the code with ctrl+b
  • In the microchip banner open the PICGUI app

  • In the PICGUI window configure

    • The COM port to COM4
    • The Baudrate to 460800
    • Click on Connexion

    • Click on Start, it should open a Matlab plot

Motor interface

For motor vector control, three main blocks need to be inserted and configured :

  • Pulse Width Modilation (PWM)
  • Quadrature Encoder (QEI)
  • Analog Digital Converters (ADC)

Inverter

A schematics of the inverter from the MCS MCLV-48V-300W Development Board datasheet is given below :

Pulse Width Modulation (PWM)

The PWM bloc needs to be configured carrefully :

  • The modulation frequency is chosen equal to 20kHz (5e-5s)
  • To synchronize the ADC measurement with the PWM. The PWM is generated center aligned. Indeed it allow the take ADC sample at the beginning of the period and measure an average current avoiding spikes caused by the switching. The ADC synchronization is represented on the figure below
  • The avoid short-circuits a dead time needs to be added between the switching of the High and Low switch. The dead time is chosen equal to Td = 0.5e-6s with respect to the switch datasheet.

The bloc configuration is the following :

Open loop control

  • On the PWM input add three sinusoidal functions

$$ \rho_a = 0.05\sin(10\times 2\pi t) + 0.5 $$

$$ \rho_b = 0.05\sin(10\times 2\pi t-2\pi/3) + 0.5 $$

$$ \rho_c = 0.05\sin(10\times 2\pi t+2\pi/3) + 0.5 $$

ADC

Currents measurements:

The shunt resistances on the inverter are placed on the lower legs and the values are 0.003 Ohms. For the control, it is necessary the measure the current of two phases only, for instance $i_a$ and $i_b$.

The voltage measured across the shunt resistor is amplified with the following Op-Amp schematics :

which leads to a gain:

$G_{ADC} = \frac{4.99\times10^3}{2\times100} = 24.95$

so, the current that can be measured for a voltage range in $[0 \quad 3.3]$ V, ranges in $[-22.04 \quad 22.04]$ A. On the simulink file, one ADC blocks configured the $i_a$ and $i_b$ measurement, synchronized with the PWM. The end of the conversion trig the time step. The configuration is shown below:

In a same way a second block is used for lower priority measurements, such as $V_{BUS}$ voltage or potentiometer.

Encoder

The quadrature encoder peripheral block provide position which can be reseted with using encoder index. The block configuration is the following:

Clone this wiki locally