0
\$\begingroup\$

I want to build a Counter using a Proximity Sensor. I want to give choice for user to use either PNP or NPN. I will give two ports for the same. I am using PIC16f887 microcontroller. How to detect that which sensor user inserted?

  • I dont want to miss any sample just to detect.
  • I dont want to put burden on user to select type of sensor from the menu.

Power supply for sensors is 12V DC.

It may be programmatically but automatically it should detect without user intervention. Or it may be electronically , may be using Gate circuit or something.

What is confusing me more is some of them come "open collector" type. When sensor detect the object, they pull down.

\$\endgroup\$
2
  • \$\begingroup\$ Define all expected sensor interface source \$\endgroup\$
    – D.A.S.
    Commented Mar 19, 2021 at 3:24
  • \$\begingroup\$ @ Tony Stewart Sunnyskyguy EE75 I am sorry , i didnt get you. Can you please elaborate more. \$\endgroup\$
    – Israr
    Commented Mar 19, 2021 at 3:28

1 Answer 1

1
\$\begingroup\$

This should be possible to do if you use a window comparator, and detect whether the input is pulled 'high' or 'low' from a known midpoint. We take advantage of the fact that both NPN and PNP type sensors use open-collector outputs.

Example (simulate it here):

enter image description here

The window comparator is high when the input voltage is between 1/3 and 1/3 of 12V (that is, between 4 and 8V). If it is pulled above that by the PNP, or below that by the NPN, the output goes low.

The comparators have open-drain outputs and are wire-OR, so this can tie to your logic with the appropriate logic voltage pull-up. I show 5V here; it can be 3.3V or whatever your system requires.

Basically, this looks like an NPN type to your system, so you need only 1 input. If you want to use two, then you can separate the comparator outputs and detect whether you have a PNP or NPN type plugged in.

Like this (simulate it here):

enter image description here

The upper comparator goes low when NPN is inserted and active, the lower one when PNP is inserted and active. So now you know which kind of sensor is in use, if it matters to you.

\$\endgroup\$
3
  • \$\begingroup\$ +1 . Superb Thank you. For so early reply. \$\endgroup\$
    – Israr
    Commented Mar 19, 2021 at 5:36
  • \$\begingroup\$ Can you please suggest any open drain op amp part number , i can get in india. \$\endgroup\$
    – Israr
    Commented Mar 29, 2021 at 8:35
  • 1
    \$\begingroup\$ LM358 or LM339. \$\endgroup\$ Commented Mar 29, 2021 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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