mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-02 10:53:01 +02:00
Minimally functional
Starting to work. Need to develop some tests
This commit is contained in:
@@ -205,7 +205,7 @@ Some features should not be changed. See notes below.
|
||||
#define CMD_RAPID_OVR_LOW 0x97
|
||||
// #define CMD_RAPID_OVR_EXTRA_LOW 0x98 // *NOT SUPPORTED*
|
||||
#define CMD_SPINDLE_OVR_RESET 0x99 // Restores spindle override value to 100%.
|
||||
#define CMD_SPINDLE_OVR_COARSE_PLUS 0x9A
|
||||
#define CMD_SPINDLE_OVR_COARSE_PLUS 0x9A // 154
|
||||
#define CMD_SPINDLE_OVR_COARSE_MINUS 0x9B
|
||||
#define CMD_SPINDLE_OVR_FINE_PLUS 0x9C
|
||||
#define CMD_SPINDLE_OVR_FINE_MINUS 0x9D
|
||||
|
@@ -26,19 +26,12 @@ int8_t spindle_pwm_chan_num;
|
||||
|
||||
// define a spindle type
|
||||
//RelaySpindle my_spindle;
|
||||
Laser my_spindle;
|
||||
|
||||
#ifdef SPINDLE_PWM_PIN
|
||||
static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
|
||||
uint32_t spindle_pwm_period; // how many counts in 1 period
|
||||
uint32_t spindle_pwm_off_value;
|
||||
uint32_t spindle_pwm_min_value;
|
||||
uint32_t spindle_pwm_max_value;
|
||||
#endif
|
||||
PWMSpindle my_spindle;
|
||||
|
||||
void spindle_init() {
|
||||
my_spindle.init();
|
||||
my_spindle.config_message();
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Spindle is rate adjustable %d", my_spindle.isRateAdjusted());
|
||||
}
|
||||
|
||||
void spindle_stop() {
|
||||
@@ -49,13 +42,6 @@ uint8_t spindle_get_state() {
|
||||
return my_spindle.get_state();
|
||||
}
|
||||
|
||||
void spindle_set_speed(uint32_t pwm_value) {
|
||||
my_spindle.set_pwm(pwm_value);
|
||||
}
|
||||
|
||||
uint32_t spindle_compute_pwm_value(float rpm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
|
||||
@@ -72,36 +58,3 @@ void spindle_sync(uint8_t state, float rpm) {
|
||||
}
|
||||
|
||||
|
||||
void grbl_analogWrite(uint8_t chan, uint32_t duty) {
|
||||
|
||||
}
|
||||
|
||||
void spindle_set_enable(bool enable) {
|
||||
|
||||
}
|
||||
|
||||
uint32_t piecewise_linear_fit(float rpm) {
|
||||
uint32_t pwm_value;
|
||||
#if (N_PIECES > 3)
|
||||
if (rpm > RPM_POINT34)
|
||||
pwm_value = floor(RPM_LINE_A4 * rpm - RPM_LINE_B4);
|
||||
else
|
||||
#endif
|
||||
#if (N_PIECES > 2)
|
||||
if (rpm > RPM_POINT23)
|
||||
pwm_value = floor(RPM_LINE_A3 * rpm - RPM_LINE_B3);
|
||||
else
|
||||
#endif
|
||||
#if (N_PIECES > 1)
|
||||
if (rpm > RPM_POINT12)
|
||||
pwm_value = floor(RPM_LINE_A2 * rpm - RPM_LINE_B2);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
pwm_value = floor(RPM_LINE_A1 * rpm - RPM_LINE_B1);
|
||||
}
|
||||
return pwm_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -33,7 +33,7 @@
|
||||
#define SPINDLE_STATE_CCW bit(1)
|
||||
|
||||
extern uint32_t spindle_pwm_off_value;
|
||||
extern Laser my_spindle;
|
||||
extern PWMSpindle my_spindle;
|
||||
|
||||
void spindle_init();
|
||||
void spindle_stop();
|
||||
|
@@ -282,7 +282,8 @@ void IRAM_ATTR onStepperDriverTimer(void* para) { // ISR It is time to take a st
|
||||
#endif
|
||||
|
||||
// Set real-time spindle output as segment is loaded, just prior to the first step.
|
||||
spindle_set_speed(st.exec_segment->spindle_rpm);
|
||||
//spindle_set_speed(st.exec_segment->spindle_rpm);
|
||||
my_spindle.set_rpm(st.exec_segment->spindle_rpm);
|
||||
|
||||
} else {
|
||||
// Segment buffer empty. Shutdown.
|
||||
@@ -290,8 +291,10 @@ void IRAM_ATTR onStepperDriverTimer(void* para) { // ISR It is time to take a st
|
||||
|
||||
if (!(sys.state & STATE_JOG)) { // added to prevent ... jog after probing crash
|
||||
// Ensure pwm is set properly upon completion of rate-controlled motion.
|
||||
if (st.exec_block->is_pwm_rate_adjusted)
|
||||
spindle_set_speed(spindle_pwm_off_value);
|
||||
if (st.exec_block->is_pwm_rate_adjusted) {
|
||||
//spindle_set_speed(spindle_pwm_off_value);
|
||||
my_spindle.set_rpm(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
system_set_exec_state_flag(EXEC_CYCLE_STOP); // Flag main program for cycle end
|
||||
|
@@ -1,3 +1,9 @@
|
||||
/*
|
||||
|
||||
|
||||
Testing
|
||||
Should $G show actual speed
|
||||
*/
|
||||
#include "grbl.h"
|
||||
#include "SpindleClass.h"
|
||||
|
||||
@@ -32,6 +38,8 @@ void PWMSpindle::init() {
|
||||
float PWMSpindle::set_rpm(float rpm) {
|
||||
uint32_t pwm_value;
|
||||
|
||||
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Set RPM %5.1f", rpm);
|
||||
|
||||
// apply overrides and limits
|
||||
rpm *= (0.010 * sys.spindle_speed_ovr); // Scale by spindle speed override value (percent)
|
||||
|
||||
@@ -117,7 +125,7 @@ void PWMSpindle::set_pwm(uint32_t duty) {
|
||||
#ifdef INVERT_SPINDLE_PWM
|
||||
duty = (1 << SPINDLE_PWM_BIT_PRECISION) - duty;
|
||||
#endif
|
||||
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Set PWM %d of %d", duty, (1 << SPINDLE_PWM_BIT_PRECISION)-1);
|
||||
ledcWrite(_spindle_pwm_chan_num, duty);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user