A driver for the analog-digital converters available on the microcontroller. More...
#include <analog_digital_converter.h>
Public Member Functions | |
uint8_t | add_channel (uint8_t channel) |
Adds a channel to the list that is scanned. More... | |
uint8_t | get_current_channel_count () const |
Checks the number of used channels. If this exceeds CHANNEL_COUNT, stuff will break. More... | |
void | init (const ADCHardwareStruct *adc_def) |
Initializes the ADC according to the definition struct provided. More... | |
bool | is_initialized () const |
Checks if the adc has been initialized, i.e. init has been called. More... | |
uint16_t | read (uint8_t index) const |
Reads a single channel. More... | |
Static Public Attributes | |
static constexpr uint8_t | CHANNEL_COUNT {16} |
static constexpr uint16_t | NO_READING {0xFFFF} |
static constexpr uint16_t | RAW_READING_MAX {0xFFF} |
static constexpr double | REFERENCE_VOLTAGE {3.3} |
Private Member Functions | |
void | init_dma () |
void | start_dma () |
Private Attributes | |
const ADCHardwareStruct * | adc_def_ |
volatile uint32_t | buffer [CHANNEL_COUNT] |
uint8_t | current_channels |
bool | is_initialized_ {false} |
Static Private Attributes | |
static constexpr uint32_t | SQR1_CHANNEL_COUNT_MASK {~0xFF0FFFFF} |
static constexpr uint8_t | SQR1_CHANNEL_COUNT_OFFSET {20} |
A driver for the analog-digital converters available on the microcontroller.
Besides initialization, it is most convenient to work with the ADC with the AnalogPin class, which handles adding channels and reading results.
Definition at line 42 of file analog_digital_converter.h.
uint8_t AnalogDigitalConverter::add_channel | ( | uint8_t | channel | ) |
Adds a channel to the list that is scanned.
This returns the index assigned to the channel, which is needed to read it later This method does not check for errors. Do not add more than CHANNEL_COUNT channels, by calling add_channel more than CHANNEL_COUNT times
channel | The index of the channel to be read |
Definition at line 95 of file analog_digital_converter.cpp.
uint8_t AnalogDigitalConverter::get_current_channel_count | ( | ) | const |
Checks the number of used channels. If this exceeds CHANNEL_COUNT, stuff will break.
Definition at line 124 of file analog_digital_converter.cpp.
void AnalogDigitalConverter::init | ( | const ADCHardwareStruct * | adc_def | ) |
Initializes the ADC according to the definition struct provided.
A | hardware struct defining the resources for the ADC |
Definition at line 34 of file analog_digital_converter.cpp.
|
private |
Definition at line 65 of file analog_digital_converter.cpp.
bool AnalogDigitalConverter::is_initialized | ( | ) | const |
Checks if the adc has been initialized, i.e. init has been called.
Definition at line 115 of file analog_digital_converter.cpp.
uint16_t AnalogDigitalConverter::read | ( | uint8_t | index | ) | const |
Reads a single channel.
The reading is between 0 and RAW_READING_MAX. 0 represents 0V, and RAW_READING_MAX represents REFERENCE_VOLTAGE (typically 3.3V). Takes the index of the channel as a parameter, which is returned from add_channel
index | The index of the channel to be read. |
Definition at line 119 of file analog_digital_converter.cpp.
|
private |
Definition at line 111 of file analog_digital_converter.cpp.
|
private |
Definition at line 102 of file analog_digital_converter.h.
|
private |
Definition at line 110 of file analog_digital_converter.h.
|
static |
The maximum number of channels on a single ADC. Hardware-dependent
Definition at line 99 of file analog_digital_converter.h.
|
private |
Definition at line 104 of file analog_digital_converter.h.
|
private |
Definition at line 103 of file analog_digital_converter.h.
|
static |
A value indicating that the channel value has not yet been read by the ADC. If you get this for more than just the startup time, your channel may not be initialized
Definition at line 95 of file analog_digital_converter.h.
|
static |
The maximum reading from a channel. This reading corresponds to REFERENCE_VOLTAGE volts.
Definition at line 90 of file analog_digital_converter.h.
|
static |
The reference voltage used for the ADC, which is hardware-dependent. Unit is volts.
Definition at line 86 of file analog_digital_converter.h.
|
staticprivate |
Definition at line 107 of file analog_digital_converter.h.
|
staticprivate |
Definition at line 108 of file analog_digital_converter.h.