ADC  8.0
ADC_Module.h File Reference
#include <Arduino.h>
#include <atomic.h>

Go to the source code of this file.

Classes

class  ADC_Module
 
struct  ADC_Module::ADC_NLIST
 Dictionary with the differential pins as keys and the SC1A number as values. More...
 
struct  ADC_Module::ADC_Config
 Store the config of the adc. More...
 

Macros

#define ADC_TEENSY_3_1
 
#define ADC_NUM_ADCS   (2)
 
#define ADC_USE_DMA   (1)
 
#define ADC_USE_PGA   (1)
 
#define ADC_USE_PDB   (1)
 
#define ADC_USE_INTERNAL_VREF   (1)
 
#define ADC_MAX_PIN   (43)
 
#define ADC_DIFF_PAIRS   (2)
 
#define ADC_SC1A_CHANNELS   (0x1F)
 
#define ADC_SC1A_PIN_INVALID   (0x1F)
 
#define ADC_SC1A_PIN_MUX   (0x80)
 
#define ADC_SC1A_PIN_DIFF   (0x40)
 
#define ADC_SC1A_PIN_PGA   (0x80)
 
#define ADC_ERROR_DIFF_VALUE   (-70000)
 
#define ADC_ERROR_VALUE   ADC_ERROR_DIFF_VALUE
 
#define ADC_debug   0
 
#define ADC_CFG1_ADIV_MASK_1   (1<<6)
 
#define ADC_CFG1_ADIV_MASK_0   (1<<5)
 
#define ADC_CFG1_MODE_MASK_1   (1<<3)
 
#define ADC_CFG1_MODE_MASK_0   (1<<2)
 
#define ADC_CFG1_ADICLK_MASK_1   (1<<1)
 
#define ADC_CFG1_ADICLK_MASK_0   (1<<0)
 
#define ADC_CFG2_ADLSTS_MASK_1   (1<<1)
 
#define ADC_CFG2_ADLSTS_MASK_0   (1<<0)
 
#define ADC_SC2_REFSEL_MASK_0   (1<<0)
 
#define ADC_SC3_AVGS_MASK_1   (1<<1)
 
#define ADC_SC3_AVGS_MASK_0   (1<<0)
 
#define ADC_PDB_CONFIG
 
#define PDB_CHnC1_TOS_1   0x0100
 
#define PDB_CHnC1_EN_1   0x01
 

Enumerations

enum  ADC_REF_SOURCE : uint8_t { REF_DEFAULT = 0, REF_ALT = 1, REF_NONE = 2 }
 
enum  ADC_REFERENCE : uint8_t { ADC_REFERENCE::REF_3V3 = ADC_REF_SOURCE::REF_DEFAULT, ADC_REFERENCE::REF_1V2 = ADC_REF_SOURCE::REF_ALT, ADC_REFERENCE::REF_EXT = ADC_REF_SOURCE::REF_DEFAULT, NONE = ADC_REF_SOURCE::REF_NONE }
 
enum  ADC_INTERNAL_SOURCE : uint8_t {
  ADC_INTERNAL_SOURCE::TEMP_SENSOR = 38, ADC_INTERNAL_SOURCE::VREF_OUT = 39, ADC_INTERNAL_SOURCE::BANDGAP = 41, ADC_INTERNAL_SOURCE::VREFH = 42,
  ADC_INTERNAL_SOURCE::VREFL = 43
}
 
enum  ADC_CONVERSION_SPEED : uint8_t {
  ADC_CONVERSION_SPEED::VERY_LOW_SPEED, ADC_CONVERSION_SPEED::LOW_SPEED, ADC_CONVERSION_SPEED::MED_SPEED, ADC_CONVERSION_SPEED::HIGH_SPEED_16BITS,
  ADC_CONVERSION_SPEED::HIGH_SPEED, ADC_CONVERSION_SPEED::VERY_HIGH_SPEED, ADC_CONVERSION_SPEED::ADACK_2_4, ADC_CONVERSION_SPEED::ADACK_4_0,
  ADC_CONVERSION_SPEED::ADACK_5_2, ADC_CONVERSION_SPEED::ADACK_6_2
}
 
enum  ADC_SAMPLING_SPEED : uint8_t {
  ADC_SAMPLING_SPEED::VERY_LOW_SPEED, ADC_SAMPLING_SPEED::LOW_SPEED, ADC_SAMPLING_SPEED::MED_SPEED, ADC_SAMPLING_SPEED::HIGH_SPEED,
  ADC_SAMPLING_SPEED::VERY_HIGH_SPEED
}
 
enum  ADC_ERROR : uint16_t {
  ADC_ERROR::OTHER = 1<<0, ADC_ERROR::CALIB = 1<<1, ADC_ERROR::WRONG_PIN = 1<<2, ADC_ERROR::ANALOG_READ = 1<<3,
  ADC_ERROR::ANALOG_DIFF_READ = 1<<4, ADC_ERROR::CONT = 1<<5, ADC_ERROR::CONT_DIFF = 1<<6, ADC_ERROR::COMPARISON = 1<<7,
  ADC_ERROR::WRONG_ADC = 1<<8, ADC_ERROR::SYNCH = 1<<9, ADC_ERROR::CLEAR = 0
}
 ADC errors. More...
 

Functions

constexpr ADC_ERROR operator| (ADC_ERROR lhs, ADC_ERROR rhs)
 OR operator for ADC_ERRORs.
 
constexpr ADC_ERROR operator& (ADC_ERROR lhs, ADC_ERROR rhs)
 AND operator for ADC_ERRORs.
 
ADC_ERROR operator|= (volatile ADC_ERROR &lhs, ADC_ERROR rhs)
 |= operator for ADC_ERRORs, it changes the left hand side ADC_ERROR.
 
ADC_ERROR operator&= (volatile ADC_ERROR &lhs, ADC_ERROR rhs)
 &= operator for ADC_ERRORs, it changes the left hand side ADC_ERROR.
 

Macro Definition Documentation

#define ADC_PDB_CONFIG
Value:
(PDB_SC_TRGSEL(15) | PDB_SC_PDBEN | PDB_SC_PDBIE \
| PDB_SC_CONT | PDB_SC_LDMOD(0))

Enumeration Type Documentation

enum ADC_CONVERSION_SPEED : uint8_t
strong

ADC conversion speed. Common set of options to select the ADC clock speed F_ADCK, which depends on F_BUS, except for the ADACK_X_Y options that are independent. This selection affects the sampling speed too. Note: the F_ADCK speed is not equal to the conversion speed; any measurement takes several F_ADCK cycles to complete including the sampling and conversion steps.

Enumerator
VERY_LOW_SPEED 

is guaranteed to be the lowest possible speed within specs for resolutions less than 16 bits (higher than 1 MHz).

LOW_SPEED 

is guaranteed to be the lowest possible speed within specs for all resolutions (higher than 2 MHz).

MED_SPEED 

is always >= LOW_SPEED and <= HIGH_SPEED.

HIGH_SPEED_16BITS 

is guaranteed to be the highest possible speed within specs for all resolutions (lower than or equal to 12 MHz).

HIGH_SPEED 

is guaranteed to be the highest possible speed within specs for resolutions less than 16 bits (lower than or equal to 18 MHz), except for Teensy 3.6 (NOT 3.5), for which the maximum is 24 MHz.

VERY_HIGH_SPEED 

may be out of specs

ADACK_2_4 

2.4 MHz asynchronous ADC clock (independent of the global clocks F_CPU or F_BUS)

ADACK_4_0 

4.0 MHz asynchronous ADC clock (independent of the global clocks F_CPU or F_BUS)

ADACK_5_2 

5.2 MHz asynchronous ADC clock (independent of the global clocks F_CPU or F_BUS)

ADACK_6_2 

6.2 MHz asynchronous ADC clock (independent of the global clocks F_CPU or F_BUS)

enum ADC_ERROR : uint16_t
strong

ADC errors.

Use adc->printError() to print the errors (if any) in a human-readable form. Use adc->resetError() to reset them.

Enumerator
OTHER 

Other error not considered below.

CALIB 

Calibration error.

WRONG_PIN 

A pin was selected that cannot be read by this ADC module.

ANALOG_READ 

Error inside the analogRead method.

ANALOG_DIFF_READ 

Error inside the analogReadDifferential method.

CONT 

Continuous single-ended measurement error.

CONT_DIFF 

Continuous differential measurement error.

COMPARISON 

Error during the comparison.

WRONG_ADC 

A non-existent ADC module was selected.

SYNCH 

Error during a synchronized measurement.

CLEAR 

No error.

enum ADC_INTERNAL_SOURCE : uint8_t
strong

Other ADC sources to measure, such as the temperature sensor.

Enumerator
TEMP_SENSOR 

Temperature sensor.

VREF_OUT 

1.2 V reference

BANDGAP 

BANDGAP

VREFH 

High VREF

VREFL 

Low VREF.

enum ADC_REFERENCE : uint8_t
strong

Reference for the ADC

Enumerator
REF_3V3 

3.3 volts

REF_1V2 

1.2 volts

REF_EXT 

External VREF

enum ADC_SAMPLING_SPEED : uint8_t
strong

ADC sampling speed. It selects how many ADCK clock cycles to add.

Enumerator
VERY_LOW_SPEED 

is the lowest possible sampling speed (+24 ADCK).

LOW_SPEED 

adds +16 ADCK.

MED_SPEED 

adds +10 ADCK.

HIGH_SPEED 

adds +6 ADCK.

VERY_HIGH_SPEED 

is the highest possible sampling speed (0 ADCK added).