Introduction
In this article, we are going to explain the torque and speed controlling methods of a Brushless Motor and compare them together and learn how you can seamlessly do it using our products and our Simulink Blockset that enables you to communicate with SOLO through USB, UART and CANopen from the Simulink environment but first, we are going to give a brief introduction to a PMSM and control scheme of it, PMSM motors are also known as AC brushless Motors too.
To get access to the source codes and the example codes please visit the link below:
The Blockset library: https://github.com/Solo-FL/SOLO-Motor-Controllers-SIMULINK
PMSM or AC brushless Motors, Dynamics and Theory
The governing equations for PMSM are as follows:

psi_m is the magnetic flux of the permanent magnet, n is the number of pole pairs,omega is the mechanical speed of the rotor, J inertia of the rotor, R_s and L_s are stator resistance and inductance respectively.
As we can see from the equation the only parameter that contributes to torque is i_sq and i_sd is just related to the joule losses, for this reason when we are controlling a PMSM, we always put the i_sd=0. It needs to mention that when we are using field weakening the is_d is not equal to zero anymore and we should calculate the value for it.
Now we are going to use the field-oriented control (FOC) technique for PMSM. The overall scheme of FOC is as below.

Figure 1 – Complete FOC scheme
Torque Controlling of a PMSM
Some applications like traction(electrical vehicles and railway) require specific torque, for these applications we should use torque control mode.
The control block diagram of torque control corresponds to the figure below.

Figure 2 – FOC scheme for torque control
As shown in the equations, when user set a reference torque, we can easily derive the i_sq, just by multiplying it by 1/npsi_m . Afterwards, we are going to regulate i_sq,ref and generate the v_sq,ref.
The use of a torque control offers several advantages such as quick, and robust torque reaction and increase efficiency. On the other hand, there are some disadvantages of it such as poor dynamic response at low speed and possible problems during the starting.
Speed Controlling of a PMSM
The control block diagram of speed control is shown in the figure below.

Figure 3 – FOC scheme for speed control
Simulink Blockset

Figure 4 – Schematic of blocksets
Calibration/ Identification phase

Figure 5 – Calibration/Identification block
The first block is the calibration/identification. This block is used to find the motor parameters as resistance and inductance of the motor. In addition, it is used to find the offset as well.
To activate this block user should push one of the buttons related to calibration and identification (top right).
Note: For activating this block the motor should be off, otherwise if you push the calibration or identification, it is not going to do anything.
TX Block

Figure 6 – Tx Block
The Serial Setup Block

Figure 7 – Initialization block
The inputs of this block are as followings:
Address: This input defines the Device address of the SOLO unit that you want to initialize, to set or change the device address of your unit you can use the SOLO Motion Terminal.
COM Port: This defines what COM port is assigned to the SOLO unit on your PC, on Windows devices you can check that in Device Manager.
Baud Rate: This defines at what baud rate your SOLO unit operates for UART communications, you can set the baud rate of the UART line in SOLO Motion Terminal.
If you are using the native USB on your SOLO unit, the value of the baud rate you put here has no effect and any value will be accepted as the notion of Baud-rate for the USB-2 protocol on SOLO is non-existent.
If you are using SOLO with a UART to USB converter connected to your PC then setting of this Baudrate will be necessary and it’s highly recommended to use the highest baud rates possible ( 937500 bits/s in SOLO UNO and MINI) to have the highest performance.
Timeout: This defines the timeout for commands in terms of milliseconds, if the DLL fails to communicate with SOLO within the timeout time, you will receive the timeout error code at the “Result” output.
Trials on Failure: This defines how many times the DLL should try automatically sending a failed command to SOLO later when you try to Write or Read some parameters, in case after finishing all the trials the command fails to be sent or received you will receive an error at the “Result” and “Error” outputs in your Write or Read functions.
Result: This output defines if the setup process went successful or if an error occurred during the process.
RX Block

Figure 8 – Rx block
Control Panel
The user sets the preference configuration, by means of these blocks such as analog/digital mode, feedback mode (sensorless, encoder, or hall sensor), motor direction (clockwise or counterclockwise), and torque of the motor. In addition, the user can tune the current controller using these blocks.


Figure 9 – Control panel
How does it work?
It is really easy, you just need to connect SOLO and set the right COM port, motor type, and feedback mode. Now, everything is ready to run your motor.
Note: If the motor does not move when you turn it on, it is probably because the control mode is on analog mode and it is not initialized correctly and you should set it to digital by means of the switch related to it.
Note 2: you need to have the correct wiring configuration and offset, otherwise your motor is not going to move. For this purpose, you just need to push the calibration button to set the offset and then try to see if this configuration works or not, otherwise, you should change the wiring and repeat the same procedure again.
Note 3: In the speed control all the blocks are the same except the control panel. For speed control our control panel becomes as below:


Figure 10 – Control panel for speed control mode
Conclusion
using our Simulink Blockset that is built on top of our C++ DLL you can test and integrate SOLO into your systems rapidly and at the same time take advantage of the vast tools made available to you in Simulink and Mathworks environment.