Free Shipping on orders over US$49.99

Supersampling with Analog Sensors – EE Times

//php echo do_shortcode(‘[responsivevoice_button voice=”US English Male” buttontext=”Listen to Post”]’) ?>

Analog sensors return a continuous voltage when a physical quantity changes. In other words, at their output, there is a potential difference proportional to the type of event measured. There are hundreds of analog sensor types, and their best use is to be connected to a microcontroller equipped with an ADC input for measurement detection and processing of the final action.

Here, we explore the best techniques for performing this important operation, using two analog sensor types to make our observations: the LM35 precision temperature sensor and the OH49E magnetic-field sensor (or equivalent). Both sensors are inexpensive and are readily accessible on the market.

Temperature and magnetic-field sensors

The LM35 is a precision integrated circuit for temperature measurement. Its output is linear and proportional to the temperature, in degrees Celsius. It requires no external calibration and provides a voltage proportional to temperature, normally between –55˚C and 150˚C. It also features a low output impedance, good linearity of measurement and excellent internal calibration accuracy. It’s a simple matter to connect and use the device in electronic systems. It absorbs only 60 µA, so its heating is extremely low and does not affect the measurement output. It can be powered by a DC voltage of between 4 V and 20 V to measure positive temperatures, and it can also be used with a dual power supply to enable the measurement of negative temperatures. The output voltage refers to the temperature.

The OH49E is a small and versatile Hall-effect linear device, driven by the magnetic field produced by a permanent magnet or electromagnet. It is smaller than the LM35 thermometer. The output voltage depends on that of the power supply and varies in proportion to the strength of the magnetic field. It does not require external filters, as the output is low-noise. Internal precision resistors ensure greater stability and accuracy.

Figure 1 shows the main characteristics of the two sensors. The output voltage refers to the magnetic field, expressed in gauss, both positive and negative. The operating temperature is between –20˚C and 100˚C, and the current consumption is approximately 4.2 mA at VCC = 5 V.

Figure 1: LM35 and OH49E sensors together with their respective packages, pinouts and output-characteristic curves (Source: National Semiconductor [LM35], Nanjing Ouzhuo Technology [OH49E] datasheets)

The error of reading one sample at a time

Today, ADC systems are widely used for the acquisition and processing of analog data of all kinds. In engineering schools, the methods used for this type of acquisition are frequently inefficient, as instructors often focus on theory rather than on the practical implications that occur in a real system.

One of the most common mistakes made by even experienced designers is to acquire a single sample of information, via an ADC system, at each time interval. Taking a single reading is never a good solution, despite its simplicity, because the result will be rendered unreliable if noise or interference affect the system at the time the data is read.

Figure 2 illustrates the incorrect acquisition of a single temperature sampled every second without further, more complex processing. The graph in the example refers to a generic temperature acquisition over a 30-second period.

Figure 2: ADC acquisition of a single sample at a time is not always the best solution. (Source: Giovanni Di Maria)

As the figure shows, because of an electrical factor like noise, interference or a sensor problem, one sample measured by the system is incorrect, and this value undoubtedly will adversely affect the measurements. An average calculation of the acquired temperatures returns an anomalous value, as it also takes measurement errors into account. Firmware, on the other hand, would try to minimize measurement errors by using mathematical methods and intelligent filters.

One method for partially solving the problem would be to discard a sample that falls outside a window of acceptable values. In this way, all values higher or lower than a certain range would be automatically eliminated. The problem becomes more obvious as the erroneous sample increases, or, to put it another way, as the sample deviates from the data’s mean.

Another option is to determine the mean temperature of the measurement interval using the geometric mean rather than the arithmetic mean. This technique is quite successful and is often conclusive, but its implementation within small microcontrollers is not always easy, for reasons of both memory and hardware power.


The following examples are generic, adaptable to any type of MCU or embedded system and represented by means of pseudocode. Designers can easily adapt the approach to their own logic system.

Supersampling, illustrated in Figure 3, is a useful technique for increasing the resolution of an ADC. A reading from an analog port of an MCU implies a digital assignment of the read voltage value to an integer-type variable.

To better understand the system, note that a 1-bit ADC has a resolution of 2.5 V, where digital value 00 corresponds to a voltage between 0 V and 2.5 V and digital value 01 corresponds to a voltage between 2.5 V and 5 V. A 2-bit ADC, on the other hand, would have a resolution of 1.25 V, with the following acquisition combinations:

  • Digital value 00 corresponds to a voltage between 0 V and 1.25 V.
  • Digital value 01 corresponds to a voltage between 1.25 V and 2.5 V.
  • Digital value 10 corresponds to a voltage between 2.5 V and 3.75 V.
  • Digital value 11 corresponds to a voltage between 3.75 V and 5 V.

Each additional bit in the ADC system doubles the acquisition capacity and read resolution of the analog data. Obviously, costs are also related to resolution so that an 8-bit ADC system costs relatively little, whereas a 24-bit acquisition circuit is much more expensive.

The following table shows the possibility of obtaining digitized voltages depending on the number of bits of the ADC.

