ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

  Analog Avenue

    Tech Notes


Download PDF

The Grey Line Gets Greyer between Digital and Analog
By Bonnie C. Baker and Dieter Peter,
Microchip Technology, Inc.

Where analog meets digital

Writing the firmware that interfaces an ADC to a microcontroller can be tedious at times. The converter manufacturers usually are not able to anticipate all of the variations on controllers available on the market. Consequently, the ADC interface is good for most, but not adequate for all. It would be most effective to have the converter on the same chip as the controller: A nice idea, but most microcontrollers do not have built-in ADCs and -- if they do have converters on board -- they are more than likely only 8-bit accurate. This situation is changing. Microcontroller companies are slowly adding analog functionality to their controllers. But if you can't wait for future developments, there is a way to beat the system. If a controller has a comparator function, with an internal or external voltage reference, a sigma-delta ADC can be implemented quite easily with a capacitor and a few external resistors. By combining these elements, a first order modulator and first order filter can be designed, emulating the function of an analog-to-digital delta-sigma conversion.

The sigma-delta "connection"

The function of the classical sigma-delta analog-to-digital converter is modeled with two circuit segments; a modulator and a digital filter. The modulator section acquires an input signal (see Fig. 1.) The input signal passes through an integrator and then to one of the two inputs of a comparator. The comparator acts like a one-bit quantizer. The output of the comparator is sent back to the integrator via a one-bit DAC. Additionally, the output of the comparator passes through a digital filter. With time, the output of the digital filter provides a multi-bit conversion result.

ChipCenter
Fig1: First order sigma-delta ADC converter block diagram

This fundamental circuit concept has been used to generate a large variety of the converters that provide high resolution, while being relatively inexpensive. If you look at the silicon implementations of these types of converters you will quickly discover that a large portion of the silicon is given to digital. The next logical step for this type of ADC is to move it into the controller. Although, today, the controllers on the market are not able to execute this type of function, a few additional peripherals make it possible to achieve higher than 8- or 10-bit resolutions on an analog input signal. This is shown in the controller circuit diagram that implements the sigma-delta converter (see Fig. 2.)

ChipCenter
Fig2: Configuration of the microcontroller for a delta-sigma conversion

Implementation with the controller

In the controller circuit shown (Fig. 2, again), the integrator function of the sigma-delta function is implemented with an external capacitor, CINT. The absolute accuracy of this external capacitor is not critical, only its stability from integration to integration, which occurs in a relatively short period of time. When RA3 of the 8-bit microcontroller is set high, the voltage at VCINT increases in voltage. This occurs until the output of the comparator (CMCON.6) goes high. At this point the driver to the RA3 output switches from high to low. Once this has occurred the voltage at the input to the comparator (RA0) decreases. This continues until the comparator is tripped low. At this point, RA3 is commanded to go high and the cycle repeats. While the modulator section of this circuit is cycling, two counters are used to keep track of the time and of the number of ones versus zeros that occur at the output of the comparator.

If this circuit were compared to the classical sigma-delta converter, the integrator would be CINT. The comparator and voltage reference are part of the controller. The one-bit DAC is implemented with the output of the comparator (CMCON.6) and PortA.3, which drives the DAC output at RA3. The digital filter is implemented with two counters and a simple averaging algorithm in the firmware.

How good can it get?

With this circuit (Fig. 2, again) it is possible to conceptualize the sigma-delta function. The controller implementation of this circuit is summarized in the flow chart (see Fig. 3), which shows that when the variable, COMP_MODE is high, the algorithm is started. Additionally, two variables are established in the forms of counters 1 and 2. Both are initialized to the number of sample periods. The number of conversions can be any integer, but numbers that are derived from powers of two are more easily manipulated later on. Counter 1, labeled "RESULTS", will increment or decrement depending on the output state of the comparator. If the voltage on the integration capacitor (VCINT) is greater than the voltage reference on the non-inverting input of the comparator, the output of the comparator will be high. In this manner, counter 1 will keep track of the number of times the comparator is high versus low. The second counter is appropriately called "COUNTER". Counter 2 will decrement every time the comparator output is checked. When counter 2 is equal to zero, the conversion process will be completed. Throughout this process a "SHADOW" is used to track the state of PORTA. This may or may not be needed, depending on the use of PORTA by the main program.

ChipCenter
Fig3: Delta-sigma A/D conversion flow chart, implemented with the circuit show in figure 2. This code is implemented until conversion is complete

Finally, the COMP_MODE is set low and the conversion subroutine returns to the main program. It is recommended that the output of the comparator drives the output port, RA3. This will keep the voltage at VCINT equal to the reference voltage of the comparator in preparation for the next conversion.

Each integration result is taken at a regular time interval. If it is assumed that the time interval of a conversion is 20 ýs, the conversion time versus bits can easily be calculated. This relationship can be shown graphically (see Fig. 4.) For instance, a 10-bit conversion would require 210 or 1024 samples. If the microcontroller checks every 20 ýs, one conversion would take 20.48 ms.

ChipCenter
Fig4: Conversion time versus bits of resolution assuming a 20ý integration time.

Once the full conversion is completed, i.e. COUNTER is equal to zero, the digital conversion is calculated by the controller. This is done with a few simple math functions.

Getting the bits you want

After the COUNTER reaches zero, the result should be multiplied by two. This is easily implemented in the controller with a shift-to-the-right instruction. Now the resulting data can be used with an averaging filter to achieve higher resolution. A simple averaging filter is listed below:

SUM = a summing variable
IN = the input to the filter or the output from the conversion
OUT = the output of the filter
FACTOR = a constant divisor used in by the filter

SUM = SUM + IN
OUT = SUM / FACTOR
SUM = SUM - OUT

If FACTOR is equal to 2^8, the MSBs of SUM are equal to OUT. With this converter and filter, any number of bits are achievable with some limitations. However, 12-bit, stable conversions (LSB = 1mV) have been demonstrated.

Are we there yet?

It's true, you can design a delta-sigma converter with a microcontroller with a capacitor and a few resistors. This solution doesn't replace the high resolution discrete devices yet because it's too slow and takes processing time away from the controller. But if you can afford these shortcomings, the real-estate savings may be worth it.

Analog Main | Product of the Week | Columns | Editorial | Tech Notes

Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