Protecting ADC input on Photon from more than 3.3V input?

I’m trying to protect a Photon analog input from up to 5V input while maintaining accuracy for 0 - 3.3V range.

A 7805 voltage regulator supplies 5V to the Photon and an environmental sensor (sensor requires 5V to operate). The output from the sensor connects to an analog pin (A1). When the sensor’s probe is connected and working, the typical output range is from 0.7V - 3V which is perfect for the Photon.

HOWEVER, when the sensor’s probe is not connected (and a user may not have it connected for very long periods) the sensor’s output is 5V (and current is 3.6 mA).

I would prefer not to use a voltage divider circuit so I don’t lose resolution on the input signal.

I’ve been trying a zener protection with a 1 ohm series resistor and both a 3.3V zener (1N746A) and 3.9V zener (1N748A). For the normal <3.3V inputs it seems to work great. Problem is at 5V (or 4.65V when testing via my USB) the zener does provide protection but drops the voltage into the range of a good sensor signal. For the 3.3V zener the voltage at A1 drops from 4.65V to 2.74V and when testing the 3.9V zener it drops to 3.12V (with 1K ohm resistor it drops to 2.8V).

My concern is the 2.74V reading is in the range of the normal input when the probe and sensor are working. Ideally, I’d like the input to be as close to 3.3V as possible for voltages over 3.3V (4.65V to 5V really) so that way in software I can determine that the probe is not plugged in and in use. Suggestions?

Interesting scenario! I was jumping to answers before I finished reading your post, and then realized you had reasons to rule out the answers I wanted to give. Now that I thought about it, I see a couple of options.

If you have a spare analog input, how about combining the voltage divider and zener protection ideas? Use an analog input on the Photon to measure the voltage divider. If that measurement is in range, then you know a probe is connected. When you know a probe is connected, then read the other analog input that has the zener protection just as you want.

Another option could be to add an accurate high-resolution ADC chip that will tolerate 5V. I would still recommend protecting it from any transients during connecting/disconnecting a probe. That way your Photon communicates digitally with the ADC chip and is not exposed to high voltages.

Thanks @cyclin_al
I think the idea of using a 2nd analog input can definitely work, but I’m low on spare inputs and trying to save the last ones I have.
I should have thought about an external ADC chip. Another option on the list now to consider.

I’m also going to test an op amp solution. My initial test of that failed but when I took a more detailed look at the datasheet I understood why it didn’t work. So getting some new supplies to see how I can do this.

Another idea I haven’t fully worked out is using the Zener output (when it turns on in an over voltage situation) to switch a transistor to cut off the analog input. Because I really have 2 options to know when the sensor is disconnected: analog input of either ~0V or ~3.3V since I know the “good” range when a sensor is plugged in to be 0.7V to 3V.

Do you have any diagrams of where you are using the zener diode? You can use a zener to regulate the voltage, something like: http://electronics.stackexchange.com/questions/35807/how-would-i-design-a-protection-clipper-circuit-for-adc-input ?

Thank you @marcusone. So my circuit is exactly the first one in the article, except for values (1ohm resistor and 3.3V zener or 3.9V Zener).

I suspect, but don’t know for sure, that my issue is what is mentioned near the bottom of that article: “Note that higher-value zeners have better stability than low-value ones.” If you look at the chart, the first 2 lines which look to be for Zeners sinking 10 mA at 3V and 2.3V it appears that at lower current the voltage drop is lower. But I’m not sure if my chart interpretation is correct.

My current (prior to resistor and Zener installation) is 3.6 mA @ 5V. Problem is the 3.3V Zener doesn’t drop a 5V analog input voltage to 3.3V but to 2.74V. So it does protect definitely! It is just that in the near to ideal situation I’d like to have a 3.3V analog input when the voltage is over 3.3V up to 5V.


Might want to ask over at http://www.eevblog.com/forum/index.php as they really know electronics :smile:

I believe you can get more stable zener diodes; or perhaps you can force the zener to pull more current with a resistor in series with it and ground? (not sure if that would work, as it may have an effect on the voltage as well).

