Trying to wrap my head around ADC's

Thread Starter

gte

Joined Sep 18, 2009
357
Can anyone give me a basic overview of Analog to Digital Converters?

I did this search
http://www.google.com/#q=analog-to-...OIG78gaB5cE0&start=0&sa=N&fp=d55d3d558932bb8c
and came up with a lot more info on DAC's, but nothing that really explained how the most significant bit and least significant bit are given values, and how a microchip actually interprets that and reads it?

The range I will be using will be 0-3.3, or maybe .3 to 3.3? That way it could be a live 0 at .3v? I'm trying to wrap my brain around how the bits are assigned and how the microchip interprets the bits that represent the analog value?
 

Markd77

Joined Sep 7, 2009
2,806
DAC = digital to analog converter
ADC = analog to digital converter
You mention both but I'm guessing ADC.
I only really know about the ones in the midrange PICs, but they can read 0-1023 (10 bits). They can all measure from VDD to VSS, where 0 is VSS and 1023 is VDD. They are linear through the range. Some also have an option to use voltage references to set the upper and/or lower point. So you could set the lower reference to 0.3V and that would read 0.
The problem with that is that you would need an accurate reference to make it worthwhile.
 

Thread Starter

gte

Joined Sep 18, 2009
357
What I wrote may have been confusing, I was saying that I found a lot of information on DAC's, but that I wanted information on ADC's. I'm sure a lot of the principles are the same, but for a beginner it would be easier for me to learn the specifics of an ADC only.
 

Thread Starter

gte

Joined Sep 18, 2009
357
Thank you both

The Ebook said:
A parallel binary number output is obtained from this circuit by averaging the serial stream of bits together. For example, a counter circuit could be designed to collect the total number of 1's output by the flip-flop in a given number of clock pulses. This count would then be indicative of the analog input voltage.
Is this how an ADC would interface with a microchip?

Let's say you had a 10 position switch, each position represented a different voltage value (based on resistance) from .3 to 3.3vDC . The analog voltage could be represented by a digital number via an ADC and then the microchip would poll the ADC output each clock cycle and that is how it would interpret it? How would it know which clock signal to start counting on?
 
Last edited:
Many microcontrollers contain their own ADC in the chip -- often a 10-bit or 12-bit ADC. Then, it is just internal programming to access the ADC from the code.

Standalone ADC chips sometimes interface with a serial output, usually using a standard like SPI or I2C for the data transfer.

Sometimes standalone ADC chips output the data in parallel, which means all the bits at once. This is important for very fast ADCs, because the data can be transferred faster.
 
Let's say you had a 10 position switch, each position represented a different voltage value (based on resistance) from .3 to 3.3vDC . The analog voltage could be represented by a digital number via an ADC and then the microchip would poll the ADC output each clock cycle and that is how it would interpret it? How would it know which clock signal to start counting on?
You could use a rotary switch that has a binary output. You can buy 10-position rotary switches with binary-coded output.

For example, check this out.
And this one.

I've seen tiny ones that cost about $1 and you have to use a little screwdriver to switch them.

A lot of products with a rotary dial have the switch built into the plastic enclosure, and the PCB has a pattern on it that outputs the status of the switch by the connection made by a small metal contact in the knob that you turn.

My point is that it's not necessary to use a resistor divider and an ADC to read a rotary switch, although that way works too.
 

Thread Starter

gte

Joined Sep 18, 2009
357
Those are perfect aside from their prices :)

I believe the microcontroller I am trying to learn to program has built in ADC's and 2 counters per processor, I just need to figure out how to interface them now.




You could use a rotary switch that has a binary output. You can buy 10-position rotary switches with binary-coded output.

For example, check this out.
And this one.

I've seen tiny ones that cost about $1 and you have to use a little screwdriver to switch them.

A lot of products with a rotary dial have the switch built into the plastic enclosure, and the PCB has a pattern on it that outputs the status of the switch by the connection made by a small metal contact in the knob that you turn.

My point is that it's not necessary to use a resistor divider and an ADC to read a rotary switch, although that way works too.
Many microcontrollers contain their own ADC in the chip -- often a 10-bit or 12-bit ADC. Then, it is just internal programming to access the ADC from the code.

Standalone ADC chips sometimes interface with a serial output, usually using a standard like SPI or I2C for the data transfer.

Sometimes standalone ADC chips output the data in parallel, which means all the bits at once. This is important for very fast ADCs, because the data can be transferred faster.
 
Those are perfect aside from their prices :)

I believe the microcontroller I am trying to learn to program has built in ADC's and 2 counters per processor, I just need to figure out how to interface them now.
Yes, I know. They are expensive, I don't know why. Maybe you can find something at Newark or Mouser or somewhere else.

Here is one that I actually used on a circuit board. It is great, but it requires a screwdriver to change it. You don't need anything else to read it with a microcontroller. You can switch on the internal pull-up resistors of the microcontroller when you want to read the value of the switch.

If you're doing a 10-position switch by resistive divider, I would say don't worry about the 0.3V floor -- just use ground. With a basic 10-bit ADC you will have enough resolution to easily determine the state of the switch. You can simply ready from the Vcc (such as 3.3V or 5V) to ground and determine the position of the switch among 10 positions very easily.

If the resistive divider is always on, then it will always use power. If low-power is important to you, then you could connect the top of the resistive divider to the output of a microcontroller pin. Then, when you want to read the value of the dial, you switch that pin high, then read the value, then switch it low again. That way, it is not wasting power in between the readings.

Make sure to use resistor values that are high enough to use little current, but low enough for the ADC to read properly. I would say a total resistance for the whole dial of 100K to 500K Ohms is good.

Hope this helps.

Oh, what kind of microcontroller are you using? If it's a PIC, Atmel, MSP430, or other common ones, you can find help here on these forums. There is also sample code online for all these microcontrollers to show how to read the ADCs.
 

Thread Starter

gte

Joined Sep 18, 2009
357
That switch is perfect, I couldn't find that anywhere before, thank you!

I'm using a parallax propeller, I'm new to this so I'm not sure as to how good of a choice that is.

This may be a stupid question, but I still can't figure out how the micro controller knows which selection pin the 10 position switch is set to. Would you mind explaining that to me?

The only possibilities I can think of would be through voltage, current or if there were 3 output pins that had to be read and depending on the combo of pins having a high or a low, it would indicate which switch position it was on? That last one seems like it'd use too many pins though?

Thanks for the help with this.



Yes, I know. They are expensive, I don't know why. Maybe you can find something at Newark or Mouser or somewhere else.

Here is one that I actually used on a circuit board. It is great, but it requires a screwdriver to change it. You don't need anything else to read it with a microcontroller. You can switch on the internal pull-up resistors of the microcontroller when you want to read the value of the switch.

If you're doing a 10-position switch by resistive divider, I would say don't worry about the 0.3V floor -- just use ground. With a basic 10-bit ADC you will have enough resolution to easily determine the state of the switch. You can simply ready from the Vcc (such as 3.3V or 5V) to ground and determine the position of the switch among 10 positions very easily.

If the resistive divider is always on, then it will always use power. If low-power is important to you, then you could connect the top of the resistive divider to the output of a microcontroller pin. Then, when you want to read the value of the dial, you switch that pin high, then read the value, then switch it low again. That way, it is not wasting power in between the readings.

Make sure to use resistor values that are high enough to use little current, but low enough for the ADC to read properly. I would say a total resistance for the whole dial of 100K to 500K Ohms is good.

Hope this helps.

Oh, what kind of microcontroller are you using? If it's a PIC, Atmel, MSP430, or other common ones, you can find help here on these forums. There is also sample code online for all these microcontrollers to show how to read the ADCs.

 
I'm glad it was helpful.

The switch has 6 leads. Two of those are "common" -- you can connect those both to ground. The other pins will be conducting to the common, or open. Conducting means "1" and open means "0".

