Some perhaps overly detailed background:
I have a Very Expensive Black Box™ piece of lab equipment that I can control via analog voltages in the range [0, 10] V.
It has two inputs that are relevant to this: a "DC" input, and an "AC" input. Both must be supplied voltages (which I call \$V_{DC}\$ and \$V_{AC}\$ respectively). They are effectively summed together to produce an input to the system that can vary over time (think \$V_{DC} + V_{AC}\sin(\omega t)\$), and they are additionally subject to the constraint that their sum must be 10 V or less.
At the moment, \$V_{AC}=0\$ and \$V_{DC}\$ is controlled by a separate microcontroller device. It is typically a few volts. I have the ability to spit out an additional arbitrary waveform in the range [-5, 5] VAC relatively easily through this second box, in a way that can play nicely with the UI on the rest of the equipment. This waveform is likely to be up to about 30 kHz and to a first approximation a sine wave is fine.
Ultimately, I would like to build a circuit that:
- takes \$V_{DC}\$ and \$V_{AC}\$ as inputs;
- computes the constant value \$V_{DC}-|V_{AC}|\$ and sets its output, \$V_{DC}'\$ to it (i.e. \$V_{DC} = V_{DC}-\max(V_{AC})\$);
- level-shifts the [-5, 5] \$V_{AC}\$ signal to be [0, 10] V, and scales it so that its minimum is set to zero (rather than 5 V, say) and provides this as its AC output, \$V_{AC}'\$.
That is quite a lot of complexity for a stack overflow post (!) but I have been trying to attack this problem as a set of chained-sub-problems: shift \$V_{AC}\$, obtain its envelop maximum, and then use that value (call it \$A\$) to either subtract from \$V_{DC}\$ or further shift the now-shifted waveform.
The problem
Here's how I've done this part so far – with two op-amps, a classic level shifter, and an envelope detector proposed previously on this site:
And, so far, it works great! Yay. You can see that the envelope is detected (with the addition of +5 V), and the levels are shifted compared to the original input:
Now, I'd like to subtract away the 5 V bias, and ultimately \$V_{DC}\$. This seems like a classic option for a subtracting op-amp, right? Just have a potential divider to split my 10 V supply in half, and provide these as inputs into a subtracting op amp, and produce a number that should be \$V_{sub}=6.5-5=1.5\$ volts with the example numbers I've chosen here:
Yet, it doesn't work: \$V_{sub}\$ is steadfastly zero (no matter what op-amp I chose or how long I wait) despite the inputs remaining at the right levels of 5 V and 6.5 V (±a little bit):
Why is this the case? What have I done wrong? Is it the case that effectively the output impedance of the envelope detector stage is too low – if I put a large resistor in series with it, the voltage reached by the last op-amp is no longer zero.
I was planning to carry on chaining stages like this to ultimately produce the other "features" remaining to be implemented in this circuit, but if anyone has a better idea, I would be very welcome to hear it.