http://www.eevblog.com/forum/beginners/0-10vdc-signal-into-3-3v-mcu-adc/msg357995/#msg357995
has some good ideas i think.

1 Like

@bloukingfisher, take a look here!

https://www.newark.com/pdfs/techarticles/microchip/3_3vto5vAnalogTipsnTricksBrchr.pdf

2 Likes

Hi @bloukingfisher

It looks like the link provided by @peekay123 is perfect for you to get started but I wanted to add two things:

  • You are asking too much of your sensor when you put a 1 ohm resistor in series with your 3.3V Zener. If the sensor was a perfect 5V supply, the resistor would have 5 - 3.3 = 1.7 V across it and because it is 1 ohm, would have 1.7 A flowing through it. That can’t happen. So somewhere between the voltage supplied by and the current limiting of the sensor, you get to 2.7V. If your 5V at 3.6mA numbers are correct, the output impedance of the sensor is around 1400 ohms, so you would want to use a value much larger than that (say 14k ohm) as a series resistor to get a good result.

  • I think the best way to do what you want here would be to buffer the analog input with an op-amp but to also add a comparator (a special op-amp) that detects the voltage is above a certain threshold (say 4.5V) and therefore detects the cable is open. This comparator output then goes to a separate digital input that just detects the cable open condition.

4 Likes

Thanks @peekay123 - the circuit on page 40 of that guide was a big help. I’ve not encountered in other documentation. From lots of testing I have two working options to report back. ( @bko thanks for the additional info. I think a lot of my headaches have been due to the sensor being high impedance that has thrown me. Since I have two satisfactory solutions I’ve not gone studying comparators.)

So I went back to check my measurements. When the sensor voltage out is measured at 5V, and I connect it to ground (no resistor) the current is 3.6 mA. HOWEVER, when I connect it to A1 as an analog input it measures 0.0 uA and same voltage signal. High impedance? Out of curiosity, an analog input at 5V and 0.0 uA current - does that pose any risk to the Photon? (I couldn’t tell from the data sheet).

SOLUTION 1: Likely to be applicable to a greater range of situations
Using an op amp and diode. Op amp non-inverting input connect to 3V3 of the Photon. The VCC on the op amp connect to the 5V rail. Result is that analog input voltage is 3.3V when the sensor voltage out is >3.3V. DAC reads 4069 on the analog input which is pretty close to the max 4095.

SOLUTION 2: Zener but may be more circuit specific
Using a 3.9V Zener (note I tested different 3.9V Zeners with different outcomes - so the slope matters). When the sensor output voltage is between 4.75V and 5V the analog input voltage is about 3.2V or 4026 on the analog input out of a max of 4095. I suspect this circuit’s success is specific to the high impedance, current and specific Zener used so may not be as accurately replicable as solution 1.

The 1 ohm resistor really doesn’t make any difference in this particular situation, but keeps the circuit consistent and would be necessary for higher current situations. Thanks again for everyone’s help. And now someone can let me know I was wasting my time perhaps that this would never have damaged the Photon? :wink:

IIRC all pins on the Photon are 5V tolerant, you should be able to find this both on the Particle datasheet and the ST one. It is fairly common to add an op-amp buffer as suggested earlier by bko who has also told whats wrong with your current setup.

All GPIO pins but A3 and DAC/A6!
3v3 and GND aren't either when shorted :wink:

2 Likes

Hehe, never trust memory eh :wink:

Some of the other solutions have other benefits - External ADC - you could have a higher resolution and a digital interface.
A different analog sensor- there should surely be one that has a lower output range. Plenty of sensors operate in the mV range and you amplify them yourself matching the full-scale to the requisite voltage of your controller.
A digital sensor or depending on your application a dedicated sensor IC (in some application like thermocouples it can simply be easier to let some specialized hardware do the hard work). Some of them may even have other features you find useful.

2 Likes

Let me be sure. Data sheet section on GPIO does state GPIO pins are 5V tolerant "(when not in analog mode)." I'm using the pin as an analog input (analogRead). In that case, I should not exceed 3.3V?

Thanks @ScruffR. @Viscacha all good points for me to consider for the future.

