cancel
Showing results for 
Search instead for 
Did you mean: 

EVLSPIN32G4-ACT quadrature encoder mode issues

shane mattner
Senior
  • MCSDK v6.3.0
  • Problem: MCWB generated code with quadrature encoder does not spin motor properly
  • STWB6 file is attached.  I had to copy and paste the contents into a .txt file to upload it

 

Here are links to videos with quadrature direction reversed and not reversed.  With the quadrature reversed I press the SW1 button and the motion seems to be somewhat smooth for the motion the motor makes.  With the quadrature signals NOT reversed the motor alternates back and forth violently and produces vibrations enough to move the motor test stand for ~5sec then cuts out and will not restart.

 

The motor commutates smoothly in sensorless FOC mode using SW1 button startup.  Then I change the Speed Sensing Config to use the encoder signals and the motor behaves as described above.  The encoder has 4096 slots which is what I'm using for pulses per revolution.  I also tried 4*4096 (16,384) ppr but that resulted in a hard fault of the firmware immediately on start up.  I confirmed Speed Sensing Mode Selection is quadrature encoder.  

 

Can anyone give some advice on how I might work through this problem?  I'll try playing with parameters today but if anyone has insights please let me know.

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

> After a bunch of testing I found that with the encoder enabled I could successfully do position commands with MCI_ExecPositionCommand().  It's weird the Motor Pilot doesn't work as expected for speed or torque control though.  Any idea how I might be able to run the velocity and torque control with the encoder enabled?

Motor Pilot does actually nothing else than sending commands to the firmware. From what you describe I suspect a hardware issue around your encoder signals. It would be interesting to do a live plot with the Pilot (By clicking on the highlighted button) of STO-PLL angle and Encoder angle with STO-PLL as primary sensor as you did before but for a longer period and increasing the speed target, I suspect that at some speed your encoder signal is corrupted, and the encoder angle will be distorted. That could explain why for position control the angle is properly tracked. 

Plugin an oscilloscope at encoder signals could also be very helpful if you can.

cedricH_1-1727855725767.png

Regards

Cedric

 

View solution in original post

8 REPLIES 8
cedric H
ST Employee

Hello @shane,

If your motor run smoothly in sensorless mode, the easiest way to debug your encoder settings is to generate a project with STO-PLL as a primary sensor and encoder as auxiliary sensor.

Once it is done, you can plot with the MC-Pilot the angle of the STO-PLL and the encoder simultaneously. Both angles must be merged.

Keep in mind that in case of sensored configuration (Hall as Encoder), the order of the motor phases does matter. Which is not the case in sensorless config.

Hope it helps.

Regards

Cedric

PS: If you still have issues, please send a plot of the two angles acquired with the MC-Pilot.

I have not been able to get the Motor Pilot to work for plotting signals.  I can get the Motor Profiler to work but but not the other part of the tool that connects to the motor and you can give commands.  V1.2.9 of Motor Pilot.

 

I tried reversing the motor phases, and then reversing the encoder phases, which resulted in the same behavior as above:  one connections of encoder wires makes the motor vibrate in place and the other connection can sometimes make the motor rotate for a bit.

But when the motor rotates it does so with inconsistent speed and the torque is very weak.  1/3 times the motor will make it a full rotation when using the encoder mode.  Then where it stops I cannot get the motor to spin again until I move the motor manually by a few degrees, then the motor will spin again weakly as described above.  All of this functional testing is by pressing the SW1 button on the dev kit.

 

Can you point me towards some variables to check?  It looks like STO_PLL_M1 is the struct to monitor the PLL and ENCODER_M1 is the struct to monitor the encoder.  Is there a way to switch the firmware from using the encoder to the PLL while the program is running?

 

Is there anything obvious in the encoder struct below that might need to be changed?

 

shanemattner_0-1727538561491.png

 

For the PLL struct I see the "is speed reliable" bit being flipped when the motor stops rotating 

shanemattner_1-1727538666583.png

 

It's weird the motor will spin a little bit sometimes and weakly.  I would expect no rotation and more consistent torque.

 

Hello,

> I have not been able to get the Motor Pilot to work for plotting signals

So let's start with the beginning. 

what is the issue you are facing with the motor Pilot ? Could you copy/paste the information from the terminal tab ?

> Is there a way to switch the firmware from using the encoder to the PLL while the program is running?

Unfortunately, this is not available yet. The auxiliary sensor capability has been designed as a debug feature. This is in the pipe for a future version.

Regards

Cedric