You connect each of the four output pins to its own microcontroller pin. You can use the pull-up resistor in the microcontroller. (I don't know the Propeller but I know most other microcontrollers have these.) When the pull-up resistor is on, then it will pull up to Vcc if the switch is open, otherwise it will be low (ground). So, read the input levels on the pins, and there you have it. You will have a 4-bit result.

By the way, when you have a 10-position switch to binary, this is called "binary coded decimal" (BCD).


Take a look at the datasheet of the switch.

You'll see in the "code format" table that the outputs are in binary.

Lastly -- if you're going for low-power, then be sure to turn off the pull-up resistors when you're not reading the switch. On some microcontrollers, these resistors are about 50K Ohms... on 3.3V Vcc, that would be 0.217 mW burning away per pin. On 5V Vcc, that would be 0.5 mW.
 

count_volta

Joined Feb 4, 2009
435
Yea these things can be complicated. We are building an integrating ADC for our last experiment in this course I'm currently taking in EE school, and man its making my head hurt. I'm still trying to figure out how it works.

The ebook section on it is very helpful with this btw. So I strongly suggest you read the AAC ebook on ADC's.
 

davebee

Joined Oct 22, 2008
540
The parallax propeller does not have a built-in ADC, but its built-in counters can be configured to perform delta-sigma ADC conversion with just a few external resistors and capacitors and a few lines of code.

It's not a particularly good ADC - not very fast, not very high resolution, has to be built physically close to the microcontroller pins to work well, but depending on what you do with it, it could be fine for your purposes.

If you're new at ADCs and want to understand them, then the sigma-delta may be a difficult one to start with. You might be better off starting to learn about ADC types like the flash or dual-slope converters.

If you mainly just want to get a working ADC, you could get an external ADC chip and wire it to the microcontroller.

The microchip TC3405 works great with the propeller. It can run at 3.3 volts, only needs a few lines of code to operate, connects serially so you don't need a lot of pins, only costs a few dollars, has four channels of 16 bit converters. It's slow, though.

The Burr-Brown ADS8320 also works well with the propeller if you want a little more speed. It's also serial, 16 bits, one channel, also is fairly inexpensive, but it can convert at 100 kHz.

If you decide to go this route, I have propeller code that runs both of these converters you can have if you want it.
 

Thread Starter

gte

Joined Sep 18, 2009
357
Prop code would be awesome, do you have a schematic also?

Will the TC3405 ADC accept input from the fixed position switches? The speed isn't super crucial, because I'll be turning the switches to indicate inputs and it'll need to check the switches maybe once a second, so very slow response (once every 80 million cycles) is fine. The important thing is being able to adjust the values via the selector switches.

Thanks!



The parallax propeller does not have a built-in ADC, but its built-in counters can be configured to perform delta-sigma ADC conversion with just a few external resistors and capacitors and a few lines of code.

It's not a particularly good ADC - not very fast, not very high resolution, has to be built physically close to the microcontroller pins to work well, but depending on what you do with it, it could be fine for your purposes.

If you're new at ADCs and want to understand them, then the sigma-delta may be a difficult one to start with. You might be better off starting to learn about ADC types like the flash or dual-slope converters.

If you mainly just want to get a working ADC, you could get an external ADC chip and wire it to the microcontroller.

The microchip TC3405 works great with the propeller. It can run at 3.3 volts, only needs a few lines of code to operate, connects serially so you don't need a lot of pins, only costs a few dollars, has four channels of 16 bit converters. It's slow, though.

The Burr-Brown ADS8320 also works well with the propeller if you want a little more speed. It's also serial, 16 bits, one channel, also is fairly inexpensive, but it can convert at 100 kHz.

If you decide to go this route, I have propeller code that runs both of these converters you can have if you want it.
 

davebee

Joined Oct 22, 2008
540
If all you want to do is have a program detect the switch position then there's really no need for an ADC converter at all.

With that digital switch, you can connect the switch common to ground, connect each switch data pin to a microcontroller pin, and connect a resistor, like 10K ohms, from each switch-microcontroller junction to 3.3 volts.

That's all there is to the wiring.

If you connected the pins to the microcontroller IO pins 0,1,2 and 3, then the code can read the switch with code like

pinvalue := ina[3..0]

After that line executes, the variable "pinvalue" will have a value from 0 to 15 (for the 16 position model) depending on the switch position. Your program can then use the value any way you want.
 

Thread Starter

gte

Joined Sep 18, 2009
357
Is there a way to do that only using 1 pin, I'm starting to run out of pins
If all you want to do is have a program detect the switch position then there's really no need for an ADC converter at all.

With that digital switch, you can connect the switch common to ground, connect each switch data pin to a microcontroller pin, and connect a resistor, like 10K ohms, from each switch-microcontroller junction to 3.3 volts.

That's all there is to the wiring.

If you connected the pins to the microcontroller IO pins 0,1,2 and 3, then the code can read the switch with code like

pinvalue := ina[3..0]

After that line executes, the variable "pinvalue" will have a value from 0 to 15 (for the 16 position model) depending on the switch position. Your program can then use the value any way you want.
 
Is there a way to do that only using 1 pin, I'm starting to run out of pins
Hmm.. now it is getting interesting!

If you don't have 4 free pins on the microcontroller, then I think you should:

(1) use a different microcontroller...
(2) consolidate some other pin usages by using shift registers or other 'helper' chips or some other strategy... or
(3) use a simple pushbutton! each time you push it, it turns to a different option!

I like number 3 best. I just did that on a board I made.

When it is powered up, it starts in "mode 1". When you push the button, it blinks an LED 2 times and changes to "mode 2". Push again, and it blinks 3 times and changes to "mode 3"... etc.

This is very simple, uses only one pin for the switch, and one pin for the LED. Maybe you have an LED already for some other purpose. You may be able to make it do double-duty.

Simple is *always* better, as long as it works.
Does this help?
 

Thread Starter

gte

Joined Sep 18, 2009
357
It definitely helps :), I'd like to use a push button with an LED representation of a number, etc . Not sure how that'd work though since I'm new to this. I'm going to guess that you'd need an input pin for switching modes, you'd need an up and down input pin and you'd need 2 output pins to represent each LED? At least if that was the case, I could designate 5 pins and have it control all inputs by changing "modes"? What do you think?
Hmm.. now it is getting interesting!

If you don't have 4 free pins on the microcontroller, then I think you should:

(1) use a different microcontroller...
(2) consolidate some other pin usages by using shift registers or other 'helper' chips or some other strategy... or
(3) use a simple pushbutton! each time you push it, it turns to a different option!

I like number 3 best. I just did that on a board I made.

When it is powered up, it starts in "mode 1". When you push the button, it blinks an LED 2 times and changes to "mode 2". Push again, and it blinks 3 times and changes to "mode 3"... etc.

This is very simple, uses only one pin for the switch, and one pin for the LED. Maybe you have an LED already for some other purpose. You may be able to make it do double-duty.

Simple is *always* better, as long as it works.
Does this help?
 
Top