1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-02 10:53:01 +02:00

more stuff

This commit is contained in:
bdring
2020-09-04 10:04:40 -05:00
parent cf4444e4f0
commit 347aab5b0c
9 changed files with 101 additions and 28 deletions

View File

@@ -119,11 +119,11 @@ Some features should not be changed. See notes below.
//#define CONNECT_TO_SSID "your SSID"
//#define SSID_PASSWORD "your SSID password"
//CONFIGURE_EYECATCH_BEGIN (DO NOT MODIFY THIS LINE)
#define ENABLE_BLUETOOTH // enable bluetooth
//#define ENABLE_BLUETOOTH // enable bluetooth
#define ENABLE_SD_CARD // enable use of SD Card to run jobs
#define ENABLE_WIFI //enable wifi
//#define ENABLE_WIFI //enable wifi
#if defined(ENABLE_WIFI) || defined(ENABLE_BLUETOOTH)
# define WIFI_OR_BLUETOOTH

View File

@@ -35,7 +35,7 @@
#define TRINAMIC_DAISY_CHAIN
#define TRINAMIC_RUN_MODE TRINAMIC_MODE_STEALTHCHOP
#define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP
#define TRINAMIC_TOFF_COOLSTEP 4
#define TRINAMIC_HEND_COOLSTEP 5
@@ -45,27 +45,27 @@
// The hardware enable pin is tied to ground
#define USE_TRINAMIC_ENABLE
#define X_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define X_RSENSE TMC2130_RSENSE_DEFAULT
#define X_TRINAMIC_DRIVER 5160 // Which Driver Type?
#define X_RSENSE TMC5160_RSENSE_DEFAULT
#define X_STEP_PIN GPIO_NUM_12
#define X_DIRECTION_PIN GPIO_NUM_14
#define X_CS_PIN GPIO_NUM_17 // Daisy Chain, all share same CS pin
#define Y_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Y_RSENSE TMC2130_RSENSE_DEFAULT
#define Y_TRINAMIC_DRIVER X_TRINAMIC_DRIVER // Which Driver Type?
#define Y_RSENSE X_RSENSE
#define Y_STEP_PIN GPIO_NUM_27
#define Y_DIRECTION_PIN GPIO_NUM_26
#define Y_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
#define Z_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Z_RSENSE TMC2130_RSENSE_DEFAULT
#define Z_TRINAMIC_DRIVER X_TRINAMIC_DRIVER // Which Driver Type?
#define Z_RSENSE X_RSENSE
#define Z_STEP_PIN GPIO_NUM_15
#define Z_DIRECTION_PIN GPIO_NUM_2
#define Z_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
#define A_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define A_RSENSE TMC2130_RSENSE_DEFAULT
#define A_TRINAMIC_DRIVER X_TRINAMIC_DRIVER // Which Driver Type?
#define A_RSENSE X_RSENSE
#define A_STEP_PIN GPIO_NUM_33
#define A_DIRECTION_PIN GPIO_NUM_32
#define A_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin

View File

