Checking if there is DC power on external copper lines and making input high if found

Zlo5

New Member
Hello,

Theoretical question, I don't have drawings or any code, just trying to grasp the concept from my inexperienced perspective.

Supposing I have a device that has a RJ45 output and that when a certain condition is met the device sends anywhere from 5-24v DC through pin 1 with pin 2 being the ground, how can I determine that this is happening?

Since I don't know what the voltage will be, my first thought was a relay that I can connect to my Picaxe project that would make one of my pins high when the condition is met. Is this the right idea or is there a more efficient (or easier) way to accomplish this? If the relay is the way to go, would the little relays that techsupplies.co.uk sells be sufficient?

I've been trying to parse through and wrap my head around all the different info on measuring/regulating voltage, but I don't care about that, just looking for a boolean ON / OFF state status.

Thank you!
 

Jeremy Harris

Senior Member
The easiest way would be to fit a potential divider to the line, with a ratio of about 5:1, and then connect the centre point to an analogue input on the Picaxe. Reading the analogue input will then tell you the voltage on the external line. If all you want is an on/off signal then one line of code that tests the analogue output and sets a flag high or low at a given threshold will do the job simply. The code would just read the analogue voltage, test to see if it was greater than a preset threshold and then set a flag or do whatever it is you want to do if a voltage over 5 V is detected.
 

boriz

Senior Member
A 2~3K resistor from your source, through a 5v zener to ground. The junction of the two goes to the Picaxe input.
 

AllyCat

Senior Member
A 2~3K resistor from your source, through a 5v zener to ground.
Hi,

IMHO that's not particularly "safe". 2K could deliver 10mA into a 5 volt rail. If the PICaxe only has a 4.5 volt rail then nearly all that current will go through the input protection diode (not the zener) and I believe that some pins might not be rated to 10mA (and/or you may not wish to drag the supply rail up to 5 volts).

The simplest solution is a single resistor of perhaps 100k to (almost) any PICaxe pin (best to avoid the one "input only" pin which may not be protected as it can be driven higher for normal PIC programming). The protection diode will clamp the input only slightly above the supply rail (i.e. logic 1) whether the "RJ45" pin is at 5v or 25v. Of course if the drain on the supply could be very low (e.g. the PICaxe in sleep mode) then it would be wise to put a zener or resistor load onto the supply rail.

The only question is whether the "not condition" is zero volts or "open circuit" (e.g. an open switch). If it's open circuit then you may need a pull-down resistor, perhaps a few kohms on the RJ45 end or another 100k on the input pin to ground. Or of course about 22k and use the A/D converter method described above.

Cheers, Alan.
 

nick12ab

Senior Member
IMHO that's not particularly "safe". 2K could deliver 10mA into a 5 volt rail. If the PICaxe only has a 4.5 volt rail then nearly all that current will go through the input protection diode (not the zener) and I believe that some pins might not be rated to 10mA (and/or you may not wish to drag the supply rail up to 5 volts).
If the PICAXE only has a 4.5V rail then you'd use a zener diode of a lower voltage.

Also, taking on board Dippy's previous comments, a zener diode needs a certain minimum amount of current to work.
 

Jeremy Harris

Senior Member
If the PICAXE only has a 4.5V rail then you'd use a zener diode of a lower voltage.

Also, taking on board Dippy's previous comments, a zener diode needs a certain minimum amount of current to work.
Typically around 1mA to 4mA for 400mW zeners, but they are very variable and have a poor knee characteristic at such low currents. A 5.1V zener (the closest available to 5 V) could easily be 6 V or more at a small current. Best to use a much lower voltage, say one rated at 3.3 or 3.9 V, as that's still above the high threshold yet may well stay below 5 V at low current.

I still think it's better to use a PD and actually measure the voltage, then digitally set a trigger level, as that would always be safe and could be adjusted in code to reliably detect the signal.
 

boriz

Senior Member
Jeez. I wasn't proffering a practical circuit, just a basic idea. If you want complete safety, use an opt-isolator. Though as a minimalist, I do like the single 100K resistor solution, if it can be made practical.
 

AllyCat

Senior Member
If the PICAXE only has a 4.5V rail then you'd use a zener diode of a lower voltage.
Hi,

As I undersand it, the "standard" (or at least typical) PICaxe supply is 3 x AA cells. With Alkalines, that might be anything from almost 5.0 volts down to say 3.5 volts. The manufacturers rate such cells down to 0.9 volts (i.e. a 2.7 volt rail) and the PICs are specified down to 1.8 volts, so what zener voltage should one recommend? But a picture is worth a thousand words, so here are typical low voltage zener characteristics. That's the best set of curves I could find (note the 10mA per division), sadly the manufacturers don't seem to characterise at currents around a few milliamps (I wonder why :) ). Actually, a white or Blue LED might be a reasonable choice, but I'd still use higher than 3k ohms.

BZX79s.jpg

However, IMHO a zener is an unnecessary complication, if it could be made to work properly at all. I'm sure the 100k resistor suggested above will work fine, probably a Megohm would do the job as well. Use a diode (even a Schottky type - low voltage drop) to the supply rail if you don't like using an "invisible" protection component. Yes, also my first thought was to use a pot divider to an A/D pin, but I wasn't sure if the OP wanted/preferred a "boolean" signal directly on the pin.

Cheers, Alan.
 

Goeytex

Senior Member
The circuit below will do what you want. Similar to what AlleyCat suggested but I added an external clamp for better clamping.
47K limits current to ~500 micro amps. 10K keeps input pin "low" if 24v line floats.
 

Attachments

Zlo5

