cancel
Showing results for 
Search instead for 
Did you mean: 

Position control (based on AN5464) using quadrature incremental encoder(ABZ)

Rajeswari
Associate III

Hello,

I'm trying to do position control using EVSPIN32G4 board and pmsm motor with incremental encoder. I followed the steps given in AN5464. The motor did not move and the rotor is locked. I'm attaching the code here. 

**********************************************************************************************************

/* 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 */

***********************************************************************************************************

While debugging the code stops at "while(MC_GetAlignmentStatusMotor1()!=TC_ALIGNMENT_COMPLETED){}". It never comes out of this while loop. 

The A,B & Z pulses are working fine. Motor runs perfectly in sensorless FOC(speed control). I think the alignment does not happen at all. kindly help with this. I'm very short on time to complete the project 

@msingh @smaiti and many others faced same issue. But there wasn't any explanation on how they overcome this issue.

MC Workbench 6.2.1

CubeMX 6.6.1

CubeIDE 1.15.0

any help guys?

13 REPLIES 13
GMA
ST Employee

Hello @Rajeswari,

Could you please check that inverter inputs U, V, and W are correctly connected to the associated motor phases and encoder inputs as well?
And once board connected by USB, are you able to use a scope to verify that, spinning the motor shaft by hands, tha A and B signals are correctly toggling?

If you agree with the answer, please accept it by clicking on 'Accept as solution'.
Best regards.
GMA

Yes the U,V,W inputs are correctly connected & the encoder inputs as well. I also checked the encoder signals with scope. They are all fine. I am able to do position control with motor pilot. But i cant with code from an5464.

Hello @Rajeswari,

Are you using the encoders with absolute position (Motor index pin Z selected and "use absolute position control pin" in Speed Sensing Config)? If yes, at MC_StartMotor1 motor should spin until signal coming from Z trigs an IT that sets TC_ALIGNMENT_COMPLETED. Did you also verify that Z signal generates a pick at each lap?

At "while(MC_GetAlignmentStatusMotor1()!=TC_ALIGNMENT_COMPLETED){}" loop could you check what is the reported value? Values are defined in AlignStatus_t enum definition.

If you agree with the answer, please accept it by clicking on 'Accept as solution'.
Best regards.
GMA
Rajeswari
Associate III

It says "5". 

There was a suggestion on mc workbench to change filter resistor incase of high resolution encoder. So I changed the value from 10k to 510 ohms. After that, I was able to do position control from both the code & pilot. The next day, it doesn't work using either. So i reverted back to default value 10k & now  i am not able to do position control from both pilot & code. What could be the issue? 

I am getting encoder pulses on both side of resistor and at the MCU pin for encoder signals, I am getting the pulses but the amplitude is less compared to value at resistor input side. 

Hello @Rajeswari,

As you can see in trajectory_ctrl.h file, 5 means TC_ALIGNMENT_ERROR. 

Does, at MC_StartMotor1 call, motor spin? At this point, it is ordered to do a 2*pi rotation during a period of 2s to have the Z signal trigged (Z_ALIGNMENT_DURATION and Z_ALIGNMENT_NB_ROTATION parameters in trajectory_ctrl.h file).

During this first rotation, does Z signal is generated?

If you agree with the answer, please accept it by clicking on 'Accept as solution'.
Best regards.
GMA

Hello @Rajeswari,

Using R81/R82/R83 resistors set to 330ohms on EVSPIN32G4, we are able to run position control feature on our side. Default RC filtering may be too strong. Could you please try with these resistor values?

If you agree with the answer, please accept it by clicking on 'Accept as solution'.
Best regards.
GMA

No, it didn't rotate at MC_StartMotor1(). But I was able to do position control before(default filter resistor 10kohm) using pilot. Now after changing the filter resistors from 10kohm to 510 ohms, I was able to do Position control using code and pilot that day. The next day both didn't work. What could be the reason? 

I even changed the filter resistor to default value 10kohm to see if I can do Pos Ctrl from pilot like before. But it was not working too. 

Could you please provide any suggestions? Any help would be much appreciated.

you are saying that you are able to do Position control by changing R81/R82/R83 to 330 ohms on evspin32g4 board?

I changed it to 510 ohms. will it make much difference?

Note: The encoder I'm using has a resolution of 4096ppr.