# Square wave (+-15V) to positive DC

How can I convert a square wave signal from -15V to 15V to a positive DC signal?

Here are the details of my problem:

I'm trying to build a duty cycle for a buck converter in the following way: I want to compare (with an op amp) a DC signal with a sawtooth signal. When the DC signal is near the amplitude of the sawtooth signal => duty cycle will be high. When the DC signal is near 0V => duty cycle will be low.

So far, when I need a high duty cycle, ratter than a positive DC signal I have a square signal from -15V to 15V. I'll spare you the details but I have to deal with that input and can't expect anything else.

The easy solution would have been to have a signal between 0 and 15V and take the average with a low pass filter (then I would have a positive DC ouptut), but it isn't possible, I have to deal with a -15V 15V signal (thus I get a ~0V output, which is of no use since I also have a ~0V signal when I need a low duty cycle.) In fact, I have at my disposal only op amps powered by -15V 15V, thus I'm not seeing an easy way to get a positive DC signal from that.

Here are the components I have at my disposal: Resistors, capacitors, -15V/15V power op amps, diodes, electronic switches, buck converter.

For further detail, here is how I produce the 0V signal from 2 signals in phase (when I need a low duty cycle) so far:

And here is how I produce the square signal from 2 signals out of phase (when I need a high duty cycle):

• Won't a diode rectifier help you convert the bipolar signal to unipolar? Feb 28 at 14:16
• Options include offset the signal, rectify, and handle it in the time domain - I think microcontroller here. Please describe more about input and output required, and where "power" is supposed to come from. How do you also have a ~0V signal when I need a low duty cycle - I thought input was square wave and output a positive DC signal? Feb 28 at 14:20
• Just a diode like a 1N4148 should do the job. Bridges are generally not very good with PWM frequencies because they are slow devices. Feb 28 at 14:29
• 2 square signals This question could significantly improve with a graph of input and output signals showing their relation. Feb 28 at 14:34
• @Andy aka found it, you're the boss :) Feb 28 at 16:11