How to remove DC bias from a square wave

Discussion in 'General Electronics Chat' started by bbiandov, Jan 1, 2009.

  1. bbiandov

    Thread Starter Active Member

    Nov 24, 2007
    31
    0
    Hi

    This is probably retarded question, so excuse my ignorance in advace.

    How do I remove DC bias from a square wave. It is a perfectly square ttl wave so there is no negative crossing. The problem is that the wave occurs between 2v and 5v, NOT 0v and 5v which casues an issue with my pic detecting the frequency. Basically the pic sees the wave as one long "1"

    How do I remove that 2v bias so the wave then will swing from 0v to 3v? I am guessing that OpAmp can do it with a single IC but that is where my expertise ends...

    Thanks
    B
     
  2. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    You can also turn a transistor on and off, or move the bias down with a diode drop.
     
  3. PRS

    Well-Known Member

    Aug 24, 2008
    989
    35
    What is the frequency of your signal?
     
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    See the attached schematic for one possible solution.
     
  5. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    In case it makes any difference, the introduction of a common emitter buffer will produce an inversion in the original square-wave. This can be accommodated by a change in the software used to read the input.

    hgmjr
     
  6. bbiandov

    Thread Starter Active Member

    Nov 24, 2007
    31
    0
    that works, thanks everyone, inverting the wave is perfectly acceptable.

    The singla is 1.2kHz. Just to clarify - what zenner will do a 2v drop?

    Thanks
    ~B
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Well, most Zeners start at about 2.5v. However, if you have some LEDs kicking around, some of the newer red and yellow LEDs have a Vf of around 2v at 20mA. Any reason why you can't use one of those?

    You could also use three switching diodes (1N4148 or 1N914) in series, forward biased with a current limiting resistor to Vcc (+5v). The actual voltage drop across them will depend upon the current being passed through them and their temperature, but somewhere around 3mA to 4mA should get you in the ballpark, or 750 to 1k Ohms.
     
  8. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Here is another suggestion which does not invert the signal. The circuit only works with a very low impedance source, i.e. direct connection to an output pin.

    [​IMG]
     
  9. bbiandov

    Thread Starter Active Member

    Nov 24, 2007
    31
    0
    eblc1388's idea was simple so I gave it a shot - I can see it works in NI sim but in real life there is ton of jitter above 1kHz. The funny thing is that I only need 1.2kHz which is just above the point where it becomes significant so the receiving circuit exibits problems, often by doubling the frequency.

    Ideas? I dont want to get into the OpAmp stuff but if that's what will provide stable output I need to face the music... :)

    In case it helps, the wave comes out of one of those RPM sensors implemented with optics. This is NOT raw output from the sensor. It comes out of little board with few ICs hence the wave is square and nice except for that darn bias. Why did they bias it I have no idea. May be the printer that it came out of needed it...

    Thanks again everyone for your feedback,

    ~B
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Your jitter may be occurring due to a long signal path that's causing an inductive ringing.

    Did you try my idea? Same number of parts... but it depends upon the +5v supply being at roughly the same level as the high voltage of your pulse, otherwise the transistor may not turn off properly.
     
  11. hobbyist

    Distinguished Member

    Aug 10, 2008
    764
    56
    Hi,
    My ways of course are always primitive in nature due to using discrete components, but I had a schmitt trigger signal I needed to use as a input when it went above a threshhold voltage, but it in it's self had a standing output voltage of around 4 volts or so, so what I did was made a voltage divider at the emitter of an NPN transistor (used as a switch with no collector bias) at around 5 volts, and took the standing output voltage from the schmit. into the base term. so when my schmit. went high it gave a 10 volt output which then allowed my npn transistor to switch on a neg. output pulse. So the npn then was able to run through an inverter to give pos. pulse from 0v. to a chosen output. volt.
     
  12. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    You are seeing jitter because your input signal's DC base level shifted up/down from the minimum 2V level. When frequency increases, the "few ICs" on your opto board might not pulldown its output voltage sufficiently.

    If the signal has a 2V DC base level changing via frequency, the circuit proposed by SgtWookie is your best choice.

    In the meantime you can try the follow to see if problem improves:

    1. increase collector resistor from 1K to 2K2
    2. swap position of the two resistor 10K and 6K8. This will bias the PNP base voltage to 3V.

    [​IMG]
     
    Last edited: Jan 3, 2009
  13. bbiandov

    Thread Starter Active Member

    Nov 24, 2007
    31
    0
    Thanks everyone for your sugestions. After playing with this for some time I ripped the electronics out of the board and connected my own simple circuit with pleanty of hysteresis to supress the noise.

    I dont know what was causing the noise before but right now it works great even at slow speeds like 1 pulse every few seconds. It actually creates a cool thumb wheel just like those on various instruments, tho I am not using it as human interface - it was supposed to be a simple RPM detector.

    I lifted the solution from the LM339 spec sheet sample application circuits.

    [​IMG]

    I found a real nice sample with the equasions and crunched the numbers in Excel to arrive at the values of those resistors. This guy had a nice site with neat sections for each application http://home.cogeco.ca/~rpaisley4/:

    [​IMG]
     
  14. KL7AJ

    AAC Fanatic!

    Nov 4, 2008
    2,040
    287
    Does your PIC only need to determine edges? If so, you can just run the square wave through a passive differentiator.
     
  15. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Good that you used an LM339 comparator instead of an LM324 opamp used as a comparator. Rob has several circuits on that page using an LM324 as a comparator, which isn't good. Using an opamp as a comparator causes the output stage to be in constant saturation, which wastes power and generates heat.

    Your R4 is a bit on the low side; the comparator output will be trying to sink 18.5mA when it's turned on.

    6mA sink when Vcc=5v is the minimum specification for an LM339, but 3mA should be more than enough for your application. 1.67k will give you 3mA, 833 Ohms would give you 6mA. Anywhere in between would be good.
     
    Last edited: Jan 5, 2009
  16. bbiandov

    Thread Starter Active Member

    Nov 24, 2007
    31
    0
    wait, wait where did you see 3mA? I looked at the PDF and it specifically says that for full saturation one would expedct 20mA so I went just a tad below that for safety - that is why I picked the R so low

    Can you tell me where you saw the optimal load on the output?
     
  17. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I'm looking at Texas Instrument's datasheet for the LM139, LM139A, LM239, LM239A, LM339, LM339A, LM2901, LM2901V, dated October 1979, revised June 2004, page 5.

    The minimum specification for V(OL) is 6mA @ 1.5v, typical 16mA.

    Since your uC has CMOS inputs, it will require very little current to provide a valid signal.

    What datasheet are you looking at?

    [eta]
    ST Microelectronics gives a specification of 400mV max, 250mV typ when sinking 4ma.
    See VOL, page 3:
    http://sigma.octopart.com/9489/datasheet/STMicroelectronics-LM339N.pdf
     
  18. bbiandov

    Thread Starter Active Member

    Nov 24, 2007
    31
    0
    you are right, my bad. I looked at Intersil PDF for another part.

    6mA it is. I will adjust my pull up to the appropriate value.

    Thanks for cathing this
    ~B
     
Loading...