Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code]

In this article we are going to talk about how to control Torque and then Speed of a Brushless motor of any kind from BLDC, PMSM or Coreless EC brushless motors using Hall sensors as their rotor position feedback precisely and efficiently, we are also going to use a new method in this article by mixing Analogue and Digital control of SOLO in a single place.

What we will do is trying to do the setups using Digital control and sending data packets through UART line from SOLO to Arduino and vice versa with our Arduino Library and then doing the control operations of the Motor like defining the Torque and Speed references using Analogue control by sending PWM pulses from Arduino to SOLO, but before that may be it’s better we answer to the fundamental question below:

What is the difference between Analogue and Digital Control of SOLO and how they overlap?

By notion of “Analogue” in SOLO we mean any interface that can be done using Analogue voltages or mechanically at hardware level to SOLO, for instance in SOLO UNO you can do the following actions completely at hardware level:

1.   Set the Speed or Torque Reference through “S/T” input
2.   Set the Current Limit or Magnetizing current through “P/F” input
3.   Tune the Speed controller Kp and Ki gains through two potentiometers mechanically
4.   Set the Motor type through Piano switch (4 types)
5.   Set the Control Mode of Torque or Speed through Piano switch
6.   Set the Open-loop or Closed-loop type of control through Piano switch
7.   Put SOLO into DFU mode through Piano switch

So for SOLO, once you are in “Analogue Mode”, these settings have the highest priority over all the settings from the same nature in Digital mode! For example, if you are in analogue Mode, you can only select the motor type from the Piano switch, and if you set it using Motion Terminal or you send the data packet through UART or CAN it will not change the Motor type unless you go to “Digital Mode”. The main reason that “Analogue Mode” exists on SOLO is to eliminate the need for the users to set a special parameter through a software and to minimize the interfacing effort to SOLO for applications that require it.

However, there are tons of settings that you can’t do them at hardware Level, like setting the motor number of poles for 3 phase motors, or setting the output switching frequency, … so for all these parameters, regardless of what mode you are in ( analogue or digital ) you can only set them digitally using Motion Terminal or with UART and CAN commands.

So if you go from “Analogue Mode” to “Digital Mode”, again for most of the Mentioned functionalities listed above you need to set them digitally like Motor type, speed or torque reference, …

The only two functionalities that can be done only at Hardware level on SOLO UNO for the moment are “Closed-loop” or “Open-loop” selection as well as putting SOLO into DFU mode using the Piano switch, this means you need to do this setup at hardware level regardless of the fact that you are in “Analogue Mode” or “Digital Mode”.

In this tutorial, as mentioned before, we are going to do a mixed control of Analogue and Digital to show the maximum flexibility of SOLO, so for parameters that are not available in analogue settings, we will set them directly using UART line of ARDUINO thanks to SOLO Arduino library, and then for the other parameters we will set them with analogue PWM outputs.

The Wirings

SOLO UNO wiring to ARDUINO UNO

SOLO MINI wiring to ARDUINO UNO

SOLO BETA wiring to ARDUINO UNO

The UART_TX and UART_RX Lines of SOLO BETA are 3.3V, so if you are going to use it with ARDUINO boards with 5V level UART lines (like Arduino UNO), you need to use circuitry similar to image above, otherwise, if your ARDUINO has 3.3V UART lines (TX and RX) you can connect them directly to SOLO.

arduino uno and solo beta wiring

The Motor

To proceed with this setup we are using a Brushless DC Motor with part number of “DB56C036030-A” and the technical datasheet that can be read here.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 2

The HALL sensor Calibrations and Motor’s Connection

If this is the first time you are connecting a motor to your SOLO, you need to make sure at least for one time, you have correctly calibrated the Hall sensors with correct connection of the Motor’s windings to ABC outputs of SOLO, to do that you need to read the article below and do the steps there at least one time, and as long as your Motor or the Hall sensors are the same or the Hall sensors mountings is not mechanically displaced with respect to the Motor, all the calibrated parameters will reside in long term memory of SOLO and they will be remembered after power recycling.

Read here the article.

