modm API documentation
modm::platform::AdcInterrupt1 Class Reference

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

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

Public Types

enum  Channel : uint8_t {
  Channel0 = 0, Channel1 = 1, Channel2 = 2, Channel3 = 3,
  Channel4 = 4, Channel5 = 5, Channel6 = 6, Channel7 = 7,
  Channel8 = 8, Channel9 = 9, Channel10 = 10, Channel11 = 11,
  Channel12 = 12, Channel13 = 13, Channel14 = 14, Channel15 = 15,
  Channel16 = 16, Channel17 = 17, Channel18 = 18, Channel::BatDiv2 = 18,
  Channel::TemperatureSensor = 16, Channel::InternalReference = 17
}
 
enum  ExternalTriggerPolarity { NoTriggerDetection = 0x0u, RisingEdge = 0x1u, FallingEdge = 0x2u, RisingAndFallingEdge = 0x3u }
 
enum  Interrupt : uint32_t { Interrupt::AnalogWatchdog = ADC_CR1_AWDIE, Interrupt::EndOfRegularConversion = ADC_CR1_EOCIE, Interrupt::EndOfInjectedConversion = ADC_CR1_JEOCIE, Interrupt::Overrun = ADC_CR1_OVRIE }
 
enum  InterruptFlag : uint32_t {
  InterruptFlag::AnalogWatchdog = ADC_SR_AWD, InterruptFlag::EndOfRegularConversion = ADC_SR_EOC, InterruptFlag::EndOfInjectedConversion = ADC_SR_JEOC, InterruptFlag::Overrun = ADC_SR_OVR,
  InterruptFlag::All = ADC_SR_AWD | ADC_SR_EOC | ADC_SR_JEOC | ADC_SR_OVR
}
 
enum  RegularConversionExternalTrigger {
  Event0 = 0x0u, Event1 = 0x1u, Event2 = 0x2u, Event3 = 0x3u,
  Event4 = 0x4u, Event5 = 0x5u, Event6 = 0x6u, Event7 = 0x7u,
  Event8 = 0x8u, Event9 = 0x9u, Event10 = 0xAu, Event11 = 0xBu,
  Event12 = 0xCu, Event13 = 0xDu, Event14 = 0xEu, Event15 = 0xFu
}
 
enum  SampleTime : uint8_t {
  SampleTime::Cycles3 = 0b000, SampleTime::Cycles15 = 0b001, SampleTime::Cycles28 = 0b010, SampleTime::Cycles56 = 0b011,
  SampleTime::Cycles84 = 0b100, SampleTime::Cycles112 = 0b101, SampleTime::Cycles144 = 0b110, SampleTime::Cycles480 = 0b111
}
 

Public Member Functions

 MODM_FLAGS32 (Interrupt)
 
 MODM_FLAGS32 (InterruptFlag)
 

Static Public Member Functions

static void attachInterruptHandler (Handler handler)
 
static void acknowledgeInterruptFlag ()
 
static void acknowledgeInterruptFlags (const InterruptFlag_t flags)
 
static bool addChannel (const Channel channel, const SampleTime sampleTime=static_cast< SampleTime >(0b000))
 Add a channel to conversion group.
 
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 
template<double available, double requested, percent_t tolerance>
static void assertDurationInTolerance ()
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
template<class... Signals>
static void connect ()
 
static void disable ()
 
static void disableDmaMode ()
 
static void disableDmaRequests ()
 
static void disableFreeRunningMode ()
 
static void disableInterrupt (const Interrupt_t interrupt)
 
static void disableScanMode ()
 
static void disableTemperatureRefVMeasurement ()
 Switch on temperature- and V_REF measurement.
 
static void enable ()
 
static void enableDmaMode ()
 
static void enableDmaRequests ()
 
static void enableFreeRunningMode ()
 
static void enableInterrupt (const Interrupt_t interrupt)
 
static void enableInterruptVector (const uint32_t priority, const bool enable=true)
 
static void enableRegularConversionExternalTrigger (ExternalTriggerPolarity externalTriggerPolarity, RegularConversionExternalTrigger regularConversionExternalTrigger)
 
static void enableScanMode ()
 
static void enableTemperatureRefVMeasurement ()
 Switch on temperature- and V_REF measurement.
 
static bool getAdcEnabled ()
 
static Channel getChannel ()
 
static uintptr_t getDataRegisterAddress ()
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static InterruptFlag_t getInterruptFlags ()
 
static void getParameter ()
 returns a parameter
 
template<class Gpio >
static constexpr Channel getPinChannel ()
 Get the channel for a Pin.
 
static uint16_t getValue ()
 