New Member
Thanks for all the info, I quite obviously was thinking about it in the wrong way. Good ideas to work with. Regarding the RJ45 connector, you are correct--it's irrelevant. The device (that I have no control of) outputs the voltage across wire 1 with wire 2 being it's ground to signify an alarm condition. It has 4 alarm conditions possible and I simplified it down to one for my question but am planning on bringing the 8 wires into my project via a RJ45 connection.
 

hippy

Technical Support
Staff member
However, IMHO a zener is an unnecessary complication, if it could be made to work properly at all. I'm sure the 100k resistor suggested above will work fine
I'd concur. A 24K would limit 24V to 1mA even if shorted to 0V and diode clamping is good for around 20mA. 24K would limit 5V to 200uA which should be enough to signal a high.

Go too high on the current limiting R and you can get problems but somewhere from 22K to 100K should be okay and no need for any zener. It's what I'd use.
 

John West

Senior Member
I'd try a 10 K Ohm resistor in series in the line, with a 1N914 or 1N4148 or similar small-signal diode with the Cathode end tied to ground and the anode tied to the PICAXE input pin. Then I'd try setting the <> reference reading at about 4 tenths of a Volt for an "over/under flag. It uses 2 parts per input, but they are dirt cheap and plentiful.

While a higher value resistor will likely work, the PICAXE manual warns against using input signals with impedances over 10 K Ohms.
 

Dippy

Moderator
Can you draw that JW. I can't follow how that works.

A note to those relying on the PIC clamp;
I received some info from Microchip Techies for newer PIC a few months back. They suggest good practice to keep the likely diode clamp current in the microamps range.
Personally, I have often done much higher without apparent fault, but they gasped when I asked if 1mA was OK.
Yeah, I have read the Data Sheet too. If you want to argue, don't argue with me as I can't be arsed, simply contact Microchip support and correct them.;)
 

John West

Senior Member
Right now I'm not anywhere that I can draw it and scan it , but basically you're just using the traditional current limiting resistor/Zener diode technique, but you are forward biasing a generic small-signal silicon diode instead of reverse-biasing as you would with a Zener. The junction drop of the diode will always ensure that a small voltage (about .7 V) will appear at the anode end of a diode that's tied to ground any time there is an incoming voltage to be detected, i.e. it latches the incoming voltage to no more than .7 volts.

So any test of that input that reads above some nominal reference voltage such as .3 or .4 V should tell you that you have a voltage present. Anything below that will indicate you don't.

It seems to me that should do the job, unless of course, I'm having a brain fart, which sometimes happens.
 

hippy

Technical Support
Staff member
you are forward biasing a generic small-signal silicon diode instead of reverse-biasing as you would with a Zener. The junction drop of the diode will always ensure that a small voltage (about .7 V) will appear at the anode end of a diode that's tied to ground any time there is an incoming voltage to be detected, i.e. it latches the incoming voltage to no more than .7 volts.
Sounds reasonable in theory; no different to monitoring the anode voltage of a LED.

The only risk is the input is made an output.
 

Attachments

John West

Senior Member
Good point, hippy. That one would require watching. It would work fine in a fixed application, but is not good for an experimental project where people may (will) make coding mistakes. That's one of the problems with working with such versatile chips. More things to go right; more things to go wrong.
 

Dippy

Moderator
Oh I see, sort of.

I had , based on the title, assumed the OP just wanted logic sensing of line. I couldn't see how a 0.7V (ish) at an I/O pin would allow that.
And ADCing would be inaccurate using that.
I can't see what's wrong with good ol' res+zener for logic or res+clamp for ADC.

Anyway, I'm sure it's all fine so off I toddle to the pub.
 

AllyCat

Senior Member
Theoretical question, I don't have drawings or any code ...
Oh I see, sort of.
I had , based on the title, assumed the OP just wanted logic sensing of line. I couldn't see how a 0.7V (ish) at an I/O pin would allow that. And ADCing would be inaccurate using that. I can't see what's wrong with good ol' res+zener for logic or res+clamp for ADC.
Hi,

I'm afraid that this thread shows (again) what happens when a "requirement" is not defined ... as many different possibilities as there are contributors. A circuit designed to "cover all bases" will usually be needlessly complicated, if it's even possible. The OP may not have, or know, any technical details but the basic concept or some "building blocks" might have given us some clues:

Where does this 5 - 25 volts come from? It could be from a mechanical switch (so a pull-down resistor and/or de-bounce may be needed) a "logic" source (where the available power is limited), or maybe from a power supply (which might have a large output reservoir capacitor that needs to be dumped for a speedy response).

Approximately how many pins will the PICaxe have? What (or who) is going to use the data that the pin signals and how quickly must it respond (e.g. is the flexibility of detecting an analogue input an advantage or disadvantage)?

But probably the most important issue is what Power Supply will the PICaxe be using? A battery or a (5 volt) regulated Power Supply? A battery design might be required to work for months or years, making low drain esential. But sinking even a few hundred uA into the supply rail of such a design could take a series regulated supply above the PIC's 6 volt limit. And the base PIC is specified to work down to 1.8 volts where a "zener" clamp probably won't conduct usefully at all.

IMHO probably the best "compromise" is using a LED (perhaps green/yellow or blue/white) as a "zener" with resistors of about 10k ohms from the signal to the LED and to ground. A LED has an added advantage of visually signalling the "boolean" state for testing. The LED should clamp ideally at about 2.4 volts to ensure the required (0.25VDD + 0.8 volts) minimum TTL "High" logic level is reached if there is a maximum (5.5 volt) supply rail, without risking the resistor sinking current into a minimum supply rail of perhaps 2.0 volts.

Cheers, Alan.
 
Top