Driver for the on-board MAX11635 12-bit ADC (U5). More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Functions | |
| void | max11635::begin () |
| Configures SPI0 and the control pins, resets the ADC and applies the averaging setting. Safe to call again. | |
| void | max11635::setAveraging (uint8_t samples) |
| Sets how many conversions the chip averages for each result. | |
| uint8_t | max11635::averaging () |
| Current averaging setting. | |
| uint16_t | max11635::read (uint8_t channel) |
| Runs one conversion (averaged if setAveraging() is on). | |
| bool | max11635::scan (uint8_t last_channel, uint16_t *results) |
| Converts channels 0 to last_channel in one scan, a few µs apart. | |
| bool | max11635::readDifferential (uint8_t pair, bool bipolar, int16_t *code) |
| True differential conversion of a channel pair, both inputs sampled at once. | |
| uint32_t | max11635::startBurst (uint8_t channel, uint16_t *buffer, size_t count, uint32_t sample_rate_hz) |
| Starts sampling one channel at a fixed rate into buffer, in the background. | |
| bool | max11635::burstDone () |
| Whether the burst has finished; tidies up the chip and SPI when it has. | |
| void | max11635::stopBurst () |
| Stops a running burst; the buffer's contents are then not valid. | |
Driver for the on-board MAX11635 12-bit ADC (U5).
Used by variant.cpp for A3-A5, so sketches normally use the core's analog functions (analogRead(), analogReadAveraging(), analogReadBurst(), ...), which work the same on every analog pin. This header is the chip-level interface underneath, by channel: 0-2 are A3-A5, 3 measures VBUS.
Configuration: external 2.048 V reference (LM4040, U7), unipolar single-ended inputs, conversions timed internally and started by a CNVST pulse (clock mode 00); EOC goes low when the results are in the chip's 16-entry FIFO. Bursts above kMaxTimedBurstHz switch to clock mode 11 (the SPI clock times the conversions) for their duration. Pins are in pins_arduino.h (PHYDUINO_EXT_ADC_*).
| uint8_t max11635::averaging | ( | ) |
Current averaging setting.
| bool max11635::burstDone | ( | ) |
Whether the burst has finished; tidies up the chip and SPI when it has.
| uint16_t max11635::read | ( | uint8_t | channel | ) |
Runs one conversion (averaged if setAveraging() is on).
| channel | Input 0-3 (0-2 are A3-A5, 3 is VBUS). |
| bool max11635::readDifferential | ( | uint8_t | pair, |
| bool | bipolar, | ||
| int16_t * | code ) |
True differential conversion of a channel pair, both inputs sampled at once.
Pair 0 is AIN0 - AIN1 (A3 - A4); pair 1 is AIN2 - AIN3 (A5 - VBUS monitor). The pair is set back to single-ended afterwards.
| pair | 0 or 1. |
| bipolar | false: unipolar, 0 to 2.048 V (a negative difference reads 0); true: bipolar, -1.024 V to +1.024 V. |
| code | Result: 0-4095 unipolar, -2048 to 2047 bipolar (0.5 mV steps). |
| bool max11635::scan | ( | uint8_t | last_channel, |
| uint16_t * | results ) |
Converts channels 0 to last_channel in one scan, a few µs apart.
| last_channel | Highest channel, 0-3. |
| results | Array of last_channel + 1 values, 0-4095. |
| void max11635::setAveraging | ( | uint8_t | samples | ) |
Sets how many conversions the chip averages for each result.
Applies to read(), scan() and readDifferential(); not to bursts.
| samples | 1 (off), 4, 8, 16 or 32; other values use the next lower one. |
| uint32_t max11635::startBurst | ( | uint8_t | channel, |
| uint16_t * | buffer, | ||
| size_t | count, | ||
| uint32_t | sample_rate_hz ) |
Starts sampling one channel at a fixed rate into buffer, in the background.
Up to kMaxTimedBurstHz a repeating timer interrupt starts each conversion; above, up to kMaxBurstHz, the SPI clock times the conversions and DMA moves the data. Averaging is off during a burst. Other calls into this driver wait until the burst has finished.
| channel | Input 0-3. |
| buffer | Array for count 12-bit samples; must stay valid until burstDone(). |
| count | Number of samples. |
| sample_rate_hz | Samples per second, 1 to kMaxBurstHz. |