template<class SystemClock , frequency_t frequency = MHz(10), percent_t tolerance = pct(10)>
static void initialize ()
 
static bool isConversionFinished ()
 
static uint16_t readChannel (Channel channel)
 
static bool setChannel (const Channel channel, const SampleTime sampleTime=static_cast< SampleTime >(0b000))
 
static bool setChannel (Channel channel)
 
static void setLeftAdjustResult ()
 
static void setParameter ()
 sets a parameter
 
template<class Gpio >
static bool setPinChannel (SampleTime sampleTime=static_cast< SampleTime >(0b000))
 Setting the channel for a Pin.
 
static void setRightAdjustResult ()
 
static void setSampleTime (const Channel channel, const SampleTime sampleTime=static_cast< SampleTime >(0b000))
 change sample time of ADC channel
 
static void startConversion ()
 
static void acknowledgeInterruptFlag ()
 
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 
template<double available, double requested, percent_t tolerance>
static void assertDurationInTolerance ()
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static void getParameter ()
 returns a parameter
 
static bool setChannel (Channel channel)
 
static void setParameter ()
 sets a parameter
 

Static Public Attributes

static Handler handler
 
static constexpr uint8_t Resolution = 12
 

Protected Typedefs

typedef void (* Handler) ()
 

Detailed Description

ADC Interrupt module

This class allows you to attach functions to the ADC Conversion Complete Interrupt via function pointers. Be aware however, that this implementation is slower and requires more resources than writing the function code directly into the interrupt service routines.

See also
AnalogSensors uses this implemenation.
Author
Niklas Hauser

Member Enumeration Documentation

enum modm::platform::Adc1::Channel : uint8_t
inheritedstrong

Channels, which can be used with this ADC.

You can specify the channel by using a pin-name, like PIN_C0, an internal sensor, like TEMPERATURE_SENSOR or just the plain channel number, like CHANNEL_0.

Enum ValuesDocumentation
BatDiv2 

Half the V_BAT voltage.

TemperatureSensor 

Measure the ambient temperature of the device.

   @li Supported temperature range: -40 to 125 C
   @li Precision: +-1.5 C

   @see Reference manual (i.e. RM0090) for the formula for the
    calculation of the actual temperature.
   @note The TSVREFE bit must be set to enable the conversion of
    this internal channel.
InternalReference 

Internal reference voltage.

   @note The TSVREFE bit must be set to enable the conversion of
    this internal channel.
enum modm::platform::Adc1::Interrupt : uint32_t
inheritedstrong

Possible interrupts.

An interrupt can be produced on the end of conversion for regular and injected groups, when the analog watchdog status bit is set and when the overrun status bit is set.

Enum ValuesDocumentation
AnalogWatchdog 

Analog watchdog status bit is set.

EndOfRegularConversion 

End of conversion of a regular group.

EndOfInjectedConversion 

End of conversion of an injected group.

Overrun 

Overrun (if data are lost)

enum modm::platform::Adc1::InterruptFlag : uint32_t
inheritedstrong
Enum ValuesDocumentation
AnalogWatchdog 

Analog watchdog status bit is set.

EndOfRegularConversion 

End of conversion of a regular group.

EndOfInjectedConversion 

End of conversion of an injected group.

Overrun 

Overrun (if data are lost)

All 

All InterruptFlags.

Enum mapping all events on a external trigger converter. The source mapped to each event varies on controller family, refer to the ADC external trigger section on reference manual of your controller for more information

enum modm::platform::Adc1::SampleTime : uint8_t
inheritedstrong

Sampling time of the input voltage.

Total conversion time is T_con = Sampling time + 12 cycles

Enum ValuesDocumentation
Cycles3 

3 ADCCLK cycles

Cycles15 

15 ADCCLK cycles

Cycles28 

28 ADCCLK cycles

Cycles56 

56 ADCCLK cycles

Cycles84 

84 ADCCLK cycles

Cycles112 

112 ADCCLK cycles

Cycles144 

144 ADCCLK cycles

Cycles480 

480 ADCCLK cycles

Member Function Documentation

static void modm::PeripheralDriver::acknowledgeInterruptFlag ( )
inheritedstatic

Acknowledge an interrupt flag.

We use acknowledge here, since it describes the intention rather than the actual implementation.

static void modm::PeripheralDriver::acknowledgeInterruptFlag ( )
inheritedstatic

Acknowledge an interrupt flag.

We use acknowledge here, since it describes the intention rather than the actual implementation.

static void modm::platform::Adc1::acknowledgeInterruptFlags ( const InterruptFlag_t  flags)
inheritedinlinestatic

Clears the specified interrupt flag.

Parameters
flagThe interrupt flag, which shall be cleared.
Precondition
The ADC clock must be started and the ADC switched on with initialize().
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void modm::PeripheralDriver::assertBaudrateInTolerance ( )
inheritedinlinestatic

Since baudrates are usually generated by prescaling a system clock, only several distinct values can be generated. This method checks if the user requested baudrate is within error tolerance of the system achievable baudrate.

template<uint64_t available, uint64_t requested, percent_t tolerance>
static void modm::PeripheralDriver::assertBaudrateInTolerance ( )
inheritedinlinestatic

Since baudrates are usually generated by prescaling a system clock, only several distinct values can be generated. This method checks if the user requested baudrate is within error tolerance of the system achievable baudrate.

static void modm::platform::Adc1::disableDmaMode ( )
inheritedinlinestatic

Disable Dma mode for the ADC

static void modm::platform::Adc1::disableDmaRequests ( )
inheritedinlinestatic

disable dma selection for the ADC. If this is disabled no new DMA requests are issued after last transfer

static void modm::platform::Adc1::disableInterrupt ( const Interrupt_t  interrupt)
inheritedinlinestatic

Disables the ADC Conversion Complete Interrupt.

static void modm::platform::Adc1::disableScanMode ( )
inheritedinlinestatic

Disables scan mode

static void modm::platform::Adc1::enableDmaMode ( )
inheritedinlinestatic

Enable Dma mode for the ADC

static void modm::platform::Adc1::enableDmaRequests ( )
inheritedinlinestatic

enable DMA selection for the ADC. If this is enabled DMA requests are issued as long as data are converted and the adc has dma enabled

static void modm::platform::Adc1::enableInterrupt ( const Interrupt_t  interrupt)
inheritedinlinestatic

Enables the ADC Conversion Complete Interrupt.

You could catch the interrupt using this example function:

Precondition
The ADC clock must be started and the ADC switched on with initialize(). Also the Interrupt Vector needs to be enabled first.
Parameters
priorityPriority to set
interruptThe interrupt, which shall be enabled. See Interrupt for available interrupts.
Note
ADC1 and ADC2 interrupts are mapped onto the same interrupt vector. ADC3 interrupts are mapped onto a separate interrupt vector.
static void modm::platform::Adc1::enableScanMode ( )
inheritedinlinestatic

Enables scan mode

static bool modm::platform::Adc1::getAdcEnabled ( )
inheritedinlinestatic

get if adc is enabled

Returns
true if ADC_CR2_ADON bit is set, false otherwise
static InterruptFlag_t modm::platform::Adc1::getInterruptFlags ( )
inheritedinlinestatic

Returns if the th interrupt flags set.

Precondition
The ADC clock must be started and the ADC switched on with initialize()
template<class SystemClock , frequency_t frequency = MHz(10), percent_t tolerance = pct(10)>
static void modm::platform::Adc1::initialize ( )
inheritedstatic

Initialize and enable the A/D converter.

Enables the ADC clock and switches on the ADC. The ADC clock prescaler will be set as well.

The ADC clock must not exceed 36 MHz for Vdd > 2.4V, or 18MHz for Vdd < 2.4V.

static bool modm::Adc::setChannel ( Channel  channel)
inheritedstatic

Analog channel selection.

Returns
true if the channel exists and was available, false otherwise
static bool modm::Adc::setChannel ( Channel  channel)
inheritedstatic

Analog channel selection.

Returns
true if the channel exists and was available, false otherwise
static bool modm::platform::Adc1::setChannel ( const Channel  channel,
const SampleTime  sampleTime = static_cast< SampleTime >(0b000) 
)
inheritedinlinestatic

Analog channel selection.

This not for scan mode. The number of channels will be set to 1, the channel selected and the corresponding pin will be set to analog input. If the the channel is modified during a conversion, the current conversion is reset and a new start pulse is sent to the ADC to convert the new chosen channnel / group of channels.

Parameters
channelThe channel which shall be read.
sampleTimeThe sample time to sample the input voltage.
Precondition
The ADC clock must be started and the ADC switched on with initialize()
static void modm::platform::Adc1::startConversion ( )
inheritedinlinestatic

Start a new conversion or continuous conversions.

Precondition
A ADC channel must be selected with setChannel(). When using a STM32F10x a delay of at least t_STAB after initialize() must be waited!
Postcondition
The result can be fetched with getValue()
Attention
When using a STM32F10x, the application should allow a delay of t_STAB between power up and start of conversion. Refer to Reference Manual (RM0008) ADC_CR2_ADON.

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