Debian Codegraph @

Documentation/iio/iio_adc.rst

raw
1 .. SPDX-License-Identifier: GPL-2.0-only
2
3 =========================
4 IIO Abstractions for ADCs
5 =========================
6
7 1. Overview
8 ===========
9
10 The IIO subsystem supports many Analog to Digital Converters (ADCs). Some ADCs
11 have features and characteristics that are supported in specific ways by IIO
12 device drivers. This documentation describes common ADC features and explains
13 how they are supported by the IIO subsystem.
14
15 1. ADC Channel Types
16 ====================
17
18 ADCs can have distinct types of inputs, each of them measuring analog voltages
19 in a slightly different way. An ADC digitizes the analog input voltage over a
20 span that is often given by the provided voltage reference, the input type, and
21 the input polarity. The input range allowed to an ADC channel is needed to
22 determine the scale factor and offset needed to obtain the measured value in
23 real-world units (millivolts for voltage measurement, milliamps for current
24 measurement, etc.).
25
26 Elaborate designs may have nonlinear characteristics or integrated components
27 (such as amplifiers and reference buffers) that might also have to be considered
28 to derive the allowed input range for an ADC. For clarity, the sections below
29 assume the input range only depends on the provided voltage references, input
30 type, and input polarity.
31
32 There are three general types of ADC inputs (single-ended, differential,
33 pseudo-differential) and two possible polarities (unipolar, bipolar). The input
34 type (single-ended, differential, pseudo-differential) is one channel
35 characteristic, and is completely independent of the polarity (unipolar,
36 bipolar) aspect. A comprehensive article about ADC input types (on which this
37 doc is heavily based on) can be found at
38 https://www.analog.com/en/resources/technical-articles/sar-adc-input-types.html.
39
40 1.1 Single-ended channels
41 -------------------------
42
43 Single-ended channels digitize the analog input voltage relative to ground and
44 can be either unipolar or bipolar.
45
46 1.1.1 Single-ended Unipolar Channels
47 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48
49 ::
50
51 ---------- VREF -------------
52 ´ ` ´ ` _____________
53 / \ / \ / |
54 / \ / \ --- < IN ADC |
55 \ / \ / \ |
56 `-´ `-´ \ VREF |
57 -------- GND (0V) ----------- +-----------+
58 ^
59 |
60 External VREF
61
62 The input voltage to a **single-ended unipolar** channel is allowed to swing
63 from GND to VREF (where VREF is a voltage reference with electrical potential
64 higher than system ground). The maximum input voltage is also called VFS
65 (Voltage input Full-Scale), with VFS being determined by VREF. The voltage
66 reference may be provided from an external supply or derived from the chip power
67 source.
68
69 A single-ended unipolar channel could be described in device tree like the
70 following example::
71
72 adc@0 {
73 ...
74 #address-cells = <1>;
75 #size-cells = <0>;
76
77 channel@0 {
78 reg = <0>;
79 };
80 };
81
82 One is always allowed to include ADC channel nodes in the device tree. Though,
83 if the device has a uniform set of inputs (e.g. all inputs are single-ended),
84 then declaring the channel nodes is optional.
85
86 One caveat for devices that support mixed single-ended and differential channels
87 is that single-ended channel nodes also need to provide a ``single-channel``
88 property when ``reg`` is an arbitrary number that doesn't match the input pin
89 number.
90
91 See ``Documentation/devicetree/bindings/iio/adc/adc.yaml`` for the complete
92 documentation of ADC specific device tree properties.
93
94
95 1.1.2 Single-ended Bipolar Channels
96 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97
98 ::
99
100 ---------- +VREF ------------
101 ´ ` ´ ` _____________________
102 / \ / \ / |
103 / \ / \ --- < IN ADC |
104 \ / \ / \ |
105 `-´ `-´ \ +VREF -VREF |
106 ---------- -VREF ------------ +-------------------+
107 ^ ^
108 | |
109 External +VREF ------+ External -VREF
110
111 For a **single-ended bipolar** channel, the analog voltage input can go from
112 -VREF to +VREF (where -VREF is the voltage reference that has the lower
113 electrical potential while +VREF is the reference with the higher one). Some ADC
114 chips derive the lower reference from +VREF, others get it from a separate
115 input. Often, +VREF and -VREF are symmetric but they don't need to be so. When
116 -VREF is lower than system ground, these inputs are also called single-ended
117 true bipolar. Also, while there is a relevant difference between bipolar and
118 true bipolar from the electrical perspective, IIO makes no explicit distinction
119 between them.
120
121 Here's an example device tree description of a single-ended bipolar channel::
122
123 adc@0 {
124 ...
125 #address-cells = <1>;
126 #size-cells = <0>;
127
128 channel@0 {
129 reg = <0>;
130 bipolar;
131 };
132 };
133
134 1.2 Differential channels
135 -------------------------
136
137 A differential voltage measurement digitizes the voltage level at the positive
138 input (IN+) relative to the negative input (IN-) over the -VREF to +VREF span.
139 In other words, a differential channel measures the potential difference between
140 IN+ and IN-, which is often denoted by the IN+ - IN- formula.
141
142 1.2.1 Differential Bipolar Channels
143 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144
145 ::
146
147 -------- +VREF ------ +-------------------+
148 ´ ` ´ ` / |
149 / \ / \ / --- < IN+ |
150 `-´ `-´ | |
151 -------- -VREF ------ | |
152 | ADC |
153 -------- +VREF ------ | |
154 ´ ` ´ ` | |
155 \ / \ / \ --- < IN- |
156 `-´ `-´ \ +VREF -VREF |
157 -------- -VREF ------ +-------------------+
158 ^ ^
159 | +---- External -VREF
160 External +VREF
161
162 The analog signals to **differential bipolar** inputs are also allowed to swing
163 from -VREF to +VREF. The bipolar part of the name means that the resulting value
164 of the difference (IN+ - IN-) can be positive or negative. If -VREF is below
165 system GND, these are also called differential true bipolar inputs.
166
167 Device tree example of a differential bipolar channel::
168
169 adc@0 {
170 ...
171 #address-cells = <1>;
172 #size-cells = <0>;
173
174 channel@0 {
175 reg = <0>;
176 bipolar;
177 diff-channels = <0 1>;
178 };
179 };
180
181 In the ADC driver, ``differential = 1`` is set into ``struct iio_chan_spec`` for
182 the channel. Even though, there are three general input types, ``differential``
183 is only used to distinguish between differential and non-differential (either
184 single-ended or pseudo-differential) input types. See
185 ``include/linux/iio/iio.h`` for more information.
186
187 1.2.2 Differential Unipolar Channels
188 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189
190 For **differential unipolar** channels, the analog voltage at the positive input
191 must also be higher than the voltage at the negative input. Thus, the actual
192 input range allowed to a differential unipolar channel is IN- to +VREF. Because
193 IN+ is allowed to swing with the measured analog signal and the input setup must
194 guarantee IN+ will not go below IN- (nor IN- will raise above IN+), most
195 differential unipolar channel setups have IN- fixed to a known voltage that does
196 not fall within the voltage range expected for the measured signal. That leads
197 to a setup that is equivalent to a pseudo-differential channel. Thus,
198 differential unipolar setups can often be supported as pseudo-differential
199 unipolar channels.
200
201 1.3 Pseudo-differential Channels
202 --------------------------------
203
204 There is a third ADC input type which is called pseudo-differential or
205 single-ended to differential configuration. A pseudo-differential channel is
206 similar to a differential channel in that it also measures IN+ relative to IN-.
207 However, unlike bipolar differential channels, the negative input is limited to
208 a narrow voltage range (taken as a constant voltage) while only IN+ is allowed
209 to swing. A pseudo-differential channel can be made out from a differential pair
210 of inputs by restricting the negative input to a known voltage while allowing
211 only the positive input to swing. Sometimes, the input provided to IN- is called
212 common-mode voltage. Besides, some parts have a COM pin that allows single-ended
213 inputs to be referenced to a common-mode voltage, making them
214 pseudo-differential channels. Often, the common mode input voltage can be
215 described in the device tree as a voltage regulator (e.g. ``com-supply``) since
216 it is basically a constant voltage source.
217
218 1.3.1 Pseudo-differential Unipolar Channels
219 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
220
221 ::
222
223 -------- +VREF ------ +-------------------+
224 ´ ` ´ ` / |
225 / \ / \ / --- < IN+ |
226 `-´ `-´ | |
227 --------- IN- ------- | ADC |
228 | |
229 Common-mode voltage --> --- < IN- |
230 \ +VREF -VREF |
231 +-------------------+
232 ^ ^
233 | +---- External -VREF
234 External +VREF
235
236 A **pseudo-differential unipolar** input has the limitations a differential
237 unipolar channel would have, meaning the analog voltage to the positive input
238 IN+ must stay within IN- to +VREF. The fixed voltage to IN- is often called
239 common-mode voltage and it must be within -VREF to +VREF as would be expected
240 from the signal to any differential channel negative input.
241
242 The voltage measured from IN+ is relative to IN- but, unlike differential
243 channels, pseudo-differential setups are intended to gauge single-ended input
244 signals. To enable applications to calculate IN+ voltage with respect to system
245 ground, the IIO channel may provide an ``_offset`` sysfs attribute to be added
246 to ADC output when converting raw data to voltage units. In many setups, the
247 common-mode voltage input is at GND level and the ``_offset`` attribute is
248 omitted due to being always zero.
249
250 Device tree example for pseudo-differential unipolar channel::
251
252 adc@0 {
253 ...
254 #address-cells = <1>;
255 #size-cells = <0>;
256
257 channel@0 {
258 reg = <0>;
259 single-channel = <0>;
260 common-mode-channel = <1>;
261 };
262 };
263
264 Do not set ``differential`` in the channel ``iio_chan_spec`` struct of
265 pseudo-differential channels.
266
267 1.3.2 Pseudo-differential Bipolar Channels
268 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
269
270 ::
271
272 -------- +VREF ------ +-------------------+
273 ´ ` ´ ` / |
274 / \ / \ / --- < IN+ |
275 `-´ `-´ | |
276 -------- -VREF ------ | ADC |
277 | |
278 Common-mode voltage --> --- < IN- |
279 \ +VREF -VREF |
280 +-------------------+
281 ^ ^
282 | +---- External -VREF
283 External +VREF
284
285 A **pseudo-differential bipolar** input is not limited by the level at IN- but
286 it will be limited to -VREF or to GND on the lower end of the input range
287 depending on the particular ADC. Similar to their unipolar counter parts,
288 pseudo-differential bipolar channels ought to declare an ``_offset`` attribute
289 to enable the conversion of raw ADC data to voltage units. For the setup with
290 IN- connected to GND, ``_offset`` is often omitted.
291
292 Device tree example for pseudo-differential bipolar channel::
293
294 adc@0 {
295 ...
296 #address-cells = <1>;
297 #size-cells = <0>;
298
299 channel@0 {
300 reg = <0>;
301 bipolar;
302 single-channel = <0>;
303 common-mode-channel = <1>;
304 };
305 };