Torque Control Setup and Code

Now once you made sure out of good calibration of the Hall sensors and the Motor wirings mentioned above, you can continue with this section in which we will firstly do the Torque control of a Brushless DC motor shown below using it’s HALL sensors outputs and then we will move to Speed control in the next section, the algorithm used in this code is pretty simple, and what we are doing is, asking the motor to go to 1.5A of “Iq current” (which is linearly related to the torque of the motor) in one specific direction and then changing the Direction of Rotation and asking for 2.5A of “Iq current” in this new direction.

Brushless Motor’s Torque [N.m] = Iq Current [A] x Motor’s Torque Constant[N.m/A]

Since we are going to proceed with this example in Analogue Mode, you need to make sure all the setups of Piano Switch are done correctly as below.

SOLO’s Setup to Operate in Analogue Torque Mode

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 3

As can be seen in this setup on the Piano switch we have:
 –   PIN 5 is DOWN : to select Closed-loop
 –   PIN 4 is UP : to operate in Torque Mode
 –   PIN 1 is UP and PIN 2 is DOWN : to select Motor type BLDC-PMSM Normal with Max speed of 8000RPM

The Code

Important Note for ARDUINO UNO users

In ARDUINO UNO , there is only 1 line of UART which is shared between the UART to USB convertor of ARDUINO board itself which is also used for flashing the ARDUINO UNO board as well, so whenever you want to program your ARDUINO UNO board through the ARDUINO IDE, YOU need to disconnect the UART_TX of SOLO from being connected to RX of ARDUINO UNO, by not doing this, you might get some errors in ARDUINO IDE during uploading the code.
To know more, read this post on ARDUINO website.

The Explanations and Results

As mentioned in this code the intention was to check the behaviour of SOLO while it’s being commanded from Arduino in Analogue manner by adjusting the duty cycle of a PWM pulse to define the desired Torque and current Limits for SOLO.

As you see in the code, the pin “~3” of Arduino UNO is connected to “S/T” input of SOLO, which in our configuration will define the Torque reference, this reference is calculated based on the maximum current that SOLO can feed into the Motor and to know more about this you can have look in the datasheets. The same story goes for pin “~9” of Arduino in which will define for SOLO the current limit and it’s connected to “P/F” input of SOLO for protection purposes.

So the thing that is happening is, we have the hardcoded desired torque in a realistic value in form of Amps, then we will convert it to a PWM duty cycle on pin “~3” for each reference, and we send it to SOLO, the PWM duty cycle will remain constant as long as the reference has not been changed. In Arduino UNO or similar devices, the PWM section has only a 8 bits counter and this means to go from 0% to 100% duty cycle we will only have 255 steps, which will define the resolution of Torque control for us, please notice that, the frequency of PWM pulses is not important and anything above 5kHz will do the job, here we chose to put both pin ~3 and ~9 on 31kHz.

For instance in Arduino UNO, the resolution of Torque reference can be calculated as 0.125A (32/255), and if you want to have a higher resolution you need to use controllers with higher PWM counters up to 16 or 32 bits, which will give you way higher resolution, below in Figure 1 and Figure 2 you can see the generated PWM pulse for two Iq references of 1.5A and 2.5A and also the generated PWM pulse for having 12.5A of current limit in Figure 3.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 4

Figure 1: PWM pulse generated on pin ~3 of Arduino for 1.5A of Iq reference.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 5

Figure 2: PWM pulse generated on pin ~3 of Arduino for 2.5A of Iq reference.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 6

Figure 3: PWM pulse generated on pin ~9 of Arduino for 12.5A of current limit.

To see the effect of the Torque reference tracking, in the first setup we have locked the shaft of the Motor to make sure the Motor doesn’t move so we can see the step response of the Torque for each cycle as you can see them in both Figure 4 and Figure 5 below, it worth mentioning that all the plots in this article are captured on Motion Terminal of SOLO using Monitoring Mode.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 7

Figure 4: Torque Step Response for -1.5A and 2.5A in different directions.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 8

Figure 5: Torque Step Response for -1.5A and 2.5A in different directions.

