How to make an analog circuit to proportionally scale a sensor output voltage? - Page 1
Forum section: electronics / beginners

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 04, 2019, 03:15:21 am
content: I have this device that takes an input from an air pressure sensor. The sensor gets a 5V reference, and the device's MCU reads the sensor's output voltage using its ADC. The sensor reads up to 2.5 Bar.However, this particular sensor is expensive and hard to get, so I have been thinking about the possibility of substituting it with something more commonly available. My mind turned to automotive MAP sensors, which are ubiquitous and cheap. In particular, the common GM 3 Bar MAP sensor would be a great candidate. But, of course, it works over a different pressure range (2.5 versus 3), so therefore the output voltage will not match for any given pressure.I found spec sheets for both my existing sensor and a Delphi-brand GM sensor, and made a graph of pressure vs. voltage using the provided transfer functions:Existing sensor is in green, GM 3 Bar in dark red. As you can see, the voltage difference is proportional to pressure; for example, at 2.5 Bar the GM one is approx. 82% of the other, but 87% at 1 Bar.The obvious solution might be to say "modify the MCU firmware with different sensor calibration data", but I can't because I didn't make the device and I can't re-program it.So, my question: is there some way, using purely analog means (i.e. no MCU/ADC/DAC), that I can scale the voltage from the new sensor to match the output of the old one? Ideally, I would be able to add the circuitry in-line in between the sensor and the device.

author: Mr.B
author_rank: Unknown
timestamp: July 04, 2019, 03:59:18 am
content: An op amp with 1.1875 times gain?4.75v / 4.0v = 1.1875 times higher for the old sensor than the new sensor at the same pressure.

author: Dundarave
author_rank: Regular Contributor
timestamp: July 04, 2019, 05:34:53 am
content: Interesting problem... If the curve of the original sensor was completely linear, it should be relatively easy to use an op-amp with a gain that matched the difference in slopes between the two curves.But since there is an inflection point at 0.5 Bar, it makes things a bit more complicated. However, I noticed that at 0.5 Bar, the output of the original looks to be 0.7ish volts, which brings to mind the voltage drop of a diode... Perhaps by arranging the feedback gain resistance in the op-amp circuit so that below 0.7 v, a fixed resistance (calibrated for the initial slope) is used, with a parallel second resister + diode (which would thus conduct at 0.7 v) to handle the slope (i.e. gain) difference for the rest of the curve.It's been a long time since I've played around with op-amp configurations, but perhaps this might give you (or others with greater op-amp expertise) an idea to run with.

author: rs20
author_rank: Super Contributor
timestamp: July 04, 2019, 05:48:55 am
content: Let's take a step back here: both of these sensors are probably specced and supposed to be nominally linear with 0 bar = 0 volts. So the fact that there is not a strict proportional relationship between the two is due to an imperfection in one of these sensors.Here's the important question: do we actually WANT to emulate this crappiness? Does this application require such precision that modelling that slight inflection point at 0.5 Bar is really necessary? The OP and reply #2 here are latching on to the mathematical challenge of mapping one slightly nonlinear or offset function to another, but this is a real world problem where such efforts may be at best a waste of time, and at worse, result in successfully replicating anundesiredbehaviour. Stop looking at every pixel in the graph and think about the broader picture. What is this device? Could you please link these spec sheets you found?

author: Mr.B
author_rank: Unknown
timestamp: July 04, 2019, 06:50:50 am
content: Quote from: rs20 on July 04, 2019, 05:48:55 amThis.The curves look linear enough to simply use an op amp to translate through a simple gain.If the accuracy is that important then buy the more expensive original sensor.If you are looking to cut cost you may have to sacrifice a little accuracy in the low end pressures.

author: SparkyFX
author_rank: Frequent Contributor
timestamp: July 04, 2019, 09:21:41 am
content: Quote from: rs20 on July 04, 2019, 05:48:55 amIn a turbo engine you rarely see negative pressure that far down. (it´s a manifoldabsolute pressuresensor)

author: GerryR
author_rank: Frequent Contributor
timestamp: July 04, 2019, 11:09:00 am
content: Quote from: Mr.B on July 04, 2019, 06:50:50 amI agree here and would ask one question, "What is the application?" Upon thinking about this a little more, the slopes of the output curves are different, so just a single scale factor won't work. At 2.5 Bar, Original at 4.75 V and GM at 4 V; at 1 Bar, original at ~1.8V and GM at 1.55 V. Therefore if you scale for 2.5 Bar, multiplier is 1.1875; at 1 Bar multiplier is 1.16. That's about a 2.5% error. That may be acceptable to your application.

author: sokoloff
author_rank: Super Contributor
timestamp: July 04, 2019, 11:24:10 am
content: Quote from: SparkyFX on July 04, 2019, 09:21:41 amIn an automotive application, at idle and partial throttle low cruise (which is pretty common), you will see intake manifold pressures under atmospheric (what the automotive world calls "vacuum")

author: sokoloff
author_rank: Super Contributor
timestamp: July 04, 2019, 11:30:23 am
content: Could you feed the GM MAP sensor with a 6V reference voltage and dispense with the op amp?

author: mikerj
author_rank: Super Contributor
timestamp: July 04, 2019, 12:01:09 pm
content: Quote from: sokoloff on July 04, 2019, 11:24:10 amAlso on the overrun (e.g. downhill with closed or almost closed throttle) the manifold pressure can drop to 0.3 bar or so irrespective of being a turbocharged or normally aspirated engine.

author: vk6zgo
author_rank: Super Contributor
timestamp: July 04, 2019, 02:45:56 pm
content: As an analog person from way back, it pains me to say that you would be better off doing it digitally.Use an ADC, then in software, modify the result to your requirement.Obviously, it can be done in analog, but it gets fairly messy quickly.

author: GerryR
author_rank: Frequent Contributor
timestamp: July 04, 2019, 03:28:30 pm
content: Quote from: sokoloff on July 04, 2019, 11:30:23 amThat's a very clever scaling solution; I like clever!!

author: David Hess
author_rank: Super Contributor
timestamp: July 04, 2019, 04:22:00 pm
content: Scaling and offset with a single operational amplifier is simple enough but if that non-linearity has to be corrected, then a break-point in the transfer function would be required. That can be done with diodes or transistors within the feedback or input network. Analog Devices has a lot of application notes on this subject.Today a tiny and inexpensive microcontroller with ADC and DAC could also do it depending on the resolution requirements.

author: james_s
author_rank: Super Contributor
timestamp: July 04, 2019, 04:30:15 pm
content: Quote from: SparkyFX on July 04, 2019, 09:21:41 amI've had cars with turbo engines for ~20 years now, and when at low throttle and especially idle the MAP is the same as on a naturally aspirated engine. The turbo only really does anything once you are producing enough exhaust gas to spool it up and start boosting the pressure. During normal driving the boost gauge is in the vacuum region.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 04, 2019, 04:43:57 pm
content: Quote from: Dundarave on July 04, 2019, 05:34:53 amYes, I screwed up the original graph which made this crucial attribute not obvious. The figure for 0 Bar on the original sensor actually comes out to -0.2V according to the transfer function, but seeing as the sensor can't actually output a negative voltage, I manually entered zero, inadvertently making the graph slightly misleading.Correct graph below.Which leads to...Quote from: GerryR on July 04, 2019, 11:09:00 amThe multipliers across the pressure range are specifically as follows:Bar:0.51.01.52.02.5Multiplier:1.0291.1451.1831.2021.213So yes, quite a large difference in gain between 0.5 Bar and 3.0, and a single scaling factor (e.g. 1.1875) wouldn't work properly. This is what I was trying, but failed, to put across in my original post - I really shouldn't do these things late when I'm tired.Now, the question of whether Ineedto handle the case of values beyond the inflection point, below 0.5 Bar, is a good one. The honest answer right now is that I don't really know. I do know that some vacuum (i.e. < 1.0) will be seen, but I don't know by how much.If it turns out that vacuum figures will not matter, then maybe, just maybe I can fudge around and find a good compromise single gain figure that works across the range and only introduces as little percentage error as possible.Quote from: sokoloff on July 04, 2019, 11:30:23 amNo, I only have the 5V reference supply to work with.Quote from: Dundarave on July 04, 2019, 05:34:53 amI'm having trouble visualising what you're talking about here. Could you possibly illustrate it?

author: mikerj
author_rank: Super Contributor
timestamp: July 04, 2019, 06:23:04 pm
content: That makes things much easier, a simple diff amp will do the job. This shows the general idea, but is not a complete design.Getting the gain and offset reasonably accurate will need low tolerance resistors, but I don't know how much error is acceptable. Deriving the offset from the 5v rail should be ok as this is a reference supply for the sensors on an engine management system, so should be well regulated.

author: SparkyFX
author_rank: Frequent Contributor
timestamp: July 04, 2019, 07:39:13 pm
content: Quote from: sokoloff on July 04, 2019, 11:24:10 amVacuum relative to the absolute pressure of 1 bar... the limitation of > 0.5bar is therefore not that bad, because it´s purpose is to check and limit the turbo function and check for intake manifold leakage (air drawn into a cracked hose/gasket). In other words it is more relevant on the upper end.Anyway, just as a reminder: the more modern ones have a built in SENT bus...

