Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoder Initialization by Hall sensors #32

Closed
Ayoub-pixe opened this issue May 3, 2023 · 4 comments
Closed

Encoder Initialization by Hall sensors #32

Ayoub-pixe opened this issue May 3, 2023 · 4 comments

Comments

@Ayoub-pixe
Copy link

Hello @trinamic,

I was examining the tmc4671_doEncoderInitializationMode2 function and I came across the following line of code:

int16_t hall_phi_e_estimated = *hall_phi_e_old + tmc4671_getS16CircleDifference(*hall_phi_e_new, *hall_phi_e_old)/2;

I was curious as to why this equation is not applied to the encoder abn_phi_e_actual. Specifically, I'm wondering why we don't calculate an abn_phi_estimated using a similar formula:

abn_phi_e_estimated = abn_phi_e_old + (abn_phi_e_new - abn_phi_e_old)/2

Then we could set the TMC4671_ABN_DECODER_PHI_E_PHI_M_OFFSET register to hall_phi_e_estimated - abn_phi_e_estimated. Can you please explain why the offset average is only calculated for the hall sensor and not the encoder?

https://github.com/trinamic/TMC-API/blob/4ced0291c5cdae49f54e7f082c3c651d03ca19e7/tmc/ic/TMC4671/TMC4671.c#L406

@croulvi
Copy link

croulvi commented May 17, 2023

Hella @trinamic .
I am working with @Ayoub-pixe.
We are asking this question because, we discovered that some encoder initialization were bad. Leading to a big error between phi-e and encoder.
This big error leads to higher current in the motor (and the regulation) to drive it with the same load.
We have identified that the high current is linked to offset error.
So before trying to modify the Encoder initialization function. We wanted to understand why this equation was used.
thanks.

@trinamic-LH
Copy link
Contributor

Hello everyone,
Apologies for the admittedly very late response!

The logic behind the hall-based ABN init goes back to the geometry of hall sensors:

Image

A digital hall encoder will divide into 6 separate 60° sections. The first section is at 0°, the second at 60° and so forth.
During the hall-based ABN init, we first store the currently reported hall angle, and then rotate until we observe a second hall angle from the motor moving to the next, adjacent hall sector. For example, if we at first observed the 120° position, and then saw the motor rotate into the 180° position, we know that we just were at the crossing point between the sectors. The formula for averaging the two angles calculates that crossing point angle, in this example 120° + (180° - 120°)/2 = 150°.

For an ABN encoder, each individual step is a much smaller angle change than 60°. Averaging two adjacent positions would not yield any practical improvement.
For exaxmple, an ABN encoder with 10000 pulses per rotation (PPR) or 40000 counts per rotation (CPR) [1] mounted on a motor with 4 pole pairs has just a 0.036° angle change with each encoder count:

  • Mechanical degrees per encoder count: 360° / CPR = 360° / 40000 = 0.009°
  • Electrical degrees per encoder count: 0.009° * pole pair count = 0.009° * 4 = 0.036°

[1]: PPR and CPR are related as such: CPR = 4*PPR. This is due to each pulse having two edges, and the pulses being staggered across the two A and B channels, giving four signal edges total for each pulse.

@trinamic-LH
Copy link
Contributor

Hella @trinamic . I am working with @Ayoub-pixe. We are asking this question because, we discovered that some encoder initialization were bad. Leading to a big error between phi-e and encoder. This big error leads to higher current in the motor (and the regulation) to drive it with the same load. We have identified that the high current is linked to offset error. So before trying to modify the Encoder initialization function. We wanted to understand why this equation was used. thanks.

For initializing an ABN, the choice in strategy matters a lot. A hall-based initialization as discussed here gives decent results only if:

  • Your time between the hall edge occuring and performing the processing of the referenced C code happens quickly. Note that this includes the time to communicate with the TMC4671.
  • There is no gearbox between the motor shaft and the ABN mounting point
    • Or if there is, little to no slack is present
    • Or if slack is present, it is well quantified and compensated (note the hysteresis-like effect of this, if the first hall edge is observed very quickly, the mechanical system may still not yet have fully started rotating)
  • Your hall sensor and ABN sensor are decently mounted and/or mounting tolerances (hall edges not being at exactly 60° apart, ABN sensor not well aligned with the rotation axis) are being compensated for.

For a more precise initialization, the ABN channel - if available - would be the best choice. Since the TMC4671 has the capability to directly process that input, no communication or processing delays are imposed like the hall. Since the N signal is part of the ABN itself, it will yield repeateable initialization. It does however require up to a full rotation of the mechanical axis to find the initially unknown N position.

Depending on your application, a multi-tier initialization strategy might also be feasible. Start with the current hall sector position estimate (+-30° error possible), then turn to identify an edge, lessening the error with at most 60° electrical rotation ( 60° / pole pair count mechanical rotation). Then rotate until you found your ABN N channel (up to 360° mechanical rotation) to fully remove any ABN initialization error from the previous steps.

@trinamic-LH
Copy link
Contributor

(Feel free to reopen if there are any further questions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants