Skyward boardcore
|
Driver for stm32 internal ADC. More...
#include <InternalADC.h>
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... | |
![]() | |
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 () |
![]() | |
Sensor () | |
Sensor (Sensor &&other) | |
virtual | ~Sensor () |
void | sample () override |
Sample the sensor. | |
virtual InternalADCData | getLastSample () |
![]() | |
virtual | ~AbstractSensor () |
SensorErrors | getLastError () |
Get last error for debugging purposes. Avoid silent fails. | |
Additional Inherited Members | |
![]() | |
DataType | lastSample |
miosix::FastMutex | mutex |
![]() | |
SensorErrors | lastError = SensorErrors::NO_ERRORS |
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.
Definition at line 50 of file InternalADC.h.
enum Boardcore::InternalADC::Channel : uint8_t |
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.
enum Boardcore::InternalADC::SampleTime : uint8_t |
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.
|
explicit |
Resets the ADC configuration and automatically enables the peripheral clock.
Definition at line 68 of file InternalADC.cpp.
Boardcore::InternalADC::~InternalADC | ( | ) |
Definition at line 90 of file InternalADC.cpp.
void Boardcore::InternalADC::disableChannel | ( | Channel | channel | ) |
Definition at line 179 of file InternalADC.cpp.
void Boardcore::InternalADC::disableTemperature | ( | ) |
Definition at line 190 of file InternalADC.cpp.
void Boardcore::InternalADC::disableVbat | ( | ) |
Definition at line 203 of file InternalADC.cpp.
void Boardcore::InternalADC::enableChannel | ( | Channel | channel, |
SampleTime | sampleTime = CYCLES_480 ) |
Definition at line 172 of file InternalADC.cpp.
void Boardcore::InternalADC::enableTemperature | ( | SampleTime | sampleTime = CYCLES_480 | ) |
Definition at line 184 of file InternalADC.cpp.
void Boardcore::InternalADC::enableVbat | ( | SampleTime | sampleTime = CYCLES_480 | ) |
Definition at line 197 of file InternalADC.cpp.
TemperatureData Boardcore::InternalADC::getTemperature | ( | ) |
Definition at line 219 of file InternalADC.cpp.
ADCData Boardcore::InternalADC::getVbatVoltage | ( | ) |
Definition at line 227 of file InternalADC.cpp.
Definition at line 210 of file InternalADC.cpp.
|
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.
|
overridevirtual |
Read a data sample from the sensor. In case of errors, the method should return the last available correct 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.
|
overridevirtual |
Check if the sensor is working.
Implements Boardcore::AbstractSensor.
Definition at line 104 of file InternalADC.cpp.