Atmel AVR 8bit RISC microcontrollers


February 9, 2002


Some devices in AVR family does not have A-D converter, and all AVR devices have an analog comparator which can be used for A-D converter. Some application notes also document on its implementation. This note introduce a very low cost and high linearity A-D converter with only an external capacitor.

Right image shows the circuit diagram for the A-D converter. It's true! Please read following description... :-)

To process the A-D convertion, start to charge the reference capacitor by any current source and start timer at same time, wait until the capacitor voltage reaches input voltage, then stop timer and its value is the result. This is the basic theory of the A-D conversion which is same as any other method using the analog compearator. All interrupt must be disabled during A-D conversion.

In this method, the reference capacitor is charged by internal pull-up resister so that external resister could be ommited. Fortunately, the pull-up current have constant current area at input voltage below 2.0 volts. Therefore, using the constant current area can eliminate linearity error.

However, the pull-up current is affected by ambient temperature. It will appear as gain error. The measurement error near room temperature (10 to 40 degree C) will become within ±5 percent. If you require temperature stability, I recommend to use extrenal current source, such as CRD (E-101, Semitec). In this case, it can be used at input voltage range of 0 to 4.0 volts with good temperature stability.



;----------------------------------------;
; A-D conversion routine

adc:    ldi     ZL, 0     ;Clear counter
        ldi     ZH, 0     ;/
        cbi     DDRB, 0   ;Start to charge
        sbi     PORTB, 0  ;/
        adiw    ZL, 1     ;Wait for Vc reaches Vi
        sbis    ACSR, ACO ;
        rjmp    PC-2      ;/
        cbi     PORTB, 0  ;Discharge capacitor
        sbi     DDRB, 0   ;/
        ret               ;Z = result