Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filament motion encoder steps counter #27587

Open
wants to merge 1 commit into
base: bugfix-2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,8 @@
//#define FIL_MOTION8_PULLUP
//#define FIL_MOTION8_PULLDOWN
#endif

//#define MOTION_STEPS_COUNTER //Adds menu that displays/resets number of pulses from filament motion encoder. Use calibration mode to count without motion.
#endif // FILAMENT_MOTION_SENSOR
#endif // FILAMENT_RUNOUT_DISTANCE_MM
#endif // FILAMENT_RUNOUT_SENSOR
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/feature/runout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ bool FilamentMonitorBase::enabled = true,
#if ENABLED(FILAMENT_MOTION_SENSOR)
uint8_t FilamentSensorEncoder::motion_detected;
#endif
#if ENABLED(MOTION_STEPS_COUNTER)
uint16_t FilamentSensorEncoder::encoder_steps;
bool FilamentSensorEncoder::extruding;
bool FilamentSensorEncoder::calibration;
#endif
#else
int8_t RunoutResponseDebounced::runout_count[NUM_RUNOUT_SENSORS]; // = 0
#endif
Expand Down
18 changes: 11 additions & 7 deletions Marlin/src/feature/runout.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,6 @@ class FilamentSensorBase {
return (0 REPEAT_1(NUM_MOTION_SENSORS, _OR_MOTION));
#undef _OR_MOTION
}

// Return a bitmask of motion flag states (1 bits always indicates runout)
static uint8_t poll_motion_states() {
#define _OR_MOTION(N) | (FIL_MOTION##N##_STATE ? 0 : _BV(N - 1))
return poll_motion_pins() ^ uint8_t(0 REPEAT_1(NUM_MOTION_SENSORS, _OR_MOTION));
#undef _OR_MOTION
}
#endif
};

Expand All @@ -254,6 +247,11 @@ class FilamentSensorBase {
change = old_state ^ new_state;
old_state = new_state;

#if ENABLED(MOTION_STEPS_COUNTER)
if (change && (extruding || calibration))
encoder_steps++;
#endif

#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
if (change) {
SERIAL_ECHOPGM("Motion detected:");
Expand All @@ -267,6 +265,12 @@ class FilamentSensorBase {
}

public:
#if ENABLED(MOTION_STEPS_COUNTER)
static bool extruding;
static bool calibration;
static uint16_t encoder_steps;
#endif

static void block_completed(const block_t * const b) {
// If the sensor wheel has moved since the last call to
// this method reset the runout counter for the extruder.
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ namespace LanguageNarrow_en {

LSTR MSG_HOST_SHUTDOWN = _UxGT("Host Shutdown");

LSTR MSG_ENCODER_INFO = _UxGT("Filament motion");
LSTR MSG_ENCODER_STEPS = _UxGT("Steps/reset");
LSTR MSG_ENCODER_CALIBRATION = _UxGT("Calibration mode");

LSTR MSG_SHORT_DAY = _UxGT("d"); // One character only
LSTR MSG_SHORT_HOUR = _UxGT("h"); // One character only
LSTR MSG_SHORT_MINUTE = _UxGT("m"); // One character only
Expand Down
18 changes: 18 additions & 0 deletions Marlin/src/lcd/menu/menu_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
#include "../../feature/repeat.h"
#endif

#if ENABLED(MOTION_STEPS_COUNTER)
#include "../../feature/runout.h"
#endif

void menu_tune();
void menu_cancelobject();
void menu_motion();
Expand Down Expand Up @@ -244,6 +248,16 @@ void menu_configuration();
#endif
#endif

#if ENABLED(MOTION_STEPS_COUNTER)
void encoder_info_menu() {
START_MENU();
BACK_ITEM(MSG_MAIN_MENU);
EDIT_ITEM(uint16_5, MSG_ENCODER_STEPS, &FilamentSensorEncoder::encoder_steps, 0, 1);
EDIT_ITEM(bool, MSG_ENCODER_CALIBRATION, &FilamentSensorEncoder::calibration);
END_MENU();
}
#endif

void menu_main() {
const bool busy = printingIsActive();
#if HAS_MEDIA
Expand Down Expand Up @@ -369,6 +383,10 @@ void menu_main() {
if (TERN1(HAS_PRUSA_MMU2, !busy)) SUBMENU(MSG_MMU2_MENU, menu_mmu2);
#endif

#if ENABLED(MOTION_STEPS_COUNTER)
SUBMENU(MSG_ENCODER_INFO,encoder_info_menu);
#endif

SUBMENU(MSG_CONFIGURATION, menu_configuration);

#if ENABLED(CUSTOM_MENU_MAIN)
Expand Down
10 changes: 10 additions & 0 deletions Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ Stepper stepper; // Singleton
#include "../HAL/ESP32/i2s.h"
#endif

#if ENABLED(MOTION_STEPS_COUNTER)
#include "../feature/runout.h"
#endif

// public:

#if ANY(HAS_EXTRA_ENDSTOPS, Z_STEPPER_AUTO_ALIGN)
Expand Down Expand Up @@ -2832,10 +2836,12 @@ hal_timer_t Stepper::block_phase_isr() {
ne_fix.A = (1L << 24) * ne.A;
ne_fix.B = (1L << 24) * ne.B;
ne_fix.C = (1L << 24) * ne.C;
FilamentSensorEncoder::extruding = true;
}
else {
ne_fix.A = ne_fix.B = 0;
ne_fix.C = (1L << 24);

}
#endif

Expand All @@ -2854,6 +2860,10 @@ hal_timer_t Stepper::block_phase_isr() {
la_interval = calc_timer_interval((current_block->initial_rate + la_step_rate) >> current_block->la_scaling);
}
#endif

#if ENABLED(MOTION_STEPS_COUNTER)
FilamentSensorEncoder::extruding = ANY_AXIS_MOVES(current_block);
#endif
}
} // !current_block

Expand Down
Loading