Skip to content

Commit c9cf11d

Browse files
author
Randall Smith
committed
Bit more work on ADC section
1 parent bb0b5e0 commit c9cf11d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

docs/how-to-use/io.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,44 @@ Bus I/O is useful for implementing parallel interfaces, where the bits of a numb
186186
This means that the Bus I/O classes are not currently suitable for implementing high speed parallel busses (~MHz clock rate). There are some options to fix this in Mbed, but for now if you need this capability you'll have to access the I/O registers directly.
187187

188188
### Interrupts
189+
190+
189191
## Analog Inputs
190192
If you want to read an analog signal on your target board, you'll need to do things a bit differently. Analog inputs can be read using the [AnalogIn](https://mbed-ce.github.io/mbed-os/classmbed_1_1_analog_in.html) class, which is a wrapper around your chip's Analog-Digital Converter (ADC) peripheral.
191193

192194
We'll first briefly go over how ADCs work and what you should be aware of when using them, and then we'll show how to actually use the ADC in Mbed!
193195
### ADC Basics
196+
194197
#### Bits
195-
ADCs are often referred to as n-Bit, e.g. 12-bit or 16-bit. This refers to how many bits of binary number your ADC produces. A 12-bit ADC can produce numbers between 0 and 4095 (2^12-1), and a 16-bit ADC can produce numbers between 0 and 65535 (2^16-1).
198+
ADCs are often referred to as n-Bit, e.g. 12-bit or 16-bit. This refers to how many bits of binary number your ADC produces. For example, a 12-bit ADC can produce numbers between 0 and 4095 (2^12-1), and a 16-bit ADC can produce numbers between 0 and 65535 (2^16-1).
196199

197200
Broadly speaking, an ADC with more bits has higher resolution and produces a more precise output (though that's not the complete picture, as we'll see below).
198201

199202
#### ADC Types
200-
There are three types of ADCs in common usage: Flash, Successive Approximation Register (SAR), and Sigma-Delta.
203+
There are three types of ADCs in common usage: Sigma-Delta, Flash, and Successive Approximation Register (SAR).
204+
205+
##### Sigma-Delta
206+
207+
Sigma-Delta ADCs have the highest resolution of all types, but are relatively slow to operate and are almost never seen integrated into microcontrollers.
208+
209+
##### Flash
201210

202-
Sigma-Delta ADCs are the most accurate, but are more complicated and are almost never seen in microcontrollers.
211+
Flash ADCs work by essentially comparing the value against 2^n analog voltages using 2^n comparators for n bits. As you might imagine, this is the fastest type of ADC as it only takes one clock cycle to go from analog value to digital code. However, the circuitry required for a flash ADC grows exponentially with the number of bits, so they are rarely seen in resolutions above 8 bits. (more info [here](https://www.allaboutcircuits.com/textbook/digital/chpt-13/flash-adc/))
203212

204-
Flash ADCs work by ess
213+
##### Successive Approximation Register (SAR)
214+
215+
![SAR ADC block diagram](https://www.mathworks.com/help/msblks/ref/model_sar_adc_arch.png)
216+
217+
SAR ADCs consist of a sample-and-hold circuit, a digital-analog converter, and a comparator, and they work using essentially a binary search. The sample-and-hold circuit latches the incoming analog value and keeps it stable. Then, a series of voltages are generated by the digital-analog converter and compared against the input. It starts with half the reference voltage, then 0.25x or 0.75x the reference voltage, etc. From there, the ADC does a binary search in order to narrow down the analog voltage to the nearest bit of the output code.
218+
219+
SAR ADCs are a good compromise option as they can be made with fairly high resolution without being too complex -- resolutions of 12 to 16 bits are common, which is enough for most real analog signals. Increasing the resolution (which is frequently software-configurable) does increase the conversion time, but SAR ADCs can still operate quite quickly -- sample rates between 100kHz and 10MHz are common.
220+
221+
The large majority of Mbed microcontrollers that have ADCs use SAR ADCs, so it's important to understand both the hardware and the software configuration in order to see how accurate your analog inputs really are.
205222

206223
#### Voltage References
224+
207225
#### Accuracy/ENOB
226+
208227
#### Conversion Time
209228
#### Aliasing
210229
### Using `AnalogIn`

0 commit comments

Comments
 (0)