• Please review our updated Terms and Rules here

Electronics question - convert audio sin wave to digital 0/5v signal?

bitfixer

Veteran Member
Joined
Apr 6, 2011
Messages
679
Location
San Francisco, CA
General electronics question:

As part of my exhibit for VCF east, I need a little circuit to take an audio signal (sine or square wave, AC coupled, between approx -1.5v to 1.5v or so) and convert it to a digital signal (0v to 5v) such that each period of the wav that dips below 0v creates an output voltage of 0, and where the sine wav is positive, it creates 5v.

I have a simple op-amp circuit that sort of works. Although it is noisy and the part that should be 0v output is more like 0.8 v or so.

I'm thinking that the easiest way would be to add a voltage to the AC coupled audio through a voltage divider, then use a comparator to make the output voltage 0 to 5v. But my attempts have so far been of limited success. Anyone have a circuit example that could help? Thanks!
 
Is your power supply such that you have +/-5V supply rails with reference to ground? That being the case, I'd simply drive a comparator (such as an LM339) and pass the output through a diode. The diode drop won't matter, as the output of the comparator is a square wave.
 
Hi Chuck, thanks.. I have a few LM311 comparators which should be able to do the trick.

The tricky part in this case is that I will only have easy access to a single +5v supply (cassette port power from a commodore PET), so ideally it would be a solution that wouldn't require a -5v rail. But I may be able to use a split power supply if needed.
I'll also most likely be interfacing the output signal with an atmel MCU - and after reading through the datasheet for an atmega644, it looks like I may be able to do this using the built-in analog comparator on that chip. That would be very convenient..
 
For a single supply with AC coupled signal to a comparator, you can do this:

ckt.jpg

You may want to add a large feedback resistor from output to positive input for some hysteresis.

Most of old bipolar op amps and comparators have a limited common mode input range that doesn't go all the way to zero. If you can find a comparator with an input range that goes a little below zero, that may work for you with just grounding one input and feeding the signal to the other input.

If you really need the output to go all the way to zero, you need a part with rail to rail outputs as well.
 
I noticed that the LM339 datasheet does show a single power supply zero crossing detector:
Capture.jpg
This is inverting, otherwise you have to swap the + and - input (except the 20M feedback resistor needs to go to the + input).
This circuit depends on the resistors to be balanced on both sides to switch right at zero volts. With the values shown it will have a small offset and won't switch exactly at zero.
 
Last edited:
Back
Top