Friday, September 11, 2015

A fun Analog to Digital converter

As an aside from doing Arduino projects with robotics, I have been building some other random circuits and experimenting with different components. Today I built an Analog to Digital converter based on a design I found in some class materials from the University of Pennsylvania. Specifically, one of the lab assignments for their ESE206 class had the students build an Analog to Digital converter.

I'd previously worked with the analog input pins of the Arduino and know that they have a built-in 10-bit analog to digital converter, but I wanted to see if I could build this circuit from discrete components. I happened to have the LM339 Comparator that is at the heart of this circuit.

Now this is basically a 4-bit ADC, so clearly it isn't super useful for real signal sampling applications, but it does illustrate the basics of analog to digital conversion.

I have a nice 5V power supply that I use for most of my circuits but this circuit asked for a Vcc of +15V. At some point, I'd like to have a nice adjustable bench power supply with multiple outputs, but today I don't have that luxury. However, I was able to make this circuit work just fine using my simple 5V supply by replacing the 12kΩ resistor between the top comparator and the supply voltage with a 1kΩ resistor.

For the Vin I made a simple voltage divider circuit consisting of a 1kΩ resistor in series with a 10kΩ potentiometer.

Also, for fun I hooked it up to the output of the FG085 Function Generator from JYE Tech. With a sufficiently slow signal, we can watch the LEDS light up in order!

I also decided to try hooking the ADC up to my Rigol DS-1054Z Oscilloscope. With the LEDs as output indicators we can visualize waves up to about 5Hz. That is, we can see how the low bit turns on before the higher bits. After that it just looks like rapidly flashing LEDs, and after about 30Hz, they basically appear to be on all the time. I generated a 100kHz sine wave with my function generator and looked at 3 of the 4 output bits on the scope.

At this speed one can readily see the rise and fall time of the ADC converter. This is especially noticable in the following close up:

After some thought, I see that calling this circuit a 4-bit ADC is not quite correct. Once would expect a 4-bit ADC capable of sampling the input and producing an output signal with 24 different possible values. My circuit can only produce 5 possible output values 0 LEDs on up to 4 LEDs on, so this is really not even a 3-bit ADC.

Also, using the cursor feature on the scope, I can see the input levels needed to drive each of the output signals high:

Output signal Minimum Vin (millivolts)
Vout1 680
Vout2 1800
Vout3 2840
Vout4 4200