# [solved] Teacup unreliable endstops

Posted by Fivefold
 [solved] Teacup unreliable endstops September 29, 2016 08:08AM Registered: 5 years ago Posts: 7
I recently built my first prusa i3, using Gen7 Electronics 2.0 ARM and the Teacup firmware. Unfortunately my endstops show very strange behaviour. They are simple mechanical endstops in a normally closed configuration. As can be seen on the pcb layout (Link), they are in series, so they should all behave the same.
In the closed state all work as expected, but as soon as one is pressed/the circuit is opened the behaviour starts to get unpredictable.

z min is the only reliable one, the other two show completely random and fast-changing states with M119 as soon as they are triggered. I suspected noise from the motor wires, but the endstop wire pairs are twisted, and checking the voltage of PIO1_8 with an oscilloscope doesn't show much noise. The voltages are ~3.3 V when closed and 0.5-0.6 when opened, regardless of endstop used.

This is my config.h:

[pastebin.com]

Any suggestions?

Edited 1 time(s). Last edit at 10/01/2016 06:49AM by Fivefold.
 Re: Teacup unreliable endstops September 29, 2016 08:53AM Admin Registered: 10 years ago Posts: 2,569
Maybe try to enable internal pull ups ? Extract from your config.h :

/** \def USE_INTERNAL_PULLUPS
The ATmega has internal pullup resistors on it's input pins which are
counterproductive with the commonly used eletronic endstops, so they should
be switched off. For other endstops, like mechanical ones, you may want to
uncomment this.
*/
//#define USE_INTERNAL_PULLUPS

Most of my technical comments should be correct, but is THIS one ?
Anyway, as a rule of thumb, always double check what people write.
 Re: Teacup unreliable endstops September 29, 2016 08:55AM Admin Registered: 10 years ago Posts: 2,569
You might also maybe want to try to play with that part - sorry if you did already, just call me captain obvious then :

/** \def ENDSTOP_STEPS
Number of steps to run into the endstops intentionally. As endstops trigger
false alarm sometimes, Teacup debounces them by counting a number of
consecutive positives.

Use 4 or less for reliable endstops, 8 or even more for flaky ones.

Valid range: 1...255.
*/
#define ENDSTOP_STEPS            5

Most of my technical comments should be correct, but is THIS one ?
Anyway, as a rule of thumb, always double check what people write.
 Re: Teacup unreliable endstops September 30, 2016 06:26AM Registered: 11 years ago Posts: 7,616
Quote
Fivefold
z min is the only reliable one, the other two show completely random and fast-changing states with M119 as soon as they are triggered.
My fault. With a triggered endstop there's no pull resistor at all, so the signal indeed picks up noise floating around.

The trick is to turn on pulldown resistors on the signal pin. And here's the fault: I forgot to push the commit which allows to do this. ATmegas have no pulldown resistors, so this requires a few lines of new code. I hope I get it done later today, currently it's a quick hack.

Doing this in hardware is also possible, a 10k or 100k resistor from the leftmost of the 6 connector pins to GND.

 Generation 7 Electronics Teacup Firmware RepRap DIY
 Re: Teacup unreliable endstops September 30, 2016 08:03AM Registered: 11 years ago Posts: 7,616
Done, just pushed to branch experimental. Printer configuration files now have this new switch:

/** \def USE_INTERNAL_PULLDOWNS

Some controller chips feature internal pulldown resistors on their input
pins, which get used for endstops by turning on this switch. Don't turn it
on when using endstops which need no pull resistor, e.g. optical endstops,
because pull resistors are counterproductive there.

One can't use USE_INTERNAL_PULLDOWNS and USE_INTERNAL_PULLUPS at the same
time, of course.
*/
//#define USE_INTERNAL_PULLDOWNS

If you don't want to start over with your printer configuration, just add this #define on the previous one.

Let's cross fingers it works, because I didn't test too much to get this into the public quickly.

 Generation 7 Electronics Teacup Firmware RepRap DIY
 Re: Teacup unreliable endstops October 01, 2016 06:48AM Registered: 5 years ago Posts: 7
The internal pulldowns did the trick, everything works as expected, now! For anyone having the same problem and trying to keep the old config by just adding the pulldown#define: there's been a small change in experimental to #define TEMP_EWMA, too. Just compare the printer.mendel90.h file with your printer.h/config.h if you get errors about temp_ewma when compiling.

Thank you Traumflug for the fast response and thanks to DeuxVis too!
Sorry, only registered users may post in this forum.