Digital input voltage limiting

I’m working on a project and I want to detect if there is DC power coming into the device by connecting the power line to a digital input. In some situations this may be 5v and I know the DIs are supposed to be 5v tolerant, but it may also have 12v coming in instead which I’m pretty sure would be bad for the digital input.

Right now I’m using a Phidget voltage sensor connected to an analog pin, but I want to simplify this thing and remove the Phidget. My thinking is a 3.3v regulator between the input line (potentially 12v) and the DI pin.

  1. Am I nuts with this idea?
  2. Do I need to throw a diode in to limit the current to the DI?
  3. Is there some other mechanism that would make this even easier?

My device has a backup battery to keep the device running even if power isn’t coming in, and that backup battery system can be powered by 5v to 12v, and that’s the input line I’m wanting to tie to a digital input.

I appreciate any ideas or suggestions anyone has.

I don’t have a 3.3v supply coming in, just the 5v out from my battery that powers the red-board. The battery is rechargeable and is a closed device I can’t tap onto. I need to tap the power going into the battery that powers the Gadgeteer which is between 5v and 12v.

Yes, but that’s not where I need to measure. I need to know if power is coming into the battery system. The battery system then feeds the red-board, so the 3.3v on the red-board is not helpful.

I think @ Andre is talking about tapping into one of the 3.3V rails which your board will generate once it has sufficient power, and feeding that voltage into one of your digital inputs.

No power = no 3.3V = no code runs. Which brings up an interesting point: the very fact that you know your code is running automatically means that you have power. The converse is also true: you will never know that you don’t have power, since the device in charge of “knowing” will not run in the first place. Maybe some clarification on what you’re actually trying to do?

@ – Are you talking about a battery switching system?

Sounds like an optical -solatoris needed: Opto-isolator - Wikipedia

I’m not sure what’s not clear. I want to measure power going into my battery system. The battery system powers the board. So if power isn’t coming from the wall the system still runs because the battery is providing power. So this is measuring the power coming from the wall.

@ Mike - thanks, I’ll look at the opto-isolator, hopefully I can find one that will work for a range of input voltages.

@ Iggmoe, I’m not looking at a battery switching system, more like the buzzer on a UPS that activates when there is no power even though the computer is still running.

@ - Wall power is AC, so you’d likely need an AC/DC converter somewhere. Afterwards, you can choose a voltage translation (level shifter) like so:

@ Iggmoe, the wall power is converted in a wall-wart, so I have DC coming in, but that portion of the circuit is designed for 5v to 12v. I’ll check out the link you listed, thanks.

@ - Try this, I’ve narrowed the parameters a bit to be more suitable for your application:

If the level-shifter’s input voltage range doesn’t match what your brick is putting out, you can always run your brick output through a simple voltage divider first.

As everyone has said, why try to measure the higher (unknown) voltage, when you can measure the resultant voltage on a 3v3 or 5v rail and achieve the same thing? If you measure the OUTPUT of the 3v3 regulator in a power circuit, then the only thing different about measuring that is that you know it will be within a certain spec. The only difference is the small amount of capacitance you’ll have around the regulator that will hold power high after the input power is removed.

The problem with simple approaches to measuring this or getting it into spec through level shifting or voltage dividers, is that you end up with not being able to guarantee the transition voltage, the point where a logic level 1 becomes a logic level 0, signifying that you’ve lost power. If you convert that back to 3v3 then you know the characteristics of that transition are exactly the same as the micro you use.

In a practical scenario you may come across, you’d measure this on the far side of the supercap that powers your device for the (micro) seconds necessary to complete pending transactions/actions/logging/alerting etc and shut down safely/cleanly

@ Brett, I can’t use the rail because it will always be powered. I have what is effectively a DC UPS powering the system (and the rails), but I am trying to see if power is coming into the “DC UPS” or not, so I have to measure completely before the Gadgeteer system.

Then besides the level shifting or voltage divider option as was mentioned before, the way I would measure that is to put a specific voltage regulator on the circuit - that way it doesn’t matter if the master input voltage is 5v or 8v or 12v, you’ll have 3v3 that you can use as a digital input. An LDO reg would be pretty easy to do and reliable

@ Brett, thanks. The 3.3v regulator was one of my first ideas, just wasn’t sure if it was a really bad one. Thanks.

are you kidding? Even the little LM1117 3v3 is a Vmax of 15v. AMS1117 equivalent on ebay is about $0.15 in 10’s.

@ PintSize.Me - Actually, Brett’s suggestion is really elegant in its simplicity!

One thing to look out for with LDOs is that they tend to be very inefficient (hotter) the greater the difference between your input and output voltages. If your output is only 3.3V but the input is 12V, it might get toasty. But for simplicity, compactness, and cost they’re hard to beat.

Here’s a LDO that goes to 15V input:

Here’s a switcher that goes to 36V input. It doesn’t have the efficiency problem that a simple LDO has, but is more expensive:

@ Iggmoe, I think heat and efficiency shouldn’t be much of an issue because as I understand it they are a function of both difference and load, if the load is minimal as it would be with a digital input, then I think the efficiency and heat should be minimal.

@ Bret, thanks for the suggestion of the AMS1117, I see it comes in multiple packages - more decisions. :slight_smile: