modm API documentation
modm::platform::Adc Class Reference

#include <modm/platform/adc/adc.hpp>

Inheritance diagram for modm::platform::Adc:
modm::Adc modm::PeripheralDriver modm::platform::AdcInterrupt

Public Typedefs

typedef uint8_t Channel
 
- Public Typedefs inherited from modm::Adc
typedef uint8_t Channel
 this type may also be an enum or enum class
 

Public Types

enum  Reference : uint8_t {
  InternalVcc = 0, ExternalRef = (1 << REFS0), Internal1V1 = (1 << REFS1), Internal2V56 = (1 << REFS2) | (1 << REFS1),
  Internal2V56WithCap = (1 << REFS2) | (1 << REFS1) | (1 << REFS0)
}
 
enum  InterruptFlag : uint8_t { All = (1<<ADIF) }
 

Public Member Functions

 MODM_FLAGS8 (InterruptFlag)
 

Static Public Member Functions

template<class... Signals>
static void connect ()
 
template<class SystemClock , frequency_t frequency = kHz(100), percent_t tolerance = pct(10)>
static void initialize ()
 
static void disable ()
 
static void startConversion ()
 
static bool isConversionFinished ()
 
static uint16_t getValue ()
 
static uint16_t readChannel (Channel channel)
 
static bool setChannel (Channel channel)
 
static uint8_t getChannel ()
 
static void enableFreeRunningMode ()
 
static void diableFreeRunningMode ()
 
static void setLeftAdjustResult ()
 
static void setRightAdjustResult ()
 
static void setReference (Reference reference)
 
static void enableInterrupt ()
 Enables the ADC Conversion Complete Interrupt.
 
static void disableInterrupt ()
 Disables the ADC Conversion Complete Interrupt.
 
static bool getInterruptFlag ()
 
static InterruptFlag_t getInterruptFlags ()
 
static void acknowledgeInterruptFlag ()
 Clears the interrupt flag.
 
static void acknowledgeInterruptFlags (const InterruptFlag_t flags)
 Clears the interrupt flag if flags is set to InterruptFlag::All
 
static void enableAutoTrigger ()
 
static void disableAutoTrigger ()
 disable auto triggering of the ADC
 
static void setAutoTriggerSource (uint8_t source)
 
- Static Public Member Functions inherited from modm::Adc
template<class... Signals>
static void connect ()
 
template<class SystemClock , frequency_t frequency = 200_kHz, percent_t tolerance = 10_pct>
static void initialize ()
 
static void disable ()
 
static void startConversion ()
 
static bool isConversionFinished ()
 
static uint16_t getValue ()
 
static uint16_t readChannel (Channel channel)
 
static bool setChannel (Channel channel)
 
static uint8_t getChannel ()
 
static void enableFreeRunningMode ()
 
static void disableFreeRunningMode ()
 
static void setLeftAdjustResult ()
 Change the presentation of the ADC conversion result to left adjusted.
 
static void setRightAdjustResult ()
 Change the presentation of the ADC conversion result to right adjusted.
 
- Static Public Member Functions inherited from modm::PeripheralDriver
static void initialize ()
 initializes the peripheral, must be called before use.
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
static void setParameter ()
 sets a parameter
 
static void getParameter ()
 returns a parameter
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static void acknowledgeInterruptFlag ()
 
template<baudrate_t available, baudrate_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 

Static Public Attributes

static constexpr uint8_t Resolution = 10
 
- Static Public Attributes inherited from modm::Adc
static constexpr uint8_t Resolution
 describes the maximum resolution in bits
 

Detailed Description

Generic Analog/Digital-Converter module

This class aims at providing a common interface to all the different register layouts of the ADC modules in most ATtinys. It takes into consideration restrictions and extensions in ADC functionality and provides the appropriate methods to configure them.

This class enables you to address and use a broader array of ATtinys with similar ADC functionality without changing a single line of code.

For best use of this class, check your device's datasheet for the supported functionality.

ADC clock frequency should be between 50 and 200 kHz for maximum resolution. If less than the full resolution of 10 bits are needed the frequency can be higher.

Author
Niklas Hauser

Member Function Documentation

static void modm::platform::Adc::enableAutoTrigger ( )
inlinestatic

Enable auto triggering of the ADC

The ADC will start a conversion on a positive edge of the selected trigger signal.

See also
setAutoTriggerSource
static bool modm::platform::Adc::getInterruptFlag ( )
inlinestatic
Returns
true if the conversion complete flag is set, false otherwise
static InterruptFlag_t modm::platform::Adc::getInterruptFlags ( )
inlinestatic
Returns
InterruptFlag::All if the flag is set, 0 otherwise
static uint16_t modm::platform::Adc::readChannel ( Channel  channel)
inlinestatic

Read the value an analog channel

A normal conversion takes 13 ADC clock cycles. With a clock frequency of for example 200 kHz a conversion therefore needs 65 microseconds. This time increases with a lower frequency.

static void modm::platform::Adc::setAutoTriggerSource ( uint8_t  source)
inlinestatic

Selects which source will trigger an ADC conversion

A conversion will be triggered by the rising edge of the selected Interrupt Flag. Note that switching from a trigger source that is cleared to a trigger source that is set, will generate a positive edge on the trigger signal. Set to 0 to enable Free Running Mode.

static void modm::platform::Adc::setReference ( Reference  reference)
inlinestatic

Voltage reference for the ADC

The internal voltage reference options may not be used if an external reference voltage is being applied to the AREF pin.


The documentation for this class was generated from the following file: