Skip to main content
Associate II
June 22, 2024
Solved

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

  • June 22, 2024
  • 3 replies
  • 3488 views

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?

Best answer by Rajeswari

So, I tried the same with a new EVSPIN32G4 board and it works fine now. I am able to do position control using pilot as well as using command from code

3 replies

GMA
Technical Moderator
July 17, 2024

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
RajeswariAuthor
Associate II
July 18, 2024

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.

GMA
Technical Moderator
July 18, 2024

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
RajeswariAuthor
Associate II
July 19, 2024

It says "5". 

RajeswariAuthor
Associate II
July 19, 2024

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. 

GMA
Technical Moderator
July 19, 2024

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
GMA
Technical Moderator
July 22, 2024

Hello @Rajeswari,

Yes, test has been done with EVSPIN32G4, 1000ppr Encoder, 4500 RPM max motor, and signal Z pulse generated at each rotation.

RC low pass is used on encoder MCU input, smaller is your resistor higher is your cutoff frequency.

If you agree with the answer, please accept it by clicking on 'Accept as solution'.Best regards.GMA
RajeswariAuthor
Associate II
July 23, 2024

I have changed the filter resistors from 10kohm to 510 ohm. Will it affect the stspin32g4 IC (any overcurrent drawn)? Why was position control working one day but not the next? 

I need some solution