Variable voltage DC-AC square wave

I need to power a device with an AC square wave with no DC bias. I have an input DC signal from a microcontroller from 0-5V.

I need to use the input signal to create a variable amplitude AC square wave from -5 to +5V. I can use a 555 timer to create an astable oscillator and op amps to double the input signal, but I don't know how to shift it to +/-5 volts. I also have some IRF540 MOSFETS I could use but I'm not sure how to vary the output voltage through the input from the microcontroller.

The output AC signal is 2khz and 50% duty cycle. It's important the signal has no DC bias as this may damage the device.

• Do you only have the +5 V rail? Or do you have access also to a -5 V rail? What exactly do you have to work with?
– jonk
Jun 24, 2020 at 4:32
• I have access to +/- 12V rail but I want a variable output, ie with a +3V input DC signal I want +/- 3V AC. Jun 24, 2020 at 4:45
• Please include all of the details you can think of into your question -- most especially this new requirement you just mentioned. Also, please include exactly how much DC offset is "too much" and how much is "acceptable." You will never get exactly zero offset.
– jonk
Jun 24, 2020 at 4:46

There's several ways to do this but here's one that comes to mind as elegantly built out of basic signal processing elements:

1. First, you need a negative supply voltage, no matter what else you are doing. You can use a specialized switching converter to generate it from your positive supply, or use a bipolar power supply.

2. Invert the input signal using an op-amp wired as inverting buffer to produce an equal magnitude negative signal. (Note that an inverting buffer's accuracy depends on the feedback resistors; calibrate with a trim pot to ensure no net DC offset.)

3. Use an analog switch IC, controlled by the oscillator, to toggle between the input signal and its inverted version.

4. Buffer the output of the switch with another op-amp.

The above requires calibration to have no DC offset. In order to be more certain of no DC offset, if you can tolerate a somewhat distorted square wave, then simply insert a series capacitor and parallel resistor to form a high-pass filter.

Once you have this, you don't have to start with a symmetric square wave — for example, you can use a transistor to chop the input signal according to the oscillator signal, then use an op-amp configured for a gain of 2 to scale it from 0-5 V to 0-10 V; after the filter it will be (after startup) ± 5 V.

(However, this will cause the output to wander slightly (but still with no DC in the long run) as the input signal changes, since it doesn't scale the signal before the filter symmetrically.)

Finally, I will note that the sub-problem of scaling an oscillator signal by a control signal is very common in the field of analog music synthesizers, and is solved by a circuit or IC known as a voltage-controlled amplifier (VCA). I mention this as a source for already-designed solutions for the problem.

To get symmetric output you'll still need either fixed offset-and-gain circuit — which is easily done with an op-amp — to create a symmetric signal from your oscillator signal, or an oscillator that is inherently symmetric.)