cancel
Showing results for 
Search instead for 
Did you mean: 

Position Control with Quadrature Encoders

smaiti
Associate III

Hi,

I am trying to create a User Application where I pass in commands from a terminal application (ex: Putty or Ucon) which results in the motor doing something.

I have configured the MC Workbench with the following options: 

smaiti_0-1704304765448.png

smaiti_1-1704304797449.png

 

 

Not using the MC Pilot so I have the following in User Interface: 


smaiti_3-1704304919032.png

For the first part of the application, I was passing 'SH\r' to start the motor and 'MO\r' to stop the motor.
The code in main.c is as follows: 

 

#define BUFFER_SIZE		3
uint8_t data_buffer[BUFFER_SIZE];

main()
{
// auto generated code
...
HAL_UART_Receive_DMA(&huart1, data_buffer, BUFFER_SIZE);
while(1)
{
}
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	if(huart == &huart1)
	{
		if(data_buffer[0] == 'S' && data_buffer[1] == 'H')
		{
			  MC_StartMotor1();
		}
		else if (data_buffer[0] == 'M' && data_buffer[1] == 'O')
		{
			MC_StopMotor1();
		}
	}
}​

 

 

The Motor Holds a position (not sure what is the default position set to?) when I send 'SH/r' and then rotor vibrates at that position.
Sending 'MO/r' stops the motor.
This is desirable but not quite.
I have the following BLDC motor: 
BL17E40-01 | BL17 Series | BLDC Motor | Lin Engineering


and I have installed the following encoder:
AMT11 Series | Modular | Incremental | Rotary Encoders (cuidevices.com)

The problem I think is these are relative encoders, and the MC workbench calls encoders with Z pins as absolute encoders.
I want to extend my user application and send commands that move the rotor to a particular position in some time.
In order to do that, I first followed the example as given in AN5464 (Position control of a three-phase permanent magnet motor using X‑CUBE‑MCSDK or X‑CUBE‑MCSDK-FUL)
I ran the following code : 

 

/* USER CODE BEGIN 2 */
MC_StartMotor1();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while(MC_GetAlignmentStatusMotor1()!=TC_ALIGNMENT_COMPLETED){}
while (1)
{
  /* USER CODE END WHILE */
  /* USER CODE BEGIN 3 */
  MC_ProgramPositionCommandMotor1(3.14/2,0.1);
  HAL_Delay(2000);
  MC_ProgramPositionCommandMotor1(-3.14/2,0.1);
  HAL_Delay(2000);
}
/* USER CODE END 3 */

 


When I run it, the rotor seems to move to a position which is not pie/2 or -pie/2 and then it just vibrates at whatever position it got to.
When I tried stepping through the code and added a breakpoint at 

while(MC_GetAlignmentStatusMotor1()!=TC_ALIGNMENT_COMPLETED){}

 I see that the Alignment never completes and the value on the left doesn't change to 2.
So, this example doesn't work as expected as given in the application note.
I want to pass strings like 'JG,3.14,1000\r' which should move the rotor 180 degrees in 1 second (something like that) but I don't even see this happening with the Application Example shared by STM32.
Please help resolve.

8 REPLIES 8
cedric H
ST Employee

Hello @smaiti ,

Could you please provide the version of the MCSDK do you use, and the ST boards you are using. If you use your own board, then MCU part number is also a useful information. 

Before debugging at application level, I strongly advise you to start at library level by making sure that your software is properly tuned according to your motor. 

Did you try to profile your motor with the ST Profiler tool, or did you enter your motor's characteristics manually in the Workbench?

Once you are confident with your motor parameters, I strongly advise you to generate a project with Speed control mode and enable the communication with the Motor Control Pilot. The first step is to guarantee that your motor spin correctly out of reset. If it is not the case the Motor control Pilot will provide you a lot of info to understand what is wrong and all the controls required to fine tune your application.

Please let us know when you are able to control nicely your motor.

Regards

Cedric

 

Hi @cedric H ,

The MCSDK version being used is 6.2.0

When I first got this board in December 23, I could profile the motor and follow the steps in your documents to spin the motor in Speed Control Mode. The observerless + PLL & Hall Sensors worked.
I wasted a lot of time trying to understand the ASPEP protocol and MCP used to send and receive data from the Motor pilot. While this GUI tool is good in the initial stages, I am at a stage where I need precise motor control using encoders. I have stopped using the GUI since that is not what our final application will be using. Need to send & receive data over UART from an STM32F4 board to control the motor and read certain outputs.
The Application Note was a good starting point, but it doesn't seem to help me achieve my goal.
I was initially supportive of the idea of using what you have. Just using the APIs and getting our application to work. But now it seems I have to start developing my firmware since I am running out of time trying to read the documentation and the code of MCSDK.
You have tried to build a product that is easy to use but in reality, it is not.

Hello @smaiti ,

First, I am glad to read that you succeed to control your motor without sensors and with Hall sensors.

I do not understand why you did not try to control your motor with your quadrature encoder ? It is the first step to do position control. Do you have a working project with your encoder ?

What do you mean by "it seems I have to start developing my firmware"? Do you plan to develop the full implementation of the FOC library? It seems to me that you are not far from having something working.

Could you help me to understand what is not easy from your point of view? 

Regards

Cedric

 

smaiti
Associate III

Hi @cedric H ,

I think you didn't read my post properly.

I have been able to run the BLDC motor in the following modes : 

  • Observerless + PLL
  • Hall Sensors
  • Quadrature Encoders

The code that I have shared is from a working project that has been configured with Quadrature Encoders. 
Let me ask you this. What do you think is going to happen if you configure your Motor Control Project with Quadrature encoders and run the following piece of code :

/* USER CODE BEGIN 2 */
MC_StartMotor1();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while(MC_GetAlignmentStatusMotor1()!=TC_ALIGNMENT_COMPLETED){}
while (1)
{
  /* USER CODE END WHILE */
  /* USER CODE BEGIN 3 */
  MC_ProgramPositionCommandMotor1(3.14/2,0.1);
  HAL_Delay(2000);
  MC_ProgramPositionCommandMotor1(-3.14/2,0.1);
  HAL_Delay(2000);
}
/* USER CODE END 3 */

What behavior do you expect ?

FouadB
ST Employee

Hello @smaiti

In this simple example, two distinct movement commands are issued by utilizing the dedicated API MC_ProgramPositionCommandMotor1:

The first one to +90° (π/2) in 100ms and the second one to -90° (-π/2) in 100ms.

A delay of two seconds is set between the two commands, which are given in a loop.

Best regards,

Fouad

If you agree with my answer, please accept it by clicking on 'Accept as solution'."

@FouadB ,

Thanks for your reply but its not doing that.
I have been able to locate the individual who is in charge of Motor Control products in North America.
I have shared the videos of the motor when I ran the code. Hoping to get some support from the Motor Control Team.

I think the ST community is not resourced to answer this question.

 

Hello @smaiti,

I sincerely hope you will receive the appropriate support from the Motor control team. Do not hesitate to share with the community your findings.

Regards

Cedric

Hi Smaiti,

I was reading all your posts on postion control using EVSPIN32G4. Have you found the solution for the issue. I am also working on the same project but for a 48V motor. Your reply will be very helpful for me.