Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::InternalADC Class Reference

Driver for stm32 internal ADC. More...

#include <InternalADC.h>

Inheritance diagram for Boardcore::InternalADC:
Collaboration diagram for Boardcore::InternalADC:

Public Types

enum  Channel : uint8_t {
  CH0 = 0 , CH1 , CH2 , CH3 ,
  CH4 , CH5 , CH6 , CH7 ,
  CH8 , CH9 , CH10 , CH11 ,
  CH12 , CH13 , CH14 , CH15 ,
  CH16 , CH17 , CH18 , CH_NUM
}
 ADC channels enumeration. More...
 
enum  SampleTime : uint8_t {
  CYCLES_15 = 0x1 , CYCLES_28 = 0x2 , CYCLES_56 = 0x3 , CYCLES_84 = 0x4 ,
  CYCLES_112 = 0x5 , CYCLES_144 = 0x6 , CYCLES_480 = 0x7
}
 Conversion sample time. See reference manual. More...
 
- Public Types inherited from Boardcore::Sensor< InternalADCData >
using DataType
 

Public Member Functions

 InternalADC (ADC_TypeDef *adc)
 Resets the ADC configuration and automatically enables the peripheral clock.
 
 ~InternalADC ()
 
bool init () override
 ADC Initialization.
 
bool selfTest () override
 Check if the sensor is working.
 
InternalADCData sampleImpl () override
 Read a data sample from the sensor. In case of errors, the method should return the last available correct sample.
 
void enableChannel (Channel channel, SampleTime sampleTime=CYCLES_480)
 
void disableChannel (Channel channel)
 
void enableTemperature (SampleTime sampleTime=CYCLES_480)
 
void disableTemperature ()
 
void enableVbat (SampleTime sampleTime=CYCLES_480)
 
void disableVbat ()
 
ADCData getVoltage (Channel channel)
 
TemperatureData getTemperature ()
 
ADCData getVbatVoltage ()
 
- Public Member Functions inherited from Boardcore::Sensor< InternalADCData >
 Sensor ()
 
 Sensor (Sensor &&other)
 
virtual ~Sensor ()
 
void sample () override
 Sample the sensor.
 
virtual InternalADCData getLastSample ()
 
- Public Member Functions inherited from Boardcore::AbstractSensor
virtual ~AbstractSensor ()
 
SensorErrors getLastError ()
 Get last error for debugging purposes. Avoid silent fails.
 

Additional Inherited Members

- Protected Attributes inherited from Boardcore::Sensor< InternalADCData >
DataType lastSample
 
miosix::FastMutex mutex
 
- Protected Attributes inherited from Boardcore::AbstractSensor
SensorErrors lastError = SensorErrors::NO_ERRORS
 

Detailed Description

Driver for stm32 internal ADC.

Allows conversions on multiple channels with per-channel sample time.

The driver uses basic ADC features, that is the single conversion mode. A previous version of the driver featured injected and regular channels with also DMA. Since ADC conversion time is very low, the driver has been simplified to provide better usability and simpler implementation.

Warning
This driver has been tested on f205, f407, f429, f767 and f769

Definition at line 50 of file InternalADC.h.

Member Enumeration Documentation

◆ Channel

ADC channels enumeration.

Enumerator
CH0 
CH1 
CH2 
CH3 
CH4 
CH5 
CH6 
CH7 
CH8 
CH9 
CH10 
CH11 
CH12 
CH13 
CH14 
CH15 
CH16 
CH17 
CH18 
CH_NUM 

Definition at line 56 of file InternalADC.h.

◆ SampleTime

Conversion sample time. See reference manual.

CYCLES_3 is not exposed because in 12-bit mode the minimum is 15

Enumerator
CYCLES_15 
CYCLES_28 
CYCLES_56 
CYCLES_84 
CYCLES_112 
CYCLES_144 
CYCLES_480 

Definition at line 85 of file InternalADC.h.

Constructor & Destructor Documentation

◆ InternalADC()

Boardcore::InternalADC::InternalADC ( ADC_TypeDef * adc)
explicit

Resets the ADC configuration and automatically enables the peripheral clock.

Definition at line 68 of file InternalADC.cpp.

◆ ~InternalADC()

Boardcore::InternalADC::~InternalADC ( )

Definition at line 90 of file InternalADC.cpp.

Member Function Documentation

◆ disableChannel()

void Boardcore::InternalADC::disableChannel ( Channel channel)

Definition at line 179 of file InternalADC.cpp.

◆ disableTemperature()

void Boardcore::InternalADC::disableTemperature ( )

Definition at line 190 of file InternalADC.cpp.

◆ disableVbat()

void Boardcore::InternalADC::disableVbat ( )

Definition at line 203 of file InternalADC.cpp.

◆ enableChannel()

void Boardcore::InternalADC::enableChannel ( Channel channel,
SampleTime sampleTime = CYCLES_480 )

Definition at line 172 of file InternalADC.cpp.

◆ enableTemperature()

void Boardcore::InternalADC::enableTemperature ( SampleTime sampleTime = CYCLES_480)

Definition at line 184 of file InternalADC.cpp.

◆ enableVbat()

void Boardcore::InternalADC::enableVbat ( SampleTime sampleTime = CYCLES_480)

Definition at line 197 of file InternalADC.cpp.

◆ getTemperature()

TemperatureData Boardcore::InternalADC::getTemperature ( )

Definition at line 219 of file InternalADC.cpp.

◆ getVbatVoltage()

ADCData Boardcore::InternalADC::getVbatVoltage ( )

Definition at line 227 of file InternalADC.cpp.

◆ getVoltage()

ADCData Boardcore::InternalADC::getVoltage ( Channel channel)

Definition at line 210 of file InternalADC.cpp.

◆ init()

bool Boardcore::InternalADC::init ( )
overridevirtual

ADC Initialization.

The ADC clock must be set beforehand as well as GPIO configuration. Also the clock for the analog circuitry should be set accordingly to the device datasheet.

Implements Boardcore::AbstractSensor.

Definition at line 96 of file InternalADC.cpp.

◆ sampleImpl()

InternalADCData Boardcore::InternalADC::sampleImpl ( )
overridevirtual

Read a data sample from the sensor. In case of errors, the method should return the last available correct sample.

Returns
sensor data sample

Quirk: the temperature and vbat sensors are enabled and then disabled. If left enabled they somehow disrupt other channels measurements. I did not find description of this behaviour anywhere but observed it during testing. Also the temperature sensors has a startup time of 10us. 12us is used because during test 10us were not enough. The startup time is the same for all Boardcore supported micros.

Implements Boardcore::Sensor< InternalADCData >.

Definition at line 106 of file InternalADC.cpp.

◆ selfTest()

bool Boardcore::InternalADC::selfTest ( )
overridevirtual

Check if the sensor is working.

Returns
boolean indicating whether the sensor is correctly working or not

Implements Boardcore::AbstractSensor.

Definition at line 104 of file InternalADC.cpp.


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