author: james_s
author_rank: Super Contributor
timestamp: July 04, 2019, 07:49:40 pm
content: In many cases the MAP sensor is not directly related to the turbo at all, it is used to measure air flow which is used to control the amount of fuel injected. When you know the absolute pressure in the intake manifold, the temperature of the air and the characteristics of the engine you can calculate the amount of air being ingested.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 04, 2019, 08:31:47 pm
content: Quote from: mikerj on July 04, 2019, 06:23:04 pmWow! Thank you very much.I would not have been able to come up with something like this on my own!I'm no good with LTSpice, so I recreated it in the Falstad simulator, and it works great! To test it, I made the addition of a voltage-controlled-voltage-source node to simulate the voltage output of the GM sensor by taking the node's voltage input as pressure instead of volts, and setting the output to be the transfer function of the sensor.A few questions about this circuit:- I see that the parallel 470k/130k pairs give a combined resistance of 101.8k. I suppose one could use instead a series pair of 100k and 1K, but was the parallel arrangement made to get exactly 101.8k, or is it something to do with tolerance error? Because, as I make it, if one were to use 1% grade resistors, the series pair has lower overall tolerance error than the parallel pair - assuming you don't need exactly 101.8K.- I looked up the LT1782, and it is described as an 'over-the-top' op-amp, where inputs can exceed the supply. I presume this has no bearing on the circuit, seeing as both inputs are ultimately derived from the same 5V reference supply as the op-amp has, so can never exceed it. Is this the case, and almost any rail-to-rail-input-output op-amp could be used? For example, MCP6001.- Extra protection of the op-amp inputs is not needed, right? Because the high resistance values used will limit current greatly? So, if for example the sensor input was accidentally shorted to +12V, the protection diodes of the op-amp should be able to handle it?Finally, could you explain a bit about how it works? Also how you derived the appropriate resistance values?

author: mikerj
author_rank: Super Contributor
timestamp: July 04, 2019, 09:36:15 pm
content: The resistor combination matched almost perfectly (to something like 5 decimal places) the ratio required (or at least the ratio I derived by squinting at your chart!) and are E24 series values. As mentioned this doesn't mean much if you use normal 1% resistors as the error will stack up.The LT1782 is simply a really nice Linear Tech RRIO op-amp that is included in LTSpice, so anyone can download the model and run it without any third party component models. AN MCP6001 will probably work ok, but has a limited supply voltage of not much over 5v, so you'll need to provide some protection to ensure it's not destroyed by small spikes. The input offset voltage range is also not the best IIRC.The reason for the high resistance values is so that the potential divider supplying the offset voltage isn't loaded much, you'll see the potential divider resistors are lower by a couple of orders of magnitude. If the offset voltage was buffered I would use lower value resistors around the diff amp, but the offset voltage is small enough that even a RRIO op-amp is going to be almost saturated.Supply decoupling/filtering, overvoltage protection and input and output protection would really ideally be needed to make this reliable for automotive use.

author: Dundarave
author_rank: Regular Contributor
timestamp: July 04, 2019, 10:48:31 pm
content: Quote from: HwAoRrDk on July 04, 2019, 04:43:57 pmThe change in the graph data rendered the diode idea irrelevant, but it looks like @mikerj's solution has you well sorted!

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 05, 2019, 03:17:20 am
content: Quote from: mikerj on July 04, 2019, 09:36:15 pmWith regard to protection, if input signal over-voltage (e.g. in case of short to +12V) is not a problem and can be handled due to the large-value series resistance on the inputs to the op-amp, what about if the 5V reference going out to the sensor is shorted to either ground or +12V? Obviously nothing good will happen if the op-amp is suddenly hit with 12V on VCC! Especially if I am going to use something like an MCP6001, which is only rated for absolute max of 6V supply.I had a thought: what about using a protective smart high-side switch IC on the outgoing 5V reference line? Maybe the kind commonly used on USB ports, as they're geared for 5V operation.After a bit of browsing around, I came across theON Semi NCP380. It has short-circuit, over-current, UVLO and reverse-voltage protection. It also allows to set a custom current limit using a resistor. So I thought maybe use one of these with the EN input tied to VIN (although not directly, as the datasheet warns against that - says to use an RC delay instead) and set a really low current limit with a resistor in the region of 100k-200k. As I understand it, GM MAP sensors consume about 20mA at most, so a current limit in the region of 50mA is probably okay.How does this sound? Or are there better options?

