Level shifter?... - Page 1
Forum section: electronics / projects

author: Bebe
author_rank: Newbie
timestamp: March 31, 2017, 05:33:06 pm
content: Hi! I'm designing a module that measures voltage with the help of a uC. I'm using a 3V voltage reference and one channel of the uC-s 10 bit ADC. I need to measure voltages up to around 16V, but the ideea is that only voltages above 7V are useful to me...My question is how can i shift the measured voltage to use the full precision of the 10 bit ADC? I was thinking that i need to subtract 7V from the measured voltage to bring it to 0 - 9V basically (since i can't measure negative voltages, anything below 7V will be zero) and then divide it by 3 to get 0 - 3V which is my full measurement scale. What is the best way of doing this without altering my signal, since i'm trying to obtain a precision of around 0.01V? I was thinking to use an op-amp configured as a differential amplifier (with a gain of 1) and some 7V reference for the subtraction part, then divide the signal by 3 with the help of a voltage divider built with 0.1% resistors. The ideea is that i don't know how much will the op-amp alter my signal or even what op-amp is best suited for this aplication...I was also thinking that i might use like a precision 7V zener diode in series with the voltage divider and ADC pin, but then i realised that his might not work since the diode needs a minium load in order to regulate properly and a precision 7V zener is pretty hard to find at my suppliers and also quite expensive. I should also mention that the supply i'm trying to measure is also the one i'm powering everything from (it's a car battery whose voltage i need to monitor). I would really appreciate some help with this... Thanks!

author: rmacintosh
author_rank: Regular Contributor
timestamp: March 31, 2017, 07:33:35 pm
content: What if you were to divide the measured voltage by 3 first thing.Then you would be working with 0-5.333333 range with your measured range in between 2.333 - 5.333v which is a 3 volt span for input to your ADCYou could take a standard 2.3v zener to clamp the output of your divider and calibrate in software?Kind of a basic solution, but im just throwing ideas out.

author: Bebe
author_rank: Newbie
timestamp: March 31, 2017, 09:14:58 pm
content: Hi! Thanks for your reply. I thought to divide the voltage first too but i think it's the same thing, the only thing that changes it's the zener diode's voltage but the problem of regulation remains the same. Also i want do do as little software calibration as possible...

author: Ian.M
author_rank: Super Contributor
timestamp: March 31, 2017, 09:42:49 pm
content: If you want to measure the voltage of a car battery that's in use to 0.01V you'll need to make a differential measurement between its + and - terminals, as you can get a significant voltage drop across its ground strap. As good quality Zeners typically have a 5% tolerance, and the slope resistance of low voltage ones is quite high, they should be avoided at all costs.Also you *MUST* use potential dividers on the differential amplifier inputs, with effective external clamping, as it needs to be run off a lower stable supply and protected against typical automotive transients. Seehttp://electronicdesign.com/power/eliminate-those-automotive-load-dump-circuit-protection-headachesfor a quick overview.To offset the differential amplifier output, subtract a proportion of the fixed reference voltage then scale it to get a 3V swing. The devil is however in the details as implementing a differential instrumentation amplifier, + offset and scaling stages using only single supply OPAMPS is going to be interesting.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: March 31, 2017, 10:51:09 pm
content: .01 V on a 16-7=9V range is 0.1%. You said 0.01V precision, but is that really what you meant, or did you mean accuracy? What about noise level? 0.1% is 10 bit, you're not going to get 10 bit ENOB out of a 10-bit uC ADC unless you average it way down, and you're not likely to get 0.1% accuracy using the built-in reference regardless.

author: Ian.M
author_rank: Super Contributor
timestamp: April 01, 2017, 01:44:24 pm
content: Quote from: Bebe, by PMQuote from: Bebe, by PMI hope you will forgive me for quoting your PMs publicly. I generally don't provide help by PM - its better to ask here where my replies will be peer reviewed.Exception: If I'm being paid for confidentiality, or if personal details are involved.I did some hacking around in LTSPICE and came up with this:which does all the scaling and shifting in a single OPAMP stageIt needs a rail-to-rail output precision low voltage single supply OPAMP with low input leakage current, and 0.1% E192 resistors for R1 through R6. The OPAMP inputs and outputs all stay within the 0V-3V range so you should be able to run it from your MCU supply railHere's the results:MinOut: V(Out)=44.28 mV at Vbatt=7 VMaxOut: V(Out)=2.996 V at Vbat=16 VADCmin: ADC(MinOut)=15ADCmax: ADC(MaxOut)=1023Run the LTSPICE sim and look at the error log for the raw .measure results.As drawn it doesn't include input protection or filtering. You will need to split the 100K input resistors (e.g. 81.6K + 18.4K) with the bigger resistor on the input side to allow caps to be added to provide low pass filtering and allow clamping. The actual input resistors *MUST* either be through hole or long body SMD with a voltage rating >200V. The clamping *MUST* be low leakage. Your proposed BAS40 diodes could leak as much as 1uA at 125 deg C - you'll need to do a detailed analysis to see if you can tolerate that.Its inputs should be wired to the actual battery terminals with a 100mA fuse inline in the positive sense lead within 3" of the battery terminal. Sleeve all thin sense wiring in the engine bay.Of course the whole circuit is useless unless you can get good enough accuracy from your MCU's on-chip ADC.

