Topics

Limit switch bug?

Aisling Lightworks
 

Is anyone else running into problems with the limit switch? When I used normally closed switches and set the parameter to detect LOW it works but if I use normally open switches and set the parameter to detect HIGH it remains constantly triggered. I actually don't remember which switch uses LOW or HIGH but all I know is that it works one way and not the other. It started doing this after I installed the PEC index sensor. But I also did it with a new alpha build. 

Pete
 

I am using limit switches on my Dob.  I have an old version MiniPCB and the relevant section of Config MiniPCB.h looks like this

#define LIMIT_SENSE_ON
// Switch close (to ground) on Aux3 (Pin 4) for optional limit sense (stops gotos and/or tracking), default=_OFF  Choose only one feature on Aux4.

The switches I am using are both wired as close on fault, so they are normally open.  Mine is working fine.  I am running OnStep V1.22d.

Aisling Lightworks
 

Thanks, Pete. I'm going to do some troubleshooting when I get home.

Aisling Lightworks
 

It works for me, it's just odd that it works with one type of switch for me and not the other. It used to work with both. I probably screwed something up.

Pete
 

Switches, being mechanical do stop working from time to time.  If you have a multimeter handy then it may be worth checking the continuity and make/break operation of each switch.  Oxidization of the contacts can cause a contact resistance higher than the Teensy may detect.

Aisling Lightworks
 

Right, I was just using a jumper on the contacts to simulate a switch. Double checked all the wiring. It's got to be something I did in the software. Or maybe my implementation of the optical sensor for the PEC index.

Pete
 

Well, it is reassuring to me to find someone making nearly as many mistaikz as I do.  Hehe.

So, try reducing this to ONE variable at a time.  Remove the PEC sensor and disable it in your config*.h file.  Take off ONE limit switch and test the other.  Check that switch with a meter.  Bang head against wall (it's nice when you stop).

Reduce your installation to just one test point.  This obviously sounds imbecilic but I go through this regularly.  I find 99% of my electronic faults with my eyeballs.  Hopefully this will be the same for you.

Good luck.

Khalid Baheyeldin
 

This may not be the issue that Aisling is facing, but it is worth a try.

In OnStep.ino, there is this segment of code.
It assumes that a limit switch is normally close (NC), and trips when it is open.
But some switches operate the other way, i.e. normally open (NO) and trip when high.

In order to verify if this is the case with a particular switch, change the LOW in this
code to HIGH in both places, and test things out.

If it works, then I can submit a pull request for an additional configuration parameter
that makes this configurable (e.g. LIMIT_SENSE_STATE HIGH, or LIMIT_SENSE_STATE LOW).

#ifdef LIMIT_SENSE_ON
    byte limit_1st = digitalRead(LimitPin);
    if (limit_1st == LOW) {
      // Wait for a short while, then read again
      delayMicroseconds(50);
      byte limit_2nd = digitalRead(LimitPin);
      if (limit_2nd == LOW) {
        // It is still low, there must be a problem
        lastError=ERR_LIMIT_SENSE;
        stopLimit();
      }
    }
#endif

Aisling Lightworks
 

Hey Khalid, I did change that to HIGH and my normally closed switches work, but now I tried to change it back to LOW to use normally open switches and Limit sense error is always triggered and I cant get it to go away

Aisling Lightworks
 

I'm about to start troubleshooting it. I'll let you know what I find

Aisling Lightworks
 

I've tried every combination of settings between PEC and limit sense and every combination of switches (PEC and limit) attached and detached and it still only works when they're set limit_1st == HIGH with a normally closed switch. Here's a copy of my config file if anyone can see anything

Pete
 

From your Config STM32.h file it clearly shows 
// Switch close (to ground) on Pin ? for optional limit sense (stops gotos and/or tracking), default=_OFF
#define LIMIT_SENSE_ON
This means (as I'm certain you know) that the limit switch is normally open (NO) when no limit is reached.  Thus the switch must be closed when the limit is reached and the switch activated.  The switch closes its contact and connects the sense wire to ground.

I just checked my scope (MiniPCB) and the switches are the way I describe them above i.e. open whilst no limit and closed to ground when activated.

I have never seen a BluePill device so I'm a bit in the dark here.  Are you using a breadboard or a PCB?  I know that my breadboard builds are often not as errr, robust let us say as a PCB build.

Question:  Where are you getting your ground wire from?  It should be electrically from the same place as the Teensy gets its ground from.  I had trouble with my 12 > 24V converter grounding.  The 12V input was different from the 24V out.  I don't know if this is the same on the STM32 board.  The LM2596 has, I believe a common ground for input and output.  

This is a puzzle.  A switch is the simplest of electrical circuits.

Just keep banging at it until it works.  Please post developments.  Encouragement is always available here.

Aisling Lightworks
 

This is basically my exact build and how my limit switches are connected. It worked before with both NC and NO switches by changing the code in Onstep,io to detect either LOW or HIGH depending on the switch. But now it only works with NC switches. I can make it work but just wiring NC switches serially as a big AND circuit, but it's just bothering me.

https://youtu.be/LaUbcb1Q2pY

Dave Schwartz
 

Its possible that this is an electrical issue in the way that low or high logic level is being detected by the MCU.

For example, the ST4 port was a known quantity in as far as signal levels were expected to behave so that circuit is explicitly designed with strong pull-up resistors that do a good job of keeping noisy or floating lines from being seen as false transitions. Its quite easy for outside-the-case, antenna-length conductors to pick up stray fields that will manifest as non-low logic levels. You probably couldn't measure this with a voltmeter but the MCU pin has such a high impedance that it could see a high logic level with just a few nano-amps of current. Lots of people have had problems like this when either the ST4PULLUP resistors are missing or were installed backward.

When Khalid and I designed the 'Multi' connector, the suggested uses of the two MCU pins on that connector as PEC or Limit Sense were just that... suggestions... and thus there was no additional circuitry included to pull the level up or down in order to prevent false level detections because we didn't want to constrain what those lines could be used for.

The implication of this is that the user is responsible for the appropriate electrical design (buffers, pull-ups, pull-downs, etc) for proper level detection.

On 2019-06-10 12:16 p.m., Aisling Lightworks wrote:
This is basically my exact build and how my limit switches are connected. It worked before with both NC and NO switches by changing the code in Onstep,io to detect either LOW or HIGH depending on the switch. But now it only works with NC switches. I can make it work but just wiring NC switches serially as a big AND circuit, but it's just bothering me.

https://youtu.be/LaUbcb1Q2pY

Howard Dutton
 
Edited

1. OnStep uses INPUT_PULLUP mode on the limit sw input pin.  This enables the weak internal pullup resistor (if present on the given MCU.).
2. My PCB designs use an external 2K pull-up resistor for better noise immunity and some ESD protection.
3. My PCB designs use an 0.1uF cap for better noise immunity and some ESD protection.

Normally the limit sw pin is HIGH (via that internal pullup resistor and/or the external one,) the button press or switch closure pulls it LOW.

Aisling Lightworks
 

Thanks for that info, Howard. And I get the feeling you're right, Dave, it's got to be an idiosyncracy with my build that's got the signal on that pin too high. I'm a little out of my depth at this point though.

Dave Schwartz
 

Well, this is why GND, 3V3 and 5V are also brought out on the MULTI connector... so that they are available to not only power things like a Hall Effect module for PEC (which already has the necessary circuitry to do effective pull-ups or pull-downs) as well as 'build-your-own' circuits for things like limit switches.

A pull-up resistor is a resistor that feeds enough current so that an MCU logic detect pin sees a high level when nothing external is actively trying to pull it down. It is sized such that when that thing does want to pull the level down to zero, as long as that thing can pass more current than the resistor (and a switch certainly can), the resistor's current capacity will be maxxed-out and thus incapable of keeping the value in the high state any longer. A pull-down resistor works similarly but in reverse... it is a resistor between the MCU pin and ground that has sufficient current capacity to shunt small stray voltages to ground (low) logic level but not enough capacity to interfere with that external thing as long as it can supply more current than the pull-down resistor can shunt to ground.

For 3V3 or 5V MCU applications, a 2K or 2K2 resistor is ideal for such uses. Such a resistor will pass between 1.5ma and 2.5ma of current at those operating voltages, thus keeping the desired 'idle' level firm in the face of moderate electrical noise, but a determined external device can easily overwhelm it.

Wikipedia has a good article and this picture is lifted from that page. The picture is of a pull-up resistor arrangement... for pull-down just reverse the placement of the switch and resistor.

Not really rocket science.

On 2019-06-10 1:11 p.m., Aisling Lightworks wrote:
Thanks for that info, Howard. And I get the feeling you're right, Dave, it's got to be an idiosyncracy with my build that's got the signal on that pin too high. I'm a little out of my depth at this point though.

Dave Schwartz
 

P.S. Don't try to tie the MCU pin directly to Vin or GND to get the correct idle state and then try to apply the other through the switch in an attempt to force the pin to the opposite state. A switch has an almost unlimited current capacity for our purposes and without that resistor you will be shorting Vin to ground which will probably brown-out the MCU due to the voltage regulator shutting down either temporarily of permanently. Maybe obvious but I think it had to be said.

On 2019-06-10 1:46 p.m., Dave Schwartz wrote:
Well, this is why GND, 3V3 and 5V are also brought out on the MULTI connector... so that they are available to not only power things like a Hall Effect module for PEC (which already has the necessary circuitry to do effective pull-ups or pull-downs) as well as 'build-your-own' circuits for things like limit switches.

A pull-up resistor is a resistor that feeds enough current so that an MCU logic detect pin sees a high level when nothing external is actively trying to pull it down. It is sized such that when that thing does want to pull the level down to zero, as long as that thing can pass more current than the resistor (and a switch certainly can), the resistor's current capacity will be maxxed-out and thus incapable of keeping the value in the high state any longer. A pull-down resistor works similarly but in reverse... it is a resistor between the MCU pin and ground that has sufficient current capacity to shunt small stray voltages to ground (low) logic level but not enough capacity to interfere with that external thing as long as it can supply more current than the pull-down resistor can shunt to ground.

For 3V3 or 5V MCU applications, a 2K or 2K2 resistor is ideal for such uses. Such a resistor will pass between 1.5ma and 2.5ma of current at those operating voltages, thus keeping the desired 'idle' level firm in the face of moderate electrical noise, but a determined external device can easily overwhelm it.

Wikipedia has a good article and this picture is lifted from that page. The picture is of a pull-up resistor arrangement... for pull-down just reverse the placement of the switch and resistor.

Not really rocket science.

On 2019-06-10 1:11 p.m., Aisling Lightworks wrote:
Thanks for that info, Howard. And I get the feeling you're right, Dave, it's got to be an idiosyncracy with my build that's got the signal on that pin too high. I'm a little out of my depth at this point though.

Aisling Lightworks
 

Certainly not obvious to me lol. I know next to nothing about electrical components. So it does feel like rocket science. Considering the fact that it used to work as designed and now doesn't I feel like maybe I damaged something by reversing the operation.

Dave Schwartz
 

It is possible to damage MCU pins by making unwise device connections.

Most STM32 pins have a current capacity of around 20ma (some have much less, i.e. PC13 - the user LED pin, which is why you should disable the onboard user LED if you are going to use an external LED) and are not intended to drive devices with greater needs than that without a buffer or driver of some sort. If you have the software and hardware in disagreement over what the pin is required to do you can burn out the circuitry for that pin (and occasionally the damage may not be limited to just that pin).

On 2019-06-10 2:12 p.m., Aisling Lightworks wrote:
Certainly not obvious to me lol. I know next to nothing about electrical components. So it does feel like rocket science. Considering the fact that it used to work as designed and now doesn't I feel like maybe I damaged something by reversing the operation.