Various updates for TMC support

This commit is contained in:
Scott Lahteine
2018-01-09 19:14:07 -06:00
parent 2c2cf5e856
commit 6a043eee55
11 changed files with 472 additions and 483 deletions

View File

@@ -35,11 +35,19 @@ enum TMC_AxisEnum {
TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4
};
constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
return 12650000UL * msteps / (256 * thrs * spmm);
}
void _tmc_say_current(const char name[], const uint16_t curr);
void _tmc_say_otpw(const char name[], const bool otpw);
void _tmc_say_otpw_cleared(const char name[]);
void _tmc_say_pwmthrs(const char name[], const uint32_t thrs);
void _tmc_say_sgt(const char name[], const uint32_t sgt);
template<typename TMC>
void tmc_get_current(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" axis driver current: ");
SERIAL_ECHOLN(st.getCurrent());
_tmc_say_current(name, st.getCurrent());
}
template<typename TMC>
void tmc_set_current(TMC &st, const char name[], const int mA) {
@@ -48,33 +56,25 @@ void tmc_set_current(TMC &st, const char name[], const int mA) {
}
template<typename TMC>
void tmc_report_otpw(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
SERIAL_EOL();
_tmc_say_otpw(name, st.getOTPW());
}
template<typename TMC>
void tmc_clear_otpw(TMC &st, const char name[]) {
st.clear_otpw();
SERIAL_ECHO(name);
SERIAL_ECHOLNPGM(" prewarn flag cleared");
_tmc_say_otpw_cleared(name);
}
template<typename TMC>
void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" stealthChop max speed set to ");
SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.TPWMTHRS() * spmm));
_tmc_say_pwmthrs(name, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
}
template<typename TMC>
void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm) {
st.TPWMTHRS(12650000UL * st.microsteps() / (256 * thrs * spmm));
st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
tmc_get_pwmthrs(st, name, spmm);
}
template<typename TMC>
void tmc_get_sgt(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" driver homing sensitivity set to ");
MYSERIAL.println(st.sgt(), DEC);
_tmc_say_sgt(name, st.sgt());
}
template<typename TMC>
void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
@@ -82,9 +82,13 @@ void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
tmc_get_sgt(st, name);
}
void _M122();
void monitor_tmc_driver();
#if ENABLED(TMC_DEBUG)
void tmc_set_report_status(const bool status);
void tmc_report_all();
#endif
/**
* TMC2130 specific sensorless homing using stallGuard2.
* stallGuard2 only works when in spreadCycle mode.
@@ -93,21 +97,7 @@ void monitor_tmc_driver();
* Defined here because of limitations with templates and headers.
*/
#if ENABLED(SENSORLESS_HOMING)
template<typename TMC>
void tmc_sensorless_homing(TMC &st, bool enable=true) {
#if ENABLED(STEALTHCHOP)
if (enable) {
st.coolstep_min_speed(1024UL * 1024UL - 1UL);
st.stealthChop(0);
}
else {
st.coolstep_min_speed(0);
st.stealthChop(1);
}
#endif
st.diag1_stall(enable ? 1 : 0);
}
void tmc_sensorless_homing(TMC2130Stepper &st, bool enable=true);
#endif
#endif // _TMC_UTIL_H_