@bloukingfisher, you need to quote correctly (for the security of drivers by that might just skim over :wink: )

And the table to which this footnote brlings does not state FT for the DAC pins but 3V3.

This means the DAC (A3 & A6) pins are under no circumstance 5V tolerant.

Other then that, you are correct, the other A-pins are also not 5V tolerant when used for analogRead().

This is a simple, accurate, and temperature stable voltage clamp:

Q1 and Q2 must be the same type. Preferably something with a decent bit of gain. It works better over temperature if the two transistors are next to each other, better still if they are in a dual package, and fantastically well if they’re a matched pair (not many options for matched pairs these days).

The circuit will clamp Vout to something around 50mV to 100mV above whatever Vclamp is. In this case it clamps to 3.35V (by simulation).

4 Likes

Thanks @twospoons. I’m trying to understand the circuit. Sorry for my ignorance but what is the “Vclamp” component? Is it a TVS diode or another type of diode? I like the idea of the precision and if clamped at ~3.35V should provide an analog read of 4095.

No need to apologize for ignorance! Ignorance is easily fixed - I’m quite happy to answer any questions.

Vclamp is any voltage source. In the case of protecting the Photon, Vclamp can simply be the 3.3V supply rail.

To help you understand: the bit doing the clamping is Q1 - when its emitter voltage exceeds its the base voltage sufficiently (also known as Vbe). The base voltage of Q1 is set by Vclamp and Q2. Q2 is in there as temperature compensation - being the same type as Q1 means its Vbe will be the same, thus the voltage at Q1 base will be Vclamp-Vbe. As Vbe in both Q1 and Q2 change with temperature, so will the base bias, keeping the clamping voltage constant.
R1 is in there to keep a small current flowing in Q2, and keep the base bias steady. It also limits the clamping current of Q1, as all Q1’s base current has to flow through R1. If you want a higher current clamp capability, either reduce R1, or use higher gain transistors. Reducing R1 will also lower the clamping voltage a bit, as Vbe is slightly dependent on the base current.

7 Likes

@twospoons, thanks for being kind and patient. I’ve strained some brain cells following the working of this. If you can indulge me with a little more education I’d appreciate it.

So here is my understanding. Starting with Q2, the emitter is connected to the Photon +3V3. Initially, the base and collector are at 0V. Since Vbe is lower most of the current flows through Q2 from E to C and via R1 to ground. At the point between the base of Q1 and G2 the voltage is now +3.3V. Good so far?

Turning to Q1, while the emitter voltage (e.g. 2V on the analog input) is < base voltage of 3.3 it is in saturation mode and turned on with the current flowing from emitter to base and via R1 to ground. However, if Q1 Ve > Vb (e.g. 5V > 3.3V) Q1 is turned off. Now the current flows from emitter to collector and to ground. This is creating something like a voltage divider and the voltage on the analog pin drops to close to 3.35V? Q2 never switches (so other than temperature/accuracy Q1 would still function, less accurately maybe, if Q2 was removed and the 3.3V connected to the base and R1).

I’m probably getting something wrong but would like to educate myself on how this works (vs. just using it without actually understanding it).

Close - the voltage at Q1 base will be 3.3V -Vbe . Vbe is typically 0.6V at room temperature, so the Q1 base voltage will be ~2.7V.

No - if the voltage at Q1 emitter is < Q1 base no current flows at all and the transistor is off. In fact Q1 E needs to be about 0.6V above Q1B (thats Vbe again) before any current flows.

No, that's the condition where Q1 turns on. A small current flows from Emitter to base, and a much larger current flows from Emitter to Collector. The ratio of emitter-base current to emitter-collector current is the gain of the transistor, also known as 'Hfe

Yes, exactly.

This is quite true, except that the turn on voltage for Q1 would be 3.3V +Vbe, or about 3.9V. And it would vary roughly -2mV per degree centigrade.

I would recommend getting hold of a circuit simulator and trying it out. There are some good free ones, such as Simetrix (intro version), LTSpice, and TI-TINA. My preference is for Simetrix, which I've used extensively for many years - even did a small analog MOS chip design with it.

1 Like