# Generate a sine wave with MCU

I want to generate a sine wave without an offset voltage. I generated a sine wave from 0 to 3.3 V and it has a 1.65 V offset. I need a sine wave from -1.65 V to 1.65 V using an MCU. How can I do that?

• DC-block it with a cap? Commented Jan 24, 2023 at 6:29
• connect the CPU to +1.65 and -1.65 supplies Commented Jan 24, 2023 at 6:48
• DC shift with an opamp? Commented Jan 24, 2023 at 7:01
• Buy a function generator on Ebay for \$20 Commented Jan 24, 2023 at 7:09
• Generate the complement on another GPIO pin and read the voltage between pins. Commented Jan 24, 2023 at 8:45

I generated sine wave from 0 to 3.3V and its has a 1.65V offset value. I need a sine wave from -1.65V to 1.65V using MCU.

Use a coupling capacitor (a.k.a. DC blocking capacitor):

simulate this circuit – Schematic created using CircuitLab

RL represents the input impedance of the load. For technical explanation purposes I put 10k but can be anything depending on the application. CX is the coupling capacitor.

Note that this RC network forms a high-pass filter with a cut-off frequency of

$$f_c=\frac{1}{2\pi \ R_L \ C_X}$$

So, CX should be selected such that the frequency of the waveform that MCU generates stays in pass band. To guarantee this, I personally recommend you to select a cut-off frequency of less than half the minimum frequency of the sine that MCU generates. For example, if the minimum frequency will be 50 Hz then a cut-off frequency of 20 Hz should be enough. This makes CX = 800 nF but 1 uF can be used.

One thing worth to note here is the value of RL. I chose it low enough so that some other equipment (e.g. AC voltmeter or oscilloscope) can be connected. If you put higher values then the CX can be reduced accordingly but anything connected in parallel with RL will reduce the effective load resistance which results in distortion or amplitude reduction on the waveform. So anything between 1k to 10k should be alright.

• Actually it's a pretty simple idea. A series capacitor block a dc voltage. Output of the capacitor is a pure sine wave. Thank you very much Mr. Rohat Kılıç. Commented Jan 25, 2023 at 11:15
• @AliBuğraÇETİN never ignore what comes after DC blocking capacitor. Commented Jan 25, 2023 at 11:31