author: Kalvin
author_rank: Super Contributor
timestamp: April 01, 2017, 02:41:57 pm
content: Instrumentation amplifier is the way to go:http://www.ti.com/lsds/ti/amplifiers/instrumentation-amplifiers/instrumentation-amplifiers-products.page#p766max=15;100http://www.linear.com/parametric/instrumentation_amplifiershttp://www.analog.com/en/products/amplifiers/instrumentation-amplifiers.htmlSelect a device with positive voltage rail input levels. Check also that the output will swing close enough to the negative power supply (ie. ground when you are doing single supply design). Discrete solutions similar to Ian.M's suggestion require good resistor match which may be hard to achieve with the typical 1% resistors.

author: Ian.M
author_rank: Super Contributor
timestamp: April 01, 2017, 03:45:18 pm
content: Kalvin is right if you want precision, but I've done a full worst case analysis*for 0.1% tolerance resistors in the circuit I posted above, and the maximum error is 0.35% FSD over the full input range + 0.40% per volt of common mode offset at a nominal battery voltage of 13.8V That's probably about as good as you can get from a MCU's 10 bit ADC and a commercial grade reference anyway, so if its got to be cheap, and you can live with the accuracy limitations its still viable.* Not a Monte Carlo analysis. I iterated for all possible combos of the 6 resistors at their upper and lower tolerance limits. 26runs + 1 for nominal values so 65 runs total then post-processed the log file in Excel to extract the worst case values and convert to percentages.

author: Zero999
author_rank: Super Contributor
timestamp: April 01, 2017, 04:43:13 pm
content: TL431+ current sink + potential divider.See attached for the simulation. Note that the .asc file looks different than the attached schematic. It's because LTSpice doesn't include the TL431 symbol and model by default. Fortunately easy to embed the model but I don't know of a way to embed the symbol so had to use the generic 8 pin DIL which is. The pin numbers are for the TO-92 version though, not the 8 pin DIL.

author: Zero999
author_rank: Super Contributor
timestamp: April 01, 2017, 11:50:44 pm
content: Quote from: evb149 on April 01, 2017, 08:28:15 pmNo, because the cathode current would depend on Vin. The cathode current would need to be much higher at the upper voltage limit, so it's still within spec' at the lower voltage limit.QuoteThe TL431 will do nothing when the cathode current is too low, but that doesn't matter, since as the 3V rail hasn't stabilised the MCU's ADC won't be doing much either. The nice thing about deriving the cathode current from 3V is it can be taken from an MCU output, so the circuit can be switched off when it isn't needed to save power.QuoteA reasonable suggestion but the circuit is reasonably tolerant to some reverse voltages and over-voltage in its current form. The maximum safe input voltage is the rating of Q2 + 7V = 45 + 7 = 52V. The MCU's input protection diodes will do the rest. The minimum safe input voltage is around -6V-0.6V = 6.6V governed by Q1's maximum emitter-base voltage and one diode drop. If this isn't enough, a zener across Q1 will protect it from higher voltage transients.QuoteSeems complicated.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: April 02, 2017, 01:11:44 am
content: Quote from: Hero999 on April 01, 2017, 11:50:44 pmHe's measuring a car battery. Presumably he intends to do this with it installed in the car, which means one of the worst reverse voltage, over voltage, load dump, etc. environments out there. The 52V continuous limit is good, but he needs +/- a couple hundred volt transient protection for an automotive environment.Anyway, all of this seems pretty over elaborate to me for less than a factor of 2 increase in resolution, that's less than 1 bit. I think we can all agree that the 10 bit ADC built into an MCU probably isn't enough for his 10-bit accuracy/precision (he hasn't clarified) requirement, so an external reference and likely an external ADC will be required anyway. At which point personally I'd rapidly sacrifice the <1-bit resolution we're talking about here for a circuit with drastically reduced complication. A reasonable external reference, 12-bit ADC, and a simple 0.1% voltage divider with schottky diodes to the rails and a buffer amp is what I would go with.

