Internal Analog-to-digital converter control.
More...
Internal Analog-to-digital converter control.
◆ rt_adc_mode_t
Enumerator |
---|
RATIOMETRIC | ADC compares value to VDD.
|
ABSOLUTE | ADC measures absolute voltage in volts.
|
Definition at line 59 of file ruuvi_task_adc.h.
◆ rt_adc_absolute_sample()
Get absolute Voltage Sample from selected ADC handle.
This function initializes ADC, reads absolute voltage sample from selected handle. The parameter sample is absolute voltage relative to the device ground.
- Parameters
-
[in] | configuration | Configuration of ADC. |
[in] | handle | Handle to ADC, i.e. ADC pin. |
[in] | sample | Pointer to a Voltage Sample. |
- Return values
-
RD_SUCCESS | on success |
error | code from stack on error. |
◆ rt_adc_configure_se()
Configure ADC before sampling.
This function readies the ADC for sampling. Configuring the ADC may take some time (< 1 ms) while actual sample must be as fast as possible to catch transients.
Note: ADC should be configured to sleep or continuous mode. To take a single sample, call rt_adc_sample after configuration. Configuring ADC into single sample mode is equivalent to calling rt_adc_sample and configuring ADC into sleep immediately.
- Parameters
-
[in,out] | config | Configuration of ADC. |
[in] | handle | Handle to ADC, i.e. ADC pin. |
[in] | mode | sampling mode, rt_adc_mode_t. |
- Return values
-
RD_SUCCESS | on success. |
RD_ERROR_INVALID_STATE | if ADC is not initialized or if it is already configured. |
◆ rt_adc_init()
Reserve ADC.
- Return values
-
RD_SUCCESS | on success. |
RD_ERROR_INVALID_STATE | if ADC is already initialized. |
◆ rt_adc_is_init()
bool rt_adc_is_init |
( |
void |
| ) |
|
Check if ADC is initialized.
- Return values
-
true | if ADC is initialized. |
false | if ADC is not initialized. |
◆ rt_adc_ratio_get()
Populate data with latest ratiometric value.
The data is ratio between 0.0 (gnd) and 1.0 (VDD). However the implementation is allowed to return negative values and values higher than 1.0 if the real voltage is beyond the supply rails or if differential sample is negative.
- Parameters
-
[in] | data | Data which has a field for ratiometric ADC value |
- Return values
-
RD_SUCCESS | on success |
RD_ERROR_INVALID_STATE | if ADC is not initialized or configured. |
error | code from stack on error. |
◆ rt_adc_ratiometric_sample()
Get ratiometric VDD Sample from selected ADC handle.
This function initializes ADC, reads ratiometric voltage sample from selected handle. The parameter sample is a ration of voltage pin, relative to VDD, varying between 0.0 (GND) and 1.0 (VDD). Additionally the parameter sample could be outside limits as described in rt_adc_ratio_get.
- Parameters
-
[in] | configuration | Configuration of ADC. |
[in] | handle | Handle to ADC, i.e. ADC pin. |
[in] | sample | Pointer to a Voltage Sample. |
- Return values
-
RD_SUCCESS | on success |
error | code from stack on error. |
◆ rt_adc_sample()
Take a new sample on ADC configured in single-shot/sleep mode.
If this function returns RD_SUCCESS new sample can be immediately read with rt_adc_voltage_get or rt_adc_ratio_get
- Return values
-
RD_SUCCESS | Sampling was successful |
RD_ERROR_INVALID_STATE | ADC is not initialized or configured |
◆ rt_adc_uninit()
Uninitialize ADC to release it for other users.
- Return values
-
RD_SUCCESS | on success. |
RD_ERROR_FATAL | if ADC lock can't be released. Reboot. |
◆ rt_adc_vdd_get()
Get VDD.
This function should be called any time after rt_adc_vdd_sample. The value returned will remain fixed until next call to rt_adc_vdd_sample.
- Parameters
-
[out] | vdd | VDD voltage in volts. |
- Return values
-
RD_SUCCESS | on success |
RD_ERROR_INVALID_STATE | if rt_adc_vdd_sample wasn't called. |
◆ rt_adc_vdd_prepare()
Prepare for sampling VDD.
This function should be called before entering energy intensive activity, such as using radio to transmit data. After calling this function ADC is primed for measuring the voltage droop of battery. On ADC configuration error, uninitialize ADC.
- Return values
-
RD_SUCCESS | on success |
RD_ERROR_INVALID_STATE | if ADC is already initialized. |
◆ rt_adc_vdd_sample()
Sample VDD.
This function should be called as soon as possible after energy intensive activity. After a successful call value returned by rt_adc_vdd_get is updated and ADC is released.
- Return values
-
RD_SUCCESS | on success |
RD_ERROR_INVALID_STATE | if rt_adc_vdd_prepare wasn't called. |
◆ rt_adc_voltage_get()
Populate data with latest sample.
The data is absolute voltage relative to device ground.
- Parameters
-
[in] | data | Data which has a field for absolute ADC value |
- Return values
-
RD_SUCCESS | on success |
RD_ERROR_INVALID_STATE | if ADC is not initialized or configured. |
error | code from stack on error. |