Closed Avataar120 closed 2 years ago
The optical endstop switches on K40s are widely known to be very noisy and sensitive to stray light. Have you tried shielding them from ambient light?
Yes for sure. I know quite well this machine and common issues associated. Even in full dark it's not working & always exactely the same sequence (fast approach works well, slow approach detects only the X switch which is hit first and not the Y one which is hit after...)
From what I observe, seems not linked to any noise issue.
Wonder if it could come from NC swicthes. I'll try to wire a setup with NC switches to test ... But I don't have switches currently
Since I cannot duplicate it, I am at a loss for how to proceed.
Understood. I'll try to make some more investigations / add probes in the code to try to understand better
Hi @MitchBradley, after some experiments, here my findings ... I have modified LimitPin code like that (just for debug purpose)
void LimitPin::run(void* arg) {
bool value = get();
log_debug ( "Before : " << value);
delay_us (100);
value = get();
log_debug ( "After : " << value);
....
You can see below that value is different before & after 100us delay causing the issue. With 100us delay, homing & endstop detection are working well Seems to be still linked to the different threshold in the input circuitry between edge detection INT & pin reading
[MSG:DBG: Homing Cycle XY] [MSG:DBG: Homing nextPhase FastApproach] [MSG:DBG: Starting from 0.000,0.000,0.000] [MSG:DBG: Planned move to -465.000,-315.000,0.000 @ 3535.534] [MSG:DBG: Before : 1] [MSG:DBG: After : 1] [MSG:DBG: X Neg Limit 1] [MSG:DBG: Homing limited X] [MSG:DBG: Before : 0] [MSG:DBG: After : 1] [MSG:DBG: Y Neg Limit 1] [MSG:DBG: Homing limited X Y] [MSG:DBG: Homing nextPhase Pulloff0] [MSG:DBG: Starting from -72.924,-94.094,0.000] [MSG:DBG: Planned move to -67.924,-89.094,0.000 @ 282.843] [MSG:DBG: CycleStop Pulloff0] [MSG:DBG: X Neg Limit 0] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Homing nextPhase SlowApproach] [MSG:DBG: Starting from -67.920,-89.091,0.000] [MSG:DBG: Planned move to -92.920,-114.091,0.000 @ 282.843] [MSG:DBG: Before : 0] [MSG:DBG: After : 0] [MSG:DBG: X Neg Limit 0] [MSG:DBG: Before : 0] [MSG:DBG: After : 0] [MSG:DBG: X Neg Limit 0] [MSG:DBG: Before : 0] [MSG:DBG: After : 1] [MSG:DBG: X Neg Limit 1] [MSG:DBG: Homing limited X] [MSG:DBG: Before : 1] [MSG:DBG: After : 1] [MSG:DBG: Y Neg Limit 1] [MSG:DBG: Homing limited X Y] [MSG:DBG: Homing nextPhase Pulloff1] [MSG:DBG: Starting from -72.847,-94.056,0.000] [MSG:DBG: Planned move to -67.847,-89.056,0.000 @ 282.843] [MSG:DBG: CycleStop Pulloff1] [MSG:DBG: X Neg Limit 0] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Homing nextPhase Pulloff2] [MSG:DBG: mpos was -67.844,-89.053,0.000] [MSG:DBG: mpos becomes 5.000,5.000,0.000] [MSG:DBG: mpos transformed 5.004,5.004,0.000] [MSG:DBG: Homing done]
I am starting to get very irritated at Espressif
Hi @MitchBradley ,
I made some tests with NC and NO mechanical switches without reproducing the same problem than before your work on limit switchs (#547).
You probably know it already, but K40 endstops are delivering an analog signal between 0 and 5V. When axis is moving toward its end position, voltage is going progressively from low value to high value with a link with axis movement speed (voltage is dependent of the light perceived by the sensor) During homing slow approach, movement is quite slow and switch from low to high voltage takes time (more than the filtering of a sharp edge by board RC filter) leading to the defect of input reading in my opinion ...
Very interesting. An extremely slow edge
This is related to the metastable synchronization problem , for which there is no complete solution. There are techniques to reduce the probability of failure to an arbitrary amount (but not to 0), at the expense of latency. Andreas Bechtolsheim was working on the problem for his PhD, which he never finished due to founding Sun Microsystems. Andy later started several other companies and sold them for large amounts of money, then became a multi-billionaire due to being the first investor in Google. When I was working at Sun, I had to diagnose a lot of problems that turned out to be synchronization failures. Often they would fail once in many millions of events.
A super-slow edge makes synchronization much more difficult because the input signal stays in the transition region for a very long time, greatly increasing the probability of an ambiguous sample where two different circuit elements disagree on the state.
In this case, I could try some more techniques for disambiguation, but it would cause additional latency, which is what I was hoping to reduce with the interrupt-driven limit switch code. Maybe a hardware solution would be better. The ESP32 GPIOs are particularly susceptible to slow edges because they have no hysteresis (8-bit AVR chips have much better GPIO input circuits with hysteresis). Putting a Schmitt trigger buffer between the optical limit and the ESP32 GPIO would probably work much better. Both of the 4x input modules for the 6 pack have Schmitt triggers.
Hi @MitchBradley,
Thanks for this very detailed answer. Honestly, if I'm the only one to have this issue, don't spend to much time on it. I have a workaround that is working on my setup (should not be implemented in other contexts). You can close the issue if relevant
Thanks,
Controller Board
Personal board
See schematic below (picture not accepted here)
Help From Board Vendor
Machine Description
K40 stock machine Optical end switches for X & Y Delivering 5V when triggered (HOME position) Delivering 0V when not triggered (NC behavior)
Mechanical switch for Z (NO behavior)
Input Circuits
No response
Configuration file
Startup Messages
User Interface Software
Lightburn or Fluidterm
What happened?
When I issue a $H command on v3.6.1 : Axis are moving to top left corner -> OK When they hit the limit switches -> movement stops -> OK Pull off on both X & Y axis at the time -> OK Slow approach starts -> OK X limit switch is hit first. X stops -> OK Y limit switch is hit -> OK Movement on Y does NOT stop -> NOK 100% repeatable. I didn't tried with NC mechanical switches as I don't have the good setup for that It was working on 3.4.4 and earlier with same config file. Works as a charm with ESP32 GRBL as well.
Thanks for your help.
Log on v3.6.1 : $h [MSG:DBG: Homing Cycle XY] [MSG:DBG: Homing nextPhase FastApproach] [MSG:DBG: Starting from 0.000,0.000,0.000] [MSG:DBG: Planned move to -465.000,-315.000,0.000 @ 3535.534] [MSG:DBG: X Neg Limit 1] [MSG:DBG: Homing limited X] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Y Neg Limit 1] [MSG:DBG: Homing limited X Y] [MSG:DBG: Homing nextPhase Pulloff0] [MSG:DBG: Starting from -50.572,-45.326,0.000] [MSG:DBG: Planned move to -45.572,-40.326,0.000 @ 282.843] [MSG:DBG: CycleStop Pulloff0] [MSG:DBG: X Neg Limit 0] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Homing nextPhase SlowApproach] [MSG:DBG: Starting from -45.568,-40.323,0.000] [MSG:DBG: Planned move to -70.568,-65.323,0.000 @ 282.843] [MSG:DBG: X Neg Limit 1] [MSG:DBG: Homing limited X] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: Y Neg Limit 0] [MSG:DBG: CycleStop SlowApproach] [MSG:DBG: X Neg Limit 1] <Home|MPos:-50.470,-65.329,0.000|FS:0,0|Pn:X|WCO:5.004,5.004,5.200> ALARM:9 Homing fail. Could not find limit switch within search distance. Defined as 1.5 max_travel on search and 5 pulloff on locate phases. ok
Log on v3.4.4 : $h [MSG:DBG: Homing XY] [MSG:DBG: PrePulloff] [MSG:DBG: Fast approach] [MSG:DBG: X target -465.000 rate 2500.000] [MSG:DBG: Y target -315.000 rate 2500.000] [MSG:DBG: Pulloff0] [MSG:DBG: X target 5.000 rate 200.000] [MSG:DBG: Y target 5.000 rate 200.000] [MSG:DBG: Slow approach] [MSG:DBG: X target -25.000 rate 200.000] [MSG:DBG: Y target -25.000 rate 200.000] [MSG:DBG: Pulloff1] [MSG:DBG: X target 5.000 rate 200.000] [MSG:DBG: Y target 5.000 rate 200.000] [MSG:DBG: Homing Z] [MSG:DBG: PrePulloff] [MSG:DBG: Fast approach] [MSG:DBG: Z target 30.000 rate 100.000] [MSG:DBG: Pulloff0] [MSG:DBG: Z target -9.500 rate 100.000] [MSG:DBG: Slow approach] [MSG:DBG: Z target 47.500 rate 100.000] [MSG:DBG: Pulloff1] [MSG:DBG: Z target -9.500 rate 100.000] ok
Other Information