Blog Discrete Signals

How to run an on-chip A/D converter on a microcontroller

We’ve spent a fair amount of space talking about adding A/D converters with higher speeds and more precision. There are applications that merit higher capability. But most makers already have a “free” A/D converter on their module of choice—integrated in the microcontroller or system-on-chip (SoC). These integrated converters vary. Instead of focusing on detailed specifications, let’s look at some features makers may get and how they can be used.

Setting up some analog channels

Most integrated A/D converters use the successive approximation register (SAR) architecture. For semiconductor companies, SAR is a good middle-of-the-road choice. It’s simple, doesn’t take up a lot of space on a small chip, and calibration is easy. For makers, integrated SAR A/Ds typically provide sample rates up to a few hundred kHz at resolutions up to 12 bits. Resolution is often tunable, like 8 bits without oversampling, and 12 bits oversampled for noise reduction.

Pin count is often a consideration, especially with very small, inexpensive microcontrollers. For bigger parts with more pins, there may be quite a few analog channels, from six to 12. The catch is there is only one A/D converter on chip, and in front of it, sits an analog multiplexer providing the channels. One implication of multiplexing is without some extra circuitry; all channels have the same sample rate. This may affect applications with different types of sensors.

For a few more dollars, some integrated solutions may have several improvements. Instead of single-ended inputs, two multiplexers support differential inputs for better noise rejection. There may be a special channel in the group configurable with a different sample rate from the others. An external voltage reference pin may allow a higher voltage source—compared to the digital power rail for the microcontroller itself—for a wider analog input range, or a more stable source for higher accuracy.

Figure 1 The block diagram of SAM G51G microcontroller highlights an 8-channel, 10-bit A/D converter. Source: Microchip

Simple to advanced data gathering

A good rule of thumb for low sample rate applications is keeping the microcontroller asleep as long as possible. In a simple configuration when a sample is needed, the A/D subsystem wakes up, a conversion occurs, and a result is created. There is some latency between the request and reading due to converter clocking and analog settling times. There are also many other modes that can come into play.

Figure 2 Port 1 of the MCU is used for A/D conversion. Source: MathWorks

Most converters can be programmed to free run, taking periodic samples and storing results. One thing to note is that sample rates are not infinitely programmable, as they are binary multiples of a clock source. As sample rates increase, reading A/D data can consume more and more of the microcontroller’s available processing time.

Moving data around is one of the most time-consuming operations any microcontroller can do. Many advanced parts offer direct memory access (DMA), where the A/D subsystem writes data straight to programmed memory locations. This can be very handy for sampling a block of data, then processing it after acquisition is complete.

Some A/D subsystems offer external triggering, waiting to gather samples until some hardware event occurs. Some parts offer comparison windows or limits. Data collects when readings are below a low threshold, over a high threshold, or between or outside of a threshold range. This minimizes time, storage, and work for the microcontroller until something of interest happens.

Where on-chip A/D converters fit

Sound like a lot of options? If one were to start from scratch with nothing but the programming manual, there can be a lot of work. Many registers need to be set up and managed in sequence for everything to happen. Vendors have realized that people don’t like hard-to-use parts. Often there are software drivers available for download that do most of the configuration and reading work.

Bear in mind though that vendor-supplied drivers are often for a simple use case, and more advanced features may need coding. Looking through online communities may turn up someone who has created and shared a customized driver.

Some use cases fit these on-chip A/D converters well. One is where several channels of the same type of sensor are needed; for example, eight temperature sensors spread around an engine. Another is localized control, such as setting a valve to get a particular pressure reading.

The more powerful the microcontroller, the more capable its integrated A/D usually is. A “free” converter is worth a look if there are enough channels, and sample rates and bit resolution are enough for the application.

After spending a decade in missile guidance systems at General Dynamics, Don Dingee became an evangelist for VMEbus and single-board computer technology at Motorola. He writes about sensors, ADCs/DACs, and signal processing for Planet Analog.

Related Content

0 comments on “How to run an on-chip A/D converter on a microcontroller

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.