# Lab : Real Time DC motor control

## Authors

* Romain DELPOUX (Romain.Delpoux at insa-lyon.fr), Assistant Professor, INSA de Lyon, Laboratoire Ampère UMR CNRS 5005.
* Lubin KERHUEL (Lubin.Kerhuel at microchip.com), Software Engineer, Microchip Technology Inc.

## Introduction

This project is offered to the 5th year students in the [electrical engineering department](http://ge.insa-lyon.fr) of [INSA Lyon](http://www.insa-lyon.fr) for the [CCSA](http://ge-option5a.insa-lyon.fr/content/ccsa-commande-de-convertisseurs-et-de-systemes-dactionnement) option. This project details the steps for the real time implementation of a velocity DC motor control on Microchip dsPIC microcontroller target. The programming environment for this project is the rapid prototype Matlab/Simulink toolbox [MPLAB Device Blocks for Simulink](https://www.microchip.com/DevelopmentTools/ProductDetails/sw007023#utm_source=MicroSolutions\&utm_medium=Link\&utm_term=FY16Q4\&utm_content=DevTools\&utm_campaign=Article).

![Motor Pravalux](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LT88KVPp4PEQhlMa6eD%2F-LT88Kzlkj-d1Y06pRLb%2FMotorPravalux.png?generation=1544194188086528\&alt=media)

The project details the following points

1. Getting started with the programming environment and hardware setup until the open-loop control of the DC motor which means :
   * Blink a LED at 5 Hz.
   * Two PWM signals to control the motor DC voltage through an H bridge structure using MOSFET.
   * Two ADC channels providing the respectively the board potentiometer position to impose a reference and the current measurement from a shunt resistor.&#x20;
   * QEI peripheral to provide shaft position and speed
   * UART connection to the computer for the data analysis.&#x20;
2. Modeling and control loop design of the DC motor.

   * Reminder on motor modeling will be exposed.
   * A basic control strategy based on state space representation will be proposed.

   Note that the modeling and the control of the DC motor are supposed as prerequisites for this project and this section is a reminder only. That's why the speed control algorithm will be given and not developed here.
3. Simulation of the DC motor
   * A control strategy for the speed control of the DC motor is proposed. The simulation file is implemented using double data types variables and variable-step solver to simulate and ideal continuous DC motor closed loop control.
   * Degradation of the control to adapt to the real-time implementation on dsPIC. It means constant sampled control and 16-bits fixed point variables.&#x20;
   * Comparison between the ideal and the real implementation cases.&#x20;
4. Experimental validation
   * Real-time implementation of the sampled fixed point control and comparison with the theory.&#x20;
   * Back to modeling with the analysis of experimental results.
   * Updating models, commands and experimentation.

[Lubin's Slides](https://lubin.kerhuel.eu/slides/slides_dcmotor_insa/)


# Getting Started

## Getting Started

### Getting Started

#### Hardware requirements:

* [MCLV-V2](https://www.microchip.com/dsPICDEMMCLV-2DevelopmentBoard866) Motor Control Board
* [PIM dsPIC33EP256MC506](https://www.microchip.com/DevelopmentTools/ProductDetails/ma330031) with internal Op-Amp
* Programmer ([PICkit 4](https://www.microchip.com/pickit4), [ICD4](https://www.microchip.com/icd4), [Real-Ice](https://www.microchip.com/realice), [PICkit 3](https://www.microchip.com/pickit3), [ICD3](https://www.microchip.com/icd3), ...)
* DC motor ([Pravalux Brushed DC Motor, 90 W, 24 V dc, 3000 rpm](https://uk.rs-online.com/web/p/dc-motors/0716200/))
* Cable to send data from the MCLV board (Tx) to the PC (Rx) (like a [FTDI cable](https://www.ftdichip.com/Products/Cables/USBTTLSerial.htm))

#### Software requirements:

* Matlab/Simulink
  * Embedded coder (Matlab Coder & Simulink Coder)
  * Fixed point toolbox
* [MPLAB device blocks for Simulink](https://www.microchip.com/SimulinkBlocks)
* [MPLAB X IDE](https://www.microchip.com/MPLABX) development (required to flash the binary from matlab)
* [XC16](https://www.microchip.com/XC16) compiler

#### Hardware Configuration

**Pinout of the MCLV-V2 with the PIM dsPIC33EP256MC506 with External Op-Amp**

The pinout for the MCLV V2 board with the dsPIC33EP256MC506 PIM for Interlnal Op Amp configuration is described in its [Information Sheet](http://ww1.microchip.com/downloads/en/DeviceDoc/dsPIC33EP256MC506%20Internal%20Op%20Amp%20PIM%20Infosheet%20Rev%20B.pdf).

The table below provide important pinout information.

| MCLV-V2 Board | dsPIC33EP256MC506 (Ext-Op-Amp) |
| :-----------: | :----------------------------: |
|      LED1     |               RD6              |
|      LED2     |               RD5              |
|               |                                |
|      SW1      |               RG6              |
|      SW2      |               RC7              |
|               |                                |
|    UART\_Rx   |               RC5              |
|    UART\_Tx   |               RF1              |
|               |                                |
|   PWM1 (L/H)  |           RB15 - RB14          |
|   PWM2 (L/H)  |           RB13 - RB12          |
|   PWM3 (L/H)  |           RB11 - RB10          |
|   MC\_FAULT   |          RB4  (FLT32)          |
|               |                                |
|  HALLA / QEA  |               RA8              |
|  HALLB / QEB  |               RC6              |
|  HALLC / INDX |               RF0              |
|      HOME     |              RC10              |
|               |                                |
|      Pot      |          RE13  (AN13)          |
|      VBUS     |          RA12  (AN10)          |
|       Ia      |         RB2   (C2IN1+)         |
|       Ib      |         RC2   (C3IN1+)         |
|  Ibus / Vbus  |          RB7   (AN14)          |
|               |                                |
|  PGC (debug)  |           RB6 (PGC2)           |
|  PGD (debug)  |           RB5 (PGD2)           |

**Analog inputs scaling**

**Currents measurements:**

All Shunt resistances are **0.025 Ohms**.

Two shunts measures Ia and Ib on PWM1 and PWM2 (low side). The third shunt measure Ibus which is the current sum of the three PWM (low side) currents.

Op-Amps (Internal or External) with a **gain of 15** boost low voltage measured to higher voltage converted by the dsPIC ADC for signals Ia, Ib and Ibus. (see [fig4 from DS52062B](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/tree/f4be492167956b5449ef4fb184332b885cf5780f/Figures/GettingStarted/Internal_OpAmp_DS52062B_Fig4.png))

$$V\_{ADC} = 0.025*15*I\_{shunt}$$

For the ADC configured for 10 bits right aligned conversion, the raw output represents:

$$ADC\_{out} = 0.025*15 \* \frac{1024}{3.3}* I\_{shunt} = 116.36 \* I\_{shunt}$$

The maximum measurable current is +-4.4 A which provides values within \[-512 512] range.

**Voltage measurement:**

A divider with a **gain of 1/15** reduce board DC+ input voltage to a lower voltage (Vbus) to fit within the \[0 3.3V] range.

$$V\_{BUS} = \frac{1}{15} \* DC+$$

The DC input range not saturating the ADC input is +- 24.75V.

#### Peripheral block for Simulink

Two Push Button **S1** and **S2** states are read using one or two Digital Input blocks. Input voltage is inverted:bBoolean output is 0 when button is pushed ; 1 otherwise.

The two LEDs D1 and D2 are on when their respective pin is set to 1.

* **LED D1** is set using a Digital Output block. It is made to blink at 5Hz proving the program is running on the board.&#x20;
* **LED D2** is used as a Busy Flag which is set in the Master block. It provides the MCU load. A scope could be used to visualize the load.

The UART Config block configure the baudrate and the pins Rx-Tx pins. Bauds as high as 2Mb can be used by connecting directly an FTDI cable on the JP4-Rx and JP5-Tx Jumpers. The board Serial connector is limited to 460Kb.

The PWM block configure the PWM1 and PWM2 channels as center aligned signals, with a fixed Period of 50us, and a dead time of 1us. The FLT32 Fault acrive low fault input force the PWMH to 0, and the PWML to 1 on both channels with automatic recovering when fault signal is released. Duty cycle is set as a block input. The Duty cycle input must be scaled using the variable PWM1max available in the matlab workspace. PWM1max value correspond to the **Max Period** set in the block. The Initial ADC Trigger set at 0 (middle of the center aligned PWM signal) provide an option in the ADC block to get triggered synchronously to the PWM signal.

The Op-Amp 2 is configured using the *Comparator - OpAmps - Volt Ref* block.

The ADC is set for 10 bits conversion which allows parallele sampling on up to 4 input channels. Result is set to be signed and left aligned. Channels AN13 (Potentiometer) and OA2 (Ia) are converted. The ADC is triggered by the PWM trigger signal. End of the ADC conversion will trigger the simulink base time step. Thus the time step period is equal to the PWM period ! **User must ensure that the fixed step period in the Simulink Configuration match with the PWM period**.

QEI block decode signal from the quadrature encoder sensor which contains 1000 lines. The position output must roll-over at value 999. Position and speed changes are likely not to change in 50us. The QEI block is likely to execute at a lower rate (40 time slower here at 2ms) than the base time step.

#### Generate code and compile:

The build icon on top right of Simulink model, (see [fig](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/tree/f4be492167956b5449ef4fb184332b885cf5780f/Figures/GettingStarted/Model_Hardware_Test_withSampleTime.png) above) do: 1. generates c source code, 2. compiles c code and 3. flash the resulting binary to the MCLV targeted board.

> If programming the board fails (not powered, not connected,...), use the **Microchip -> Flash** within the Simulink model menu.

#### Data Visualization with picgui:

Open the picgui interface ([fig](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/tree/f4be492167956b5449ef4fb184332b885cf5780f/Figures/GettingStarted/DataVisu.png)) (type **picgui** at matlab prompt or double click on the **Interface Tx-Matlab block** in the model)

1. Select host UART port and connect at 115200 bauds
2. Replace the default script within the picgui interface to a call the customized matlab script [DataVisu.m](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/tree/f4be492167956b5449ef4fb184332b885cf5780f/DataVisu.m) (see figure below)
3. Push the **start** button to visualize runtime curves showing potentiometer, motor position, motor speed and current measured on shunt resistor *apabilities to customize visualization or perform further analysis on received data in real-time.*

![fig: The picgui interface decode the incoming UART data stream and plot in real-time received values, here potentiometer, motor speed and current measured. Plots in figure are realized with a matlab script which is continuously refreshing the graphs using incoming data. This script can be modified providing all the matlab capabilities to customize visualization or perform further analysis on received data in real-time.](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LTd3p-lSjUKDpfUFRvq%2F-LTd45Tqpkzu2B6MUr8q%2FDataVisu.png?alt=media\&token=96c69251-beaf-43b9-bd7a-2408019ee86c)

## To do

1. Starting from the empty file to download [here](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/raw/f4be492167956b5449ef4fb184332b885cf5780f/LABMatlabFiles/02_GettingStarted/MCLV2_dsPIC33EP256MC506_base_R2017a.zip)

   , add the configuration blocks

   * Microchip Master
   * Compiler Options&#x20;
   * UART Configuration
   * Graphical Interface   &#x20;
   * Port Info
2. Blink LED D1 at 5hz to verify the configuration
3. Configure the peripherals :
   * Two PWM signals to control the motor DC voltage through an H bridge structure using MOSFET.
   * Two ADC channels providing the respectively the board potentiometer position to impose a reference and the current measurement from a shunt resistor.&#x20;
   * QEI peripheral to provide shaft position and speed
   * UART connection to the computer for the data analysis.    &#x20;
4. With the MCLV2 board powered and programmed, rotate the potentiometer to accelerate motor / reverse direction. **Setting the potentiometer at middle position (off) at power on to avoid current surge.**

The model should look like ([fig](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/tree/f4be492167956b5449ef4fb184332b885cf5780f/Figures/GettingStarted/Model_Hardware_Test_withSampleTime.png))

![](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LTd4LzHZxpCDUVBDpPK%2F-LTd4dqFAOn0LbB5deYz%2FModel_Hardware_Test_withSampleTime.png?alt=media\&token=70a63b5d-d9d7-4821-9a51-81d640aa509a)

[Solution](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/raw/master/LABMatlabFiles/02_GettingStarted/Correction/Correction2.zip)


# DC motor modeling and control loop design

## Motor description

![Motor Scheme](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LT8a7zgxhSp4S49L2dI%2F-LT8a8YkstXkzevNCh-8%2FMCC.png?generation=1544201753698614\&alt=media)

![Variables and parameters table](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LT8a7zgxhSp4S49L2dI%2F-LT8a8YmpTopinM6GK6m%2FTable_Variables.png?generation=1544201739312460\&alt=media)

## System modeling

**Electric equation:**

From kirchhoff's voltage law :

$$
L\frac{di(t)}{dt} =v(t) - Ri(t) - e(t)
$$

**Mechanical equation:**

By Newton's law:

$$
J\frac{d\omega(t)}{dt} = \sum T(t) = T\_m(t)-f\omega(t)
$$

where $$T(t)$$ is the total torque applied on the rotor.

**Electro-mechanical coupling:**

The back EMF is proportional to speed :

$$
e(t) = K\_e \omega(t)
$$

$$K\_e$$ : electromotive constant $$(V.rad^{-1}.s)$$

The motor torque is proportional to current :

$$
T\_m(t) = K\_T i(t)
$$

$$K\_T$$ : Torque constant $$(N.m.A^{-1})$$

The mechanical power produced by the DC motor is $$T\_m\omega = K\_Ti\omega$$. The electric power $$P\_e = vi$$ delivered by the source goes into heat loss in the resistance $$R$$, into stored magnetic energy in the inductance $$L$$ and the remaining quantity $$iK\_e\omega$$ is converted in mechanical energy $$T\_m\omega$$. It leads to $$T\_m\omega = K\_Ti\omega = K\_ei\omega$$ whether $$K\_T = K\_e = K\_\phi$$ (Chiasson2005).

## Motor Bloc Diagram

![DC Motor Bloc Diagram](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LT8a7zgxhSp4S49L2dI%2F-LT8a8YoBParE8_iLdjE%2FDCMotorDiagram.png?generation=1544201753445030\&alt=media)

## Motor control : cascaded strategy

The control synthesis is inspired by Permanent Magnet Synchronous Motor control synthesis based on cascaded control synthesis. Due to frequency separation the control can be divided into two control loops. The inner loop control the electrical dynamic while the outer loop treats the mechanical dynamic. Generally the the electrical dynamics is neglected and the mechanical dynamics is considered only. However in the case where motor resistance is low, this strategy can damage the motor.

### Electrical dynamics control

The objective is to control the motor torque $$T\_m(t)$$. Indeed $$T\_m(t) = K\_\phi i(t)$$ the motor torque is imposed by the current.

![Closed loop electrical system](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LTHJM05ZsDoO7sSbQ4I%2F-LTHJMRCF9tbPy0vlf3A%2FCLElecDyn.png?generation=1544348072847932\&alt=media)

With the assumption that the mechanical dynamic is slower the the electrical one, one has :

$$
\tau\_{\rm elec} = \frac{L}{R}<<\tau\_{\rm meca} = \frac{J}{f}
$$

The velocity $$\omega$$ can then be considered as constant from the point of view of the electrical dynamics.

**Feedback control with integral action**

The electrical dynamics is given by

$$
\begin{array}{lcl}
\dot{i}  &=& -\frac{R}{L} i + \frac{1}{L}v -\frac{K\_\phi}{L}w\\
&=& -\frac{1}{\tau\_e} i + \frac{K\_e}{\tau\_e}v -\frac{K\_\phi}{L}w
\end{array}
$$

The control objective is to ensure $$i^\star =i\_{\rm ref}$$, where $$i^\star$$ is the current steady state and $$i\_{\rm ref}$$ is the current reference. To ensure zero steady state error, an integral action is necessary. The principle is to insert an integral action the the feed-forward loop between the error compactor and the process (Ogata2010). The control scheme is given by :

![Electrical dynamics state feedback](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LTJxompglFr6ySAw4S-%2F-LTHKnH7zUKWkUMhF1qy%2FElecSFB.png?generation=1544392496819413\&alt=media)

From the figure one gets :

$$
\begin{array}{lcl}
\dot{i}  & = & -\frac{R}{L} i + \frac{1}{L}v -\frac{K\_\phi}{L}w \\
\dot{\varepsilon} & = & i\_{\rm ref} - i \\
v & = & -Ki+K\_I\varepsilon
\end{array}
$$

with $$\varepsilon$$ the output of the integrator.

The system dynamics can be described by

$$
\begin{bmatrix}
\dot{i}\\\dot{\varepsilon}
\end{bmatrix} =
\begin{bmatrix}
-\frac{R}{L} & 0\\-1 &0
\end{bmatrix} \begin{bmatrix}
{i}\\{\varepsilon}
\end{bmatrix}+
\begin{bmatrix}
\frac{1}{L}\0
\end{bmatrix}v+
\begin{bmatrix}
\frac{K\_\phi}{L}\0
\end{bmatrix}\omega+
\begin{bmatrix}
0\1
\end{bmatrix}i\_{\rm ref}
$$

with the control

$$
v  =  -Ki-K\_I\varepsilon
$$

The closed loop system leads to :

$$
\begin{bmatrix}
\dot{i}\\\dot{\xi}
\end{bmatrix} =
\left(\begin{bmatrix}
-\frac{R}{L} & 0\\-1 &0
\end{bmatrix} -
\begin{bmatrix}
\frac{1}{L}\0
\end{bmatrix} \begin{bmatrix}K\&K\_I\end{bmatrix}\begin{bmatrix}i\\\varepsilon\end{bmatrix}\right)+
\begin{bmatrix}
\frac{K\_\phi}{L}\0
\end{bmatrix}\omega+
\begin{bmatrix}
0\1
\end{bmatrix}i\_{\rm ref}
$$

The closed loop dynamics depends on the eigenvalues of the matrix :

$$
\left(\begin{bmatrix}
-\frac{R}{L} & 0\\-1 &0
\end{bmatrix} -
\begin{bmatrix}
\frac{1}{L}\0
\end{bmatrix} \begin{bmatrix}K\&K\_I\end{bmatrix}\right)=
\begin{bmatrix}
-\frac{R+K}{L} & -\frac{K\_I}{L}\\-1 &0
\end{bmatrix}
$$

One has

$$
{\rm eig}\left(
\begin{bmatrix}
-\frac{R+K}{L} & -\frac{K\_I}{L}\\-1 &0
\end{bmatrix}\right) = {\rm det}\left(sI-\begin{bmatrix}
-\frac{R+K}{L} & -\frac{K\_I}{L}\\-1 &0
\end{bmatrix}\right)
$$

It leads to a characteristic equation

$$
P(s) = s^2+\frac{K+R}{L}s -K\_I
$$

to be identified with the classical second order characteristic equation

$$
P(s) = p^2+2\zeta\omega\_n s +\omega\_n^2
$$

where $$\omega\_n$$ is the desired closed loop natural frequency and $$\zeta$$ the damping coefficient.

### Mechanical dynamics control

![Closed loop cascaded system](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LTK2rdK_q8zqUEsGyBT%2F-LTK2s6m8BXFbe2pj8TR%2Fclmecadyn.png?generation=1544394082480509\&alt=media)

Assuming the electrical control has been correctly synthesized with respect to frequency separation principle, which means that the closed loop electrical dynamics is faster than the mechanical desired dynamics, then the mechanical dynamics control synthesis can be designed without considering the closed loop electrical system. The control scheme can be simplified as :

![Closed loop mechanical system](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LTK2rdK_q8zqUEsGyBT%2F-LTK2s6oPeqPCN-_qetA%2Fclmecadyn2.png?generation=1544394082277806\&alt=media)

The mechanical dynamics is

$$
\begin{array}{lcl}
\dot{\omega} &=&  \frac{1}{J}T\_m-\frac{f}{J}\omega\\
&=&  \frac{K\_\phi}{J}i-\frac{f}{J}\omega
\end{array}
$$

where $$T\_m = K\_\phi i$$

The control synthesis is similar than the one proposed for the electrical dynamics with $$\dot\varepsilon\_\omega = \omega\_{\rm ref}-\omega$$ leading to

$$
\begin{bmatrix}
\dot{\omega}\\\dot{\varepsilon\_\omega}
\end{bmatrix} =
\begin{bmatrix}
-\frac{f}{J} & 0\\-1 &0
\end{bmatrix} \begin{bmatrix}
{\omega}\\{\varepsilon\_\omega}
\end{bmatrix}+
\begin{bmatrix}
\frac{K\_\phi}{J}\0
\end{bmatrix}i+
\begin{bmatrix}
0\1
\end{bmatrix}\omega\_{\rm ref}
$$

with the control

$$
i  =  -K\_\omega \omega-K\_{\omega,I}\varepsilon\_\omega
$$

By analogy, it leads to a characteristic equation

$$
P(s) = s^2+\frac{K\_\phi K\_\omega+f}{L}s -K\phi K\_{\omega,I}
$$

to be identified with the classical second order characteristic equation

$$
P(s) = p^2+2\zeta\omega\_n s +\omega\_n^2 .
$$

## References

(Chiasson2005) Chiasson, J.-N. (2005). Modeling and High-Performance Control of Electric Machines (IEEE Press).

(Ogata2010) Ogata, K. (2010). Modern Control Engineering. Prentice Hall.


# Simulation

## Simulation

![Double precision simulation](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LTdkWi-ztMNEchvucgN%2F-LTdkfTUSq4awO3E5i7j%2FFigureSimu.png?alt=media\&token=99f76843-2538-4d68-bb7c-36109f69cd20)

1. Download the simulation files [here](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/raw/master/LABMatlabFiles/01_Simulation/Simulation.zip). These files are Matlab/Simulink files for the simulation of the control law proposed section [DC motor modeling and control loop design](https://rtdc.ctrl-elec.fr/control-loop-design).
2. For the realtime application the controlleur needs to be sampled. The inner electrical control loop will be sampled à 20kHz (PWM frequency). The outer mechanical control loop will be sampled at 500Hz. For this purpose, use the Sampling block commented in the simulation. Apply the sampled control to the downloaded model and compare with the continous control.
3. The DSpic support 16bits fixed point variables. The control needs to be converted to use 16bits fixed point variable only. Here use the quantization block. Compare the this control with the two previous one.

## Comparison between model and simulation

Here the objective is to compare the difference between the modeling and motor real measurement.

![Model vs Logs](https://570408004-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LT7vvW1gQMpF9H-pyyo%2F-LTdoay9PiLXUu77uM48%2F-LTdoeS4oZOcQcZwsTuN%2FModelVsLog.png?alt=media\&token=79090e62-2e2c-4efa-ae88-98bbcbb4a0b3)

1. Download the model [here](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/raw/master/LABMatlabFiles/05_Log_Validation/LogVsSimu.zip)
2. Using the simulink file MCLV2\_dsPIC33EP256MC506\_internalOpAmp\_DataLog\_R2017a.mdl record real data from motor measurement.
3. Compare the simulation with the real measurment using the simulink file Simu\_Model\_vs\_Logs\_R2017a.mdl


# Experimentation

## Apply the control&#x20;

1. Apply the electrical controller, verify the results
2. Apply the mechanical controller, verify the results.

{% hint style="info" %}
&#x20;Low pass filter to download [here](https://github.com/rdelpoux/INSA_TP_CommandeTempsReel_MCC/raw/master/LABMatlabFiles/07_Final_Ctrl/LPF_R2017a.zip)
{% endhint %}

## Good Luck!


