# OpAmp: Calculating A - MAX(B, 2V)

I require an opamp-based circuit that calculates the expression OUT = A - max(B, 2V), as shown here:

There are no strict requirements on the shape or exact position of the transition, however in the linear region (B > 2.5V), the curve should be precise.

Below is a circuit for a regular difference calculator (OUT = A - B); is there a simple way to modify this in order to achieve the desired effect? I was thinking of employing a diode to achieve the nonlinear effect, but I'm at loss on exactly how to proceed.

simulate this circuit – Schematic created using CircuitLab

I'm using a rail-to-rail output, over-the-rail input amplifier, and have no requirements on the input/output impedance of the circuit. I have all sorts of positive reference voltages and supply rails available, should those be necessary.

### Application info

I need this circuit as the feedback loop of a switching + linear voltage regulator; A must be about B + 0.8V to compensate the linear regulator's drop, so feedback = A - B would suffice. However, the linear regulator requires at least 1.4V to run, thus the max(B, 2V) requirement.

simulate this circuit

• Is this purely an exercise or trying to solve some real problem? Maybe you want to tell more about the real problem then, it smells like an xy problem and might actually have a better solution. Commented Apr 27, 2016 at 12:00
• @PlasmaHH: I've added some info about my application. Commented Apr 27, 2016 at 12:16
• You are not really explaining what you want at a higher level thus it IS still an xy problem. Commented Apr 27, 2016 at 12:31
• In order for the linear regulator to output 5V, its input voltage should be >= 5.8V; thus the switching regulator needs to be regulated to LDO output + 0.8V (A = B + feedback). However, when turning the device on, the LDO output is 0V, so the switching regulator output will be 0.8V, so the LDO won't even start up. Thus, if the linear regulator output is < 2V, I want the LDO to output 2.8V nevertheless (A = max(B, 2V) + feedback). I suppose max(B, 1V) would suffice, but better safe than sorry. Commented Apr 27, 2016 at 12:34
• Why not just make the switcher output always produce 5.8 volts. For the short period during power-up there will be a little heat generated by the LDO regulator but is that really a big deal? Commented Apr 27, 2016 at 14:32

Here is one easy way, but probably not the best way given your actual situation!

Since you say you have all sorts of supply rails and references available, this way requires +/- supplies and +/- references.

simulate this circuit – Schematic created using CircuitLab

R2/-10V reference determines where the input meets the clamped voltage R5/R6/+10V reference determines the clamp voltage OA2 and OA4 are just buffers.

• I don't have any negative supplies, sorry. Commented Apr 27, 2016 at 12:59
• Oh, that's not all sorts then. You can adapt the clamp I've shown. Commented Apr 27, 2016 at 13:10

Another method could be used

simulate this circuit – Schematic created using CircuitLab

Use the output of the comparator to control an analogue multiplexer (typical device linked) where B and 2V are inputs to the multiplexer as well such that the output of the multiplexer becomes Max(B, 2V)

I could do a multiplexer with JFETs but I doubt I would get the performance of commercially available ICs.

Now take the output of the multiplexer to your subtraction circuit and you will yield A - (max(B, 2V))

As an exercise, I did the circuit:

I used an 8 to 1 multiplexer (the easiest to find for simulation).

The response of the circuit is:

All seems to operate in a single supply world. Note the comparator has a push-pull output to switch cleanly.