Bit ADC Combinations Resolution
(0–5 V)
8 256 19.531 mV
10 1,024 4.882 mV
12 4,096 1.220 mV
16 65,536 76.293 µV
20 1,048,576 4.768 µV
24 16,777,216 298.023 nV
36 68,719,476,736 72.759 pV

Its equations are as follows:

We have already seen that sequential reading cadenced every second, for example, is a flawed solution because of the possible interference that can occur on the circuit. Taking many close readings of the same port, summing the acquired samples and calculating the relative arithmetic mean—better still, the geometric mean—greatly improves the result. The graph of the acquisitions shows how effective this technique is, especially when the signal is affected by noise. Geometric averaging is the best solution for most applications. Logarithms must be used for its calculation.

This is essentially the approach of supersampling, which lets a designer “simulate” at a higher resolution than the current ADC system. By performing many close acquisitions, the resolution increases as the system’s digital rate is lowered, and uncertainty levels are converted into near-real value levels. The more readings taken over a small time interval, the higher the final resolution.

Figure 3: With supersampling, measurements are more accurate, and the error rate is reduced. (Source: Giovanni Di Maria)

Digital thermometer and magnetic-field detector

Now we can talk about how the two circuit diagrams of the digital thermometer and the magnetic-field detector work with the LM35 and OH49E integrated circuits (Figure 4).

Figure 4: Diagrams of the temperature sensor and the magnetic-field detector (Source: Giovanni Di Maria)

Both diagrams are supplied with 5 V. The output terminal must be connected to an ADC of a microcontroller. The resistor R1 is calculated according to the official datasheet of the LM35, with the following relation:

In theory, one could simply connect a tester to the outputs of the two sensors, read the outgoing voltages and convert them into valid temperature and magnetic-field measurements. With a microcontroller, of course, the operation is simpler, and there is also the possibility of storing the data in memory. The two sensors provide an electrical voltage that must be converted, using appropriate formulas, into the respective physical quantities.

In a system running at Vref of 5 V and with a 10-bit ADC, the equation for calculating temperature using the LM35 is as follows:

The following equation can be used to determine the magnetic field using the OH49E integrated circuit in a system with a 5-V reference voltage and a 10-bit ADC:

It should also be remembered that 1 tesla = 10,000 gauss, so this conversion can be easily done.


The first pseudocode now concerns the acquisition of data from an analog sensor. (The distinction between the two sensors we’ve used in our examination is irrelevant, as the principle is the same and applies to both.)

Suppose we want to acquire a temperature (or a magnetic-field value) every second. The first pseudocode, adaptable to any system, concerns the simple raw acquisition of samples without any processing. The recordings, in this case, could be affected by errors and interference.

On the other hand, the much more performant and efficient source list involves the use of supersampling, in this case performed 100 times per second. As can be seen in Figure 5, by increasing the degree of supersampling, the signal is improved and made cleaner, especially from any sporadic noise that may occur on the line.

Figure 5: The signal from the analog thermometer was digitized with different degrees of oversampling. (Source: Giovanni Di Maria)

The first recording of the graph (top and in black) shows the “raw” acquisition of the signal, with the traditional technique seen before. The second recording of the graph (red) shows the acquisition of the signal with an oversampling degree of 10. This value simulates an ADC resolution of approximately 13 bits. The third graph recording (green) shows signal acquisition with an oversampling rate of 100. This value simulates an ADC resolution of approximately 16 bits. The fourth recording in the graph (blue) shows signal acquisition with an oversampling degree of 1,000. This value simulates an ADC resolution of about 20 bits.

In other words, we have transformed an ADC from 10 bits to 20 bits at zero cost.

ADC at the highest level

Using oversampling generally means increasing the resolution of the ADC of your embedded system or MCU. A microcontroller equipped with a 10-bit digital analog input, for example, can increase its resolution simply by introducing the concept of oversampling. The following table shows the resolutions achieved by one virtual acquisition system, starting with the degree of oversampling.

Degree of supersampling Simulated resolution of the ADC
1 10 bits
2 11 bits
4 12 bits
8 13 bits
16 14 bits
32 15 bits
64 16 bits
128 17 bits
256 18 bits
512 19 bits
1,024 20 bits
2,048 21 bits
4,096 22 bits
8,192 23 bits
16,384 24 bits

This means that if the loop in a source code includes 100 sum and average steps, it is as if one’s ADC had a resolution of 16.6438 bits, according to the following basic formula:

The number of decimal digits in the formula is important for the accuracy of the calculations. To obtain an integer number of bits, it is always advisable to use a supersampling degree with a power of 2, to have control over the final resolution (2, 4, 8, 16, etc.).

The supersampling technique can greatly improve the performance of data-acquisition circuits using analog sensors. The method, in fact, improves the signal-to-noise ratio of the system. Supersampling can be used to enhance dynamic range, even if doing so necessitates writing some additional source code.

One cautionary reminder: Because sensor pinouts can vary from one model to another, it is always advisable to check them carefully.

Source link

We will be happy to hear your thoughts

Leave a reply

Enable registration in settings - general
Compare items
  • Total (0)
Shopping cart