mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-20 05:11:38 +02:00
Fixed Spindle Bug
- Bug when using 16 bit PWM for the spindle. Stepper.cpp copied the PWM into 8 bit variables and corrupted the value.
This commit is contained in:
@@ -126,6 +126,8 @@
|
|||||||
// For 5000 that is 80,000,000 / 5000 = 16000
|
// For 5000 that is 80,000,000 / 5000 = 16000
|
||||||
// round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192)
|
// round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define SPINDLE_PWM_BASE_FREQ 5000 // Hz
|
#define SPINDLE_PWM_BASE_FREQ 5000 // Hz
|
||||||
#define SPINDLE_PWM_BIT_PRECISION 8
|
#define SPINDLE_PWM_BIT_PRECISION 8
|
||||||
#define SPINDLE_PWM_OFF_VALUE 0
|
#define SPINDLE_PWM_OFF_VALUE 0
|
||||||
@@ -133,8 +135,9 @@
|
|||||||
//#define INVERT_SPINDLE_PWM
|
//#define INVERT_SPINDLE_PWM
|
||||||
|
|
||||||
#ifndef SPINDLE_PWM_MIN_VALUE
|
#ifndef SPINDLE_PWM_MIN_VALUE
|
||||||
#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
|
#undef SPINDLE_PWM_MIN_VALUE
|
||||||
#endif
|
#endif
|
||||||
|
#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
|
||||||
|
|
||||||
#define SPINDLE_ENABLE_PIN GPIO_NUM_22
|
#define SPINDLE_ENABLE_PIN GPIO_NUM_22
|
||||||
|
|
||||||
@@ -209,20 +212,21 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CPU_MAP_ESP32_ESC_SPINDLE
|
#ifdef CPU_MAP_ESP32_ESC_SPINDLE
|
||||||
// This is the CPU Map for the ESP32 CNC Controller R2
|
// This is an example of using a Brushless DC Hobby motor as
|
||||||
|
// a spindle motor
|
||||||
|
// See this wiki page for more info
|
||||||
|
// https://github.com/bdring/Grbl_Esp32/wiki/BESC-Spindle-Feature
|
||||||
|
|
||||||
// It is OK to comment out any step and direction pins. This
|
|
||||||
// won't affect operation except that there will be no output
|
|
||||||
// form the pins. Grbl will virtually move the axis. This could
|
|
||||||
// be handy if you are using a servo, etc. for another axis.
|
|
||||||
#define CPU_MAP_NAME "CPU_MAP_ESP32_ESC_SPINDLE"
|
#define CPU_MAP_NAME "CPU_MAP_ESP32_ESC_SPINDLE"
|
||||||
|
|
||||||
|
#define USE_RMT_STEPS
|
||||||
|
|
||||||
#define X_STEP_PIN GPIO_NUM_12
|
#define X_STEP_PIN GPIO_NUM_12
|
||||||
#define X_DIRECTION_PIN GPIO_NUM_26
|
#define X_DIRECTION_PIN GPIO_NUM_14
|
||||||
#define X_RMT_CHANNEL 0
|
#define X_RMT_CHANNEL 0
|
||||||
|
|
||||||
#define Y_STEP_PIN GPIO_NUM_14
|
#define Y_STEP_PIN GPIO_NUM_26
|
||||||
#define Y_DIRECTION_PIN GPIO_NUM_25
|
#define Y_DIRECTION_PIN GPIO_NUM_15// #define Y_STEP_PIN (see versions above)
|
||||||
#define Y_RMT_CHANNEL 1
|
#define Y_RMT_CHANNEL 1
|
||||||
|
|
||||||
#define Z_STEP_PIN GPIO_NUM_27
|
#define Z_STEP_PIN GPIO_NUM_27
|
||||||
@@ -232,43 +236,32 @@
|
|||||||
// OK to comment out to use pin for other features
|
// OK to comment out to use pin for other features
|
||||||
#define STEPPERS_DISABLE_PIN GPIO_NUM_13
|
#define STEPPERS_DISABLE_PIN GPIO_NUM_13
|
||||||
|
|
||||||
// *** the flood coolant feature code is activated by defining this pins
|
#define SPINDLE_PWM_PIN GPIO_NUM_2
|
||||||
// *** Comment it out to use the pin for other features
|
|
||||||
#define COOLANT_FLOOD_PIN GPIO_NUM_16
|
|
||||||
//#define COOLANT_MIST_PIN GPIO_NUM_21
|
|
||||||
|
|
||||||
// If SPINDLE_PWM_PIN is commented out, this frees up the pin, but Grbl will still
|
|
||||||
// use a virtual spindle. Do not comment out the other parameters for the spindle.
|
|
||||||
#define SPINDLE_PWM_PIN GPIO_NUM_17
|
|
||||||
#define SPINDLE_PWM_CHANNEL 0
|
#define SPINDLE_PWM_CHANNEL 0
|
||||||
|
|
||||||
// RC ESC Based Spindle
|
// Begin RC ESC Based Spindle #defines ======================
|
||||||
// An ESC works like a hobby servo with 50Hz PWM 1ms to 2 ms pulse range
|
|
||||||
#define SPINDLE_PWM_BASE_FREQ 50 // Hz for ESC
|
#define SPINDLE_PWM_BASE_FREQ 50 // Hz for ESC
|
||||||
#define SPINDLE_PWM_BIT_PRECISION 16 // 16 bit required for ESC
|
#define SPINDLE_PWM_BIT_PRECISION 16 // 16 bit required for ESC
|
||||||
#define SPINDLE_PULSE_RES_COUNT 65535
|
#define SPINDLE_PULSE_RES_COUNT 65535
|
||||||
|
|
||||||
#define ESC_MIN_PULSE_SEC 0.001 // min pulse in seconds (OK to tune this one)
|
#define ESC_MIN_PULSE_SEC 0.0007 // min pulse in seconds (OK to tune this one)
|
||||||
#define ESC_MAX_PULSE_SEC 0.002 // max pulse in seconds (OK to tune this one)
|
#define ESC_MAX_PULSE_SEC 0.0022 // max pulse in seconds (OK to tune this one)
|
||||||
#define ESC_TIME_PER_BIT ((1.0 / (float)SPINDLE_PWM_BASE_FREQ) / ((float)SPINDLE_PULSE_RES_COUNT) ) // seconds
|
#define ESC_TIME_PER_BIT ((1.0 / (float)SPINDLE_PWM_BASE_FREQ) / ((float)SPINDLE_PULSE_RES_COUNT) ) // seconds
|
||||||
|
|
||||||
#define SPINDLE_PWM_OFF_VALUE (uint16_t)(ESC_MIN_PULSE_SEC / ESC_TIME_PER_BIT) // in timer counts
|
#define SPINDLE_PWM_OFF_VALUE (uint16_t)(ESC_MIN_PULSE_SEC / ESC_TIME_PER_BIT) // in timer counts
|
||||||
#define SPINDLE_PWM_MAX_VALUE (uint16_t)(ESC_MAX_PULSE_SEC / ESC_TIME_PER_BIT) // in timer counts
|
#define SPINDLE_PWM_MAX_VALUE (uint16_t)(ESC_MAX_PULSE_SEC / ESC_TIME_PER_BIT) // in timer counts
|
||||||
|
|
||||||
#ifndef SPINDLE_PWM_MIN_VALUE
|
#ifndef SPINDLE_PWM_MIN_VALUE
|
||||||
#define SPINDLE_PWM_MIN_VALUE SPINDLE_PWM_OFF_VALUE // Must be greater than zero.
|
#undef SPINDLE_PWM_MIN_VALUE
|
||||||
#endif
|
#endif
|
||||||
|
#define SPINDLE_PWM_MIN_VALUE SPINDLE_PWM_OFF_VALUE // Must be greater than zero.
|
||||||
|
|
||||||
#define SPINDLE_ENABLE_PIN GPIO_NUM_22
|
#define SPINDLE_ENABLE_PIN GPIO_NUM_22
|
||||||
|
// End RC ESC Based Spindle #defines ===========================
|
||||||
|
|
||||||
// if these spindle function pins are defined, they will be activated in the code
|
#define X_LIMIT_PIN GPIO_NUM_17
|
||||||
// comment them out to use the pins for other functions
|
|
||||||
//#define SPINDLE_ENABLE_PIN GPIO_NUM_16
|
|
||||||
//#define SPINDLE_DIR_PIN GPIO_NUM_16
|
|
||||||
|
|
||||||
#define X_LIMIT_PIN GPIO_NUM_2
|
|
||||||
#define Y_LIMIT_PIN GPIO_NUM_4
|
#define Y_LIMIT_PIN GPIO_NUM_4
|
||||||
#define Z_LIMIT_PIN GPIO_NUM_15
|
#define Z_LIMIT_PIN GPIO_NUM_16
|
||||||
#define LIMIT_MASK B111
|
#define LIMIT_MASK B111
|
||||||
|
|
||||||
#define PROBE_PIN GPIO_NUM_32
|
#define PROBE_PIN GPIO_NUM_32
|
||||||
@@ -277,7 +270,6 @@
|
|||||||
#define CONTROL_RESET_PIN GPIO_NUM_34 // needs external pullup
|
#define CONTROL_RESET_PIN GPIO_NUM_34 // needs external pullup
|
||||||
#define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // needs external pullup
|
#define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // needs external pullup
|
||||||
#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup
|
#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CPU_MAP_PEN_LASER // The Buildlog.net pen laser controller V1 & V2
|
#ifdef CPU_MAP_PEN_LASER // The Buildlog.net pen laser controller V1 & V2
|
||||||
|
@@ -57,7 +57,7 @@ typedef struct {
|
|||||||
uint8_t prescaler; // Without AMASS, a prescaler is required to adjust for slow timing.
|
uint8_t prescaler; // Without AMASS, a prescaler is required to adjust for slow timing.
|
||||||
#endif
|
#endif
|
||||||
#ifdef VARIABLE_SPINDLE
|
#ifdef VARIABLE_SPINDLE
|
||||||
uint8_t spindle_pwm;
|
uint16_t spindle_pwm;
|
||||||
#endif
|
#endif
|
||||||
} segment_t;
|
} segment_t;
|
||||||
static segment_t segment_buffer[SEGMENT_BUFFER_SIZE];
|
static segment_t segment_buffer[SEGMENT_BUFFER_SIZE];
|
||||||
@@ -147,7 +147,7 @@ typedef struct {
|
|||||||
|
|
||||||
#ifdef VARIABLE_SPINDLE
|
#ifdef VARIABLE_SPINDLE
|
||||||
float inv_rate; // Used by PWM laser mode to speed up segment calculations.
|
float inv_rate; // Used by PWM laser mode to speed up segment calculations.
|
||||||
uint8_t current_spindle_pwm;
|
uint16_t current_spindle_pwm;
|
||||||
#endif
|
#endif
|
||||||
} st_prep_t;
|
} st_prep_t;
|
||||||
static st_prep_t prep;
|
static st_prep_t prep;
|
||||||
|
Reference in New Issue
Block a user