Maple Reference Documentation

# Maple Reference Documentation: ADC

Analog-Digital Conversion is the process of reading a physical voltage as a number. The Maple has a large number of pins which are capable of taking 12-bit ADC measurements, which means that voltages from ground to +3.3v are read as numbers from 0 to 4095; this corresponds to a theoretical sensitivity of just under 1 millivolt. In reality, a number of factors introduce noise and bias into this reading and a number of techniques must be used to get good precision and accuracy.

Header pins with ADC functionality (marked as "AIN" on the silkscreen):

    D0,D1,D2,D3,D10,D11,D12,D13,D15,D16,D17,D18,D19,D20,D27,D28

- Noise and Bias
- Function Reference
- Recommended Reading

## Noise and Bias

The biggest issues with analog-digital conversion are noise and bias. With the Maple we have tried to isolate the ADC pins and traces from strong noise sources but there are always trade-offs between noise, additional functionality, cost, and package size.

The 6 ADC pins in a bank (D15-D20) generally have the least noise and should be used for fine measurements. If the input voltage is relatively slow to change, a number of samples can be taken in succession and averaged together, or the same voltage can even be sampled by multiple ADC pins at the same time.

An important factor when taking a voltage reading is the reference voltages that the sample is being compared against. In the case of the Maple, the high reference is Vcc and the low reverence is ground: this means that noise or fluctuations on either Vcc or ground will effect the measurement. It also means that the voltage you are trying to sample must be between ground and 3.3v. In the case of a variable reading, it is best if the voltage varies over the entire range of 0-3.3v; otherwise only a fraction of the sensitivity is being leveraged. Resistor dividers and constant voltage diodes are basic tools which can help bring a given voltage signal into the appropriate range; opamps and other powered components can also be used.

## Function Reference

`pinMode(pin_num, INPUT_ANALOG)`
  This function is usually called from `setup()` to configure the pin hardware for analog sampling.
`analogRead(pin_num)`
  Returns the voltage read as a number with 4095 corresponding to Vref (about 3.3v) and 0 corresponding to ground.

## Recommended Reading

- Wikipedia article on Analog-to-digital converter
- Arduino Analog Input Tutorial
- STMicro documentation for STM32F103RB microcontroller:
  - All
  - Datasheet (pdf)
  - Reference Manual (pdf)
  - Application Note on ADC Modes (pdf)
  - Application Note on ADC Oversampling (pdf)

### About this Document

A more recent version of this document may be available from the LeafLabs website. Our documentation is versioned on github; you can track changes to the master branch at this link.

This documentation is released under a Creative Commons Attribution-Share Alike 3.0 license.

Translations are welcomed; give us a ping to make sure we aren't in the process of revising or editing first.