Driver to perform analogue measurements.
File(s):
The driver must be configured by supplying a project specific "px_adc_cfg.h". "px_adc_cfg_template.h" can be copied, renamed and modified to supply compile time options.
- Example:
#include "px_adc.h"
#include "px_board.h"
int main(void)
{
uint16_t data;
}
void px_board_init(void)
Initialise the board hardware.
void px_adc_init(void)
Initialise ADC driver.
bool px_adc_close(px_adc_handle_t *handle)
Close specified device.
bool px_adc_open(px_adc_handle_t *handle, px_adc_nr_t adc_nr)
Open ADC peripheral using predefined (default) parameters.
uint16_t px_adc_sample(px_adc_handle_t *handle, px_adc_ch_t ch)
Perform a single measurement on the specified ADC channel.
@ PX_ADC_CH0
ADC Channel 0.
|
| enum | px_adc_nr_t |
| | Specify ADC peripheral. More...
|
| |
| enum | px_adc_ch_t {
PX_ADC_CH0 = 0
, PX_ADC_CH1 = 1
, PX_ADC_CH2 = 2
, PX_ADC_CH3 = 3
,
PX_ADC_CH4 = 4
, PX_ADC_CH5 = 5
, PX_ADC_CH6 = 6
, PX_ADC_CH7 = 7
,
PX_ADC_CH8 = 8
, PX_ADC_CH9 = 9
, PX_ADC_CH10 = 10
, PX_ADC_CH11 = 11
,
PX_ADC_CH12 = 12
, PX_ADC_CH13 = 13
, PX_ADC_CH14 = 14
, PX_ADC_CH15 = 15
,
PX_ADC_CH16 = 16
, PX_ADC_CH17 = 17
, PX_ADC_CH18 = 18
} |
| | Specify ADC channel. More...
|
| |
| enum | px_adc_cfg_clk_t { PX_ADC_CFG_CLK_PCLK = 0
, PX_ADC_CFG_CLK_PCLK_DIV2 = 1
, PX_ADC_CFG_CLK_PCLK_DIV4 = 2
} |
| | Specify ADC peripheral clock source. More...
|
| |
| enum | px_adc_cfg_sample_time_t {
PX_ADC_CFG_SAMPLE_TIME_1_5 = 0
, PX_ADC_CFG_SAMPLE_TIME_3_5 = 1
, PX_ADC_CFG_SAMPLE_TIME_7_5 = 2
, PX_ADC_CFG_SAMPLE_TIME_12_5 = 3
,
PX_ADC_CFG_SAMPLE_TIME_19_5 = 4
, PX_ADC_CFG_SAMPLE_TIME_39_5 = 5
, PX_ADC_CFG_SAMPLE_TIME_79_5 = 6
, PX_ADC_CFG_SAMPLE_TIME_160_5 = 7
} |
| | Specify ADC sampling time. More...
|
| |
| enum | px_adc_cfg_res_t { PX_ADC_CFG_RES_12_BITS = 0
, PX_ADC_CFG_RES_10_BITS = 1
, PX_ADC_CFG_RES_8_BITS = 2
, PX_ADC_CFG_RES_6_BITS = 3
} |
| | Specify ADC resolution. More...
|
| |
| enum | px_adc_cfg_oversampling_t {
PX_ADC_CFG_OVERSAMPLING_NONE = 0
, PX_ADC_CFG_OVERSAMPLING_2 = 1
, PX_ADC_CFG_OVERSAMPLING_4 = 2
, PX_ADC_CFG_OVERSAMPLING_8 = 3
,
PX_ADC_CFG_OVERSAMPLING_16 = 4
, PX_ADC_CFG_OVERSAMPLING_32 = 5
, PX_ADC_CFG_OVERSAMPLING_64 = 6
, PX_ADC_CFG_OVERSAMPLING_128 = 7
,
PX_ADC_CFG_OVERSAMPLING_256 = 8
} |
| | Specify ADC oversampling. More...
|
| |
| enum | px_adc_cfg_oversampling_shift_t {
PX_ADC_CFG_OVERSAMPLING_SHIFT_NONE = 0
, PX_ADC_CFG_OVERSAMPLING_SHIFT_1 = 1
, PX_ADC_CFG_OVERSAMPLING_SHIFT_2 = 2
, PX_ADC_CFG_OVERSAMPLING_SHIFT_3 = 3
,
PX_ADC_CFG_OVERSAMPLING_SHIFT_4 = 4
, PX_ADC_CFG_OVERSAMPLING_SHIFT_5 = 5
, PX_ADC_CFG_OVERSAMPLING_SHIFT_6 = 6
, PX_ADC_CFG_OVERSAMPLING_SHIFT_7 = 7
,
PX_ADC_CFG_OVERSAMPLING_SHIFT_8 = 8
} |
| | Specify ADC oversampling. More...
|
| |
◆ px_adc_handle_t
Define ADC handle.
Definition at line 162 of file px_adc.h.
| Data Fields |
|
struct px_adc_per_s * |
adc_per |
ADC peripheral data. |
◆ PX_ADC_CFG_PER_COUNT
Number of enabled peripherals.
Definition at line 64 of file px_adc.h.
◆ PX_ADC_CH_TO_BITMASK
| #define PX_ADC_CH_TO_BITMASK |
( |
|
ch | ) |
((uint32_t)1 << (ch)) |
Convert ADC channel number into bit mask.
Definition at line 212 of file px_adc.h.
◆ PX_ADC_CFG_ADC1_EN
| #define PX_ADC_CFG_ADC1_EN 1 |
◆ PX_ADC_CFG_CLK
◆ PX_ADC_CFG_SAMPLE_TIME
◆ PX_ADC_CFG_RES
◆ PX_ADC_CFG_OVERSAMPLING
◆ PX_ADC_CFG_OVERSAMPLING_SHIFT
Specify ADC oversampling (see 'px_adc_cfg_oversampling_shift_t')
Definition at line 49 of file px_adc_cfg_template.h.
◆ px_adc_nr_t
Specify ADC peripheral.
Definition at line 74 of file px_adc.h.
◆ px_adc_ch_t
Specify ADC channel.
| Enumerator |
|---|
| PX_ADC_CH0 | ADC Channel 0.
|
| PX_ADC_CH1 | ADC Channel 1.
|
| PX_ADC_CH2 | ADC Channel 2.
|
| PX_ADC_CH3 | ADC Channel 3.
|
| PX_ADC_CH4 | ADC Channel 4.
|
| PX_ADC_CH5 | ADC Channel 5.
|
| PX_ADC_CH6 | ADC Channel 6.
|
| PX_ADC_CH7 | ADC Channel 7.
|
| PX_ADC_CH8 | ADC Channel 8.
|
| PX_ADC_CH9 | ADC Channel 9.
|
| PX_ADC_CH10 | ADC Channel 10.
|
| PX_ADC_CH11 | ADC Channel 11.
|
| PX_ADC_CH12 | ADC Channel 12.
|
| PX_ADC_CH13 | ADC Channel 13.
|
| PX_ADC_CH14 | ADC Channel 14.
|
| PX_ADC_CH15 | ADC Channel 15.
|
| PX_ADC_CH17 | Internal Voltage Reference (Vrefint)
|
| PX_ADC_CH18 | Temperature sensor (Tsense)
|
Definition at line 80 of file px_adc.h.
◆ px_adc_cfg_clk_t
Specify ADC peripheral clock source.
| Enumerator |
|---|
| PX_ADC_CFG_CLK_PCLK | Peripheral Clock.
|
| PX_ADC_CFG_CLK_PCLK_DIV2 | Peripheral Clock / 2.
|
| PX_ADC_CFG_CLK_PCLK_DIV4 | Peripheral Clock / 4.
|
Definition at line 104 of file px_adc.h.
◆ px_adc_cfg_sample_time_t
Specify ADC sampling time.
| Enumerator |
|---|
| PX_ADC_CFG_SAMPLE_TIME_1_5 | 1.5 ADC clock cycles
|
| PX_ADC_CFG_SAMPLE_TIME_3_5 | 3.5 ADC clock cycles
|
| PX_ADC_CFG_SAMPLE_TIME_7_5 | 7.5 ADC clock cycles
|
| PX_ADC_CFG_SAMPLE_TIME_12_5 | 12.5 ADC clock cycles
|
| PX_ADC_CFG_SAMPLE_TIME_19_5 | 19.5 ADC clock cycles
|
| PX_ADC_CFG_SAMPLE_TIME_39_5 | 39.5 ADC clock cycles
|
| PX_ADC_CFG_SAMPLE_TIME_79_5 | 79.5 ADC clock cycles
|
| PX_ADC_CFG_SAMPLE_TIME_160_5 | 160.5 ADC clock cycles
|
Definition at line 112 of file px_adc.h.
◆ px_adc_cfg_res_t
Specify ADC resolution.
| Enumerator |
|---|
| PX_ADC_CFG_RES_12_BITS | 12-bit resolution
|
| PX_ADC_CFG_RES_10_BITS | 10-bit resolution
|
| PX_ADC_CFG_RES_8_BITS | 8-bit resolution
|
| PX_ADC_CFG_RES_6_BITS | 6-bit resolution
|
Definition at line 125 of file px_adc.h.
◆ px_adc_cfg_oversampling_t
Specify ADC oversampling.
| Enumerator |
|---|
| PX_ADC_CFG_OVERSAMPLING_NONE | No oversampling.
|
| PX_ADC_CFG_OVERSAMPLING_2 | 2 x oversampling
|
| PX_ADC_CFG_OVERSAMPLING_4 | 4 x oversampling
|
| PX_ADC_CFG_OVERSAMPLING_8 | 8 x oversampling
|
| PX_ADC_CFG_OVERSAMPLING_16 | 16 x oversampling
|
| PX_ADC_CFG_OVERSAMPLING_32 | 32 x oversampling
|
| PX_ADC_CFG_OVERSAMPLING_64 | 64 x oversampling
|
| PX_ADC_CFG_OVERSAMPLING_128 | 128 x oversampling
|
| PX_ADC_CFG_OVERSAMPLING_256 | 256 x oversampling
|
Definition at line 134 of file px_adc.h.
◆ px_adc_cfg_oversampling_shift_t
Specify ADC oversampling.
| Enumerator |
|---|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_NONE | No shift.
|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_1 | Shift 1-bit.
|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_2 | Shift 2-bits.
|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_3 | Shift 3-bits.
|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_4 | Shift 4-bits.
|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_5 | Shift 5-bits.
|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_6 | Shift 6-bits.
|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_7 | Shift 7-bits.
|
| PX_ADC_CFG_OVERSAMPLING_SHIFT_8 | Shift 8-bits.
|
Definition at line 148 of file px_adc.h.
◆ px_adc_init()
| void px_adc_init |
( |
void |
| ) |
|
Initialise ADC driver.
Definition at line 128 of file px_adc.c.
◆ px_adc_open()
Open ADC peripheral using predefined (default) parameters.
- Parameters
-
| handle | Pointer to handle data structure |
| adc_nr | ADC peripheral number |
- Return values
-
| false | Error: peripheral was not opened |
| true | Success: peripheral was opened |
Definition at line 136 of file px_adc.c.
◆ px_adc_close()
Close specified device.
- Parameters
-
| handle | Pointer to handle data structure |
- Return values
-
| true | Success |
| false | Specified device was already closed (or not opened) |
Definition at line 181 of file px_adc.c.
◆ px_adc_sample()
Perform a single measurement on the specified ADC channel.
- Parameters
-
| handle | Pointer to handle data structure |
| ch | Specified ADC channel |
- Returns
- uint16_t Raw ADC value
Definition at line 235 of file px_adc.c.