Loading...
Searching...
No Matches
max11635.h File Reference

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.

Variables

constexpr uint8_t max11635::kChannels = 4
 Number of input channels (AIN0-AIN3).
constexpr uint32_t max11635::kMaxTimedBurstHz = 20000
 Fastest burst taken with a timer interrupt (clock mode 00), in samples per second.
constexpr uint32_t max11635::kMaxBurstHz = 300000
 Fastest burst (clock mode 11, SCLK = 16 x rate, at most 4.8 MHz), in samples per second.

Detailed Description

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_*).

Function Documentation

◆ averaging()

uint8_t max11635::averaging ( )

Current averaging setting.

Returns
1, 4, 8, 16 or 32.

◆ burstDone()

bool max11635::burstDone ( )

Whether the burst has finished; tidies up the chip and SPI when it has.

Returns
true once every sample is in the buffer (and when no burst was started).

◆ read()

uint16_t max11635::read ( uint8_t channel)

Runs one conversion (averaged if setAveraging() is on).

Parameters
channelInput 0-3 (0-2 are A3-A5, 3 is VBUS).
Returns
0-4095 (0 V to 2.048 V), or 0 if the ADC does not respond.

◆ readDifferential()

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.

Parameters
pair0 or 1.
bipolarfalse: unipolar, 0 to 2.048 V (a negative difference reads 0); true: bipolar, -1.024 V to +1.024 V.
codeResult: 0-4095 unipolar, -2048 to 2047 bipolar (0.5 mV steps).
Returns
false if the arguments are invalid or the ADC does not respond.

◆ scan()

bool max11635::scan ( uint8_t last_channel,
uint16_t * results )

Converts channels 0 to last_channel in one scan, a few µs apart.

Parameters
last_channelHighest channel, 0-3.
resultsArray of last_channel + 1 values, 0-4095.
Returns
false if the arguments are invalid or the ADC does not respond.

◆ setAveraging()

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.

Parameters
samples1 (off), 4, 8, 16 or 32; other values use the next lower one.

◆ startBurst()

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.

Parameters
channelInput 0-3.
bufferArray for count 12-bit samples; must stay valid until burstDone().
countNumber of samples.
sample_rate_hzSamples per second, 1 to kMaxBurstHz.
Returns
Rate used in Hz (it can differ slightly from the one asked for), or 0 if the arguments are invalid or a burst is already running.