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

Fixed stepstick and laser. Added dir/ena wait & pulse micros.

This commit is contained in:
Stefan de Bruijn
2021-05-20 22:59:27 +02:00
parent de407666c9
commit ac6c94e1a6
6 changed files with 30 additions and 23 deletions

View File

@@ -98,16 +98,6 @@ Axes::Axes() : _axis() {
void Axes::init() { void Axes::init() {
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Init Motors"); grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Init Motors");
// TODO FIXME! If use_stepstick, this should be in stepstick?
#ifdef USE_STEPSTICK
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Using StepStick Mode");
if (StepperResetPin->get().defined()) {
// !RESET pin on steppers (MISO On Schematic)
StepperResetPin->get().setAttr(Pin::Attr::Output | Pin::Attr::InitialOn);
}
#endif
if (_sharedStepperDisable.defined()) { if (_sharedStepperDisable.defined()) {
_sharedStepperDisable.setAttr(Pin::Attr::Output); _sharedStepperDisable.setAttr(Pin::Attr::Output);
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Shared stepper disable pin:%s", _sharedStepperDisable.name()); grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Shared stepper disable pin:%s", _sharedStepperDisable.name());

View File

@@ -346,8 +346,11 @@ public:
Probe* _probe = nullptr; Probe* _probe = nullptr;
Communications* _comms = nullptr; Communications* _comms = nullptr;
bool _laserMode = false;
int _pulseMicroSeconds = 3; int _pulseMicroSeconds = 3;
int _directionDelayMilliSeconds = 0;
int _disableDelayMilliSeconds = 0;
bool _laserMode = false;
float _arcTolerance = 0.002; float _arcTolerance = 0.002;
float _junctionDeviation = 0.01; float _junctionDeviation = 0.01;

View File

@@ -19,14 +19,24 @@ namespace Motors {
handler.handle("ms1", _MS1); handler.handle("ms1", _MS1);
handler.handle("ms2", _MS2); handler.handle("ms2", _MS2);
handler.handle("ms3", _MS3); handler.handle("ms3", _MS3);
handler.handle("reset", _Reset);
}
void StepStick::afterParse() {
if (!_Reset.undefined()) {
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Using StepStick Mode");
// !RESET pin on steppers (MISO On Schematic)
_Reset.setAttr(Pin::Attr::Output | Pin::Attr::InitialOn);
_Reset.on();
}
} }
// Name of the configurable. Must match the name registered in the cpp file. // Name of the configurable. Must match the name registered in the cpp file.
const char* StepStick::name() const { return "stepstick"; } const char* StepStick::name() const { return "stepstick"; }
// Configuration registration // Configuration registration
namespace namespace {
{
MotorFactory::InstanceBuilder<StepStick> registration("stepstick"); MotorFactory::InstanceBuilder<StepStick> registration("stepstick");
} }
} }

View File

@@ -3,11 +3,11 @@
#include "StandardStepper.h" #include "StandardStepper.h"
namespace Motors { namespace Motors {
class StepStick : public StandardStepper class StepStick : public StandardStepper {
{
Pin _MS1; Pin _MS1;
Pin _MS2; Pin _MS2;
Pin _MS3; Pin _MS3;
Pin _Reset;
public: public:
StepStick() = default; StepStick() = default;
@@ -18,6 +18,8 @@ namespace Motors {
void validate() const override; void validate() const override;
void handle(Configuration::HandlerBase& handler) override; void handle(Configuration::HandlerBase& handler) override;
void afterParse() override;
// Name of the configurable. Must match the name registered in the cpp file. // Name of the configurable. Must match the name registered in the cpp file.
const char* name() const override; const char* name() const override;

View File

@@ -20,6 +20,7 @@
*/ */
#include "Laser.h" #include "Laser.h"
#include "../MachineConfig.h"
// ===================================== Laser ============================================== // ===================================== Laser ==============================================
@@ -31,12 +32,12 @@ namespace Spindles {
void Laser::config_message() { void Laser::config_message() {
grbl_msg_sendf(CLIENT_ALL, grbl_msg_sendf(CLIENT_ALL,
MsgLevel::Info, MsgLevel::Info,
"Laser spindle on Pin:%s, Enbl:%s, Freq:%dHz, Res:%dbits Laser mode:%s", "Laser spindle on Pin:%s, Enbl:%s, Freq:%dHz, Res:%dbits Laser mode:%d",
_output_pin.name().c_str(), _output_pin.name().c_str(),
_enable_pin.name().c_str(), _enable_pin.name().c_str(),
int(_pwm_freq), int(_pwm_freq),
_pwm_precision, _pwm_precision,
laser_mode->getStringValue()); // the current mode (MachineConfig::instance()->_laserMode ? 1 : 0)); // the current mode
use_delays = false; // this will override the value set in Spindle::PWM::init() use_delays = false; // this will override the value set in Spindle::PWM::init()
} }

View File

@@ -225,7 +225,7 @@ static void stepper_pulse_func() {
#ifdef LATER #ifdef LATER
// XXX this should be in the motor driver, not here // XXX this should be in the motor driver, not here
if (motors_direction(st.dir_outbits)) { if (motors_direction(st.dir_outbits)) {
auto wait_direction = direction_delay_microseconds->get(); auto wait_direction = MachineConfig::instance()->_directionDelayMilliSeconds;
if (wait_direction > 0) { if (wait_direction > 0) {
// Stepper drivers need some time between changing direction and doing a pulse. // Stepper drivers need some time between changing direction and doing a pulse.
switch (current_stepper) { switch (current_stepper) {
@@ -333,16 +333,17 @@ static void stepper_pulse_func() {
} }
} }
auto pulseMicros = MachineConfig::instance()->_pulseMicroSeconds;
switch (current_stepper) { switch (current_stepper) {
case ST_I2S_STREAM: case ST_I2S_STREAM:
// Generate the number of pulses needed to span pulse_microseconds // Generate the number of pulses needed to span pulse_microseconds
i2s_out_push_sample(pulse_microseconds->get()); i2s_out_push_sample(pulseMicros);
MachineConfig::instance()->_axes->unstep(); MachineConfig::instance()->_axes->unstep();
break; break;
case ST_I2S_STATIC: case ST_I2S_STATIC:
case ST_TIMED: case ST_TIMED:
// wait for step pulse time to complete...some time expired during code above // wait for step pulse time to complete...some time expired during code above
while (esp_timer_get_time() - step_pulse_start_time < pulse_microseconds->get()) { while (esp_timer_get_time() - step_pulse_start_time < pulseMicros) {
NOP(); // spin here until time to turn off step NOP(); // spin here until time to turn off step
} }
MachineConfig::instance()->_axes->unstep(); MachineConfig::instance()->_axes->unstep();
@@ -394,13 +395,13 @@ void st_wake_up() {
// Initialize step pulse timing from settings. Here to ensure updating after re-writing. // Initialize step pulse timing from settings. Here to ensure updating after re-writing.
#ifdef USE_RMT_STEPS #ifdef USE_RMT_STEPS
// Step pulse delay handling is not require with ESP32...the RMT function does it. // Step pulse delay handling is not require with ESP32...the RMT function does it.
if (direction_delay_microseconds->get() < 1) { if (MachineConfig::instance()->_disableDelayMilliSeconds < 1) {
// Set step pulse time. Ad hoc computation from oscilloscope. Uses two's complement. // Set step pulse time. Ad hoc computation from oscilloscope. Uses two's complement.
st.step_pulse_time = -(((pulse_microseconds->get() - 2) * ticksPerMicrosecond) >> 3); st.step_pulse_time = -(((MachineConfig::instance()->_pulseMicroSeconds - 2) * ticksPerMicrosecond) >> 3);
} }
#else // Normal operation #else // Normal operation
// Set step pulse time. Ad hoc computation from oscilloscope. Uses two's complement. // Set step pulse time. Ad hoc computation from oscilloscope. Uses two's complement.
st.step_pulse_time = -(((pulse_microseconds->get() - 2) * ticksPerMicrosecond) >> 3); st.step_pulse_time = -(((MachineConfig::instance()->_pulseMicroSeconds - 2) * ticksPerMicrosecond) >> 3);
#endif #endif
// Enable Stepper Driver Interrupt // Enable Stepper Driver Interrupt