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

Issues with 2209s #8

Closed
troth530 opened this issue Jan 23, 2023 · 6 comments
Closed

Issues with 2209s #8

troth530 opened this issue Jan 23, 2023 · 6 comments

Comments

@troth530
Copy link

troth530 commented Jan 23, 2023

Hi, I'm having 2 main issues. 1) Enabling hybrid mode for switching between stealthchop and spreadcycle and 2) Stallguard for sensorless homing.

Hybrid Issue:
I cannot determine if TMC2209_TPWM_THRS in tmc2209.h is being honored or overwritten by PWM_THRESHOLD_VELOCITY in trinamic.h. TPWMTHRS from the 2209 datasheet is the TSTEP at the desired velocity, I cannot determine if you account for the unit conversion between velocity and TSTEP properly. Also after setting PWM_THRESHOLD_VELOCITY a broken piece of code is exposed here:

stepper[motor.id]->set_tpwmthrs(motor.id, (float)PWM_THRESHOLD_VELOCITY / 60.0f, cfg.settings->steps_per_mm);

The error is
../main/motors/trinamic.c:670:98: error: 'motor_settings_t' {aka 'struct '} has no member named 'steps_per_mm'

Stallguard Issue:
When enabled, stallguard seems to be oversensitive even during a typical jog. There is persistent stalling after issuing M122 x S1. M122 x S1 shows SG_RESULT ranging from 0 to 300 which almost implies either it's configured wrong or stallguard cannot be used except during homing. Using the calculator below, TMC2209_TPWM_THRS is set to 38 (corresponding to 6000mm/min). I've tried TMC2209_COOLSTEP_THRS ranging from 100 to 200 (which is 1000-2200mm/min and reasonable homing speeds). The datasheet says diag is only pulsed when TCOOLTHRS ≥ TSTEP > TPWMTHRS. I used the calculator below for calculating Txxx. I've been trying to unravel this mystery, but I need your help in figuring it out. I know for instance your default settings do not satisfy the conditions gating diag being pulsed and perhaps the unit consistency is a problem as everything must be implemented in units of TSTEP.

TMC2209_Calculations.zip

Thank you!

@wakass
Copy link

wakass commented Jan 23, 2023

This could be related to the pwm_autoscale being disabled on enableStallguard. I created an issue on this: terjeio/Trinamic-library#6
Would be good to get some confirmation.

@troth530
Copy link
Author

@wakass, that helps part of the issue (I believe). Thank you!

Still not sure about units, I also notice there are raw values being read, but not sure what is being written. I still believe unit consistency should be required for trinamic internal algorithms at least for this condition of this comparison tcoolthrs < tstep < tpwmthres.

@wakass
Copy link

wakass commented Jan 24, 2023

@troth530 Regarding your first question, first keep in mind that tpwm threshold is the threshold where pwm-mode/stealthchop is operational (TSTEP ≥ TPWMTHRS), i.e. velocity_step < velocity_tpwmthrs. Above the velocity_tpwmthrs, spreadcycle is enabled (and pwm regulation disabled). In that regards, a 'desired' velocity as you mention

TPWMTHRS from the 2209 datasheet is the TSTEP at the desired velocity

is correct, but the desired velocity will likely not be the velocity at which you will be driving. It needs to be set a-priori to where you expect the pwm regulation of stealthchop to not be reliable. Anyway, i'm being a little pedantic here.

The trinamic plugin sets the tpwm_threshold also in the code below, which I think gets run after initialization. But i'm not too sure about that, you can put some debug output lines to make sure. In that sense I think the code that is giving you the error can be removed entirely. Do note that the same threshold velocity is set for all axes.

stepper[motor]->set_tpwmthrs(motor, (float)PWM_THRESHOLD_VELOCITY / 60.0f, steps_per_mm[idx]);

Conversion from speed to time step is achieved here:
https://github.com/terjeio/Trinamic-library/blob/9eae92beab071f00d188f9da25672ab9f2aaa116/tmc2209.c#L190

M122 also gives debug output on tpwm btw.

@troth530
Copy link
Author

@wakass can you provide more details about M122 debug output, what is the syntax?
So far I have confirmed pmw_autoscale fixes the stallguard issues- great find. I still need to confirm hybrid behavior.
Thank you!

@wakass
Copy link

wakass commented Jan 26, 2023

See this issue here for output from M122, grblHAL/RP2040#41 (comment)

Note the pwm section with the threshold and mm/s setting. This should give you an idea.

Syntax for M122 is described in this very repository: https://github.com/grblHAL/Plugins_motor

@troth530
Copy link
Author

troth530 commented May 8, 2023

Sensorless homing is fixed with re-enabling pwm_autoscale.
Hybrid mode is fixed adding float steps_per_mm; to struct in motor_settings_t in motors/trinamic.h

@troth530 troth530 closed this as completed May 8, 2023
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

2 participants