Chrispy
High-performance multichannel ADC sampling and audio recording.
Loading...
Searching...
No Matches
Adc.cpp File Reference
#include "Adc.h"
#include <Arduino.h>
#include <SdFat.h>
#include <stddef.h>
#include <stdint.h>

Data Structures

struct  adc::AdcFrame
 Private/static data member for use by the ISR.
 
struct  adc::Adc
 Singleton instance of the ADC.
 

Namespaces

namespace  adc
 

Macros

#define TEN_BIT_BIAS   0x1FF
 
#define TEN_TO_SIXTEEN_BIT(x)   (((x) - TEN_BIT_BIAS) << 6)
 
#define MUX_MASK   0b11111
 
#define SOURCE_MASK   0b111
 
#define LOW_CHANNEL_MASK   0b111
 
#define HIGH_CHANNEL_MASK   ~LOW_CHANNEL_MASK
 
#define PRESCALER_MASK   0b111
 
#define DIV_128   0b111
 
#define DIV_64   0b110
 
#define DIV_32   0b101
 
#define DIV_16   0b100
 
#define DIV_8   0b011
 
#define DIV_4   0b010
 
#define DIV_2   0b001
 
#define DIV_2_2   0b000
 
#define MIN_BUF_SZ_PER_CHANNEL   512
 
#define ADC_CYCLES_PER_SAMPLE   13.5
 

Functions

 adc::ISR (ADC_vect)
 Interrupt service routine responsible for reading samples from the ADC.
 
int8_t adc::drain_buffer (uint8_t **buf, size_t &sz, size_t &ch_index)
 NOT SAFE TO USE WHEN THE ADC IS ENABLED!
 
int8_t adc::swap_buffer (uint8_t **buf, size_t &sz, size_t &ch_index)
 Retrieve a buffer from the module belonging to a specific channel, writing the size and channel index to the reference arguments.
 
bool adc::init (uint8_t _nchannels, Channel *_channels, uint8_t *_buf, size_t _sz)
 Initialize ADC module with these parameters for sampling.
 
void adc::on ()
 Activate internal board's ADC.
 
void adc::off ()
 Turn off ADC.
 
void adc::sleep ()
 Turn off ADC and enter sleep mode.
 
int8_t adc::start (BitResolution res, uint32_t sample_rate, size_t ch_window_sz=1, uint32_t warmup_ms=100)
 Start ADC sampling at a certain rate with a given bit resolution.
 
uint32_t adc::collected ()
 
uint32_t adc::stop ()
 Stops ADC sampling and performs cleanup on registers.
 
size_t adc::bytes_per_sample (BitResolution res)
 

Variables

const size_t adc::MAX_CHANNEL_COUNT = 16
 Number of channels supported by the ADC (0 - 15).
 

Macro Definition Documentation

◆ ADC_CYCLES_PER_SAMPLE

#define ADC_CYCLES_PER_SAMPLE   13.5

◆ DIV_128

#define DIV_128   0b111

◆ DIV_16

#define DIV_16   0b100

◆ DIV_2

#define DIV_2   0b001

◆ DIV_2_2

#define DIV_2_2   0b000

◆ DIV_32

#define DIV_32   0b101

◆ DIV_4

#define DIV_4   0b010

◆ DIV_64

#define DIV_64   0b110

◆ DIV_8

#define DIV_8   0b011

◆ HIGH_CHANNEL_MASK

#define HIGH_CHANNEL_MASK   ~LOW_CHANNEL_MASK

◆ LOW_CHANNEL_MASK

#define LOW_CHANNEL_MASK   0b111

◆ MIN_BUF_SZ_PER_CHANNEL

#define MIN_BUF_SZ_PER_CHANNEL   512

◆ MUX_MASK

#define MUX_MASK   0b11111

◆ PRESCALER_MASK

#define PRESCALER_MASK   0b111

◆ SOURCE_MASK

#define SOURCE_MASK   0b111

◆ TEN_BIT_BIAS

#define TEN_BIT_BIAS   0x1FF

◆ TEN_TO_SIXTEEN_BIT

#define TEN_TO_SIXTEEN_BIT (   x)    (((x) - TEN_BIT_BIAS) << 6)