1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-03 11:22:38 +02:00

More cleanup and testing

- A basic PWM spindle appears to work now.
- More testing of options and edge cases needed.
This commit is contained in:
bdring
2020-04-04 10:53:02 -05:00
parent f9593975ce
commit b9140e66b4
3 changed files with 19 additions and 2 deletions

View File

@@ -31,19 +31,20 @@ PWMSpindle my_spindle;
void spindle_init() { void spindle_init() {
my_spindle.init(); my_spindle.init();
my_spindle.config_message(); my_spindle.config_message();
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Spindle is rate adjustable %d", my_spindle.isRateAdjusted());
} }
void spindle_stop() { void spindle_stop() {
my_spindle.stop(); my_spindle.stop();
} }
uint8_t spindle_get_state() { uint8_t spindle_get_state() {
return my_spindle.get_state(); return my_spindle.get_state();
} }
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient. // Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
void spindle_set_state(uint8_t state, float rpm) { void spindle_set_state(uint8_t state, float rpm) {
my_spindle.set_state(state, rpm); my_spindle.set_state(state, rpm);

View File

@@ -81,8 +81,10 @@ float PWMSpindle::set_rpm(float rpm) {
sys.spindle_speed = 0.0; sys.spindle_speed = 0.0;
pwm_value = _pwm_off_value; pwm_value = _pwm_off_value;
} else { // Set minimum PWM output } else { // Set minimum PWM output
sys.spindle_speed = settings.rpm_min; rpm = settings.rpm_min;
sys.spindle_speed = rpm;
pwm_value = _pwm_min_value; pwm_value = _pwm_min_value;
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Spindle RPM less than min RPM:%5.2f %d", rpm, pwm_value);
} }
} else { } else {
// Compute intermediate PWM value with linear spindle speed model. // Compute intermediate PWM value with linear spindle speed model.
@@ -92,6 +94,7 @@ float PWMSpindle::set_rpm(float rpm) {
pwm_value = piecewise_linear_fit(rpm); pwm_value = piecewise_linear_fit(rpm);
#else #else
pwm_value = floor((rpm - settings.rpm_min) * _pwm_gradient) + _pwm_min_value; pwm_value = floor((rpm - settings.rpm_min) * _pwm_gradient) + _pwm_min_value;
//pwm_value = map_float(rpm, settings.rpm_min, settings.rpm_max, _pwm_min_value, _pwm_max_value);
#endif #endif
} }
@@ -140,6 +143,7 @@ void PWMSpindle::stop() {
// prints the startup message of the spindle config // prints the startup message of the spindle config
void PWMSpindle :: config_message() { void PWMSpindle :: config_message() {
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "PWM spindle on GPIO %d, freq %.2fHz, Res %d bits", SPINDLE_PWM_PIN, settings.spindle_pwm_freq, SPINDLE_PWM_BIT_PRECISION); grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "PWM spindle on GPIO %d, freq %.2fHz, Res %d bits", SPINDLE_PWM_PIN, settings.spindle_pwm_freq, SPINDLE_PWM_BIT_PRECISION);
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "PWM Off:%d Min:%d Max:%d", _pwm_off_value, _pwm_min_value, _pwm_max_value);
} }

View File

@@ -41,6 +41,18 @@ class Spindle {
}; };
// This is a dummy spindle that has no I/O.
// It is used to ignore spindle activity when no spinde is desired
class NullSpindle : public Spindle {
void init();
float set_rpm(float rpm);
void set_pwm(uint32_t duty);
void set_state(uint8_t state, float rpm);
uint8_t get_state();
void stop();
void config_message();
};
class PWMSpindle : public Spindle { class PWMSpindle : public Spindle {
public: public:
void init(); void init();