author: Bebe
author_rank: Newbie
timestamp: April 02, 2017, 04:06:51 pm
content: Thank you Ian.M and Hero999 for your time and effort to draw and simulate those schematics, i'll play around with both of them to see which one suits my needs best.Quote from: Hero999 on April 01, 2017, 04:43:13 pmSorry if this question seems stupid but what exactly is the role of Q1 from your schematic? I played around with it in the simulator and i noticed it the circuit works fine without it.Quote from: suicidaleggroll on April 02, 2017, 01:11:44 amThe 3V reference im using it's not the uC-s internal reference, it's a LM4040 3V 0.1% voltage reference, and about the external ADC, unfortunately i can't really use one because i'm trying to keep the cost of this build as low as possible and also board space is verry limited and i already used all my uC's comunication interfaces with other devices like a display, and some shiftregisters.

author: Zero999
author_rank: Super Contributor
timestamp: April 02, 2017, 05:59:47 pm
content: Quote from: Bebe on April 02, 2017, 04:06:51 pmIt's not a stupid question. Q1 forms part of a current mirror and is very important for stability. Try removing it and look at the current through Vin, Q2 & U1.

author: Kalvin
author_rank: Super Contributor
timestamp: April 02, 2017, 06:16:03 pm
content: In practice to get the best accuracy, you should really look at the matched pair transistors instead of two discrete transistors BC547C.https://www.digikey.com/products/en/discrete-semiconductor-products/transistors-bipolar-bjt-arrays/277?FV=ffe00115%2C128009e%2C12800a2&mnonly=0&newproducts=0&ColumnSort=1000011&page=1&stock=0&pbfree=0&rohs=0&quantity=&ptm=0&fid=0&pageSize=25

author: Kalvin
author_rank: Super Contributor
timestamp: April 02, 2017, 06:28:47 pm
content: You might be able to increase the ADC resolution by using the over-sampling technique:http://www.atmel.com/images/doc8003.pdfYou just need to supply some uncorrelated noise to the ADC reference or ADC input. Typically this is not an issue

author: Ian.M
author_rank: Super Contributor
timestamp: April 02, 2017, 06:48:40 pm
content: I really don't like the idea of having silicon with a fairly low voltage rating directly connected to a car battery. Even in a 12V system, transients >100V are quite usual, and due to the need for a standing current through the TL431, its difficult to protect without introducing an offset. Also the current mirror has a non-zero dropout voltage so its going to have linearity problems near its lower limit.

author: Zero999
author_rank: Super Contributor
timestamp: April 02, 2017, 10:05:41 pm
content: Quote from: Ian.M on April 02, 2017, 06:48:40 pmThen replace it with a higher voltage rated piece of silicon, such as the 2N5551. They're not expensive and widely available.QuoteYes, that is a problem with this approach. The minimum output voltage will be Q2's saturation voltage divided by three, so you'll lose the lower few counts on the ADC. The op-amp circuit design you posted might also have this problem, as the output stage may not fully go to 0V. An op-amp with a CMOS output stage would be best.

author: Kalvin
author_rank: Super Contributor
timestamp: April 03, 2017, 04:30:18 pm
content: Quote from: Hero999 on April 02, 2017, 10:05:41 pmThe problem with the op amp output will only be present when measuring the lowest voltage levels, thus it may not be an issue. This may apply also to the Q2's saturation voltage, but I am not 100% sure what the temperature dependent behaviour will be or how the saturation voltage will vary from one device to another.

author: Zero999
author_rank: Super Contributor
timestamp: April 04, 2017, 08:22:30 pm
content: Similar to your circuit. Here's a guide on how to design an op-amp circuit with biasing and scaling.http://www.ti.com/lit/an/sloa097/sloa097.pdf

author: Ian.M
author_rank: Super Contributor
timestamp: April 04, 2017, 09:03:12 pm
content: That's a good application note, and its well worth saving a copy, but it doesn't cover differential amps with offset. I designed the circuit I posted to handle the offset across the battery ground strap, which can swing positive or negative depending on the net current into or out of the battery. Especially during engine starting, the drop accross the strap can be quite significant. Due to the way the offset derived from the reference voltage is introduced, and the OPAMP's feed back loop forcing the chip's -in to track its + in so long as the output hasn't railed, it can tolerate up to +/-4V of common mode offset with both OPAMP inputs remaining within the OPAMP supply rails, so with no degradation in accuracy other than that due to mismatches in the equal value resistor pairs.With clamping and input filtering added as described, assuming its power supply is also protected, the inputs should be reasonably robust and survive a worst case ISO7637 pulse 5A load dump test..