# Add DC component to signal

I want to add a DC component to a pulsed signal to prevent it from taking negative values. For this, I connect the pulse signal to a capacitor and a voltage divider. With the capacitor we eliminate the continuous component that the signal could have and it is centered at zero. So, with the voltage divider we define the DC component that we want to add to our signal. In ours, we would need to add 1.75 V, since the peak-peak voltage is 3.5 V.

However, when simulating the circuit we do not obtain a pulse signal that is worth 0 V or 3.5 V, but rather a signal with a kind of voltage peaks on the falling and rising edges of the signal. I don't understand it...can anyone tell me why this is happening?

UPDATE

The pulse signal would be the output of the comparator in the following circuit:

Expansion of the "comparator-add DC" circuit:

• How did you select the resistor and capacitor values? They are completely wrong but the reason may be important for answering the question.
– pipe
Apr 5, 2022 at 21:51
• @rdtsc If it works, should he delete the question? Or accept your comment somehow?
– pipe
Apr 5, 2022 at 21:52
• I choose the resistors so that the continuous component is 1.75 V, the necessary one so that it remains between 0-3.5 V. The value of the capacitor has been chosen so that the pulse signal does not encounter much resistance. I don't know if this is quite right... Apr 5, 2022 at 21:58

The resistor values are much too low.

The resistors and capacitor create what is known as a RC time constant. When the input level changes the capacitor will gradually charge to this new value but you must select the values so that it charges slowly enough not to distort the AC signal.

This means that the product of the effective resistor value and the value of the capacitor must be much greater than the period of the input signal.

The effective resistor value for the circuit you have is equal to both resistors in parallel. For your use that should be high enough so as not to load the input excessively - as others have suggested a value of 10k for each resistor is reasonable for many applications and would provide an effective resistance of 5k. The values you currently have give a very heavy load of 5 ohms.

You have set the period of each half of the signal set to 10ms so the capacitor must not charge significantly within that time. We will select a time of ten times that, ie 100ms.

Using the effective resistance value of 5k we need a capacitor value of 20uF to meet the 100ms time constant. 5k * 20uF = 100ms.

The values you have in your circuit have a time constant of only 5 microseconds giving the very short pulses you are seeing.

## Update

With the additional information provided in the question a better solution is just to used a couple of resistors and a diode to provide the correct levels for the input of the following circuit. This has the advantage of operation down to DC.

The 4.7k and 10k resistors shift the output of the comparator from the -2.5V to approximately ground when conducting. The 10k resistor pulls it up to 5V when the comparator is not conducting. The schottky diode prevents the output voltage ever going negative by more than a few tenths of a volt. It is not absolutely necessary as the Arduino following can tolerate a negative voltage provided it is very low current.

simulate this circuit – Schematic created using CircuitLab

• Thanks so much for the explanation. I have tried to simulate the circuit with those values and now it works better. However, the displaced signal continues to take a minimum value of around -62 mV. Could I increase the time constant by changing the values of the resistors and capacitance or would another circuit to add DC be preferable? I have seen that an inverting amplifier with continuous input could also perform this function Apr 6, 2022 at 16:08
• @Sharik_97 - Increase the value of the capacitor. What sort of signal are you dealing with? Is it an analog signal or a logic signal? Apr 6, 2022 at 16:17
• It's the output of a dual powered comparator, I'll probably use the LM139 Apr 6, 2022 at 16:54
• @Sharik_97 - how come it is bipolar? Can't you arrange that it is unipolar? What is the signal feeding? Apr 6, 2022 at 17:29
• In the datasheet for the comparator it says: "The common mode input voltage of any of the input signal voltages must not be allowed to be negative by more than 0.3V". But the comparator can have a dual power supply and, in this way, it already admits an input voltage range with negative values. Among its features it says: "Wide single supply voltage range or dual supplies for all devices: +2 to +36 V or ±1 V to ±18 V" and "Differential input voltage range equal to the supply voltage" Apr 6, 2022 at 18:59