ADC on AVR using on chip comparator
Not all AVR microcontrollers come with built in ADC. But there is a way of building one using on chip comparator and timer counter.
The comparator compares voltages on +v (Ain0) and –v (Ain1) inputs. If voltage in Ain0 pin is greater than in Ain1 then comparator ACO is set to “1” otherwise it is “0”.
Bellow you see AVR comparator circuit.

The working of this ADC is as follows. First PB0 is set to “0” in order to discharge capacitor. Then PB0 is programmed as input with no pull-ups and Timer is started to count.

The capacitor starts charging to 5V through 10k resistor. When voltage on capacitor becomes greater than in input Vin, the comparator state switches to “1”. Program detects this and stops the timer counter and accumulated count is proportional to the input voltage Vin. So if Vin is greater, then timer counts more, and if Vin is less then timer counts less. Just one thing… The voltage on capacitor rises not linearly but exponentially. But if we restrict the input to the range of like 2.5V then this voltage raise can be considered as linear.

In a example RC time constant is 1ms and capacitor charges to 2.5V in about 720us. So this is the worst case of conversion if Vin is equal 2.5V.
There are techniques of removing the nonlinearity of RC charging. One of them is Transistor current source usage.

In this circuit PNP transistor provides current about 80uA. Time to charge capacitor can be calculated as follows: T=(C*5)/I=6.25ms. So iv Vin would be 5V, then conversion time = 6.25ms.
So this takes some conversion time, but for processes like temperature monitoring is suitable.
Note that 200 Ohm resistor is used to limit capacitor discharging current to protect port from damage.
Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post | TrackBack URI for this post
New on WinAVR Tutorial
Running TX433 and RX433 RF modules with AVR microcontrollers,Sometimes in embedded design you may want to go wireless. Might be you will want to log various readi …Programming AVR ADC module with WinAVR,Most of AVR microcontrollers have Analog to Digital Converter (ADC) integrated in to chip. Such solut … |
New on WinARM Tutorial
What are differences between WinARM and WinAVR,Everyone who is working with AVR microcontrollers knows this powerful tool – WinAVR (http://win …LPC2000 watchdog timer,As in all microcontrollers watchdog timers purpose isto reset microcontroller after reasonable amount … |
