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

[FR] Filament width sensor calibration #19530

Closed
hamster65 opened this issue Sep 27, 2020 · 6 comments
Closed

[FR] Filament width sensor calibration #19530

hamster65 opened this issue Sep 27, 2020 · 6 comments

Comments

@hamster65
Copy link

As far as I understand, Marlin expects the measured filament diameter as a voltage. So 1,75 V means 1,75 mm etc.
This requires the filament width sensor to have an microcontroller for calibration / scaling. You cannot just connect an analog sensor to the ADC.

There was also an issue with 3.3 V boards like LPC1786: #14680
I've got an LPC1786 3.3 V board and with an open (unconnected) ADC input, it shows a fluctuating diameter of around 4.7 mm. Since the ADC only goes to 3.3 V, it should not measure more than 3.3 mm under any condition. So I assume it has not been fixed and the scaling is still wrong for 3.3 V ADCs/boards.

Both problems could be solved with an internal calibration feature.
The procedure would be like this (for 1.75 mm printers):

  1. Insert a small reference object into the sensor, say a 1.5 mm drill shaft.
  2. Send Gcode1 to the printer, with argument 15 for the width of the reference object.
  3. Insert a larger reference object into the sensor, say a 2 mm drill shaft.
  4. Send Gcode2 to the printer, with argument 20 for the width of the reference object.

Both inputs and the sensor value applied to a map function, should give the actual filament diameter. That should work for any ADC reference voltage / range and any analogue sensor, provided it has a linear output. Even if it doesn't, I think it should be close enough. A third measurement could also be added in the middle, let's say with 1,75 mm filament measured with a caliper.

Optionally, menu entries for calibration and sensor on/off.

@hamster65 hamster65 added the T: Feature Request Features requested by users. label Sep 27, 2020
@hamster65
Copy link
Author

Would it make sense to combine it with a runout feature? When the diameter is too low -> runout.

@hamster65
Copy link
Author

hamster65 commented Nov 23, 2020

I am trying to adapt the code so that it works with 3.3V boards. However, I have never looked into the depths of Marlin and I am not a programmer.

I connected a potentiometer between GND and 3.3V and the wiper to the TX pin auf the Aux connector of my MKS S GEN L.
#define FILWIDTH_PIN P0_02_A7 //AUX1 TX-Pin

In src/feature/filwidth.h, line 70 there is
static inline float raw_to_mm(const uint16_t v) { return v * 5.0f * RECIPROCAL(float(MAX_RAW_THERMISTOR_VALUE)); }

Changing 5.0f to 3.3f gives wrong results for the filament width. I thought that maybe it relies on the 10 bit ADCs of the AVR controllers, so I divided by 4. Still way off. Dividing by 16 gives the right reading. Could it be that this function assumes an 8 bit ADC with 5V reference voltage? In this case it should give wrong readings even on 5V 8 Bit AVR boards because they have a 10 but ADC.... Can someone test on an 8 Bit AVR board?

So I get correct readings with this line for LPC1786 / MKS SGEN L:
static inline float raw_to_mm(const uint16_t v) { return v * (3.3f / 16) * RECIPROCAL(float(MAX_RAW_THERMISTOR_VALUE)); }

How can we make this work for all boards?
3.3f can be replaced with HAL_ADC_VREF (defined as 3.3 in Marlin/src/HAL/LPC1768/HAL.h).
Not sure about the divider, though.
There is a "#define HAL_ADC_RESOLUTION 12" in HAL.h for LPC1768.
and "#define HAL_ADC_RESOLUTION 10" in HAL.h vor AVR. But I still do not understand why I have to divide by 16.

@RicardoGA
Copy link
Contributor

hi, i´m having the exact same issue with a BTT skr 2 i connect the filament width sensor and the readings are wrong

@thisiskeithb
Copy link
Member

#23977 addresses the 3.3/5V issue, so do you still want add a calibration mechanism?

@thisiskeithb
Copy link
Member

The original bug has been fixed in #23977, so this isn't needed.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants