8
\$\begingroup\$

I need to pass the signal from an end stop (limit switch) to an MCU and I'd like to make it flexible (to make it possible to work with both types of limit switch: normally-open and normally-closed) as cheap and easy as possible.

I could use two inverters one after another, but it looks too bulky. I hope there is a better solution.

I'd like to avoid using firmware configuration. A jumper looks very convenient for production and configuration.

UPDATE

I made the following simulation, which is working as expected:

enter image description here

Does this solution look OK?

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Place an inverter and short it with a zero-Ohm resistor or a jumper. If you don't place the jumper the inverter will be active and vice versa. \$\endgroup\$ Nov 30, 2021 at 10:15
  • 10
    \$\begingroup\$ Programmable inverter. It's just an XOR gate with a pullup on one input (and a jumper to pull that input low). \$\endgroup\$ Nov 30, 2021 at 14:44
  • 5
    \$\begingroup\$ "Does this solution look OK?" In 2021? That's way bigger than a 4-input XOR gate, will cost you more than a 4-input XOR gate just in circuit board space not to mention production costs. If you're handing production to a factory it'll cause never-ending irritation to their manufacturing engineering personnel, who already understand XOR gates. \$\endgroup\$
    – TimWescott
    Nov 30, 2021 at 19:24
  • 1
    \$\begingroup\$ @J..., until OP answers, my guess is the same board with the same software is used in different machines. \$\endgroup\$
    – TonyM
    Nov 30, 2021 at 22:02
  • 1
    \$\begingroup\$ For production, a SMD DIP switch is usually cheaper and better than a jumper. Especially through-hole pin header is costlier to assemble & set up than a DIP switch. \$\endgroup\$
    – jpa
    Dec 1, 2021 at 12:52

7 Answers 7

32
\$\begingroup\$

Simplest way is to not invert the signal to begin with. Have the MCU firmware read the presence or absence of the jumper and based on that have the firmware consider the limit switch as normally closed or normally open.

And if you want to have a purely hardware solution, but with more hardware on the signal route, then add a XOR gate, where basically the jumper just selects to invert the signal or leave it uninverted.

\$\endgroup\$
1
  • \$\begingroup\$ You should mention that, since the XOR gate will replace 2 inverters, it may actually be less hardware intensive. Assuming that the OP is willing to use other XO sections for other purposes such as buffers or inverters. \$\endgroup\$ Dec 1, 2021 at 20:03
20
\$\begingroup\$

You could use 1/4 of an EX-OR gate (eg. 74HC86) rather than an inverter, with a pull-up resistor and jumper. Jumper in place = non-inverted. Jumper removed = inverted.

Replace the jumpers with a DIPSWITCH for more convenience.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ An alternative (that I'm sure you're aware of) to using 1/4 of a quad XOR part is to use a single gate variant which comes in a convenient SOT-23 package (e.g. SN74AHCT1G86 ) \$\endgroup\$
    – W5VO
    Dec 1, 2021 at 19:48
8
\$\begingroup\$

(a) If you can change the MCU software and you have a spare MCU I/O pin, you could use one jumper and no inverters:

  • Connect the switch from VDD to the MCU with a pull-down resistor
  • Connect the jumper from VDD to a separate MCU input pin with a pull-down resistor
  • MCU software XORs the two pin levels to obtain the final switch state

(b) If you can use selection in the connector, you could use one jumper and no inverters. It depends on your situation whether you could use such a connector but this circuit show the principles

  • Connect NO switch across J1-1 and J1-2, put jumper on JP2 and COM

  • Connect NC switch across J1-2 and J1-3, put jumper on JP1 and COM

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
5
\$\begingroup\$

enter image description here

Have two sets of pads to connect the switch: one for normally open, one for normally closed. If the switch is on the PCB, since NO and NC usually have different pinouts, you can just use the NO and NC pads of the same footprint. If the switch is NO, it sets the signal to +5V when closed. If the switch is NC, it sets the signal to 0V when opened.

Then use a jumper to set the resistor as a pullup or a pulldown.

Cost: since you needed that resistor anyway, cost is one extra pad, and one 3 pin 0.1" header and jumper.

\$\endgroup\$
3
\$\begingroup\$

I could use two inverters one after another. But it looks too bulky. I hope there is a better solution.

Just use one inverter and employ the link to select the inverter input or the inverter output. No need for two inverters.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This solution needs two jumpers, with one (and only one) implemented. Thank you for the idea! \$\endgroup\$ Nov 30, 2021 at 10:48
  • 3
    \$\begingroup\$ Just one jumper (the shorting piece that you hold and reposition) and a three way header. Locate the single jumper to one pair or the other pair @romanmatveev \$\endgroup\$
    – Andy aka
    Nov 30, 2021 at 11:19
2
\$\begingroup\$

Do it in software

Most micros these days include some kind of EEPROM/flash storage, so store the setting in there. Then you can handle this entirely in software.

How to configure this setting? I'd be incredibly surprised if you don't have some kind of configuration/monitoring/debugging interface set up, even if that's only an RS-232 port. If you don't, I would strongly recommend getting this in place as best practise, otherwise you're going to find it very hard to test/debug/maintain your firmware in the real world. And assuming you do, it's a no-brainer to use that for configuration.

Cheaply? It doesn't get cheaper per unit than costing nothing. Like I said, it's almost guaranteed that you've got this storage already. If you're at the point of choosing a micro, choosing one with or without EEPROM storage is likely to be a zero-cost option.

Convenient? Very. There's a reason you set up your PC BIOS from a menu-based system, instead of from hundreds of jumpers like you used to back in 1990.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ This is from the perspective of being in a shed on your own, doing what you like for 1 person, but you've (a) made a lot of assumptions about the OPs situation which may well be wrong as OP's not daft and might just understand 'the real world' very well already and have discredited it, (b) ignored the development and labour costs for developing the software, documenting it for prodn/service and the inconvenience in their completely-unknown mass production set-up. Downvoting for all those reasons, I'm afraid - as written, it's guesswork rather than real world. It should be an enquiring comment. \$\endgroup\$
    – TonyM
    Dec 1, 2021 at 17:12
  • 2
    \$\begingroup\$ @TonyM This is from the perspective of having been an embedded software and electronics developer for 25 years across a variety of industries, with design for manufacture being one of the things I have to consider in our systems. The OP may have considered this and discounted it, sure, but all they say is that it "looks" more convenient. 25 years of experience in industry tells me that you need a cast-iron reason not to do this in firmware. If the OP can only say it "looks" better then I'm pretty confident in saying that they don't have that reason. \$\endgroup\$
    – Graham
    Dec 1, 2021 at 20:06
  • 1
    \$\begingroup\$ Years are irrelevant after a very short amount, outweighed by aptitude and open-mindedness. I've also seen quite a lot. There's no excuse for not investigating the question properly and experience should teach you that's above everything. Your confidence is somewhat alarming in that respect. This is guesswork. Rearranging the facts to fit one's views, instead of one's views to fit the facts, is not the way forward. Anyway, I'll leave you to it. \$\endgroup\$
    – TonyM
    Dec 1, 2021 at 21:56
  • 2
    \$\begingroup\$ @TonyM Certainly it's possible they have a genuinely exceptional situation which doesn't match anything I've ever seen or even heard of in 25 years of being paid to interface electronics to micros. (Oh, and 10 years of running a forum helping beginners to electronics.) Since they're asking for help from more experienced people on designing a very simple circuit, I'd strongly bet on them having an X-Y problem and just not having the experience to know the best way to do the job. Which, in this case, is very clearly with firmware. It's not guesswork if you've done this hundreds of times. \$\endgroup\$
    – Graham
    Dec 1, 2021 at 22:24
  • 1
    \$\begingroup\$ Years are irrelevant after a very short amount, outweighed by aptitude and open-mindedness. Number dropping is pointless, though it seems to be treasured here. You won't alter my views on understanding the question before trundling out an answer. But I lost interest in the exchange very early because there will be no progress. Anyway, it sounds like you know my reply, know everyone's situation and what's good for them. Adios. \$\endgroup\$
    – TonyM
    Dec 1, 2021 at 22:34
1
\$\begingroup\$

I'd suggest using a three-pin connector for the switch and allowing operation only when pin 1 is connected to pin 2 but not pin 3. This could be accomplished by having a pin 1 tied to VDD via 1K resistor, pin 2 connected to ground via 10K resistor, and pin 3 connected directly to ground, and requiring that the voltage on pin 2 be a logic high. An advantage of doing things this way, versus having a jumper on the board, is that even if one is using a fault-on-closed switch, connecting it via two-wire-plus-shield cable with pin 3 connected to the shield would trigger a fault indication if the cable is cut completely or is damaged such that the shield shorts to either of the internal wires. The only kind of cable fault that would go undetected would be damage that somehow shorted the two wires within the shield together, without shorting either of them to the shield.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.