The main reason that we have locked the shaft is, if you are controlling the Torque and you apply no load on the shaft of the motor, the motor will start spinning and accelerating to it’s nominal speed or speeds near that, so the torque control makes sense when there is a load involved on the shaft of the Motor, for this case on Figure 6 you can see what happens in this example when the shaft is free, and the motor can spin up all the way to high speeds and you can’t also see how the torque is fixed on 1.5A or 2.5A as there is no load on the shaft, however, in this case if you suddenly apply some load on the shaft of the motor the torques will be fixed on desired references if the load is big enough.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 9

Figure 6: Torque control effect on the Motor’s speed in no-load condition.

Speed Control Setup and Code

Now after testing the Torque controller, we can test the speed controller, the two main differences here are the setup of the piano switch and the fact that, when you are in Torque mode, the Torque controller ( current controller) is automatically tuned by SOLO after running Motor Identification which is done in the Arduino example code using Digital commands, but for tuning the Speed controller we need to tune the Two potentiometers on the board to tune Speed controller Kp and Ki since now we are operating in Analogue mode, so we will have

SOLO’s Setup to Operate in Analogue Speed Mode

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 10
As can be seen in this setup on the Piano switch we have:
–   PIN 5 is DOWN : to select Closed-loop
–   PIN 4 is DOWN : to operate in Speed Mode
–   PIN 1 is UP and PIN 2 is DOWN : to select Motor type BLDC-PMSM Normal with Max speed of 8000RPM

You need to make sure also you have tuned properly the two Kp and Ki potentiometers shown in image below, so if you turn them all the way back in CW direction till they get blocked, it means you are at zero value, starting from there, you can increase the Kp potentiometer for something like 5 degrees in CCW direction and then the Ki for 1 or 2 degrees in CCW direction and see how the system behaves later on, you can always fine tune these value to find the best tunings. To Learn more you can have a look at this article.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 11

The Code

Important Note for ARDUINO UNO users

In ARDUINO UNO , there is only 1 line of UART which is shared between the UART to USB convertor of ARDUINO board itself which is also used for flashing the ARDUINO UNO board as well, so whenever you want to program your ARDUINO UNO board through the ARDUINO IDE, YOU need to disconnect the UART_TX of SOLO from being connected to RX of ARDUINO UNO, by not doing this, you might get some errors in ARDUINO IDE during uploading the code.
To know more, read this post on ARDUINO website.

The Explanations and Results

In this part, similar to the Torque part mentioned above, we are going to set the speed reference on “S/T” input of SOLO using PWM pulses going out of pin ~3 of Arduino to SOLO to have two different speed references of 1000RPM as well as 3000RPM in different directions.

Since we are in analogue mode, and the Motor type we have selected is Normal BLDC-PMSM, the maximum duty cycle or +5V on “S/T” input of SOLO will result in 8000RPM, so given this the speed control resolution for 8 bit PWM pins of Arduino UNO will be around 32 RPM (8000/255), which is good for our need, but if you need higher resolutions, you need to increase your PWM counter size all the way up to 16 or 32 bits using more advanced controllers like Teensy or etc.

The PWM pulses to generate 1000RPM and 3000RPM reference from Arduino at pin ~3 are shown in Figure 7 and 8 respectively:

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 12

Figure 7: PWM pulse generated on pin ~3 of Arduino for 1000RPM of Speed reference.

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 13

Figure 8: PWM pulse generated on pin ~3 of Arduino for 3000RPM of Speed reference.

The current limit here kept the same as the Torque control section and the PWM pulses from pin ~9 of Arduino are identical to Figure 3 shown above.

After applying each of these pulses and having two different speed while abruptly changing the direction of rotation when the reference changes, we saw the following speed tracking behaviour on the motor which is pretty much very near to what we were expecting:

Speed and Torque Control of a Brushless Motor with Hall sensors using Arduino and SOLO [+ Arduino Code] 14

Figure 9: Speed tracking result for 1000RPM and 3000RPM using Analogue control in two different directions.

Share This

Share This

Share this post with your friends!