author: mikerj
author_rank: Super Contributor
timestamp: July 05, 2019, 08:57:15 am
content: That quite a nice part, but I don't think it provides any over-voltage protection and it's voltage operating range is lower than the MCP6001. I'd think I'd choose an op-amp with a wider supply range and then use a TVS and maybe a polyfuse for protection. You'll want to add some resistance on the op-amp output to limit current if that is connected to something bad, it can go before the feedback resistor so any voltage drop is compensated.

author: max_torque
author_rank: Super Contributor
timestamp: July 05, 2019, 09:00:56 am
content: The question i'd ask is "how much money are you saving"?Making long term automotive electronics robust is actually quite hard (i should know, i do it for a living...) and yes, you could probably knock together some circuit to modify the MAP signal to the ecu, but if that messing around takes hours of your time, and leads to a car with poor reliability, then you'll wish you just bought the "expensive" MAP sensor......

author: Zero999
author_rank: Super Contributor
timestamp: July 05, 2019, 09:58:56 am
content: Quote from: mikerj on July 05, 2019, 08:57:15 amIf 12V is available anyway, then why not use the cheap and cheerful LM358?

author: mikerj
author_rank: Super Contributor
timestamp: July 05, 2019, 10:06:48 am
content: Quote from: Zero999 on July 05, 2019, 09:58:56 am12v typically isn't available on the sensor wiring, they run from a 5v reference. He could run another wire but a module that just sits inline with the sensor would be much neater.

author: vk6zgo
author_rank: Super Contributor
timestamp: July 05, 2019, 10:15:05 am
content: Quote from: HwAoRrDk on July 04, 2019, 03:15:21 amThe OP isn't using it in an automotive application, see part of post I emphasised inred.

author: GerryR
author_rank: Frequent Contributor
timestamp: July 05, 2019, 11:07:50 am
content: Quote from: mikerj on July 04, 2019, 06:23:04 pmCould you explain your circuit a little. I see how you offset the voltage and match the gain of the original sensor, but don't see how you modified the output (slope) to make the GM sensor match the original sensor. Please explain; sometimes I can be a little slow. Thanks.

author: Rerouter
author_rank: Super Contributor
timestamp: July 05, 2019, 11:16:46 am
content: Here is the breakdown, it is a normal differential amplifier summed with a fixed offset voltage,

author: mikerj
author_rank: Super Contributor
timestamp: July 05, 2019, 12:47:27 pm
content: Quote from: GerryR on July 05, 2019, 11:07:50 amGain and slope are effectively the same thing, the higher the gain of the amplifier, the steeper the slope at the output. The gain we need is = Slope Original / Slope GM ~ 1.277

author: GerryR
author_rank: Frequent Contributor
timestamp: July 05, 2019, 01:32:26 pm
content: The multipliers across the pressure range are specifically as follows:Bar: 0.5 1.0 1.5 2.0 2.5Multiplier: 1.029 1.145 1.183 1.202 1.213I'm probably complicating this more than necessary, but from the chart, above, given by the OP, the sensor output requires a different multiplier (gain) at the different pressures in order for the new sensor to match the original sensor output. A fixed multiplier would seem to address the output difference at only one point. It would seem that a variable gain amp, or as a previous poster stated, a MPU with a look-up table, to set the output per the new input levels, would be what's needed??? What am I missing? (I told you I can be a little slow.) Thank you.

author: sokoloff
author_rank: Super Contributor
timestamp: July 05, 2019, 02:03:29 pm
content: Quote from: GerryR on July 05, 2019, 01:32:26 pmProbably just missing this later update from OP:Quote from: HwAoRrDk on July 04, 2019, 04:43:57 pm

author: rs20
author_rank: Super Contributor
timestamp: July 05, 2019, 02:04:04 pm
content: Quote from: GerryR on July 05, 2019, 01:32:26 pmYou are right in that you would have to mess with different gain values for different pressures IF all you had was gain. But mikerj's circuit has gain AND OFFSET. You're missing the offset part. With a fixed gain and a fixed offset, a nearly perfect conversion is achieved.

author: GerryR
author_rank: Frequent Contributor
timestamp: July 05, 2019, 04:15:55 pm
content: Got it!!

