Exact match. Not showing close matches.
'[OT] Sinking, sourcing, NPN, PNP sensors and switc'
I am updating a PC board in a machine that reads inputs from two sensors or
switches. I've already build logic boards for these machines sometime ago,
but I always run into this problem:
Over the years various people assembled these machines and it seems to me
each had their own idea of what (industrial proximity and opto) sensor to
use, so I have forever have to modify my board so that it can work.
< aggressive frustrated mode on > I am now going to chuck the whole design
and replace it with a PIC, possibly a 12Cxxx < aggressive frustrated mode
And to make it compatible, I am looking for an idea that will read any of
these sensors, whether its a NPN or PNP sensor, or a switch that is
switching through high or low. All I need to read is the change of state
from low to high or high to low (doesn't matter which). The input voltage
must also be dropped from 12V to 5V (for the PIC). As the boards must be
very small, I can not use too many components.
Anybody with some ideas?
(I know this list loves a challenge)
Been there, done that.
Basically you need to design a signal conditioning board.
Arcom Control Systems (http://www.arcom.co.uk) have loads of this
sort of stuff in their industrial I/O product range.
They'll even send you the circuit diagrams so you can check
they do what you want. Some of their stuff is in the RS,
Farnell and CPC catalogues.
The only reason for inventing your own is to get it into
a particular package or avoid unused circuitry.
When I had to, I designed a simple circuit where you
fitted/omitted particular resistors or chose values
to suit the voltage and polarity of the sensors.
This controlled the flow of current into the
Thus one PCB layout can serve various sensors.
You could have the input types link-selectable.
> the boards must be very smallSure, I used SM resistors.
The problem is that I don't install these boards myself, they get send all
over the country and get installed by so called "technicians".
So the board must be universal.
(Plug and Play if you like)
> The problem is that I don't install these boards myself,
> they get sent all over the country and get
> installed by so called "technicians".
There's only so much you can do.
If the sensors source current, you could rectify this
or use AC optocouplers to detect the energised state.
If they sink current, you have to have a known polarity.
I think Einstein said that the difference between
genius and stupidity is that genius has its limits.
You can make it more idiot proof but sooner or later
it will meet an outstandingly stupid meathead.
Count your blessings, I had to work for one
for nearly two years. I saw a greetings card in
the style of a B-movie poster:
"The Job That Ate My Brain!"
It was that kind of job.
What I would do is use two pins to sense each input. Both pins would be go
through 10K resistors and then tie to a common cap (1000pF). The sensor
input would be tied to this cap through a 100 ohm resistor. The 100 ohms and
1000pF provides a good line terminator for the input and greatly improves
the static discharge capability of the inputs.
Sensor 100R 10K
Input -----/\/\/\----+----/\/\/\------ PIC Output pin.
+----/\/\/\------ PIC Input pin.
To read an input which sinks current pull the output pin high and watch for
a low on the input pin. To read an input which sources current pull the
output pin low and watch for a high on the input pin. The 10K resistors will
provide current limits for the internal protection diodes. 12V will supply
less than .7mA of current per pin into the microprocessors Vcc. With 4 pins
as possible inputs this is 2.8mA. Make sure your circuit draws more than
that, else Vcc can creep up on you.
If you don't know if the input sensor sinks or sources you detect if the
input is floating by first charging it with the output pin and reading the
input once charged, and then discharging it with the output pin and
re-reading. When computing the charge time remember to add the cabling
capacitance, it can easily become many nF with a long cable. I would wait
about 5 time constants before making a reading. The problem with this is the
time it take to make the initial readings until you determine if the sensor
is sinking or sourcing current. Once that is determined you can make
readings fairly quickly.
I have used a scheme like this, only using 1 pin when I know the input would
always sink current. I would drive the pin high and wait for 5 time
constants. (The sensors could be up to 1000ft from my controller, so this
was about 250usec.) Then I would switch the pin to input and read the value.
If high the sensor was open, if low then closed. As this was a low power
application I would switch the input back to an output and echo my reading.
I would update the readings once a second, and inputs changed only about
once an hour.
Peter L. Peres
I hate to do this, but it has no PICs:
Switched 1/4 CD 4070B (fed by +12V thru 220R FR)
fm. 1k FR +----+
Sensor O---/\/\/\---*------+ | 220R FR
| | X1 >---/\/\/\---O Out to computer
\ +--+ | Active: H
4K7 / | +----+
+---*-------O Internal control:
- tie to +12V for input LOW=active
- tie to GND for input HIGH=active
You may need to add a 5V1 zener between the output point and GND to
protect the computer input, depending on what you do, and you may
actively control the control pin if you wish. Normally it is to be a
jumper or a switch.
BTW a PIC can be used instead of the CD, using 2 of its pins per
switch/channel to be read. There is a way to use 1 pin, but that assumes
that the sensor admits pulses in the supply voltage.
|At 10:52 AM 10/6/98 +0200, Quentin wrote...
>And to make it compatible, I am looking for an idea that will read any of
>these sensors, whether its a NPN or PNP sensor, or a switch that is
>switching through high or low. All I need to read is the change of state
>from low to high or high to low (doesn't matter which). The input voltage
>must also be dropped from 12V to 5V (for the PIC). As the boards must be
>very small, I can not use too many components.
You don't really need a level converter, Microchip specs the clamp current on th
e '508 at 20ma, so just feed your input directly via a limiting resistor. I've s
uccessfully interfaced directly with 0-12v levels by running them through a 100K
resistor (120uA). To accomodate NPN/PNP sensors, you could have a spdt switch t
o connect a pullup/pulldown resistor to the appropriate rail. Or, if you will ha
ve a spare output pin, use that to control pullup/down. Note however, that Micro
chip specs maximum low level output voltage at 0.6V, and maximum low level input
voltage at 0.5V - which is quite brain dead, since they won't guarantee that th
eir own low outputs will read as low inputs. To overcome this, you could do some
thing like that shown below, using an output to control a pullup:
output A <---v^v^v^v^--+
| R2 3.3K
input B <-------------+---v^v^v^v^--------> sensor
> R3 150K
For an NPN sensor; assuming a 5V Vcc, setting output A high will pull up to 2.58
V ((Vcc-0.7)*150K/250K) or more, meeting the minimum high level input requiremen
t. The sensor must be able to sink to ~0.3V @ < 1mA.
For a PNP sensor; setting output A to tristate (input) will allow R3 to pull the
input below 0.5V, meeting the minimum low level input requirement. The sensor m
ust be able to source a minimum of ~2.1V @ < 1mA. It should be safe to >60V.
Mike Sauve | Bay Networks USA
baynetworks.com | Oak Hollow Gateway msauve
Voice: +1 (248) 304-2563 | 24800 Denso Drive, Suite 300
Fax: +1 (248) 304-2512 | Southfield, MI 48034
Thanks to all that replied.
Using another pin to set high and read and then set low to read to
determine sink or source is a good idea, but I see some problems as you
don't know at that stage if the sensor is sensing or not, or if it is in
I try to stay away from any kind of switches as that is what confuse the
people that install it.
I've tinkered a bit with electronic workbench and came up with this:
As I want to use a 12C508 the pins already give me part of the solution. I
can use the Shmidt Trigger (sp) and do this:
2K | ||20nF
0------VVVV---0-----||----0 PIC Pin
This will then give a pulse every time there is a change in the state of
the sensor. I might also have to put in a diode from 0V to PIC Pin, to clip
neg. going pulses.
The only disadvantage of this is that with a source sensor the pulse occur
when it switches on and on a sink, the pulse occur when it switches off.
This might not be a problem in my application.
Peter L. Peres
|On Wed, 7 Oct 1998, Quentin wrote:
> Thanks to all that replied.
> Using another pin to set high and read and then set low to read to
> determine sink or source is a good idea, but I see some problems as you
> don't know at that stage if the sensor is sensing or not, or if it is in
Write a software filter to debounce transitions.
> I try to stay away from any kind of switches as that is what confuse the
> people that install it.
Ok, no jumpers.
This won't work. It makes pulses that are 1/2 Vcc 'tall' due to clamping
in the PIC input, AND the PIC input is d.c. floating meanwhile.
Now, my second proposal:
Input O---/\/\/\---*---*---/\/\/\---O PIC pin
K - - C1
A - |
Z5V1 0.01 uF
For every measuring cycle, you do the following:
1. Test the state on the PIC pin and store it as S0
2. Turn the pin to output, and output ~S0 for T = 3 * R2 * C1
3. Turn the pin to input, and start a counter.
If after T = 3 * R1 * C1 the input is still ~S0: fail, switch not
connected or open collector (?)
If the pin returns to S0 (i.e. != ~S0) after a period shorter than this,
then the state to be read is S0.
Now, to detect changes only, for each measurement, have a 'last state'
register, and a 'new states' register. After running the subroutine
described above, XOR the byte containing S0 (if it succeeded) with OS0
(where OS0 is the stored 'old' state). This will set the corresponding bit
IFF there was a change. Store S0 in OS0 for the next pass. For 2 or more
bits to sense on a chip, run the #1 subroutine for each bit, then run the
XOR. Its result may serve to trigger a network transmission etc (only if
the result of the XOR is not all 0s).
Bonuses: The input switch is debounced free of charge, and the PIC input
protected from transients. There is a switch failure detection, that will
also detect a very noisy switch as a failure sometimes, and will also
detect open collector or momentary switches as failures - it's up to you
Assumptions: The circuit assumes that the source can supply or sink
current at least sometimes ;) and that it is relatively slow changing.
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- New search...