I was able to get the Motor Pilot working by loading the MC_FOC_SDK.qml file, instead of leaving the Pilot in default mode.  Idk if this is in the documentation somewhere but it's confusing I need to do this step when the Motor Profiler will work ok on the next tab.

shanemattner_8-1727721292391.png

 

 

I recorded some data from encoder and FOC control.  Here is a plot of the encoder angle vs foc when the firmware is using encoder for control.  You can see how the FOC angle is pretty far off from the encoder angle.  Also interestingly, the FOC angle (purple) keeps increasing after the motor stops spinning.  In this mode, the motor sometimes spins one direction for a rotation, then the other direction, then after that it has a weak torque pushing in one direction which I can get the motor to spin a bit by hand by pushing it.

shanemattner_4-1727721042905.png

Start-up and first ramp:

shanemattner_5-1727721137795.png

Change of directions and second ramp:

shanemattner_6-1727721179431.png

End of run where FOC angle seems to roll-over repeatedly.  The motor was not moving during this period:

shanemattner_7-1727721226973.png

 

 

 

 

 

 

Here is a screenshot of the encoder vs FOC when the firmware is generated with FOC control.  In this mode the motor spins smoothly at a certain frequency.

shanemattner_1-1727720801416.png

Interestingly, the encoder seems to track FOC estimated angle closely for a few seconds, then it seems to stop updating properly:

shanemattner_2-1727720901883.png

Here is the FOC angle from that entire run, during which the motor was spinning smoothly at a certain velocity:

shanemattner_3-1727720944015.png

 

 

Let me know if there's any other tests I can run or example code using a quadrature encoder.  When I debug the firmware in FOC mode I see the encoder values change and then eventually they stop changing, but the motor is still spinning in FOC mode.

 

Hello,

In MCSDK 6.3.1, the Pilot does a better job to propose you the right UI by default.

Be aware that Profiler binary (when profiler check box is selected from the WB) is intended only to profile your motor. Once your motor is profiled, you have to re-generate a new project without the profiler selected to be able to use your  motor application as intended, and connect to the MC Pilot with the standard MC_FOC_SDK.qml UI. 

The screenshot "of the encoder vs FOC when the firmware is generated with FOC control" shows that both angles are aligned. Your hardware config is correct, the phases (U,V,W) of your motor is aligned with the phases U,V,W of the firmware, and the encoder is properly configured.

Your screenshots don't appear to be from MCPilot, may I ask you how did you generate them ?

Regards

Cedric

 

 

Thank you for the tip on the Profiler, I found that out the hard way after struggling for 2 days and another ST employee on the forum told me this non-obvious step.

The plots are generated from saving Motor Pilot data and then plotting it with Plotly Dash python scripts.  I couldn't figure out how to see the whole plots in Motor Pilot so I had to export the data.

If it helps I'm using CubeMX 6.12.1 and Firmware 1.6.0 for generating the project and get the same results.  Could there be some gains I need to tune?  Here's the working Motor Pilot with sensorless FOC control:

 

shanemattner_1-1727804660428.png

It seems like the encoder is kinda working:  in sensorless mode it tracks position for a few seconds before stopping for some reason.  And in sensored mode it can spin for a rotation or 2.  

 

After a bunch of testing I found that with the encoder enabled I could successfully do position commands with MCI_ExecPositionCommand().  It's weird the Motor Pilot doesn't work as expected for speed or torque control though.  Any idea how I might be able to run the velocity and torque control with the encoder enabled?

 

> After a bunch of testing I found that with the encoder enabled I could successfully do position commands with MCI_ExecPositionCommand().  It's weird the Motor Pilot doesn't work as expected for speed or torque control though.  Any idea how I might be able to run the velocity and torque control with the encoder enabled?

Motor Pilot does actually nothing else than sending commands to the firmware. From what you describe I suspect a hardware issue around your encoder signals. It would be interesting to do a live plot with the Pilot (By clicking on the highlighted button) of STO-PLL angle and Encoder angle with STO-PLL as primary sensor as you did before but for a longer period and increasing the speed target, I suspect that at some speed your encoder signal is corrupted, and the encoder angle will be distorted. That could explain why for position control the angle is properly tracked. 

Plugin an oscilloscope at encoder signals could also be very helpful if you can.

cedricH_1-1727855725767.png

Regards

Cedric

 

I spun up some custom hardware based on the dev kit, but with a different encoder circuit that I've been using successfully for a while on another design.  Hopefully that fixes the issue.  

 

I appreciate your help @cedric H .  I think I have enough to keep making progress for now.