@@ -341,8 +341,7 @@ void motors_set_disable(bool disable) {
}
void motors_read_settings() {
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Read Settings");
for (uint8_t gang_index = 0; gang_index < 2; gang_index++) {
for (uint8_t gang_index = 0; gang_index < MAX_GANGED; gang_index++) {
for (uint8_t axis = X_AXIS; axis < N_AXIS; axis++)
myMotor[axis][gang_index]->read_settings();
}

View File

@@ -44,6 +44,8 @@ namespace Motors {
config_message();
}
//void StandardStepper::read_settings() {}
void StandardStepper::init_step_dir_pins() {
// TODO Step pin, but RMT complicates things
_invert_step_pin = bit_istrue(step_invert_mask->get(), bit(axis_index));

View File

@@ -13,6 +13,7 @@ namespace Motors {
virtual void set_direction_pins(uint8_t onMask);
void init_step_dir_pins();
virtual void set_disable(bool disable);
uint8_t step_pin;
protected:

View File

@@ -44,6 +44,8 @@ namespace Motors {
_homing_mode = TRINAMIC_HOMING_MODE;
_homing_mask = 0; // no axes homing
has_errors = false;
set_axis_name();
if (_driver_part_number == 2130)
@@ -155,6 +157,7 @@ namespace Motors {
void TrinamicDriver::read_settings() {
if (has_errors)
return;
uint16_t run_i_ma = (uint16_t)(axis_settings[axis_index]->run_current->get() * 1000.0);
float hold_i_percent;
@@ -169,6 +172,13 @@ namespace Motors {
tmcstepper->microsteps(axis_settings[axis_index]->microsteps->get());
tmcstepper->rms_current(run_i_ma, hold_i_percent);
tmcstepper->en_pwm_mode(trinamic_en_pwm_mode->get());
tmcstepper->pwm_autoscale(trinamic_pwm_auto_scale->get());
tmcstepper->TCOOLTHRS(trinamic_tcoolthrs->get()); // when to turn on coolstep
tmcstepper->THIGH(trinamic_thigh->get());
tmcstepper->toff(trinamic_toff->get());
tmcstepper->hend(trinamic_hend->get());
tmcstepper->hstrt(trinamic_hstrt->get());
}
void TrinamicDriver::set_homing_mode(uint8_t homing_mask, bool isHoming) {
@@ -182,6 +192,8 @@ namespace Motors {
Coolstep mode, so it will need to switch to Coolstep when homing
*/
void TrinamicDriver::set_mode(bool isHoming) {
if (has_errors)
return;
if (isHoming)
@@ -202,10 +214,10 @@ namespace Motors {
break;
case TRINAMIC_MODE_COOLSTEP:
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "TRINAMIC_MODE_COOLSTEP");
tmcstepper->en_pwm_mode(false);
tmcstepper->pwm_autoscale(false);
tmcstepper->en_pwm_mode(trinamic_en_pwm_mode->get());
tmcstepper->pwm_autoscale(trinamic_pwm_auto_scale->get());
tmcstepper->TCOOLTHRS(trinamic_tcoolthrs->get()); // when to turn on coolstep
tmcstepper->THIGH(NORMAL_THIGH);
tmcstepper->THIGH(trinamic_thigh->get());
tmcstepper->toff(trinamic_toff->get());
tmcstepper->hend(trinamic_hend->get());
tmcstepper->hstrt(trinamic_hstrt->get());
@@ -228,6 +240,9 @@ namespace Motors {
This is the stallguard tuning info. It is call debug, so it could be generic across all classes.
*/
void TrinamicDriver::debug_message() {
error_check();
return;
if (has_errors)
return;
uint32_t tstep = tmcstepper->TSTEP();
@@ -246,6 +261,44 @@ namespace Motors {
axis_settings[axis_index]->stallguard->get());
}
void TrinamicDriver::error_check() {
TMC2130_n ::DRV_STATUS_t status { 0 }; // a useful struct to access the bits.
status.sr = tmcstepper->DRV_STATUS();
bool err = false;
if (status.s2ga || status.s2gb) {
grbl_msg_sendf(
CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Motor Short Coil a:%s b:%s", _axis_name, status.s2ga ? "Y" : "N", status.s2gb ? "Y" : "N");
err = true;
}
// check for over temp or pre-warning
if (status.ot || status.otpw) {
grbl_msg_sendf(
CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Driver Temp Warning:%s Fault:%s", _axis_name, status.otpw ? "Y" : "N", status.ot ? "Y" : "N");
err = true;
}
if (status.ola || status.olb) {
grbl_msg_sendf(
CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Motor open load a:%s b:%s", _axis_name, status.ola ? "Y" : "N", status.olb ? "Y" : "N");
err = true;
}
return;
if (!err) {
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Motor OK status %x", status);
}
}
// calculate a tstep from a rate
// tstep = TRINAMIC_FCLK / (time between 1/256 steps)
// This is used to set the stallguard window from the homing speed.

View File

@@ -85,6 +85,7 @@ namespace Motors {
void trinamic_test_response();
void trinamic_stepper_enable(bool enable);
void debug_message();
void error_check();
void set_homing_mode(uint8_t homing_mask, bool ishoming);
void set_disable(bool disable);
bool test();

View File

@@ -57,6 +57,10 @@ IntSetting* trinamic_toff;
IntSetting* trinamic_hend;
IntSetting* trinamic_hstrt;
IntSetting* trinamic_tcoolthrs;
IntSetting* trinamic_thigh;
IntSetting* trinamic_tbl;
FlagSetting* trinamic_en_pwm_mode;
FlagSetting* trinamic_pwm_auto_scale;
enum_opt_t spindleTypes = {
// clang-format off
@@ -169,6 +173,11 @@ static bool checkStallguard(char* value) {
return true;
}
static bool trinamic_change(char* value) {
motorSettingChanged = true;
return true;
}
static bool checkMicrosteps(char* value) {
motorSettingChanged = true;
return true;
@@ -329,11 +338,15 @@ void make_settings() {
spindle_type = new EnumSetting(NULL, EXTENDED, WG, NULL, "Spindle/Type", SPINDLE_TYPE, &spindleTypes);
stallguard_debug_mask = new AxisMaskSetting(EXTENDED, WG, NULL, "Report/StallGuard", 0, checkStallguardDebugMask);
trinamic_toff = new IntSetting(GRBL, WG, NULL, "Trinamic/toff", 4, 0, 255, trinamic_change);
trinamic_hend = new IntSetting(GRBL, WG, NULL, "Trinamic/hend", 5, 0, 255, trinamic_change);
trinamic_hstrt = new IntSetting(GRBL, WG, NULL, "Trinamic/hstrt", 0, 0, 255, trinamic_change);
trinamic_tcoolthrs = new IntSetting(GRBL, WG, NULL, "Trinamic/tcoolthrs", 0, 1000, 0xFFFFF, trinamic_change);
trinamic_thigh = new IntSetting(GRBL, WG, NULL, "Trinamic/thigh", 0, 1000, 0xFFFFF, trinamic_change);
trinamic_tbl = new IntSetting(GRBL, WG, NULL, "Trinamic/tbl", 1, 0, 3, trinamic_change);
trinamic_en_pwm_mode = new FlagSetting(GRBL, WG, NULL, "Trinamic/EnPwmMode", 1, trinamic_change);
trinamic_pwm_auto_scale = new FlagSetting(GRBL, WG, NULL, "Trinamic/PwmAutoScale", 1, trinamic_change);
trinamic_toff = new IntSetting(GRBL, WG, NULL, "Trinamic/toff", 4, 0, 255);
trinamic_hend = new IntSetting(GRBL, WG, NULL, "Trinamic/hend", 5, 0, 255);
trinamic_hstrt = new IntSetting(GRBL, WG, NULL, "Trinamic/hstrt", 0, 0, 255);
trinamic_tcoolthrs = new IntSetting(GRBL, WG, NULL, "Trinamic/tcoolthrs", 0, 1000, 0xFFFFF);
//trinamic_s2vs = new IntSetting(GRBL, WG, NULL, "Trinamic/s2vs", 0, 1000, 0xFFFFF);
//trinamic_s2g = new IntSetting(GRBL, WG, NULL, "Trinamic/s2g", 0, 1000, 0xFFFFF);
}

View File

@@ -61,3 +61,7 @@ extern IntSetting* trinamic_toff;
extern IntSetting* trinamic_hend;
extern IntSetting* trinamic_hstrt;
extern IntSetting* trinamic_tcoolthrs;
extern IntSetting* trinamic_thigh;
extern IntSetting* trinamic_tbl;
extern FlagSetting* trinamic_en_pwm_mode;
extern FlagSetting* trinamic_pwm_auto_scale;