author: max_torque
author_rank: Super Contributor
timestamp: July 05, 2019, 05:44:44 pm
content: Quote from: vk6zgo on July 05, 2019, 10:15:05 amer, the OP hasn't actually said what the application is have they? All the talk has been about "engine vacuum" and "boost pressure" etc, so i was thinking the application is automotive??

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 05, 2019, 05:49:51 pm
content: Quote from: mikerj on July 05, 2019, 08:57:15 amIt does provide over-voltage protection:"An internal reverse-voltage detection comparator disables the power-switch if the output voltage is higher than the input voltage to protect devices on the input side of the switch."I found it because it is one of the few USB-focused high-side switches that actually does that; most only give reverse-current protection when off and don't prevent the output going higher than input.I'm not concerned with over-voltage on the 5V referencesupplyfeeding this circuit. The existing sensor is actually contained within the device's enclosure (have to run a hose to it, which is inconvenient, thus part of my motivation for replacing it), and this add-on circuitry, while 'in-line', would live there too, so there is no possibility of wire shorts, etc. between the device and it. And if the device's 5V rail goes over-voltage, then the device itself has probably had the magic smoke escape, so the continued functionality of this op-amp circuitry becomes immaterial!With a new external remote pressure sensor however, there becomes a risk of incorrect connection, shorts, etc. on wiring so I think it is indeed right to give attention to some protection, but only that side.Oh, also, the device itself already has some series resistance on the sensor input signal (and hence to be on op-amp's output): a 1K/470pF low-pass filter. Not much, but it's something.

author: GerryR
author_rank: Frequent Contributor
timestamp: July 06, 2019, 11:11:51 am
content: Just because I'm nosy, and after all this, and if it's not a big secret, what is the application??Just very Curious.

author: HighVoltage
author_rank: Super Contributor
timestamp: July 06, 2019, 11:20:16 am
content: Some of the modern automotive pressure sensors are no longer analog.The new types are digital and can be programmed.And they run at about 1000 Hz update rate.Many of them even have a temperature compensation.

author: max_torque
author_rank: Super Contributor
timestamp: July 06, 2019, 01:33:51 pm
content: Quote from: HighVoltage on July 06, 2019, 11:20:16 amhttps://en.wikipedia.org/wiki/SENT_(protocol)

author: JustMeHere
author_rank: Frequent Contributor
timestamp: July 07, 2019, 02:41:08 am
content: Micro with ADC and DAC. Then let the micro do the math.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 07, 2019, 11:02:21 pm
content: Back at looking at this again after the weekend, and I thought I would knuckle down and get my brain in gear to try and understand how the resistance values mikerj arrived at for the differential op-amp circuit were calculated.Once it twigged about the relationship between slope of the line and gain (i.e. they're the same thing - and mikerj basically said so already!), and that I could calculate the slope trivially using a spreadsheet function, I thought I would work out exactly what the gain figure should be for the differential amplification. It worked out to be a slightly different value: 1.258, versus the 1.277 mikerj estimated. Using this new figure in a diff. op-amp circuit calculator, I came out with resistor values of 120k & 150k.However, simulating the circuit with these new resistance values actually gave a slightly greater error than the original. However, the, err... parallelism? of the line on the graph matched that of the original sensor's much better; the old values actually had worsening error towards the bottom of the pressure range (as much as 5% at 0.25 Bar). All it appeared I needed to do to get a better match was to bump the output up a tad, and so I guess this is where the offset voltage divider comes in. After playing around a bit, I settled on changing the 6.8k to 7.5k, which netted me <1% error across the board.Here's a graph of the results:I'm still not clear about how the offset voltage figure was arrived at, though. Is it simply the distance on the graph between where the original sensor intersects zero on the Y-axis and the Y-value of the same horizontal point for the GM sensor? That appears to be around 0.15V, which matches what a 6.8k/220R divider gives when supplied with 5V. But the 7.5k/220R I experimentally ended up with is kind of away from that, at 0.142V...

author: GerryR
author_rank: Frequent Contributor
timestamp: July 08, 2019, 05:28:11 pm
content: My guess would be that the sensor outputs are not as "linear" as indicated on the data sheets, and the values given are more nominal than exact. I think your method of measuring, and then adjusting to suit, is the best approach.

author: mikerj
author_rank: Super Contributor
timestamp: July 08, 2019, 05:51:07 pm
content: Quote from: HwAoRrDk on July 07, 2019, 11:02:21 pmI did say I got the gains from eyeballing the charts! If you have raw data you can fit a line to, it will be far more accurate.Quote from: HwAoRrDk on July 07, 2019, 11:02:21 pmLook at the diff-amp circuit and imagine the MAP sensor input is held at a fixed voltage. The other arm which the divider is connected to is effectively an inverting amplifier, and it's gain is greater than unity (1.25 in this case) so whatever voltage you provide from the divider will be amplified by that gain. In other words if you change the gain you will have to change the voltage at the divider to maintain the same offset voltage.